@@ -1117,17 +1117,17 @@ mechanism. We use newlib, so let's modify `_write()` syscall to print to the
11171117UART3.
11181118
11191119Before that, let' s organise our source code in the following way:
1120- - move all API definitions to the file ` mcu .h`
1120+ - move all API definitions to the file ` hal .h` (Harware Abstraction Layer)
11211121- move startup code to ` startup.c`
11221122- create an empty file ` syscalls.c` for newlib " syscalls"
11231123- modify Makefile to add ` syscalls.c` and ` startup.c` to the build
11241124
1125- After moving all API definitions to the ` mcu .h` , our ` main.c` file becomes
1125+ After moving all API definitions to the ` hal .h` , our ` main.c` file becomes
11261126quite compact. Note that it does not have any mention of the low-level
11271127registers, just a high level API functions that are easy to understand:
11281128
11291129` ` ` c
1130- # include "mcu .h"
1130+ # include "hal .h"
11311131
11321132static volatile uint32_t s_ticks;
11331133void SysTick_Handler(void) {
@@ -1157,7 +1157,7 @@ Great, now let's retarget printf to the UART3. In the empty syscalls.c,
11571157copy/paste the following code:
11581158
11591159```c
1160- #include "mcu .h"
1160+ #include "hal .h"
11611161
11621162int _write(int fd, char *ptr, int len) {
11631163 (void) fd, (void) ptr, (void) len;
@@ -1272,7 +1272,7 @@ Choose our firmware.elf file:
12721272< img src=" images/ozone3.png" width=" 50%" />
12731273
12741274Leave the defaults on the next screen, click Finish, and we' ve got our
1275- debugger loaded (note the mcu .h source code is picked up):
1275+ debugger loaded (note the hal .h source code is picked up):
12761276
12771277
12781278
@@ -1329,8 +1329,8 @@ The ST CMSIS package also provides startup files for all their MCUs. We
13291329can use those instead of hand-writing the startup.c. The ST-provided startup
13301330file calls `SystemInit()` function, so we define it in the `main.c`.
13311331
1332- Now, let' s replace our API functions in the ` mcu .h` using CMSIS definitions,
1333- and leave the rest of the firmware intact. From the ` mcu .h` , remove all
1332+ Now, let' s replace our API functions in the ` hal .h` using CMSIS definitions,
1333+ and leave the rest of the firmware intact. From the ` hal .h` , remove all
13341334peripheral API and definitions, and leave only standard C inludes, vendor CMSIS
13351335include, defines to PIN, BIT, FREQ, and `timer_expired ()` helper function.
13361336
@@ -1343,7 +1343,7 @@ Let's start from `systick_init()`. ARM core CMSIS headers provide a
13431343
13441344Next goes `gpio_set_mode()` function. The `stm32f429xx.h` header has
13451345`GPIO_TypeDef` structure, identical to our `struct gpio`. Let' s use it:
1346- https://github.com/cpq/bare-metal-programming-guide/blob/785aa2ead0432fc67327781c82b9c41149fba158/step-5-cmsis/mcu .h#L24-L33
1346+ https://github.com/cpq/bare-metal-programming-guide/blob/785aa2ead0432fc67327781c82b9c41149fba158/step-5-cmsis/hal .h#L24-L33
13471347
13481348The ` gpio_set_af()` and ` gpio_write()` functions is also trivial -
13491349simply replace ` struct gpio` with ` GPIO_TypeDef` , and that' s all.
0 commit comments