Skip to content

Commit 665298a

Browse files
author
robert
committed
H7 dual core OTA compatibility
1 parent 85414cf commit 665298a

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

mongoose.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6654,7 +6654,7 @@ bool mg_ota_end(void) {
66546654

66556655

66566656

6657-
#if MG_OTA == MG_OTA_STM32H7
6657+
#if MG_OTA == MG_OTA_STM32H7 || MG_OTA == MG_OTA_STM32H7_DUAL_CORE
66586658

66596659
// - H723/735 RM 4.3.3: Note: The application can simultaneously request a read
66606660
// and a write operation through the AXI interface.
@@ -6687,7 +6687,15 @@ static struct mg_flash s_mg_flash_stm32h7 = {
66876687
#define FLASH_OPTSR_PRG 0x20
66886688
#define FLASH_SIZE_REG 0x1ff1e880
66896689

6690+
#define IS_DUALCORE() (MG_OTA == MG_OTA_STM32H7_DUAL_CORE)
6691+
66906692
MG_IRAM static bool is_dualbank(void) {
6693+
if (IS_DUALCORE()) {
6694+
// H745/H755 and H747/H757 are running on dual core.
6695+
// Using only the 1st bank (mapped to CM7), in order not to interfere
6696+
// with the 2nd bank (CM4), possibly causing CM4 to boot unexpectedly.
6697+
return false;
6698+
}
66916699
return (s_mg_flash_stm32h7.size < 2 * 1024 * 1024) ? false : true;
66926700
}
66936701

@@ -6824,6 +6832,10 @@ MG_IRAM static void single_bank_swap(char *p1, char *p2, size_t s, size_t ss) {
68246832

68256833
bool mg_ota_begin(size_t new_firmware_size) {
68266834
s_mg_flash_stm32h7.size = MG_REG(FLASH_SIZE_REG) * 1024;
6835+
if (IS_DUALCORE()) {
6836+
// Using only the 1st bank (mapped to CM7)
6837+
s_mg_flash_stm32h7.size /= 2;
6838+
}
68276839
return mg_ota_flash_begin(new_firmware_size, &s_mg_flash_stm32h7);
68286840
}
68296841

mongoose.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2651,7 +2651,8 @@ void mg_rpc_list(struct mg_rpc_req *r);
26512651
#define MG_OTA_NONE 0 // No OTA support
26522652
#define MG_OTA_STM32H5 1 // STM32 H5
26532653
#define MG_OTA_STM32H7 2 // STM32 H7
2654-
#define MG_OTA_STM32F 3 // STM32 F7/F4/F2
2654+
#define MG_OTA_STM32H7_DUAL_CORE 3 // STM32 H7 dual core
2655+
#define MG_OTA_STM32F 4 // STM32 F7/F4/F2
26552656
#define MG_OTA_CH32V307 100 // WCH CH32V307
26562657
#define MG_OTA_U2A 200 // Renesas U2A16, U2A8, U2A6
26572658
#define MG_OTA_RT1020 300 // IMXRT1020

src/ota.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
#define MG_OTA_NONE 0 // No OTA support
99
#define MG_OTA_STM32H5 1 // STM32 H5
1010
#define MG_OTA_STM32H7 2 // STM32 H7
11-
#define MG_OTA_STM32F 3 // STM32 F7/F4/F2
11+
#define MG_OTA_STM32H7_DUAL_CORE 3 // STM32 H7 dual core
12+
#define MG_OTA_STM32F 4 // STM32 F7/F4/F2
1213
#define MG_OTA_CH32V307 100 // WCH CH32V307
1314
#define MG_OTA_U2A 200 // Renesas U2A16, U2A8, U2A6
1415
#define MG_OTA_RT1020 300 // IMXRT1020

src/ota_stm32h7.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "log.h"
33
#include "ota.h"
44

5-
#if MG_OTA == MG_OTA_STM32H7
5+
#if MG_OTA == MG_OTA_STM32H7 || MG_OTA == MG_OTA_STM32H7_DUAL_CORE
66

77
// - H723/735 RM 4.3.3: Note: The application can simultaneously request a read
88
// and a write operation through the AXI interface.
@@ -35,7 +35,15 @@ static struct mg_flash s_mg_flash_stm32h7 = {
3535
#define FLASH_OPTSR_PRG 0x20
3636
#define FLASH_SIZE_REG 0x1ff1e880
3737

38+
#define IS_DUALCORE() (MG_OTA == MG_OTA_STM32H7_DUAL_CORE)
39+
3840
MG_IRAM static bool is_dualbank(void) {
41+
if (IS_DUALCORE()) {
42+
// H745/H755 and H747/H757 are running on dual core.
43+
// Using only the 1st bank (mapped to CM7), in order not to interfere
44+
// with the 2nd bank (CM4), possibly causing CM4 to boot unexpectedly.
45+
return false;
46+
}
3947
return (s_mg_flash_stm32h7.size < 2 * 1024 * 1024) ? false : true;
4048
}
4149

@@ -172,6 +180,10 @@ MG_IRAM static void single_bank_swap(char *p1, char *p2, size_t s, size_t ss) {
172180

173181
bool mg_ota_begin(size_t new_firmware_size) {
174182
s_mg_flash_stm32h7.size = MG_REG(FLASH_SIZE_REG) * 1024;
183+
if (IS_DUALCORE()) {
184+
// Using only the 1st bank (mapped to CM7)
185+
s_mg_flash_stm32h7.size /= 2;
186+
}
175187
return mg_ota_flash_begin(new_firmware_size, &s_mg_flash_stm32h7);
176188
}
177189

0 commit comments

Comments
 (0)