Skip to content

Commit 90179d0

Browse files
authored
Merge pull request #1374 from fpistm/USB
USB reviews and Device library update
2 parents cd912ef + 9181ce9 commit 90179d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+7046
-3081
lines changed

cores/arduino/stm32/usb/cdc/usbd_cdc.c

Lines changed: 297 additions & 241 deletions
Large diffs are not rendered by default.

cores/arduino/stm32/usb/cdc/usbd_cdc.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ extern "C" {
3838
* @{
3939
*/
4040

41+
4142
/** @defgroup usbd_cdc_Exported_Defines
4243
* @{
4344
*/
@@ -58,6 +59,7 @@ extern "C" {
5859
#define CDC_DATA_FS_IN_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE
5960
#define CDC_DATA_FS_OUT_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE
6061

62+
#define CDC_REQ_MAX_DATA_SIZE 0x7U
6163
/*---------------------------------------------------------------------*/
6264
/* CDC definitions */
6365
/*---------------------------------------------------------------------*/
@@ -100,7 +102,7 @@ typedef struct _USBD_CDC_Itf {
100102

101103

102104
typedef struct {
103-
uint32_t data[CDC_DATA_HS_MAX_PACKET_SIZE / 4U]; /* Force 32bits alignment */
105+
uint32_t data[CDC_DATA_HS_MAX_PACKET_SIZE / 4U]; /* Force 32-bit alignment */
104106
uint8_t CmdOpCode;
105107
uint8_t CmdLength;
106108
uint8_t *RxBuffer;
@@ -126,25 +128,25 @@ typedef struct {
126128
* @{
127129
*/
128130

129-
extern USBD_ClassTypeDef USBD_CDC;
130-
#define USBD_CDC_CLASS &USBD_CDC
131+
extern USBD_ClassTypeDef USBD_CDC;
132+
#define USBD_CDC_CLASS &USBD_CDC
131133
/**
132134
* @}
133135
*/
134136

135137
/** @defgroup USB_CORE_Exported_Functions
136138
* @{
137139
*/
138-
uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev,
139-
USBD_CDC_ItfTypeDef *fops);
140+
uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev,
141+
USBD_CDC_ItfTypeDef *fops);
140142

141-
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff,
142-
uint32_t length);
143+
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff,
144+
uint32_t length);
143145

144-
uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff);
145-
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev);
146-
uint8_t USBD_CDC_ClearBuffer(USBD_HandleTypeDef *pdev);
147-
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev);
146+
uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff);
147+
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev);
148+
uint8_t USBD_CDC_ClearBuffer(USBD_HandleTypeDef *pdev);
149+
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev);
148150
/**
149151
* @}
150152
*/

cores/arduino/stm32/usb/cdc/usbd_cdc_if.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static int8_t USBD_CDC_Receive(uint8_t *Buf, uint32_t *Len)
243243

244244
/**
245245
* @brief USBD_CDC_TransmitCplt
246-
* Data transmited callback
246+
* Data transmitted callback
247247
*
248248
* @note
249249
* This function is IN transfer complete callback used to inform user that

cores/arduino/stm32/usb/hid/usbd_hid_composite.c

Lines changed: 268 additions & 246 deletions
Large diffs are not rendered by default.

cores/arduino/stm32/usb/usbd_conf.c

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,22 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
7373
/* Enable USB FS Clock */
7474
__HAL_RCC_USB_CLK_ENABLE();
7575

76-
#if defined (USE_USB_INTERRUPT_REMAPPED)
77-
/*USB interrupt remapping enable */
76+
#if defined(SYSCFG_CFGR1_USB_IT_RMP) && defined(USE_USB_INTERRUPT_REMAPPED)
77+
/* USB interrupt remapping enable */
7878
__HAL_REMAPINTERRUPT_USB_ENABLE();
7979
#endif
8080

81-
#if defined(STM32G4xx) || defined(STM32WBxx)
81+
#if defined(USB_H_IRQn)
82+
/* Set USB High priority Interrupt priority */
8283
HAL_NVIC_SetPriority(USB_HP_IRQn, USBD_IRQ_PRIO, USBD_IRQ_SUBPRIO);
84+
/* Enable USB High priority Interrupt */
8385
HAL_NVIC_EnableIRQ(USB_HP_IRQn);
84-
HAL_NVIC_SetPriority(USB_LP_IRQn, USBD_IRQ_PRIO, USBD_IRQ_SUBPRIO);
85-
HAL_NVIC_EnableIRQ(USB_LP_IRQn);
86-
#else
87-
/* Set USB FS Interrupt priority */
86+
#endif
87+
/* Set USB Interrupt priority */
8888
HAL_NVIC_SetPriority(USB_IRQn, USBD_IRQ_PRIO, USBD_IRQ_SUBPRIO);
8989

90-
/* Enable USB FS Interrupt */
90+
/* Enable USB Interrupt */
9191
HAL_NVIC_EnableIRQ(USB_IRQn);
92-
#endif /* STM32WBxx */
9392

9493
if (hpcd->Init.low_power_enable == 1) {
9594
/* Enable EXTI for USB wakeup */
@@ -100,12 +99,12 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
10099
__HAL_USB_WAKEUP_EXTI_ENABLE_RISING_EDGE();
101100
#endif
102101
__HAL_USB_WAKEUP_EXTI_ENABLE_IT();
103-
#if defined(STM32F1xx) || defined(STM32F3xx)
102+
#if defined(USB_WKUP_IRQn)
104103
/* USB Wakeup Interrupt */
105-
HAL_NVIC_EnableIRQ(USBWakeUp_IRQn);
104+
HAL_NVIC_EnableIRQ(USB_WKUP_IRQn);
106105

107106
/* Enable USB Wake-up interrupt */
108-
HAL_NVIC_SetPriority(USBWakeUp_IRQn, 0, 0);
107+
HAL_NVIC_SetPriority(USB_WKUP_IRQn, 0, 0);
109108
#endif
110109
}
111110
}
@@ -163,7 +162,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
163162
/* Enable USB HS Clocks */
164163
__HAL_RCC_USB_OTG_HS_CLK_ENABLE();
165164

166-
/* Set USBHS Interrupt priority */
165+
/* Set USB HS Interrupt priority */
167166
HAL_NVIC_SetPriority(OTG_HS_IRQn, USBD_IRQ_PRIO, USBD_IRQ_SUBPRIO);
168167

169168
/* Enable USB HS Interrupt */
@@ -318,7 +317,7 @@ void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
318317
void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
319318
{
320319
if (hpcd->Init.low_power_enable) {
321-
SystemClock_Config();
320+
USBD_SystemClockConfigFromResume();
322321

323322
/* Reset SLEEPDEEP bit of Cortex System Control Register */
324323
SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
@@ -369,8 +368,6 @@ void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
369368
USBD_LL_DevDisconnected(hpcd->pData);
370369
}
371370

372-
373-
374371
/**
375372
* @brief This function handles USB-On-The-Go FS/HS global interrupt request.
376373
* @param None
@@ -387,47 +384,39 @@ void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
387384
HAL_PCD_IRQHandler(&g_hpcd);
388385
}
389386

390-
#if defined(STM32WBxx)
387+
#if defined(USB_H_IRQn)
391388
/**
392389
* @brief This function handles USB high priority interrupt.
393390
* @param None
394391
* @retval None
395392
*/
396-
void USB_HP_IRQHandler(void)
393+
void USB_H_IRQHandler(void)
397394
{
398395
HAL_PCD_IRQHandler(&g_hpcd);
399396
}
397+
#endif /* USB_H_IRQn */
400398

401399
/**
402-
* @brief This function handles USB low priority interrupt, USB wake-up interrupt through EXTI line 28.
403-
* @param None
404-
* @retval None
405-
*/
406-
void USB_LP_IRQHandler(void)
407-
{
408-
HAL_PCD_IRQHandler(&g_hpcd);
409-
}
410-
#else
411-
/**
412-
* @brief This function handles USB OTG FS Wakeup IRQ Handler.
400+
* @brief This function handles USB Wakeup IRQ Handler.
413401
* @param None
414402
* @retval None
415403
*/
416404
#ifdef USE_USB_HS
417405
void OTG_HS_WKUP_IRQHandler(void)
418406
#elif defined(USB_OTG_FS)
419407
void OTG_FS_WKUP_IRQHandler(void)
408+
#elif defined(USB_WKUP_IRQHandler)
409+
void USB_WKUP_IRQHandler(void)
420410
#else
421-
void USBWakeUp_IRQHandler(void)
411+
void USBWakeUp_IRQHandler_dummy(void)
422412
#endif
423413
{
424414
if ((&g_hpcd)->Init.low_power_enable) {
425415
/* Reset SLEEPDEEP bit of Cortex System Control Register */
426416
SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
427417

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

432421
/* ungate PHY clock */
433422
__HAL_PCD_UNGATE_PHYCLOCK((&g_hpcd));
@@ -442,7 +431,7 @@ void USB_LP_IRQHandler(void)
442431
__HAL_USB_WAKEUP_EXTI_CLEAR_FLAG();
443432
#endif
444433
}
445-
#endif
434+
446435
/*******************************************************************************
447436
LL Driver Interface (USB Device Library --> PCD)
448437
*******************************************************************************/
@@ -644,7 +633,7 @@ uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
644633
/**
645634
* @brief Assigns a USB address to the device.
646635
* @param pdev: Device handle
647-
* @param ep_addr: Endpoint Number
636+
* @param dev_addr: Endpoint Number
648637
* @retval USBD Status
649638
*/
650639
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr)

0 commit comments

Comments
 (0)