|
STM32 RTOS 0.2.3
Bare-metal preemptive RTOS for STM32F446RE
|
How the code is organised, how the chip boots, and how it is clocked. The reasons behind the conventions are in Design notes.
Each layer includes headers only from itself and the layers below it. Dashed layers are planned and do not exist yet.
flowchart TD
app["app/<br/>application"]
api["Peripheral API<br/>LED, debug print"]
rapi["RTOS API<br/>tasks, semaphores, queues"]
board["board/nucleo-f446re/<br/>board support"]
kernel["kernel/<br/>scheduler, context switch"]
drivers["drivers/<br/>GPIO, RCC, Flash, PWR, UART, NVIC, SysTick, Fault, EXTI, IWDG, WWDG"]
regs["arch/cortex-m4/ + soc/stm32f446/<br/>registers, startup, linker script"]
app --> api
app --> rapi
api --> board
rapi --> kernel
board --> drivers
kernel --> drivers
drivers --> regs
classDef todo stroke-dasharray: 5 5
class api,rapi,kernel todo
Every inc/ directory is on the include path, so the build does not enforce the rule; review does.
flowchart LR
reset["Reset"] --> vt["Core loads SP and PC<br/>from the vector table"]
vt --> fpu["Reset_Handler:<br/>enable FPU (CPACR CP10/CP11)"]
fpu --> prio["Set PRIGROUP = 3<br/>(4 preemption bits)"]
prio --> data["Copy .data from flash"]
data --> bss["Zero .bss"]
bss --> main["main()"]
main -. returns .-> trap["Spin in MainReturned"]
bspClockInit() produces this configuration (constants in board/nucleo-f446re/inc/bsp.h):
flowchart LR
hse["HSE 8 MHz<br/>ST-LINK MCO, bypass"] --> m["/M = 8<br/>1 MHz"]
m --> n["xN = 360<br/>VCO 360 MHz"]
n --> p["/P = 2"]
p --> sys["SYSCLK 180 MHz"]
sys --> ahb["AHB /1<br/>HCLK 180 MHz<br/>core, SysTick, GPIO"]
ahb --> apb1["APB1 /4<br/>45 MHz<br/>USART2, PWR"]
ahb --> apb2["APB2 /2<br/>90 MHz<br/>SYSCFG"]
This needs regulator scale 1 with over-drive and 5 flash wait states. See Clock bring-up order for the order RM0390 imposes.
Defined in soc/stm32f446/STM32F446RE.ld.
| Region | Base | Size | Contents |
|---|---|---|---|
| FLASH | 0x08000000 | 512 KB | .isr_vector first, then code and data |
| RAM | 0x20000000 | 128 KB | .data, .bss, heap and stack reserve |
| Function | Pin | Peripheral |
|---|---|---|
| User LED (LD2) | PA5 | GPIOA |
| User button (B1) | PC13 | GPIOC |
| ST-LINK VCP | PA2 (TX), PA3 (RX) | USART2 |
| HSE input | MCO from ST-LINK | 8 MHz |