Hi,
I’m trying to build an ArduPilot ChibiOS bootloader for a custom STM32G491CEU6 (G4) board (PCBMagNode).
Goal
-
Bootloader: USB serial only (CDC / SDU1), basic LEDs
-
Application: AP_Periph over CAN to a Pixhawk
-
Flashing: USB preferred, STLink V3 Mini available
Build command:
rm -rf build/PCBMagNode
Tools/scripts/build_bootloaders.py PCBMagNode
Environment
-
MCU: STM32G491CEU6 (512 KB flash, 128 KB RAM)
-
Host: macOS (Apple Silicon)
-
Toolchain: arm-none-eabi gcc 10.2.1 (2020-q4-major)
-
ArduPilot: ChibiOS (commit/branch can be provided)
Problem A — USB / SDU1 not generated
Depending on the USB syntax used in hwdef-bl.dat, I get one of the following:
A1 — USB peripheral not assigned
#error "USB driver activated but no USB peripheral assigned"
A2 — SDU1 missing
error: 'SDU1' was not declared in this scope
#define BOOTLOADER_DEV_LIST (BaseChannel *)&SDU1,(BaseChannel *)&SD1
So maybe either:
-
the USB peripheral is not bound correctly, or
-
USB compiles but SDU1 is never generated in hwdef.h.
Question A
For STM32G491 / STM32G4xx, what is the correct hwdef-bl.dat syntax to enable Serial-over-USB (CDC) so that SDU1 exists?
Specifically:
-
What is the correct USB peripheral name for G4 (USB vs USB1 vs OTG1)?
-
What are the correct pin function tokens for PA11 / PA12?
-
What is the correct usage of:
-
USB USB_SERIAL
-
SERIAL_ORDER …
-
any required define HAL_USE_SERIAL_USB or related flags?
-
Problem B — Linker error / flash layout
When I get past the USB compile stage, linking sometimes fails with:
ld: common.ld:202 cannot move location counter backwards
(from 0x080021e0 to 0x0800000)
In some configure runs I also see:
env set FLASH_TOTAL=0
Question B
What are the correct flash / reserve directives for an STM32G491 bootloader?
For example, for a typical 32 KB bootloader:
-
Which of these must be set in hwdef-bl.dat?
-
FLASH_SIZE_KB
-
FLASH_RESERVE_START_KB
-
FLASH_BOOTLOADER_LOAD_KB
-
-
What must match in the application hwdef.dat so AP_Periph starts after the bootloader region?
Current
hwdef-bl.dat
(attempt)
# hwdef-bl.dat — PCBMagNode Bootloader (STM32G491xx)
APJ_BOARD_ID 99
MCU STM32G4xx STM32G491xx
FLASH_SIZE_KB 512
FLASH_BOOTLOADER_LOAD_KB 0
FLASH_RESERVE_START_KB 0
OSCILLATOR_HZ 8000000
# USB attempt
PA11 USB_DM USB
PA12 USB_DP USB
USB USB_SERIAL
# Optional UART
PA9 USART1_TX USART1
PA10 USART1_RX USART1
SERIAL_ORDER USB USART1
USB_VENDOR 0x0483
USB_PRODUCT 0x5740
STRING_PRODUCT "MagNode BL"
define HAL_USE_EMPTY_STORAGE 1
# LEDs
PA0 LED1 OUTPUT LOW
PA1 LED2 OUTPUT LOW
# keep bootloader minimal
define AP_SCRIPTING_ENABLED 0
define AP_NETWORKING_ENABLED 0
define AP_FILESYSTEM_ENABLED 0
define HAL_LOGGING_ENABLED 0
define HAL_USE_ADC FALSE
define HAL_USE_I2C FALSE
define HAL_USE_SPI FALSE
define HAL_USE_CAN FALSE
define HAL_USE_PWM FALSE
What I already tried
- OTG-style tokens:
PA11 OTG_FS_DM OTG1
PA12 OTG_FS_DP OTG1
-
→ parser errors or “unknown pin function”
-
SERIAL_ORDER OTG1, USB1, etc.
-
Multiple combinations of USB naming
I haven’t yet found a configuration where:
-
the USB peripheral is assigned correctly,
-
SDU1 exists, and
-
the bootloader links cleanly.
Looking for
-
A known working hwdef-bl.dat example for STM32G4xx / G491
-
The correct USB token naming for this MCU in ArduPilot
-
The correct flash reserve setup for bootloader + matching app layout
Thanks in advance for any pointers!!