Using STM32CubeIDE with Swan
STM32CubeIDE lets you build bare-metal and HAL-based firmware for Swan, and step debug it over SWD. This guide covers selecting Swan's microcontroller in the STM32CubeIDE project wizard, the hardware you need to flash the resulting binary, and the Swan-specific hardware details that CubeMX does not know about.
If you would rather work in Arduino or PlatformIO, see the Swan Quickstart or Using PlatformIO with Swan.
Prerequisites
Swan does not include an on-board debugger. To flash and step debug from STM32CubeIDE you need an STLINK-V3MINI (or another SWD-capable ST-LINK probe) connected to Swan's Cortex-Debug connector.
You can also flash a build over USB with Swan's DFU bootloader instead, which requires no probe. See Flashing Firmware below.
Setting Up a Project
-
Download and install STM32CubeIDE and STM32CubeProgrammer if you don't already have them installed. Be sure to follow these installation notes when installing STM32CubeProgrammer.
-
During the STM32CubeIDE configuration, select
STM32L4R5ZIYxas the target device. This is the WLCSP144 entry for theSTM32L4R5ZIY6microcontroller Swan uses.
-
Once you've selected the
STM32L4R5ZIYx, you'll be able to use STM32CubeIDE as you would for any STMicroelectronics dev kit.
Swan-Specific Configuration
Because STM32CubeIDE targets the bare microcontroller rather than a Swan board definition, a few of CubeMX's defaults do not match Swan's hardware.
Here are a few things worth knowing:
- USB requires its own supply rail.
VDDUSBis fed by a separate 3.3V regulator rather than byVDD, so USB peripherals needPWR_CR2 USVenabled (HAL_PWREx_EnableVddUSB()) before they will work. PE6(DISCHRG) must be open drain, with no pull-up or pull-down. This pin discharges the switchable 3.3V output rail; CubeMX's default push-pull GPIO configuration violates the board's design note.PE4(nEN_3V3_OUT) enables that same rail.- Do not connect
PB2(BOOT1) to VDD. PA13,PA14,PA15, andPB3are the debug pins (SWDIO, SWCLK, JTDI, and JTDO). Repurposing them as GPIO will cost you SWD access.PB4is wired toUSART1_CTSthrough a 0Ω resistor.- Feather analog pins do not map to the ports you might guess —
A4andA5arePC4andPC5, and the two DAC outputs arePA4(D10) andPA5(D13). See Pin Information in the Swan Datasheet for the full mapping.
Flashing Firmware
With an STLINK-V3MINI attached to Swan's Cortex-Debug connector, use STM32CubeIDE's Run and Debug commands as you would with any ST development board.
To flash over USB instead, put Swan into DFU mode before every upload:
- Press and hold the
BOOTbutton. - Press and release the
RESETbutton. - Release the
BOOTbutton.
Then flash the .elf or .hex your build produced with STM32CubeProgrammer,
selecting USB as the connection type. If you flash a raw .bin instead,
set the start address to 0x08000000, since a .bin carries no address
information of its own.
Viewing Serial Output
Swan routes LPUART1 to the STLINK's virtual COM port on PG7 (TX) and PG8
(RX), so a debug probe can carry both SWD and console output over one cable.
See Serial Logging With STLINK for
the wiring details.