Skip to content

Commit 329bb10

Browse files
committed
USB: review WakeUp IRQn and IRQHandler across series
Signed-off-by: Frederic Pillon <[email protected]>
1 parent adc9a43 commit 329bb10

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

cores/arduino/stm32/usb/usbd_conf.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
9999
__HAL_USB_WAKEUP_EXTI_ENABLE_RISING_EDGE();
100100
#endif
101101
__HAL_USB_WAKEUP_EXTI_ENABLE_IT();
102-
#if defined(STM32F1xx) || defined(STM32F3xx)
102+
#if defined(USB_WKUP_IRQn)
103103
/* USB Wakeup Interrupt */
104-
HAL_NVIC_EnableIRQ(USBWakeUp_IRQn);
104+
HAL_NVIC_EnableIRQ(USB_WKUP_IRQn);
105105

106106
/* Enable USB Wake-up interrupt */
107-
HAL_NVIC_SetPriority(USBWakeUp_IRQn, 0, 0);
107+
HAL_NVIC_SetPriority(USB_WKUP_IRQn, 0, 0);
108108
#endif
109109
}
110110
}
@@ -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));
@@ -368,8 +368,6 @@ void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
368368
USBD_LL_DevDisconnected(hpcd->pData);
369369
}
370370

371-
372-
373371
/**
374372
* @brief This function handles USB-On-The-Go FS/HS global interrupt request.
375373
* @param None
@@ -399,26 +397,26 @@ void USB_H_IRQHandler(void)
399397
#endif /* USB_H_IRQn */
400398

401399
/**
402-
/**
403-
* @brief This function handles USB OTG FS Wakeup IRQ Handler.
400+
* @brief This function handles USB Wakeup IRQ Handler.
404401
* @param None
405402
* @retval None
406403
*/
407404
#ifdef USE_USB_HS
408405
void OTG_HS_WKUP_IRQHandler(void)
409406
#elif defined(USB_OTG_FS)
410407
void OTG_FS_WKUP_IRQHandler(void)
408+
#elif defined(USB_WKUP_IRQHandler)
409+
void USB_WKUP_IRQHandler(void)
411410
#else
412-
void USBWakeUp_IRQHandler(void)
411+
void USBWakeUp_IRQHandler_dummy(void)
413412
#endif
414413
{
415414
if ((&g_hpcd)->Init.low_power_enable) {
416415
/* Reset SLEEPDEEP bit of Cortex System Control Register */
417416
SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
418417

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

423421
/* ungate PHY clock */
424422
__HAL_PCD_UNGATE_PHYCLOCK((&g_hpcd));

cores/arduino/stm32/usb/usbd_conf.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,22 @@ extern "C" {
4949
#define USB_IRQHandler USB_LP_CAN_RX0_IRQHandler
5050
#define USB_H_IRQn USB_HP_CAN_TX_IRQn
5151
#define USB_H_IRQHandler USB_HP_CAN_TX_IRQHandler
52+
#if defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32G4xx)
53+
#define USB_WKUP_IRQn USBWakeUp_RMP_IRQn
54+
#define USB_WKUP_IRQHandler USBWakeUp_RMP_IRQHandler
55+
#endif
5256
#else
5357
#define USB_IRQn USB_LP_IRQn
5458
#define USB_IRQHandler USB_LP_IRQHandler
5559
#define USB_H_IRQn USB_HP_IRQn
5660
#define USB_H_IRQHandler USB_HP_IRQHandler
61+
#if defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32G4xx)
62+
#define USB_WKUP_IRQn USBWakeUp_IRQn
63+
#define USB_WKUP_IRQHandler USBWakeUp_IRQHandler
64+
#else /* STM32L1xx || STM32WBxx */
65+
#define USB_WKUP_IRQn USB_FS_WKUP_IRQn
66+
#define USB_WKUP_IRQHandler USB_FS_WKUP_IRQHandler
67+
#endif
5768
#endif
5869
#elif defined(STM32L5xx)
5970
#define USB_IRQn USB_FS_IRQn

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, call '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)