Skip to content

Commit 000eb0a

Browse files
author
robert
committed
H7 dual core OTA fix
1 parent 85414cf commit 000eb0a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

mongoose.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6687,6 +6687,9 @@ static struct mg_flash s_mg_flash_stm32h7 = {
66876687
#define FLASH_OPTSR_PRG 0x20
66886688
#define FLASH_SIZE_REG 0x1ff1e880
66896689

6690+
#define STM_DBGMCU_IDCODE 0x5C001000
6691+
#define STM_DEV_ID (MG_REG(STM_DBGMCU_IDCODE) & (MG_BIT(12) - 1))
6692+
66906693
MG_IRAM static bool is_dualbank(void) {
66916694
return (s_mg_flash_stm32h7.size < 2 * 1024 * 1024) ? false : true;
66926695
}
@@ -6773,6 +6776,12 @@ MG_IRAM static bool mg_stm32h7_swap(void) {
67736776
flash_clear_err(bank);
67746777
// printf("OPTSR_PRG 1 %#lx\n", FLASH->OPTSR_PRG);
67756778
MG_SET_BITS(MG_REG(bank + FLASH_OPTSR_PRG), MG_BIT(31), desired);
6779+
if (STM_DEV_ID == 0x450) {
6780+
// H745/H755 and H747/H757 are running on dual core
6781+
// Disable CM4 to prevent the old and the new firmwares from booting
6782+
// simultaneously on each core.
6783+
MG_SET_BITS(MG_REG(bank + FLASH_OPTSR_PRG), MG_BIT(22), 0);
6784+
}
67766785
// printf("OPTSR_PRG 2 %#lx\n", FLASH->OPTSR_PRG);
67776786
MG_REG(bank + FLASH_OPTCR) |= MG_BIT(1); // OPTSTART
67786787
while ((MG_REG(bank + FLASH_OPTSR_CUR) & MG_BIT(31)) != desired) (void) 0;

src/ota_stm32h7.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ static struct mg_flash s_mg_flash_stm32h7 = {
3535
#define FLASH_OPTSR_PRG 0x20
3636
#define FLASH_SIZE_REG 0x1ff1e880
3737

38+
#define STM_DBGMCU_IDCODE 0x5C001000
39+
#define STM_DEV_ID (MG_REG(STM_DBGMCU_IDCODE) & (MG_BIT(12) - 1))
40+
3841
MG_IRAM static bool is_dualbank(void) {
3942
return (s_mg_flash_stm32h7.size < 2 * 1024 * 1024) ? false : true;
4043
}
@@ -121,6 +124,12 @@ MG_IRAM static bool mg_stm32h7_swap(void) {
121124
flash_clear_err(bank);
122125
// printf("OPTSR_PRG 1 %#lx\n", FLASH->OPTSR_PRG);
123126
MG_SET_BITS(MG_REG(bank + FLASH_OPTSR_PRG), MG_BIT(31), desired);
127+
if (STM_DEV_ID == 0x450) {
128+
// H745/H755 and H747/H757 are running on dual core
129+
// Disable CM4 to prevent the old and the new firmwares from booting
130+
// simultaneously on each core.
131+
MG_SET_BITS(MG_REG(bank + FLASH_OPTSR_PRG), MG_BIT(22), 0);
132+
}
124133
// printf("OPTSR_PRG 2 %#lx\n", FLASH->OPTSR_PRG);
125134
MG_REG(bank + FLASH_OPTCR) |= MG_BIT(1); // OPTSTART
126135
while ((MG_REG(bank + FLASH_OPTSR_CUR) & MG_BIT(31)) != desired) (void) 0;

0 commit comments

Comments
 (0)