Skip to content

Commit 5d10ae1

Browse files
author
peter
committed
translate to Chinese
modified: README.md new file: README_zh-CN.md
1 parent 3213dfa commit 5d10ae1

File tree

13 files changed

+1488
-32237
lines changed

13 files changed

+1488
-32237
lines changed

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
[![License: MIT](https://img.shields.io/badge/license-MIT-blue)](https://opensource.org/licenses/MIT)
44
[![Build Status]( https://github.com/cpq/bare-metal-programming-guide/workflows/build/badge.svg)](https://github.com/cpq/bare-metal-programming-guide/actions)
55

6+
[English](README.md) | [中文](README_zh-CN.md)
7+
68
This guide is written for developers who wish to start programming
79
microcontrollers using GCC compiler and a datasheet - nothing else! The
810
fundamentals explained in this guide, will help you understand better how
@@ -156,6 +158,8 @@ from A0 to A15, to input mode:
156158
* (volatile uint32_t *) (0x40020000 + 0) = 0; // Set A0-A15 to input mode
157159
```
158160

161+
> Note the `volatile` specifier. Its meaning will be covered later.
162+
159163
By setting individual bits, we can selectively set specific pins to a desired
160164
mode. For example, this snippet sets pin A3 to output mode:
161165

@@ -576,6 +580,11 @@ uses a configuration file named `Makefile` where it reads instructions
576580
how to execute actions. This automation is great because it also documents the
577581
process of building firmware, used compilation flags, etc.
578582

583+
There is a great Makefile tutorial at https://makefiletutorial.com - for those
584+
new to `make`, I suggest to take a look. Below, I list the most essential
585+
concepts required to understand our simple bare metal Makefile. Those who
586+
already familiar with `make`, can skip this section.
587+
579588
The `Makefile` format is simple:
580589

581590
```make
@@ -856,13 +865,24 @@ every millisecond. We should have interrupt handler function defined - here
856865
it is, we simply increment a 32-bit millisecond counter:
857866
858867
```c
859-
static volatile uint32_t s_ticks;
868+
static volatile uint32_t s_ticks; // volatile is important!!
860869
void SysTick_Handler(void) {
861870
s_ticks++;
862871
}
863872
```
864873
865-
And we should add this handler to the vector table:
874+
> The `volatile` specifier is required here becase `s_ticks` is modified by the
875+
> interrupt handler. `volatile` prevents the compiler to optimise/cache
876+
> `s_ticks` value in a CPU register: instead, generated code always accesses
877+
> memory. That is why `volatile` keywords is present in the peripheral struct
878+
> definitions, too.
879+
880+
Note the `volatile` specifier for `s_ticks`. Any variable that is changed
881+
by the IRQ handler, must be marked as `volatile`, in order to prevent the
882+
compiler to optimize the operation by caching its value in a register.
883+
The `volatile` keyword makes generated code always load it from memory.
884+
885+
Now we should add this handler to the vector table:
866886
867887
```c
868888
__attribute__((section(".vectors"))) void (*tab[16 + 91])(void) = {

README_zh-CN.md

Lines changed: 1311 additions & 0 deletions
Large diffs are not rendered by default.

images/moder.png

-13.2 KB
Loading

step-7-webserver/pico-w/Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ SOURCES = main.c startup.c syscalls.c
77

88
ifeq ($(OS),Windows_NT)
99
RM = cmd /C del /Q /F
10+
BIN2UF2 = bin2uf2.exe
1011
else
12+
BIN2UF2 = ./bin2uf2
1113
RM = rm -f
1214
endif
1315

@@ -19,11 +21,10 @@ firmware.elf: $(SOURCES) mcu.h
1921
firmware.bin: firmware.elf
2022
arm-none-eabi-objcopy -O binary $< $@
2123

22-
firmware.uf2: firmware.bin bin2uf2
23-
./bin2uf2 $< $@
24-
# bin2uf2 -i $< -o $@
24+
firmware.uf2: firmware.bin $(BIN2UF2)
25+
$(BIN2UF2) $< $@
2526

26-
bin2uf2: tools/bin2uf2.c
27+
$(BIN2UF2): tools/bin2uf2.c
2728
$(CC) -W -Wall $< -o $@
2829

2930
clean:

step-7-webserver/pico-w/include/cmsis_compiler.h

Lines changed: 0 additions & 283 deletions
This file was deleted.

0 commit comments

Comments
 (0)