Skip to content

Commit 15d0fa8

Browse files
committed
[stm32] Adapt startup code and clock configuration for H7 dual-core
1 parent f610421 commit 15d0fa8

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

src/modm/platform/clock/stm32/rcc.cpp.in

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,4 +529,22 @@ Rcc::setCanPrescaler(CanPrescaler prescaler)
529529
}
530530
%% endif
531531

532+
%% if target.family == "h7" and target.name in ["45", "47", "55", "57"] and target.core == "m7"
533+
void
534+
Rcc::bootCortexM4()
535+
{
536+
// Enable Cortex-M4 boot in case it is disabled via option bytes
537+
RCC->GCR |= RCC_GCR_BOOT_C2;
538+
539+
// Lock hardware semaphore 0
540+
// Cortex-M4 startup code will continue to boot
541+
RCC->AHB4ENR |= RCC_AHB4ENR_HSEMEN_Msk;
542+
constexpr unsigned CortexM7CoreId{3};
543+
HSEM->R[0] = HSEM_R_LOCK | (CortexM7CoreId << HSEM_R_COREID_Pos);
544+
545+
// Wait for unlock by Cortex-M4 core
546+
while((HSEM->R[0] & HSEM_R_LOCK) != 0);
547+
}
548+
%% endif
549+
532550
}

src/modm/platform/clock/stm32/rcc.hpp.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,17 @@ public:
826826
setVoltageScaling(VoltageScaling voltage, uint32_t waitCycles = 2048);
827827
%% endif
828828

829+
%% if target.family == "h7" and target.name in ["45", "47", "55", "57"] and target.core == "m7"
830+
/**
831+
* Release lock in Cortex-M4 startup code to continue boot. Call this function
832+
* after system initialization has been completed.
833+
*
834+
* In case automatic Cortex-M4 boot is disabled in the option bytes, the core will
835+
* be enabled.
836+
*/
837+
static void bootCortexM4();
838+
%% endif
839+
829840
public:
830841
/** Set flash latency for CPU frequency and voltage.
831842
* Does nothing if CPU frequency is too high for the available

src/modm/platform/clock/systick/module.lb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def build(env):
3636
# Interrupt Frequency must not overflow the 2^24 SysTick->VAL!
3737
freq = 1000 if "m0" in core else 4
3838
# STM32H7 goes up to 550MHz, so make the Frequency higher
39-
if target.family == "h7": freq = 100;
39+
if target.family == "h7" and target.get("core", "cm7") == "cm7":
40+
freq = 100
4041

4142
# SysTick clock prescaler is dynamically chosen as /1 or /8
4243
div = 8

src/modm/platform/core/stm32/startup_platform.c.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@
2828
void
2929
__modm_initialize_platform(void)
3030
{
31+
%% if target.family == "h7" and target.name in ["45", "47", "55", "57"] and target.core == "m4"
32+
/* Use hardware semaphore 0 as a spin lock to delay Cortex-M4 boot until
33+
* the system has been initialized by the Cortex-M7 core */
34+
RCC->AHB4ENR |= RCC_AHB4ENR_HSEMEN_Msk;
35+
// wait until hardware semaphore 0 has been locked by Cortex-M7
36+
while((HSEM->R[0] & HSEM_R_LOCK) == 0);
37+
// unlock hardware semaphore
38+
const unsigned CortexM7CoreId = 3;
39+
HSEM->CR = HSEM->KEYR | (CortexM7CoreId << HSEM_CR_COREID_Pos);
40+
%% endif
41+
3142
// Enable SYSCFG
3243
%% if target.family == "g0"
3344
RCC->APBENR2 |= RCC_APBENR2_SYSCFGEN;

src/modm/platform/gpio/stm32/enable.cpp.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,6 @@ modm_gpio_enable(void)
5959
%% endfor
6060
}
6161

62+
%% if not (target.family == "h7" and target.name in ["45", "47", "55", "57"] and target.core == "m4")
6263
MODM_HARDWARE_INIT_ORDER(modm_gpio_enable, 80);
64+
%% endif

0 commit comments

Comments
 (0)