STM32 ROM Bootloader
The STM32 ROM Bootloader is a jump-to type bootloader, with some extra setup used to integrate with it.
By default, when integrating this bootloader, a "double tap reset to enter the bootloader" feature will be enabled, to help with designs that do not easily expose a BOOT pin.
Kconfig Symbol Enablement
Three Kconfig symbols need to be enabled for this feature to work, namely RETAINED_MEM, RETENTION, and RETENTION_BOOT_MODE. Typically, this is done by implying the symbols for the board symbol in the Kconfig.<board>, file, e.g.:
config BOARD_TOFU65
select SOC_RP2040
imply RETAINED_MEM
imply RETENTION
imply RETENTION_BOOT_MODE
By using imply at the board level, users of the board can choose to override the setting and disable the feature if they so choose.
Adjust Existing SRAM Node
First, we'll adjust the existing SRAM node to shrink it by one byte so Zephyr will not interfere with the retained mem:
/* Reduce SRAM0 usage by 1 byte to account for non-init area */
&sram0 {
reg = <0x20000000 0x3FFF>;
};
Note:
- The
0x20000000address is the address of the RAM for the target. This is nearly always0x20000000 - The exact value of
0x3FFFwill depend on the total RAM on the target. The value should be the total RAM, minus 1-bytes, in hex
New Memory Region & Nested Retained Mem
/ {
sram@20003FFF {
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x20003FFF 0x1>;
zephyr,memory-region = "RetainedMem";
status = "okay";
retainedmem {
compatible = "zephyr,retained-ram";
status = "okay";
#address-cells = <1>;
#size-cells = <1>;
retention0: retention@0 {
compatible = "zephyr,retention";
status = "okay";
reg = <0x0 0x1>;
};
};
};
};
Note:
- The node
sram@20003FFFand the correspondingregproperty values are obtained by adding the base RAM address (.e.g.0x20000000) to the shrunk RAM size (e.g.0x3FFF) to get the new start address for the area of reserved RAM.
Chosen Boot Mode Node
Finally, we'll set a chosen property to select the created retention node:
/ {
chosen {
zephyr,boot-mode = &retention0;
};
};