Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions libraries/SrcWrapper/inc/stm32_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,13 @@ __STATIC_INLINE void LL_RTC_SetBinMixBCDU(RTC_TypeDef *RTCx, uint32_t BinMixBcdU
}
#endif // STM32U0xx

/* STM32G0xx, STM32U0xx and some STM32U5xx defined USB_DRD_FS */
/* Some STM32 series define USB_DRD_FS instead of the legacy USB instance. */
#if !defined(USB) && defined(USB_DRD_FS)
#define USB USB_DRD_FS
#define PinMap_USB PinMap_USB_DRD_FS
#if defined(STM32H5xx) || defined(STM32U0xx) ||\
#if defined(STM32C5xx)
#define USB_BASE USB_DRD_FS_BASE
#elif defined(STM32H5xx) || defined(STM32U0xx) ||\
defined(STM32U3xx) || defined(STM32U5xx)
#define USB_BASE USB_DRD_BASE
#if !defined(__HAL_RCC_USB_CLK_ENABLE)
Expand Down
3 changes: 3 additions & 0 deletions libraries/USBDevice/inc/usbd_cdc_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ uint8_t CDC_getStopBits(void);
uint8_t CDC_getParity(void);
uint8_t CDC_getDataBits(void);

/* Optional board hook invoked after the host changes the CDC line coding. */
void CDC_LineCodingChanged(uint32_t bitrate);

#ifdef __cplusplus
}
#endif
Expand Down
16 changes: 11 additions & 5 deletions libraries/USBDevice/inc/usbd_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@ extern "C" {
#include "stm32_def.h"

#if defined(USE_HALV2_DRIVER)
#error "USB library is not yet compatible with HALv2 driver."
#else
#if !defined(STM32C5xx)
#warning "USB device support is currently implemented only for STM32C5xx HAL v2."
#endif
#endif

#if defined(STM32C5xx)
#define PCD_SNG_BUF HAL_PCD_SNG_BUF
#define PCD_DBL_BUF HAL_PCD_DBL_BUF
#endif

#if !defined(USB_BASE) && !defined(USB_OTG_DEVICE_BASE)
#error "This board does not support USB! Select 'None' in the 'Tools->USB interface' menu"
#endif
Expand All @@ -40,8 +48,6 @@ extern "C" {
#endif
#if !defined(USB_BASE) && !defined(USB_OTG_FS) && defined(USB_OTG_HS) && !defined(USE_USB_HS)
#error "This board support only USB High Speed! Select 'High Speed' or 'High Speed in Full Speed mode' in the 'Tools->USB interface' menu"
#endif

#endif
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -77,7 +83,7 @@ extern "C" {
#elif defined(STM32G0B1xx) || defined(STM32G0C1xx)
#define USB_IRQn USB_UCPD1_2_IRQn
#define USB_IRQHandler USB_UCPD1_2_IRQHandler
#elif defined(STM32C0xx) || defined(STM32H5xx) || defined(STM32U0xx)
#elif defined(STM32C0xx) || defined(STM32C5xx) || defined(STM32H5xx) || defined(STM32U0xx)
#define USB_IRQn USB_DRD_FS_IRQn
#define USB_IRQHandler USB_DRD_FS_IRQHandler
#elif defined(STM32U5xx) && !defined(USB_DRD_FS)
Expand Down
13 changes: 12 additions & 1 deletion libraries/USBDevice/inc/usbd_ep_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,21 @@ typedef struct {

#ifdef USBD_USE_CDC
#define PMA_CDC_OUT_BASE (PMA_EP0_IN_ADDR + USB_MAX_EP0_SIZE)
#if defined(STM32C5xx)
/*
* The C5 USB DRD FS peripheral is used with bulk double buffering disabled.
* Keep each CDC endpoint in its own 64-byte PMA area; in particular, the
* interrupt IN endpoint must not overlap the bulk IN data buffer.
*/
#define PMA_CDC_OUT_ADDR PMA_CDC_OUT_BASE
#define PMA_CDC_IN_ADDR (PMA_CDC_OUT_BASE + USB_FS_MAX_PACKET_SIZE)
#define PMA_CDC_CMD_ADDR (PMA_CDC_IN_ADDR + USB_FS_MAX_PACKET_SIZE)
#else
#define PMA_CDC_OUT_ADDR ((PMA_CDC_OUT_BASE + USB_FS_MAX_PACKET_SIZE) | \
(PMA_CDC_OUT_BASE << 16U))
#define PMA_CDC_IN_ADDR (PMA_CDC_OUT_BASE + USB_FS_MAX_PACKET_SIZE * 2)
#define PMA_CDC_CMD_ADDR (PMA_CDC_IN_ADDR + CDC_CMD_PACKET_SIZE)
#endif
#endif /* USBD_USE_CDC */
#ifdef USBD_USE_HID_COMPOSITE
#define PMA_MOUSE_IN_ADDR (PMA_EP0_IN_ADDR + HID_MOUSE_EPIN_SIZE)
Expand All @@ -86,4 +97,4 @@ extern const ep_desc_t ep_def[DEV_NUM_EP + 1];
#endif /* USBCON */
#endif /* __USBD_EP_CONF_H */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
5 changes: 5 additions & 0 deletions libraries/USBDevice/src/cdc/cdc_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ uint8_t *CDC_TransmitQueue_ReadBlock(CDC_TransmitQueue_TypeDef *queue,
} else {
*size = CDC_TRANSMIT_QUEUE_BUFFER_SIZE - queue->read;
}

/* Limit the queued transaction to one endpoint packet. */
if (*size > CDC_QUEUE_MAX_PACKET_SIZE) {
*size = CDC_QUEUE_MAX_PACKET_SIZE;
}
queue->reserved = *size;
return &queue->buffer[queue->read];
}
Expand Down
12 changes: 11 additions & 1 deletion libraries/USBDevice/src/cdc/usbd_cdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,11 @@ static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev,
static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
{
USBD_CDC_HandleTypeDef *hcdc;
#if defined(USE_HALV2_DRIVER)
hal_pcd_handle_t *hpcd = (hal_pcd_handle_t *)pdev->pData;
#else
PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef *)pdev->pData;
#endif

if (pdev->pClassDataCmsit[pdev->classId] == NULL) {
return (uint8_t)USBD_FAIL;
Expand All @@ -710,7 +714,13 @@ static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];

if ((pdev->ep_in[epnum & 0xFU].total_length > 0U) &&
((pdev->ep_in[epnum & 0xFU].total_length % hpcd->IN_ep[epnum & 0xFU].maxpacket) == 0U)) {
((pdev->ep_in[epnum & 0xFU].total_length %
#if defined(USE_HALV2_DRIVER)
hpcd->in_ep[epnum & 0xFU].max_packet
#else
hpcd->IN_ep[epnum & 0xFU].maxpacket
#endif
) == 0U)) {
/* Update the packet total length */
pdev->ep_in[epnum & 0xFU].total_length = 0U;

Expand Down
8 changes: 7 additions & 1 deletion libraries/USBDevice/src/cdc/usbd_cdc_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ USBD_CDC_LineCodingTypeDef linecoding = {
0x08 /* nb. of bits 8*/
};

/* Boards that need a CDC line-coding side effect can override this hook. */
WEAK void CDC_LineCodingChanged(uint32_t bitrate)
{
(void)bitrate;
}

/* Private functions ---------------------------------------------------------*/

/**
Expand Down Expand Up @@ -175,6 +181,7 @@ static int8_t USBD_CDC_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
linecoding.format = pbuf[4];
linecoding.paritytype = pbuf[5];
linecoding.datatype = pbuf[6];
CDC_LineCodingChanged(linecoding.bitrate);
break;

case CDC_GET_LINE_CODING:
Expand Down Expand Up @@ -406,4 +413,3 @@ uint8_t CDC_getDataBits(void)
#endif /* USBD_USE_CDC */
#endif /* USBCON */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

5 changes: 2 additions & 3 deletions libraries/USBDevice/src/usbd_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
******************************************************************************
*/
#ifdef USBCON
#if defined(USBCON) && !defined(USE_HALV2_DRIVER)
/* Includes ------------------------------------------------------------------*/
#include "usbd_core.h"
#include "usbd_if.h"
Expand Down Expand Up @@ -718,6 +718,5 @@ void USBD_LL_Delay(uint32_t Delay)
HAL_Delay(Delay);
}
#endif /* HAL_PCD_MODULE_ENABLED */
#endif /* USBCON */
#endif /* USBCON && !USE_HALV2_DRIVER */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Loading