![]() |
px-fwlib 0.10.0
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers generated with Doxygen 1.9.2
|
This bootloader implements the UF2 bootloader communication layer over USB MSC (Mass Storage Class). It emulates (fakes) a USB removable flash drive with a FAT16 file system to provide info when reading files and to write a new application to FLASH if the file is properly formatted using the UF2 tool.
Read these pages for an excellent introduction:
A single press of the RESET button will perform a normal reset and the bootloader will jump to the application after a 1/2 second timeout. A "double-tap" of the RESET button (press twice within 0.5 s) will start the UF2 bootloader: the micro will enumerate over USB and appear as a removable drive with the volume label "HERO-BOOT". The LED will blink continously to indicate that it is in UF2 boot mode.
The bootloader will ignore a UF2 file with the wrong Family ID. See PX_UF2_CFG_FAMILY_ID
Apologies for stating the obvious, but the board must be connected via the USB1 connector to your PC ;)
The LED will blink continuously to indicate that it is in UF2 boot mode.
Locate the UF2 application file, for example:
px-fwlib/boards/arm/stm32/px_hero/examples/gpio/BUILD_RELEASE_BOOT/gpio.uf2
That's it! If the file is very big, the LED will dim while the file is being copied. It's actually flashing very fast as each block of FLASH is written.
After the file is written to the micro's FLASH, the application will start automatically.
The UF2 bootloader occupies the first 16k of FLASH. The application that would normally start at the first address in FLASH must be moved to a higher address to accomodate the bootloader which is executed first.
The application Makefile and linker script have been set up to make the creation of a UF2 file for upload super simple.
For a gentle introduction to Make, see 7.2 How to understand and modify Makefiles
Execute 'make build=release-boot':
Observe on line 19 that the FLASH offset is specified with -b 0x4000
and the UF2 Family ID is specified with -f 0xe892273c
.
The UF2 bootloader is ~13.5k in size and occupies the first 16k (0x00000000 to 0x00003FFF). The start address of the application is set in the bootloader's main.c (0x4000 = 16384 = 16k):
The application would normally start at the first address in FLASH, but it must be moved to a higher address to accomodate the bootloader which is executed first. The start address is set in the application's Makefile with the BOOTLOADER_SIZE symbol:
# (1b) Offset from start of FLASH to reserve space for bootloader (release for bootloader build) BOOTLOADER_SIZE = 0x4000
The template px-fwlib/arch/arm/stm32/MakeRules.mk uses this symbol to set the Vector Table Offset Register to the correct value in system_stm32l0xx.c and also to specify the offset for the linker script:
# Allocate space for bootloader in release for boot build (if specified) # # VTOR register (Vector Table Offset Register) must be set to correct value in: # libs/STM32Cube/L0/Drivers/CMSIS/Device/ST/STM32L0xx/Source/Templates/system_stm32l0xx.c # # FLASH_OFFSET must be specified in linker script. ifeq ($(BUILD), release_boot) ifndef BOOTLOADER_SIZE $(error "BOOTLOADER_SIZE not defined") endif CDEFS += VECT_TAB_OFFSET=$(BOOTLOADER_SIZE) LDFLAGS += -Wl,--defsym,FLASH_OFFSET=$(BOOTLOADER_SIZE) endif
The startup file system_stm32l0xx.c is located here:
px-fwlib/libs/STM32Cube/L0/Drivers/CMSIS/Device/ST/STM32L0xx/Source/Templates/system_stm32l0xx.c
It has been modified to allow VECT_TAB_OFFSET to be overriden externally:
// piconomix [mod start] - Allow VECT_TAB_OFFSET to be overridable with compiler switches #ifndef VECT_TAB_OFFSET #define VECT_TAB_OFFSET 0x00U /*!< Vector Table base offset field. This value must be a multiple of 0x100. */ #endif // piconomix [mod end]
The linker script is located here:
px-fwlib/boards/arm/stm32/px_hero/stm32l072xb.ld
It allows the start address to be changed with the FLASH_OFFSET symbol:
/* * Describe the location and size of blocks of memory in the target */ FLASH_OFFSET = DEFINED(FLASH_OFFSET)? FLASH_OFFSET : 0; FLASH_ORIGIN = 0x08000000 + FLASH_OFFSET; FLASH_LENGTH = 128k - FLASH_OFFSET;
The generated LSS file is located here:
px-fwlib/boards/arm/stm32/px_hero/examples/gpio/BUILD_RELEASE_BOOT/gpio.lss
It can be inspected to verify that the application has been moved to the right address:
BUILD_RELEASE_BOOT/gpio.elf: file format elf32-littlearm Sections: Idx Name Size VMA LMA File off Algn 0 .isr_vector 000000c0 08004000 08004000 00004000 2**0 CONTENTS, ALLOC, LOAD, READONLY, DATA 1 .init 0000000c 080040c0 080040c0 000040c0 2**2 CONTENTS, ALLOC, LOAD, READONLY, CODE 2 .text 0000049c 080040cc 080040cc 000040cc 2**2 CONTENTS, ALLOC, LOAD, READONLY, CODE
".isr_vector" is the first section and contains the vector table. The VMA / LMA (Virtual / Load Memory Address) are both set to 0x08004000.
The bootloader will perform a number of sanity checks on the UF2 file programmed in FLASH, before it will jump to the start address of the application: