@@ -1323,6 +1323,7 @@ There are two sets of CMSIS headers:
13231323 https://github.com/STMicroelectronics/cmsis_device_f4
13241324
13251325We can pull those headers by a simple Makefile snippet:
1326+ https://github.com/cpq/bare-metal-programming-guide/blob/785aa2ead0432fc67327781c82b9c41149fba158/step-5-cmsis/Makefile#L27-L31
13261327
13271328The ST CMSIS package also provides startup files for all their MCUs. We
13281329can use those instead of hand-writing the startup.c. The ST-provided startup
@@ -1331,33 +1332,7 @@ file calls `SystemInit()` function, so we define it in the `main.c`.
13311332Now, let' s replace our API functions in the ` mcu.h` using CMSIS definitions,
13321333and leave the rest of the firmware intact. From the ` mcu.h` , remove all
13331334peripheral API and definitions, and leave only standard C inludes, vendor CMSIS
1334- include, defines to PIN, BIT, FREQ, and `timer_expired ()` helper function:
1335-
1336- ` ` ` c
1337- # pragma once
1338-
1339- # include <inttypes.h>
1340- # include <stdbool.h>
1341- # include <stdlib.h>
1342- # include <stdio.h>
1343- # include <sys/stat.h>
1344-
1345- # include "stm32f429xx.h"
1346-
1347- # define FREQ 16000000 // CPU frequency, 16 Mhz
1348- # define BIT(x) (1UL << (x))
1349- # define PIN(bank, num) ((((bank) - 'A') << 8) | (num))
1350- # define PINNO(pin) (pin & 255)
1351- # define PINBANK(pin) (pin >> 8)
1352-
1353- static inline void spin(volatile uint32_t count) {
1354- while (count--) (void) 0;
1355- }
1356-
1357- static inline bool timer_expired(uint32_t * t, uint32_t prd, uint32_t now) {
1358- ...
1359- }
1360- ` ` `
1335+ include, defines to PIN, BIT, FREQ, and `timer_expired ()` helper function.
13611336
13621337If we try to rebuild the firmware - ` make clean build` , then GCC will fail
13631338complaining about missing ` systick_init()` , ` GPIO_MODE_OUTPUT` , ` uart_init()` ,
@@ -1368,7 +1343,7 @@ Let's start from `systick_init()`. ARM core CMSIS headers provide a
13681343
13691344Next goes `gpio_set_mode()` function. The `stm32f429xx.h` header has
13701345`GPIO_TypeDef` structure, identical to our `struct gpio`. Let' s use it:
1371- https://github.com/cpq/bare-metal-programming-guide/blob/2a61ea23e44c4531b66f6508238cfc43ca7c2634 /step-5-cmsis/mcu.h#L32-L41
1346+ https://github.com/cpq/bare-metal-programming-guide/blob/785aa2ead0432fc67327781c82b9c41149fba158 /step-5-cmsis/mcu.h#L24-L33
13721347
13731348The ` gpio_set_af()` and ` gpio_write()` functions is also trivial -
13741349simply replace ` struct gpio` with ` GPIO_TypeDef` , and that' s all.
@@ -1390,7 +1365,10 @@ shows the output. Congratulations, we have adopted our firmware code to
13901365use vendor CMSIS header files. Now let' s reorganise the repository a bit
13911366by moving all standard files into `include` directory and updating Makefile
13921367to let GCC know about it:
1393- https://github.com/cpq/bare-metal-programming-guide/blob/2a61ea23e44c4531b66f6508238cfc43ca7c2634/step-5-cmsis/Makefile#L3
1368+ https://github.com/cpq/bare-metal-programming-guide/blob/785aa2ead0432fc67327781c82b9c41149fba158/step-5-cmsis/Makefile#L4
1369+
1370+ Also, let' s include CMSIS header pulling as a dependency for the binary:
1371+ https://github.com/cpq/bare-metal-programming-guide/blob/785aa2ead0432fc67327781c82b9c41149fba158/step-5-cmsis/Makefile#L18
13941372
13951373We have left with a project template that can be reused for the future
13961374projects. A complete project source code you can find in
0 commit comments