Skip to content

Commit 1b869c5

Browse files
committed
USB: add weaked system clock config from resume
USBD_SystemClockConfigFromResume allows to configure system clock and system IP clocks after wake-up from USB resume callBack. It can be redefined by user at sketch level. By default, calls 'SystemClock_Config()'. Signed-off-by: Frederic Pillon <[email protected]>
1 parent 8d17711 commit 1b869c5

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

cores/arduino/stm32/usb/usbd_conf.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
317317
void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
318318
{
319319
if (hpcd->Init.low_power_enable) {
320-
SystemClock_Config();
320+
USBD_SystemClockConfigFromResume();
321321

322322
/* Reset SLEEPDEEP bit of Cortex System Control Register */
323323
SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
@@ -415,9 +415,8 @@ void USB_H_IRQHandler(void)
415415
/* Reset SLEEPDEEP bit of Cortex System Control Register */
416416
SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
417417

418-
/* Configures system clock after wake-up from STOP: enable HSE, PLL and select
419-
PLL as system clock source (HSE and PLL are disabled in STOP mode) */
420-
SystemClock_Config();
418+
/* Configures system clock after wake-up */
419+
USBD_SystemClockConfigFromResume();
421420

422421
/* ungate PHY clock */
423422
__HAL_PCD_UNGATE_PHYCLOCK((&g_hpcd));

cores/arduino/stm32/usb/usbd_if.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,19 @@ void USBD_CDC_init(void)
175175
CDC_init();
176176
}
177177
#endif /* USBD_USE_CDC */
178+
179+
/**
180+
* @brief Configures system clock and system IP clocks after wake-up from USB
181+
* resume callBack
182+
* @note Weaked function which can be redefined by user at the sketch level.
183+
* By default, calls 'SystemClock_Config()'.
184+
* @param None
185+
* @retval None
186+
*/
187+
WEAK void USBD_SystemClockConfigFromResume(void)
188+
{
189+
configIPClock();
190+
SystemClock_Config();
191+
}
192+
178193
#endif /* USBCON */

cores/arduino/stm32/usb/usbd_if.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ void USBD_reenumerate(void);
2727
#ifdef USBD_USE_CDC
2828
void USBD_CDC_init(void);
2929
#endif
30+
31+
/* Weaked function */
32+
void USBD_SystemClockConfigFromResume(void);
33+
3034
#ifdef __cplusplus
3135
}
3236
#endif

0 commit comments

Comments
 (0)