Skip to content

Add composite MSC CDC USB device #586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 20 commits into from
Closed
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
Empty file modified CI/utils/gen_wrapper.sh
100755 → 100644
Empty file.
15 changes: 9 additions & 6 deletions cores/arduino/stm32/usb/cdc/usbd_cdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

#ifdef USBCON
#ifdef USBD_USE_CDC
#ifndef USBD_USE_CDC_COMPOSITE

/* Includes ------------------------------------------------------------------*/
#include "usbd_cdc.h"
Expand Down Expand Up @@ -190,7 +191,7 @@ __ALIGN_BEGIN uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
0x01, /* bNumEndpoints: One endpoints used */
0x02, /* bInterfaceClass: Communication Interface Class */
0x02, /* bInterfaceSubClass: Abstract Control Model */
0x00, /* bInterfaceProtocol: No specific protocol */
0x01, /* bInterfaceProtocol: Common AT commands */
0x00, /* iInterface: */

/*Header Functional Descriptor*/
Expand Down Expand Up @@ -285,7 +286,7 @@ __ALIGN_BEGIN uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
0x01, /* bNumEndpoints: One endpoints used */
0x02, /* bInterfaceClass: Communication Interface Class */
0x02, /* bInterfaceSubClass: Abstract Control Model */
0x00, /* bInterfaceProtocol: No specific protocol */
0x01, /* bInterfaceProtocol: Common AT commands */
0x00, /* iInterface: */

/*Header Functional Descriptor*/
Expand Down Expand Up @@ -375,7 +376,7 @@ __ALIGN_BEGIN uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIG
0x01, /* bNumEndpoints: One endpoints used */
0x02, /* bInterfaceClass: Communication Interface Class */
0x02, /* bInterfaceSubClass: Abstract Control Model */
0x00, /* bInterfaceProtocol: No specific protocol */
0x01, /* bInterfaceProtocol: Common AT commands */
0x00, /* iInterface: */

/*Header Functional Descriptor*/
Expand Down Expand Up @@ -651,9 +652,9 @@ static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
USBD_CDC_ItfTypeDef *ctrl = (USBD_CDC_ItfTypeDef *)pdev->pUserData;

if (pdev->pClassData != NULL) {
if ((pdev->ep_in[epnum].total_length > 0U) && ((pdev->ep_in[epnum].total_length % hpcd->IN_ep[epnum].maxpacket) == 0U)) {
if ((hcdc->TxLastLength > 0U) && ((hcdc->TxLastLength % hpcd->IN_ep[epnum].maxpacket) == 0U)) {
/* Update the packet total length */
pdev->ep_in[epnum].total_length = 0U;
hcdc->TxLastLength = 0U;

/* Send ZLP */
USBD_LL_Transmit(pdev, epnum, NULL, 0U);
Expand Down Expand Up @@ -835,7 +836,7 @@ uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)
hcdc->TxState = 1U;

/* Update the packet total length */
pdev->ep_in[CDC_IN_EP & 0xFU].total_length = hcdc->TxLength;
hcdc->TxLastLength = hcdc->TxLength;

/* Transmit next packet */
USBD_LL_Transmit(pdev, CDC_IN_EP, hcdc->TxBuffer,
Expand Down Expand Up @@ -894,6 +895,8 @@ uint8_t USBD_CDC_ClearBuffer(USBD_HandleTypeDef *pdev)
}
}

#endif /* !USBD_USE_CDC_COMPOSITE */
#endif /* USBD_USE_CDC */
#endif /* USBCON */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

41 changes: 30 additions & 11 deletions cores/arduino/stm32/usb/cdc/usbd_cdc.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern "C" {

/* Includes ------------------------------------------------------------------*/
#include "usbd_ioreq.h"
#include "usbd_ep_conf.h"
#include <stdint.h>

/** @addtogroup STM32_USB_DEVICE_LIBRARY
* @{
Expand All @@ -38,18 +38,33 @@ extern "C" {
* @{
*/


/** @defgroup usbd_cdc_Exported_Defines
* @{
*/

#ifdef USBD_USE_CDC_COMPOSITE
#define CDC_IN_EP 0x82U /* EP2 for data IN */
#define CDC_OUT_EP 0x02U /* EP2 for data OUT */
#define CDC_CMD_EP 0x83U /* EP3 for CDC commands */
#else
#define CDC_IN_EP 0x82U /* EP1 for data IN */
#define CDC_OUT_EP 0x01U /* EP1 for data OUT */
#define CDC_CMD_EP 0x83U /* EP2 for CDC commands */
#endif

#ifndef CDC_HS_BINTERVAL
#define CDC_HS_BINTERVAL 0x10U
#define CDC_HS_BINTERVAL 0x10U
#endif /* CDC_HS_BINTERVAL */

#ifndef CDC_FS_BINTERVAL
#define CDC_FS_BINTERVAL 0x10U
#define CDC_FS_BINTERVAL 0x10U
#endif /* CDC_FS_BINTERVAL */

/* CDC Endpoints parameters */
/* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */
#define CDC_DATA_HS_MAX_PACKET_SIZE 512U /* Endpoint IN & OUT Packet size */
#define CDC_DATA_FS_MAX_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */
#define CDC_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */

#define USB_CDC_CONFIG_DESC_SIZ 67U
#define CDC_DATA_HS_IN_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE
Expand Down Expand Up @@ -99,20 +114,23 @@ typedef struct _USBD_CDC_Itf {

} USBD_CDC_ItfTypeDef;

#ifndef __IO
#define __IO volatile /*!< \brief Defines 'read / write' permissions */
#endif

typedef struct {
typedef struct _USBD_CDC_HandleTypeDef {
uint32_t data[CDC_DATA_HS_MAX_PACKET_SIZE / 4U]; /* Force 32bits alignment */
uint8_t CmdOpCode;
uint8_t CmdLength;
uint8_t *RxBuffer;
uint8_t *TxBuffer;
uint8_t *RxBuffer;
uint8_t *TxBuffer;
uint32_t RxLength;
uint32_t TxLength;
uint32_t TxLastLength;

__IO uint32_t TxState;
__IO uint32_t RxState;
}
USBD_CDC_HandleTypeDef;
} USBD_CDC_HandleTypeDef;



Expand All @@ -127,8 +145,8 @@ USBD_CDC_HandleTypeDef;
/** @defgroup USBD_CORE_Exported_Variables
* @{
*/

extern USBD_ClassTypeDef USBD_CDC;
struct _Device_cb; // USBD_ClassTypeDef
extern struct _Device_cb USBD_CDC;
#define USBD_CDC_CLASS &USBD_CDC
/**
* @}
Expand Down Expand Up @@ -170,3 +188,4 @@ uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev);
*/

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

2 changes: 2 additions & 0 deletions cores/arduino/stm32/usb/cdc/usbd_cdc_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#ifdef USBCON
#ifdef USBD_USE_CDC
#ifndef USBD_USE_CDC_COMPOSITE

/* Includes ------------------------------------------------------------------*/
#include "usbd_desc.h"
Expand Down Expand Up @@ -335,6 +336,7 @@ bool CDC_resume_receive(void)
return false;
}

#endif /* !USBD_USE_CDC_COMPOSITE */
#endif /* USBD_USE_CDC */
#endif /* USBCON */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Expand Down
Loading