H7 dual core OTA fix

This commit is contained in:
robert 2024-11-13 06:32:21 -05:00
parent 85414cfec2
commit 000eb0a25d
2 changed files with 18 additions and 0 deletions

View File

@ -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;
}
@ -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;

View File

@ -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;
}
@ -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;