STM32F103 Mass Storage Device Bootloader
STM32F103 Mass Storage Device Bootloader
Device: STM32F103C8T6 (Flash size: 64KB) / STM32F103CBT6 (Flash size: 128KB)
My example:
Name | STM32F103C8T6 Address | STM32F103CBT6 Address |
---|---|---|
Appcode starts from: | 0x0800_4000 - 0x0800_FFFF (48KB) | 0x0800_4000 - 0x0801_FFFF (112KB) |
(Unused) starts from: | 0x0800_36E0 - 0x0800_3FFF (2.28KB) | 0x0800_36E0 - 0x0800_3FFF (2.28KB) |
Bootloader starts from: | 0x0800_0000 - 0x0800_36DF (13.72KB) | 0x0800_0000 - 0x0800_36DF (13.72KB) |
Simulate a USB removable disk (FAT32).
Just drag and drop the intel hex file to update the appcode. The bootloader will automatically restart if EOF RecordType is found in the hex file. Drag and drop the BIN file is removed. Since intel hex file has the following advantages over the bin file:
During power up, the bootloader will check the content of 0x0800_4000 exists or not. Hold PA0 (Connect to GND) during power up can force to enter bootloader mode.
Several examples are provided in "example-hex" folder to validate the bootloader feature.
The following features can be activated by preprocessor constant in btldr_config.h
For more detail, please see the tools/hex-crypt folder.
Before bootloader jumps to main application, it calculates the app's CRC32 checksum and compares it to the CRC32 calculated at build time (which is stored at end of flash). Jump to app is only performed in case of valid checksum.
It is possible to activate the bootloader from a running main application.
*((volatile uint32_t*)0x20004ffc) = BOOTKEY; //same BOOTKEY as defined in Bootloader
/* Pull USB D+ PIN to GND so USB Host detects device disconnect */
LL_GPIO_SetPinMode(GPIOA,LL_GPIO_PIN_12, LL_GPIO_MODE_OUTPUT);
LL_GPIO_SetPinSpeed(GPIOA, LL_GPIO_PIN_12, LL_GPIO_SPEED_FREQ_LOW);
LL_GPIO_SetPinOutputType(GPIOA,LL_GPIO_PIN_12, LL_GPIO_OUTPUT_PUSHPULL);
LL_GPIO_ResetOutputPin(GPIOA, LL_GPIO_PIN_12);
LL_mDelay(1000);
NVIC_SystemReset();
In btldr_config.h, set CONFIG_READ_FLASH to 1u to read the appcode content in firmware.bin. The content in firmware.bin is mapped to appcode area. Hence, the bin file size (flash) is also 48KB / 112KB.