Skip to content

Commit ef0b9cd

Browse files
committed
Add STM32C5 target (NUCLEO-C5A3ZG)
1 parent 8c7b864 commit ef0b9cd

10 files changed

Lines changed: 915 additions & 0 deletions

File tree

.github/workflows/test-configs.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,12 @@ jobs:
542542
arch: arm
543543
config-file: ./config/examples/stm32u3.config
544544

545+
stm32c5_test:
546+
uses: ./.github/workflows/test-build.yml
547+
with:
548+
arch: arm
549+
config-file: ./config/examples/stm32c5.config
550+
545551
stm32u5_nonsecure_dualbank_test:
546552
uses: ./.github/workflows/test-build.yml
547553
with:

arch.mk

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,15 @@ ifeq ($(ARCH),ARM)
264264
SPI_TARGET=stm32
265265
endif
266266

267+
ifeq ($(TARGET),stm32c5)
268+
CORTEX_M33=1
269+
CFLAGS+=-Ihal
270+
ARCH_FLASH_OFFSET=0x08000000
271+
WOLFBOOT_ORIGIN=0x08000000
272+
LSCRIPT_IN=hal/$(TARGET).ld
273+
SPI_TARGET=stm32
274+
endif
275+
267276
ifeq ($(TARGET),stm32h5)
268277
CORTEX_M33=1
269278
CFLAGS+=-Ihal

config/examples/stm32c5.config

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
ARCH?=ARM
2+
TZEN?=0
3+
TARGET?=stm32c5
4+
SIGN?=ECC256
5+
HASH?=SHA256
6+
DEBUG?=0
7+
VTOR?=1
8+
CORTEX_M0?=0
9+
CORTEX_M33?=1
10+
NO_ASM?=0
11+
NO_MPU=1
12+
EXT_FLASH?=0
13+
SPI_FLASH?=0
14+
ALLOW_DOWNGRADE?=0
15+
NVM_FLASH_WRITEONCE?=1
16+
WOLFBOOT_VERSION?=1
17+
V?=0
18+
SPMATH?=1
19+
RAM_CODE?=1
20+
DUALBANK_SWAP?=0
21+
# Flash layout for dual-bank (2x512KB, 8KB pages, 1MB total):
22+
# Bank 1 (0x08000000): wolfBoot (64KB) + BOOT partition (448KB)
23+
# Bank 2 (0x08080000): UPDATE partition (448KB) + SWAP (8KB)
24+
WOLFBOOT_SECTOR_SIZE?=0x2000
25+
WOLFBOOT_PARTITION_SIZE?=0x70000
26+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x08010000
27+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x08080000
28+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x080F0000
29+
FLAGS_HOME=0
30+
DISABLE_BACKUP=0
31+
DEBUG_UART=1

docs/Targets.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ This README describes configuration of supported targets.
3939
* [Renesas RZN2L](#renesas-rzn2l)
4040
* [SiFive HiFive1 RISC-V](#sifive-hifive1-risc-v)
4141
* [STM32C0](#stm32c0)
42+
* [STM32C5](#stm32c5)
4243
* [STM32F1](#stm32f1)
4344
* [STM32F4](#stm32f4)
4445
* [STM32F7](#stm32f7)
@@ -1779,6 +1780,97 @@ the new image. LD2 transitions from the slow (v1) blink to the fast
17791780
transition.
17801781
17811782
1783+
## STM32C5
1784+
1785+
The STM32C5 family (for example the STM32C5A3ZGT6 on NUCLEO-C5A3ZG) is
1786+
a mainstream Cortex-M33 part **without TrustZone**, so the port is
1787+
single-image only (no `-tz` or `-ns` variants). On the -ZG variant:
1788+
1 MB internal flash, 256 KB SRAM, 8 KB pages, **128-bit (quad-word)
1789+
flash write quantum** with per-quad-word ECC.
1790+
1791+
The HAL writes flash in 16-byte aligned quad-words. When wolfBoot
1792+
asks for a smaller or unaligned write, the HAL reads the surrounding
1793+
flash and merges so each programmed quad-word is a complete ECC
1794+
block - sub-quad-word writes leave ECC undefined and reads come back
1795+
with bit-flipped "corrected" data.
1796+
1797+
### Flash layout (stm32c5.config)
1798+
1799+
Dual-bank flash (2 x 512 KB, 8 KB pages). Bank 1 holds wolfBoot +
1800+
BOOT, bank 2 holds UPDATE + SWAP:
1801+
1802+
```
1803+
Bank 1:
1804+
0x08000000 - 0x0800FFFF wolfBoot bootloader (64 KB)
1805+
0x08010000 - 0x0807FFFF BOOT partition (0x70000, 448 KB)
1806+
Bank 2:
1807+
0x08080000 - 0x080EFFFF UPDATE partition (0x70000, 448 KB)
1808+
0x080F0000 - 0x080F1FFF SWAP sector (8 KB)
1809+
```
1810+
1811+
### Clock and UART
1812+
1813+
The bootloader runs at the post-reset HSI clock (HSI / 3 = 48 MHz
1814+
HCLK; no PLL bring-up). UART is always available in the test-app and
1815+
enabled in wolfBoot via `DEBUG_UART=1` (on by default in the example
1816+
config). The NUCLEO-C5A3ZG ST-LINK virtual COM port is wired to MCU
1817+
pins 36/37 (PA2/PA3) - **USART2** on AF7, 115200 8N1, **not USART1
1818+
on PA9/PA10** (PA9/PA10 only reach the Arduino headers).
1819+
1820+
### Building
1821+
1822+
```sh
1823+
cp config/examples/stm32c5.config .config
1824+
make clean
1825+
make
1826+
```
1827+
1828+
Default signing scheme is ECC256 + SHA256. Produces `wolfboot.bin`
1829+
(~25 KB), `test-app/image_v1_signed.bin`, and `factory.bin` (BL +
1830+
signed v1).
1831+
1832+
### Flashing
1833+
1834+
Use `STM32_Programmer_CLI` (from STM32CubeIDE or STM32CubeProgrammer
1835+
v2.22+). pyocd has no STM32C5 target as of this writing. The C5
1836+
debug access port is AP2; `mode=UR` (under-reset) is the most
1837+
reliable connect mode while a previous image is running.
1838+
1839+
```sh
1840+
STM32_Programmer_CLI -c port=swd mode=UR -e all \
1841+
-d factory.bin 0x08000000 -v -rst
1842+
```
1843+
1844+
The test app blinks LD2 (PG1, **active low**): five slow blinks on
1845+
v1 then it triggers an update and resets; v2 blinks fast forever
1846+
once `wolfBoot_success()` is acknowledged.
1847+
1848+
### Testing an Update
1849+
1850+
Sign the test application as version 2 and flash it directly to the
1851+
update partition:
1852+
1853+
```sh
1854+
./tools/keytools/sign --ecc256 --sha256 \
1855+
test-app/image.bin wolfboot_signing_private_key.der 2
1856+
STM32_Programmer_CLI -c port=swd mode=UR \
1857+
-d test-app/image_v2_signed.bin 0x08080000 -v -rst
1858+
```
1859+
1860+
On reset wolfBoot detects the staged v2, the v1 test-app calls
1861+
`wolfBoot_update_trigger()` after its blink sequence and resets,
1862+
wolfBoot performs the bank-to-bank swap, and v2 boots. With
1863+
`DEBUG_UART=1` the UART log shows:
1864+
1865+
```
1866+
Booting version: 0x1
1867+
TEST APP / App version: 1 / triggering update -> reset
1868+
... swap output ...
1869+
Booting version: 0x2
1870+
TEST APP / App version: 2 / update OK -- success confirmed
1871+
```
1872+
1873+
17821874
## STM32H5
17831875
17841876
Like [STM32L5](#stm32l5) and [STM32U5](#stm32u5), STM32H5 support is also demonstrated

0 commit comments

Comments
 (0)