Skip to content

Commit 0f06efb

Browse files
committed
Add wolfBoot support for STM32G4
1 parent 7b0bee5 commit 0f06efb

10 files changed

Lines changed: 755 additions & 0 deletions

File tree

.github/workflows/test-configs.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,12 @@ jobs:
444444
arch: arm
445445
config-file: ./config/examples/stm32g0.config
446446

447+
stm32g4_test:
448+
uses: ./.github/workflows/test-build.yml
449+
with:
450+
arch: arm
451+
config-file: ./config/examples/stm32g4.config
452+
447453
stm32h5_test:
448454
uses: ./.github/workflows/test-build.yml
449455
with:

arch.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ ifeq ($(ARCH),ARM)
167167
ARCH_FLASH_OFFSET=0x08000000
168168
endif
169169

170+
ifeq ($(TARGET),stm32g4)
171+
ARCH_FLASH_OFFSET=0x08000000
172+
endif
173+
170174
ifeq ($(TARGET),stm32f1)
171175
CORTEX_M3=1
172176
NO_ARM_ASM=1

config/examples/stm32g4.config

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
ARCH?=ARM
2+
TARGET?=stm32g4
3+
SIGN?=ECC256
4+
HASH?=SHA256
5+
DEBUG?=0
6+
VTOR?=1
7+
NO_ASM?=0
8+
EXT_FLASH?=0
9+
SPI_FLASH?=0
10+
ALLOW_DOWNGRADE?=0
11+
NVM_FLASH_WRITEONCE?=1
12+
WOLFBOOT_VERSION?=0
13+
V?=0
14+
SPMATH?=1
15+
RAM_CODE?=1
16+
DUALBANK_SWAP?=0
17+
18+
# Single-bank 512KB flash, 2KB pages.
19+
# Layout: 32K boot, 232K app, 232K update, 16K swap.
20+
WOLFBOOT_SECTOR_SIZE?=0x800
21+
WOLFBOOT_PARTITION_SIZE?=0x3A000
22+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x08008000
23+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x08042000
24+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x0807C000

docs/Targets.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ This README describes configuration of supported targets.
4545
* [STM32F4](#stm32f4)
4646
* [STM32F7](#stm32f7)
4747
* [STM32G0](#stm32g0)
48+
* [STM32G4](#stm32g4)
4849
* [STM32H5](#stm32h5)
4950
* [STM32H7](#stm32h7)
5051
* [STM32L0](#stm32l0)
@@ -527,6 +528,79 @@ add-symbol-file test-app/image.elf 0x08008100
527528
mon reset init
528529
```
529530

531+
## STM32G4
532+
533+
Supports STM32G4 single-bank Category 3 parts (verified on NUCLEO-G491RE,
534+
STM32G491RET6: 512KB flash, 96KB SRAM, Cortex-M4F).
535+
536+
The HAL boots at 170 MHz using HSI16 + PLL with PWR Range 1 Boost mode
537+
(RM0440 6.1.4), 4 flash wait states, prefetch + I/D-cache enabled.
538+
539+
Example 512KB partitioning on STM32G491RE:
540+
541+
- Sector size: 2KB
542+
- wolfBoot partition size: 32KB
543+
- Application partition size: 232KB
544+
545+
```C
546+
#define WOLFBOOT_SECTOR_SIZE 0x800 /* 2 KB */
547+
#define WOLFBOOT_PARTITION_BOOT_ADDRESS 0x08008000
548+
#define WOLFBOOT_PARTITION_SIZE 0x3A000 /* 232 KB */
549+
#define WOLFBOOT_PARTITION_UPDATE_ADDRESS 0x08042000
550+
#define WOLFBOOT_PARTITION_SWAP_ADDRESS 0x0807C000 /* 16 KB swap */
551+
```
552+
553+
### Building STM32G4
554+
555+
Reference configuration (see [/config/examples/stm32g4.config](/config/examples/stm32g4.config)).
556+
You can copy this to wolfBoot root as `.config`: `cp ./config/examples/stm32g4.config .config`.
557+
To build you can use `make`.
558+
559+
The TARGET for this is `stm32g4`: `make TARGET=stm32g4`.
560+
Cortex-M4F is the default ARM core for this target.
561+
The option `NVM_FLASH_WRITEONCE=1` is mandatory: the IAP driver writes one
562+
64-bit doubleword per location and cannot rewrite without an erase first.
563+
The default signing scheme is ECC256 with SHA256.
564+
565+
NUCLEO-G491RE has no HSE, so HSI16 is used as the PLL source. The ST-LINK
566+
virtual COM port is wired to LPUART1 on PA2 (TX) / PA3 (RX) via AF12.
567+
Optional boot logs over LPUART1 at 115200 8N1 are enabled with
568+
`CFLAGS_EXTRA+=-DDEBUG_UART`.
569+
570+
This target is single-bank only -- keep `DUALBANK_SWAP=0`.
571+
572+
### STM32G4 Programming
573+
574+
Compile requirements: `make TARGET=stm32g4 NVM_FLASH_WRITEONCE=1`
575+
576+
The output is a single `factory.bin` that includes `wolfboot.bin` and
577+
`test-app/image_v1_signed.bin` combined together. This should be programmed
578+
to the flash start address `0x08000000`.
579+
580+
Flash using the STM32CubeProgrammer CLI:
581+
582+
```
583+
STM32_Programmer_CLI -c port=swd -d factory.bin 0x08000000
584+
```
585+
586+
### STM32G4 Debugging
587+
588+
Use `make DEBUG=1` and program firmware again.
589+
590+
Start GDB server on port 3333:
591+
592+
```
593+
ST-LINK_gdbserver -d -e -r 1 -p 3333
594+
OR
595+
st-util -p 3333
596+
```
597+
598+
```
599+
arm-none-eabi-gdb
600+
add-symbol-file test-app/image.elf 0x08008100
601+
mon reset init
602+
```
603+
530604
## STM32C0
531605

532606
Supports STM32C0x0/STM32C0x1. Instructions are for the STM Nucleo-C031C6 dev board.

0 commit comments

Comments
 (0)