Skip to content

Commit 30e54d0

Browse files
committed
Use only one backup register for CMD_BOOT for stm32f103 based targets
This is behavior is more akin to what most STM32F103xx applications wanting to enter the bootloader are accustomed to. Should retain backwards compatibility with existing applications writing to both registers, the higher one just won't be checked by the bootloader anymore.
1 parent aea139a commit 30e54d0

3 files changed

Lines changed: 8 additions & 11 deletions

File tree

src/stm32f103/backup.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@
2424

2525
#define RTC_BKP_DR(reg) MMIO16(BACKUP_REGS_BASE + 4 + (4 * (reg)))
2626

27-
void backup_write(enum BackupRegister reg, uint32_t value) {
27+
void backup_write(enum BackupRegister reg, uint16_t value) {
2828
rcc_periph_clock_enable(RCC_PWR);
2929
rcc_periph_clock_enable(RCC_BKP);
3030

3131
pwr_disable_backup_domain_write_protect();
32-
RTC_BKP_DR((int)reg) = value & 0xFFFFUL;
33-
RTC_BKP_DR((int)reg+1) = (value & 0xFFFF0000UL) >> 16;
32+
RTC_BKP_DR((int)reg) = value;
3433
pwr_enable_backup_domain_write_protect();
3534
}
3635

37-
uint32_t backup_read(enum BackupRegister reg) {
38-
uint32_t value = (uint32_t)RTC_BKP_DR((int)reg)
39-
| ((uint32_t)RTC_BKP_DR((int)reg+1) << 16);
40-
return value;
36+
uint16_t backup_read(enum BackupRegister reg) {
37+
return RTC_BKP_DR((int)reg);
4138
}

src/stm32f103/backup.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ enum BackupRegister {
3232
BKP10,
3333
};
3434

35-
extern void backup_write(enum BackupRegister reg, uint32_t value);
36-
extern uint32_t backup_read(enum BackupRegister reg);
35+
extern void backup_write(enum BackupRegister reg, uint16_t value);
36+
extern uint16_t backup_read(enum BackupRegister reg);
3737

3838
#endif

src/stm32f103/target_stm32f103.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ _Static_assert((FLASH_BASE + FLASH_SIZE_OVERRIDE >= APP_BASE_ADDRESS),
6060
#endif
6161

6262
#ifndef CMD_BOOT
63-
#define CMD_BOOT 0x544F4F42UL
63+
#define CMD_BOOT 0x4F42UL
6464
#endif
6565

6666
void target_clock_setup(void) {
@@ -166,7 +166,7 @@ const usbd_driver* target_usb_init(void) {
166166
bool target_get_force_bootloader(void) {
167167
bool force = false;
168168
/* Check the RTC backup register */
169-
uint32_t cmd = backup_read(REG_BOOT);
169+
uint16_t cmd = backup_read(REG_BOOT);
170170
if (cmd == CMD_BOOT) {
171171
force = true;
172172
}

0 commit comments

Comments
 (0)