Skip to content

Commit df7431d

Browse files
committed
TARGET_STM: Improve H747 dual core Deepsleep robustness
1 parent affe711 commit df7431d

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

targets/TARGET_STM/TARGET_STM32H7/objects.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ struct analogin_s {
151151
#if defined(DUAL_CORE)
152152
/* HW semaphore Complement ID list defined in hw_conf.h from STM32WB */
153153
/* Index of the semaphore used to manage the entry Stop Mode procedure */
154-
#define CFG_HW_ENTRY_STOP_MODE_SEMID 4
155-
#define CFG_HW_ENTRY_STOP_MODE_MASK_SEMID (1 << CFG_HW_ENTRY_STOP_MODE_SEMID)
154+
#define CFG_HW_STOP_MODE_SEMID 4
155+
#define CFG_HW_STOP_MODE_MASK_SEMID (1 << CFG_HW_STOP_MODE_SEMID)
156156

157157
/* Index of the semaphore used to access the RCC */
158158
#define CFG_HW_RCC_SEMID 3

targets/TARGET_STM/mbed_overrides.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void mbed_sdk_init()
6060
/* CM4 boots at the same time than CM7. It is necessary to synchronize with CM7, by mean of HSEM, that CM7 finishes its initialization. */
6161

6262
/* Activate HSEM notification for Cortex-M4*/
63-
LL_HSEM_EnableIT_C2IER(HSEM, CFG_HW_ENTRY_STOP_MODE_MASK_SEMID);
63+
LL_HSEM_EnableIT_C2IER(HSEM, CFG_HW_STOP_MODE_MASK_SEMID);
6464

6565
/*
6666
* Domain D2 goes to STOP mode (Cortex-M4 in deep-sleep) waiting for
@@ -89,7 +89,8 @@ void mbed_sdk_init()
8989
LL_LPM_EnableSleep();
9090

9191
/* Clear HSEM flag */
92-
LL_HSEM_ClearFlag_C2ICR(HSEM, CFG_HW_ENTRY_STOP_MODE_MASK_SEMID);
92+
LL_HSEM_DisableIT_C2IER(HSEM, CFG_HW_STOP_MODE_MASK_SEMID);
93+
LL_HSEM_ClearFlag_C2ICR(HSEM, CFG_HW_STOP_MODE_MASK_SEMID);
9394
}
9495

9596
// Update the SystemCoreClock variable.
@@ -109,9 +110,9 @@ void mbed_sdk_init()
109110
/* Check wether CM4 boot in parallel with CM7. If CM4 was gated but CM7 trigger the CM4 boot. No need to wait for synchronization.
110111
otherwise CM7 should wakeup CM4 when system clocks initialization is done. */
111112
if (READ_BIT(SYSCFG->UR1, SYSCFG_UR1_BCM4)) {
112-
LL_HSEM_1StepLock(HSEM, CFG_HW_ENTRY_STOP_MODE_SEMID);
113+
LL_HSEM_1StepLock(HSEM, CFG_HW_STOP_MODE_SEMID);
113114
/*Release HSEM in order to notify the CPU2(CM4)*/
114-
LL_HSEM_ReleaseLock(HSEM, CFG_HW_ENTRY_STOP_MODE_SEMID, 0);
115+
LL_HSEM_ReleaseLock(HSEM, CFG_HW_STOP_MODE_SEMID, 0);
115116
} else {
116117
LL_RCC_ForceCM4Boot();
117118
}

targets/TARGET_STM/sleep.c

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ static void ForcePeriphOutofDeepSleep(void)
5757
uint32_t pFLatency = 0;
5858
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
5959

60-
#if defined(DUAL_CORE)
61-
while (LL_HSEM_1StepLock(HSEM, CFG_HW_RCC_SEMID)) {
62-
}
63-
#endif /* DUAL_CORE */
6460
/* Get the Clocks configuration according to the internal RCC registers */
6561
HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency);
6662

@@ -85,9 +81,6 @@ static void ForcePeriphOutofDeepSleep(void)
8581
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency) != HAL_OK) {
8682
error("ForcePeriphOutofDeepSleep clock issue\r\n");
8783
}
88-
#if defined(DUAL_CORE)
89-
LL_HSEM_ReleaseLock(HSEM, CFG_HW_RCC_SEMID, HSEM_CR_COREID_CURRENT);
90-
#endif /* DUAL_CORE */
9184
}
9285

9386

@@ -98,10 +91,6 @@ static void ForceOscOutofDeepSleep(void)
9891
/* Enable Power Control clock */
9992
__HAL_RCC_PWR_CLK_ENABLE();
10093

101-
#if defined(DUAL_CORE)
102-
while (LL_HSEM_1StepLock(HSEM, CFG_HW_RCC_SEMID)) {
103-
}
104-
#endif /* DUAL_CORE */
10594
/* Get the Oscillators configuration according to the internal RCC registers */
10695
HAL_RCC_GetOscConfig(&RCC_OscInitStruct);
10796

@@ -121,9 +110,7 @@ static void ForceOscOutofDeepSleep(void)
121110
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
122111
error("ForceOscOutofDeepSleep clock issue\r\n");
123112
}
124-
#if defined(DUAL_CORE)
125-
LL_HSEM_ReleaseLock(HSEM, CFG_HW_RCC_SEMID, HSEM_CR_COREID_CURRENT);
126-
#endif /* DUAL_CORE */
113+
127114
}
128115

129116

@@ -236,25 +223,43 @@ __WEAK void hal_deepsleep(void)
236223
* us_ticker timestamp until the us_ticker context is restored. */
237224
mbed_sdk_inited = 0;
238225

239-
/* We've seen unstable PLL CLK configuration when DEEP SLEEP exits just few µs after being entered
240-
* So we need to force clock init out of Deep Sleep.
241-
* This init has been split into 2 separate functions so that the involved structures are not allocated on the stack in parallel.
242-
* This will reduce the maximum stack usage in case on non-optimized / debug compilers settings
243-
*/
244-
ForceOscOutofDeepSleep();
245-
ForcePeriphOutofDeepSleep();
246-
247226
/* After wake-up from STOP reconfigure the PLL */
248227
#if defined(DUAL_CORE)
249-
while (LL_HSEM_1StepLock(HSEM, CFG_HW_RCC_SEMID)) {
228+
/* CFG_HW_STOP_MODE_SEMID is used to protect read access to STOP flag, and this avoid both core to configure clocks if both exit from stop at the same time */
229+
while (LL_HSEM_1StepLock(HSEM, CFG_HW_STOP_MODE_SEMID)) {
250230
}
251231

252-
if ((LL_RCC_GetSysClkSource() == LL_RCC_SYS_CLKSOURCE_STATUS_HSI)) {
253-
LL_PWR_ClearFlag_CPU();
232+
/* Clocks need to be reconfigured only if system has been in stop mode */
233+
if (LL_PWR_CPU_IsActiveFlag_STOP() && LL_PWR_CPU2_IsActiveFlag_STOP()) {
234+
/* We've seen unstable PLL CLK configuration when DEEP SLEEP exits just few µs after being entered
235+
* So we need to force clock init out of Deep Sleep.
236+
* This init has been split into 2 separate functions so that the involved structures are not allocated on the stack in parallel.
237+
* This will reduce the maximum stack usage in case on non-optimized / debug compilers settings
238+
*/
239+
while (LL_HSEM_1StepLock(HSEM, CFG_HW_RCC_SEMID)) {
240+
}
241+
ForceOscOutofDeepSleep();
242+
ForcePeriphOutofDeepSleep();
254243
SetSysClock();
244+
LL_HSEM_ReleaseLock(HSEM, CFG_HW_RCC_SEMID, HSEM_CR_COREID_CURRENT);
255245
}
256-
LL_HSEM_ReleaseLock(HSEM, CFG_HW_RCC_SEMID, HSEM_CR_COREID_CURRENT);
246+
#if defined(CORE_CM7)
247+
LL_PWR_ClearFlag_CPU();
248+
#elif defined(CORE_CM4)
249+
LL_PWR_ClearFlag_CPU2();
257250
#else
251+
#error "Core not supported"
252+
#endif
253+
254+
LL_HSEM_ReleaseLock(HSEM, CFG_HW_STOP_MODE_SEMID, HSEM_CR_COREID_CURRENT);
255+
#else
256+
/* We've seen unstable PLL CLK configuration when DEEP SLEEP exits just few µs after being entered
257+
* So we need to force clock init out of Deep Sleep.
258+
* This init has been split into 2 separate functions so that the involved structures are not allocated on the stack in parallel.
259+
* This will reduce the maximum stack usage in case on non-optimized / debug compilers settings
260+
*/
261+
ForceOscOutofDeepSleep();
262+
ForcePeriphOutofDeepSleep();
258263
SetSysClock();
259264
#endif
260265

0 commit comments

Comments
 (0)