this firmware template is designed for development boards based around STM32 F1 series micro-controller.
both project are already git submodules. to initialize and get them you just need to run once:
git submodule init git submodule update
currently the following development boards are supported:
- Maple Mini, based on a STM32F103CBT6
- System Board, based on a STM32F103C8T6
- blue pill, based on a STM32F103C8T6
you need to define which board you are using in the Makefile
this is required:
- for the linker script to know the memory layout (flash and RAM)
- to flash the corresponding bootloader
- map the user LEDs and buttons provided on the board
Makefile offers two ways of flashing the firmware on the board:
- over the SWD port (Serial Wire Debug)
- using the USB DFU interface (Device Firmware Upgrade)
the default mechanism
make flash uses DFU.
to flash over SWD you need an SWD adapter.
Makefile uses a ST-Link V2, along with the OpenOCD software.
the main firmware will be placed after the bootloader.
thus you first need to flash the bootloader first (see below), else the main firmware will not be started.
to flash the bootloader run
SWD is nice because it will always work, even if USB is buggy, or the code on the board is stuck. it also does not require to press on any reset button.
to flash using SWD run
SWD also allows you to debug the code running on the micro-controller using GDB.
to start the debugging session use
to flash using DFU you just need to connect the USB port. when booting the micro-controller will start the STM32duino-bootloader bootloader. this configures the USB to accept firmware updates. after a short timeout (<1s) it will start the main firmware.
the main firmware will not be started if the bootloader is missing.
you only have to flash the bootloader once, using the SWD method.
to flash the bootloader run
to then flash using DFU run
this will try to reset the board to start the bootloader.
else you will need to reset the board manually using the reset button.
the firmware provides basic example code for various peripherals.
to compile the firmware run
if a button is present on the board, pressing it will toggle the LED.
whatever you send over UART (USART1) will be echoed back (also over USB).
the firmware also offer serial communication over USB using the CDC ACM device class. since the micro-controller first starts the bootloader, it is recognised a DFU device. to provide the CDC ACM interface the host needs to re-enumerate the USB device. for this a disconnect disconnect is simulated by pulling USB D+ low for a short time (in software or using a dedicated circuit). then the host will re-enumerate the USB device and see the CDC ACM interface.
whatever you send over USB (CDC ACM) will be echoed back (also over UART).
additionally you can reset the board by setting the serial width to 5 bits.
this allows to restart the bootloader and flash new firmware using DFU.
to reset the board run
this only works if the USB CDC ACM run correctly and the micro-controller isn't stuck.