Skip to content

Commit

Permalink
H7 dual core OTA fix
Browse files Browse the repository at this point in the history
  • Loading branch information
robert committed Nov 13, 2024
1 parent 85414cf commit 000eb0a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mongoose.c
Original file line number Diff line number Diff line change
Expand Up @@ -6687,6 +6687,9 @@ static struct mg_flash s_mg_flash_stm32h7 = {
#define FLASH_OPTSR_PRG 0x20
#define FLASH_SIZE_REG 0x1ff1e880

#define STM_DBGMCU_IDCODE 0x5C001000
#define STM_DEV_ID (MG_REG(STM_DBGMCU_IDCODE) & (MG_BIT(12) - 1))

MG_IRAM static bool is_dualbank(void) {
return (s_mg_flash_stm32h7.size < 2 * 1024 * 1024) ? false : true;
}
Expand Down Expand Up @@ -6773,6 +6776,12 @@ MG_IRAM static bool mg_stm32h7_swap(void) {
flash_clear_err(bank);
// printf("OPTSR_PRG 1 %#lx\n", FLASH->OPTSR_PRG);
MG_SET_BITS(MG_REG(bank + FLASH_OPTSR_PRG), MG_BIT(31), desired);
if (STM_DEV_ID == 0x450) {
// H745/H755 and H747/H757 are running on dual core
// Disable CM4 to prevent the old and the new firmwares from booting
// simultaneously on each core.
MG_SET_BITS(MG_REG(bank + FLASH_OPTSR_PRG), MG_BIT(22), 0);
}
// printf("OPTSR_PRG 2 %#lx\n", FLASH->OPTSR_PRG);
MG_REG(bank + FLASH_OPTCR) |= MG_BIT(1); // OPTSTART
while ((MG_REG(bank + FLASH_OPTSR_CUR) & MG_BIT(31)) != desired) (void) 0;
Expand Down
9 changes: 9 additions & 0 deletions src/ota_stm32h7.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ static struct mg_flash s_mg_flash_stm32h7 = {
#define FLASH_OPTSR_PRG 0x20
#define FLASH_SIZE_REG 0x1ff1e880

#define STM_DBGMCU_IDCODE 0x5C001000
#define STM_DEV_ID (MG_REG(STM_DBGMCU_IDCODE) & (MG_BIT(12) - 1))

MG_IRAM static bool is_dualbank(void) {
return (s_mg_flash_stm32h7.size < 2 * 1024 * 1024) ? false : true;
}
Expand Down Expand Up @@ -121,6 +124,12 @@ MG_IRAM static bool mg_stm32h7_swap(void) {
flash_clear_err(bank);
// printf("OPTSR_PRG 1 %#lx\n", FLASH->OPTSR_PRG);
MG_SET_BITS(MG_REG(bank + FLASH_OPTSR_PRG), MG_BIT(31), desired);
if (STM_DEV_ID == 0x450) {
// H745/H755 and H747/H757 are running on dual core
// Disable CM4 to prevent the old and the new firmwares from booting
// simultaneously on each core.
MG_SET_BITS(MG_REG(bank + FLASH_OPTSR_PRG), MG_BIT(22), 0);
}
// printf("OPTSR_PRG 2 %#lx\n", FLASH->OPTSR_PRG);
MG_REG(bank + FLASH_OPTCR) |= MG_BIT(1); // OPTSTART
while ((MG_REG(bank + FLASH_OPTSR_CUR) & MG_BIT(31)) != desired) (void) 0;
Expand Down

0 comments on commit 000eb0a

Please sign in to comment.