Skip to content

Commit 197736b

Browse files
committed
at32: Artery MCU does not have backup regs in the STM32 location
Hence the firmware-update flag simply did not work. Instead copy the flag-in-ram approach already used by the AT32F435 build. Keep the flag-in-bkp approach only for STM32F105, and only for compatibility with old versions of the update bootloader.
1 parent cc9039c commit 197736b

File tree

5 files changed

+30
-29
lines changed

5 files changed

+30
-29
lines changed

inc/mcu/at32f435.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ void gpio_set_af(GPIO gpio, unsigned int pin, unsigned int af);
6666
#define SOFTIRQ_0 85
6767
#define SOFTIRQ_1 86
6868

69-
extern volatile uint32_t _reset_flag;
70-
#define RESET_FLAG_BOOTLOADER 0xdeadbeefu
71-
7269
/*
7370
* Local variables:
7471
* mode: C

inc/util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ extern const char fw_ver[];
187187
extern const char build_date[];
188188
extern const char build_time[];
189189

190+
/* Bootloader mode flag. */
191+
extern volatile uint32_t _reset_flag;
192+
#define RESET_FLAG_BOOTLOADER 0xdeadbeefu
193+
190194
/* Text/data/BSS address ranges. */
191195
extern char _stext[], _etext[];
192196
extern char _smaintext[], _emaintext[];

scripts/stm32.ld.S

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ SECTIONS
2424
_etext = .;
2525
} >FLASH
2626

27-
#if MCU == MCU_at32f435
2827
.flags : {
2928
_reset_flag = .;
3029
. = . + 4;
3130
} >RAM
32-
#endif
3331

3432
.data : AT (_etext) {
3533
. = ALIGN(4);

src/fw_update.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,29 +93,33 @@ static bool_t main_fw_requested(void)
9393

9494
static bool_t fw_update_requested(void)
9595
{
96-
bool_t requested;
96+
bool_t requested = FALSE;
9797

9898
#if MCU == MCU_stm32f105
9999

100-
/* Power up the backup-register interface and allow writes. */
101-
rcc->apb1enr |= RCC_APB1ENR_PWREN | RCC_APB1ENR_BKPEN;
102-
pwr->cr |= PWR_CR_DBP;
100+
/* We detect an Artery MCU by presence of Cortex-M4 CPUID.
101+
* Cortex-M4: 41xfc24x ; Cortex-M3: 41xfc23x */
102+
is_artery_mcu = ((scb->cpuid >> 4) & 0xf) == 4;
103103

104-
/* Has bootloader been requested via magic numbers in the backup regs? */
105-
requested = ((bkp->dr1[0] == 0xdead) && (bkp->dr1[1] == 0xbeef));
104+
if (!is_artery_mcu) {
105+
/* Power up the backup-register interface and allow writes. */
106+
rcc->apb1enr |= RCC_APB1ENR_PWREN | RCC_APB1ENR_BKPEN;
107+
pwr->cr |= PWR_CR_DBP;
106108

107-
/* Clean up backup registers and peripheral clocks. */
108-
bkp->dr1[0] = bkp->dr1[1] = 0;
109-
rcc->apb1enr = 0;
109+
/* Has bootloader been requested via magic in the backup regs? */
110+
requested |= ((bkp->dr1[0] == 0xdead) && (bkp->dr1[1] == 0xbeef));
110111

111-
#elif MCU == MCU_at32f435
112+
/* Clean up backup registers and peripheral clocks. */
113+
bkp->dr1[0] = bkp->dr1[1] = 0;
114+
rcc->apb1enr = 0;
115+
}
116+
117+
#endif
112118

113119
/* Check-and-clear a magic value poked into SRAM1 by the main firmware. */
114-
requested = (_reset_flag == RESET_FLAG_BOOTLOADER);
120+
requested |= (_reset_flag == RESET_FLAG_BOOTLOADER);
115121
_reset_flag = 0;
116122

117-
#endif
118-
119123
return requested;
120124
}
121125

src/main.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2891,21 +2891,19 @@ static void factory_reset(void)
28912891
static void update_firmware(void)
28922892
{
28932893
#if MCU == MCU_stm32f105
2894+
if (!is_artery_mcu) {
2895+
/* Power up the backup-register interface and allow writes. */
2896+
rcc->apb1enr |= RCC_APB1ENR_PWREN | RCC_APB1ENR_BKPEN;
2897+
pwr->cr |= PWR_CR_DBP;
28942898

2895-
/* Power up the backup-register interface and allow writes. */
2896-
rcc->apb1enr |= RCC_APB1ENR_PWREN | RCC_APB1ENR_BKPEN;
2897-
pwr->cr |= PWR_CR_DBP;
2898-
2899-
/* Indicate to bootloader that we want to perform firmware update. */
2900-
bkp->dr1[0] = 0xdead;
2901-
bkp->dr1[1] = 0xbeef;
2902-
2903-
#elif MCU == MCU_at32f435
2899+
/* Indicate to bootloader that we want to perform firmware update. */
2900+
bkp->dr1[0] = 0xdead;
2901+
bkp->dr1[1] = 0xbeef;
2902+
}
2903+
#endif
29042904

29052905
_reset_flag = RESET_FLAG_BOOTLOADER;
29062906

2907-
#endif
2908-
29092907
system_reset();
29102908
}
29112909

0 commit comments

Comments
 (0)