Skip to content

Commit 9394d64

Browse files
committed
[stm32f0] Implement initial support for stm32f0
1 parent fabe894 commit 9394d64

33 files changed

Lines changed: 2067 additions & 12 deletions

.claude/skills/port-stm32-platform/SKILL.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ typedef whal_<OrigPlatform><Type>_PinCfg whal_<NewPlatform><Type>_PinCfg;
140140

141141
That is the entire file. Examples in-tree: `src/gpio/stm32f4_gpio.c`, `src/gpio/stm32wba_gpio.c`, `src/i2c/stm32wba_i2c.c`, `src/uart/stm32wba_uart.c`, `src/watchdog/stm32wba_iwdg.c` — each is one line. The stub exists so the board's Makefile wildcard (`src/*/<newplatform>_*.c`) compiles the original implementation under the new-prefix filename. The original `.c` is NOT added to the Makefile separately; the `#include` pulls it into this translation unit exactly once.
142142

143+
**Test alias** — when a driver is reused via alias AND the original driver already has a platform-specific test file (`tests/<type>/test_<origplatform>_<type>.c`), create a matching test alias at `tests/<type>/test_<newplatform>_<type>.c`:
144+
145+
```c
146+
#include "test_<origplatform>_<type>.c"
147+
```
148+
149+
This is the same one-line pattern as the driver stub. The build system auto-discovers `test_$(PLATFORM)_$(t).c` files and defines `WHAL_TEST_ENABLE_<TYPE>_PLATFORM`, which gates the `whal_Test_<Type>_Platform()` call in `tests/main.c`. Examples in-tree: `tests/gpio/test_stm32c0_gpio.c`, `tests/gpio/test_stm32f0_gpio.c`.
150+
143151
### Common driver pitfalls (from prior ports)
144152
- **Flash**: check if already unlocked before writing keys — double-unlock hard-faults. Bit positions (LOCK, STRT, PNB) differ between families; do not copy-paste.
145153
- **RNG**: CONDRST + per-config register sequence goes in Init, not per Generate call. Select RNG clock source via `RCC_CCIPR`/`CCIPR2` before Init — default is often LSE, which requires LSE running.
@@ -158,6 +166,9 @@ Exports `extern whal_<Type>` instances and declares `Board_Init`/`Board_Deinit`/
158166
### `board.c`
159167
Define each `whal_<Type>` global with its platform macro + board-specific config (pins, baud rates, timeout, DMA channel assignments). Implement `Board_Init` in dependency order: PWR → Clock → peripheral clock enables → GPIO → UART → Timer → the rest. Keep the watchdog out of `Board_Init` (the app starts it when ready to refresh) per `docs/adding_a_board.md`. Guard DMA-specific setup under `#ifdef BOARD_DMA`, matching `boards/stm32wba55cg_nucleo/board.c`.
160168

169+
### GPIO pin conflict check
170+
After writing the `pinCfg` array in `board.c`, scan every entry pair and verify no two entries share the same physical port+pin. This is a common mistake when a pin serves double duty (e.g., PA5 used as both an LED and SPI1_SCK). If a conflict is found, consult the chip's alternate-function table in the datasheet and remap the conflicting peripheral to an alternate pin on a different port.
171+
161172
### `Makefile.inc`
162173
Model on `boards/stm32wba55cg_nucleo/Makefile.inc`:
163174
- `PLATFORM = <platform>` — matches the prefix used in `src/*/<platform>_*.c`
@@ -171,6 +182,14 @@ Copy from a similar board and update the `MEMORY` block's FLASH/RAM origins and
171182
### `ivt.c`
172183
Copy from a similar board with the same core (M4/M33). Update the vector table — vectors from position 16 onward are device-specific and listed in the TRM's interrupt mapping table. At minimum: SysTick plus any peripheral IRQs the tests exercise (USART1_IRQHandler, GPDMAx_ChannelY_IRQHandler, etc.).
173184

185+
### boards/README.md
186+
187+
Add a row to the **Supported Boards** table in `boards/README.md` with the board name, platform, CPU core, and directory. Keep the table sorted alphabetically by platform name.
188+
189+
### GitHub CI
190+
191+
Add the new board to `.github/workflows/boards.yml` by appending it to the `board` matrix list. This ensures the board builds are verified on every PR and push to main. If the board supports peripheral devices (BMI270, SPI-NOR, etc.), also add entries to `.github/workflows/peripheral-tests.yml`. If it supports watchdog, add entries to `.github/workflows/watchdog-tests.yml`.
192+
174193
## Phase 5 — Build and validate
175194

176195
1. `make BOARD=<board_name>` from the repo root. Fix errors in order. Typical failures:

.github/workflows/boards.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
board: [stm32wb55xx_nucleo, pic32cz_curiosity_ultra, stm32h563zi_nucleo, stm32f411_blackpill, stm32c031_nucleo]
14+
board: [stm32wb55xx_nucleo, stm32wba55cg_nucleo, pic32cz_curiosity_ultra, stm32h563zi_nucleo, stm32f411_blackpill, stm32c031_nucleo, stm32f091rc_nucleo]
1515
extra_cflags: ["", "-DWHAL_CFG_NO_TIMEOUT"]
1616
include:
1717
- board: stm32wb55xx_nucleo

.github/workflows/watchdog-tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ jobs:
1616
watchdog: iwdg
1717
- board: stm32wb55xx_nucleo
1818
watchdog: wwdg
19+
- board: stm32f091rc_nucleo
20+
watchdog: iwdg
21+
- board: stm32f091rc_nucleo
22+
watchdog: wwdg
1923
steps:
2024
- uses: actions/checkout@v4
2125

boards/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ build configuration.
1616
|-------|----------|-----|-----------|
1717
| Microchip PIC32CZ CA Curiosity Ultra | PIC32CZ | Cortex-M7 | `pic32cz_curiosity_ultra/` |
1818
| ST NUCLEO-C031C6 | STM32C0 | Cortex-M0+ | `stm32c031_nucleo/` |
19+
| ST NUCLEO-F091RC | STM32F0 | Cortex-M0 | `stm32f091rc_nucleo/` |
1920
| WeAct BlackPill STM32F411 | STM32F4 | Cortex-M4 | `stm32f411_blackpill/` |
2021
| ST NUCLEO-H563ZI | STM32H5 | Cortex-M33 | `stm32h563zi_nucleo/` |
2122
| ST NUCLEO-WB55RG | STM32WB | Cortex-M4 | `stm32wb55xx_nucleo/` |
23+
| ST NUCLEO-WBA55CG | STM32WBA | Cortex-M33 | `stm32wba55cg_nucleo/` |
2224

2325
## Board Directory Contents
2426

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
_BOARD_DIR := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
2+
3+
PLATFORM = stm32f0
4+
TESTS ?= clock gpio timer flash uart spi
5+
6+
GCC = $(GCC_PATH)arm-none-eabi-gcc
7+
LD = $(GCC_PATH)arm-none-eabi-gcc
8+
OBJCOPY = $(GCC_PATH)arm-none-eabi-objcopy
9+
10+
CFLAGS += -Wall -Werror $(INCLUDE) -g3 \
11+
-ffreestanding -nostdlib -mcpu=cortex-m0 -mthumb \
12+
-DPLATFORM_STM32F0 -MMD -MP \
13+
-DWHAL_CFG_GPIO_API_MAPPING_STM32F0 \
14+
-DWHAL_CFG_CLOCK_API_MAPPING_STM32F0 \
15+
-DWHAL_CFG_UART_API_MAPPING_STM32F0 \
16+
-DWHAL_CFG_SPI_API_MAPPING_STM32F0 \
17+
-DWHAL_CFG_I2C_API_MAPPING_STM32F0 \
18+
$(if $(filter iwdg,$(WATCHDOG)),-DBOARD_WATCHDOG_IWDG) \
19+
$(if $(filter wwdg,$(WATCHDOG)),-DBOARD_WATCHDOG_WWDG)
20+
LDFLAGS = -mcpu=cortex-m0 -mthumb -ffreestanding -nostartfiles \
21+
-Wl,--omagic -static
22+
23+
LINKER_SCRIPT ?= $(_BOARD_DIR)/linker.ld
24+
25+
INCLUDE += -I$(_BOARD_DIR) -I$(WHAL_DIR)/boards/peripheral
26+
27+
BOARD_SOURCE = $(_BOARD_DIR)/ivt.c
28+
BOARD_SOURCE += $(_BOARD_DIR)/board.c
29+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*.c)
30+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/timer.c)
31+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/supply.c)
32+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/flash.c)
33+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/rng.c)
34+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/crypto.c)
35+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/sensor.c)
36+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/block.c)
37+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/watchdog.c)
38+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/stm32f0_*.c)
39+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/systick.c)
40+
41+
# Peripheral devices
42+
include $(WHAL_DIR)/boards/peripheral/Makefile.inc

0 commit comments

Comments
 (0)