Skip to content

STM32: allow HS USB endpoints and increase USB OTG_HS endpoints number #13816

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

Merged
merged 2 commits into from
Nov 11, 2020
Merged
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 drivers/include/drivers/USBCDC.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class AsyncOp;
* @{
*/

#define CDC_MAX_PACKET_SIZE 64

class USBCDC: public USBDevice {
public:

Expand Down Expand Up @@ -219,13 +221,13 @@ class USBCDC: public USBDevice {

OperationList<AsyncWrite> _tx_list;
bool _tx_in_progress;
uint8_t _tx_buffer[64];
uint8_t _tx_buffer[CDC_MAX_PACKET_SIZE];
uint8_t *_tx_buf;
uint32_t _tx_size;

OperationList<AsyncRead> _rx_list;
bool _rx_in_progress;
uint8_t _rx_buffer[64];
uint8_t _rx_buffer[CDC_MAX_PACKET_SIZE];
uint8_t *_rx_buf;
uint32_t _rx_size;
};
Expand Down
2 changes: 0 additions & 2 deletions drivers/source/usb/USBCDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ static const uint8_t cdc_line_coding_default[7] = {0x80, 0x25, 0x00, 0x00, 0x00,
#define CLS_DTR (1 << 0)
#define CLS_RTS (1 << 1)

#define CDC_MAX_PACKET_SIZE 64

class USBCDC::AsyncWrite: public AsyncOp {
public:
AsyncWrite(USBCDC *serial, uint8_t *buf, uint32_t size):
Expand Down
29 changes: 28 additions & 1 deletion targets/TARGET_STM/USBPhy_STM32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,29 @@
#define IDX_TO_EP(idx) (((idx) >> 1)|((idx) & 1) << 7)

/* endpoint defines */
#define NUM_ENDPOINTS 4

#if (MBED_CONF_TARGET_USB_SPEED == USE_USB_OTG_HS)

#define NUM_ENDPOINTS 6
#define MAX_PACKET_SIZE_NON_ISO 512
#define MAX_PACKET_SIZE_ISO 1023

#else

#define NUM_ENDPOINTS 4
#define MAX_PACKET_SIZE_NON_ISO 64
#define MAX_PACKET_SIZE_ISO (256 + 128) // Spec can go up to 1023, only ram for this though

#endif

static const uint32_t tx_ep_sizes[NUM_ENDPOINTS] = {
MAX_PACKET_SIZE_NON_ISO,
MAX_PACKET_SIZE_NON_ISO,
MAX_PACKET_SIZE_NON_ISO,
#if (MBED_CONF_TARGET_USB_SPEED == USE_USB_OTG_HS)
MAX_PACKET_SIZE_NON_ISO,
MAX_PACKET_SIZE_NON_ISO,
#endif
MAX_PACKET_SIZE_ISO
};

Expand Down Expand Up @@ -333,8 +348,11 @@ void USBPhyHw::init(USBPhyEvents *events)
total_bytes += fifo_size;
}

#if (MBED_CONF_TARGET_USB_SPEED != USE_USB_OTG_HS)
/* 1.25 kbytes */
MBED_ASSERT(total_bytes <= 1280);
#endif
Comment on lines +351 to +354
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if this total_bytes calculation is really useful...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably it can be avoided, there are a lot of other sanity checks in the endpoint creation phase


#endif

// Configure interrupt vector
Expand Down Expand Up @@ -424,11 +442,18 @@ void USBPhyHw::remote_wakeup()
const usb_ep_table_t *USBPhyHw::endpoint_table()
{
static const usb_ep_table_t table = {
#if (MBED_CONF_TARGET_USB_SPEED != USE_USB_OTG_HS)
1280, // 1.25K for endpoint buffers but space is allocated up front
#else
4096,
#endif
{
{USB_EP_ATTR_ALLOW_CTRL | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0},
{USB_EP_ATTR_ALLOW_BULK | USB_EP_ATTR_ALLOW_INT | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0}, // NON ISO
{USB_EP_ATTR_ALLOW_BULK | USB_EP_ATTR_ALLOW_INT | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0}, // NON ISO
#if (MBED_CONF_TARGET_USB_SPEED == USE_USB_OTG_HS)
{USB_EP_ATTR_ALLOW_ALL | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0},
#endif
Comment on lines +454 to +456
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this change can be the default configuration for all?
and then remove #if (MBED_CONF_TARGET_USB_SPEED == USE_USB_OTG_HS) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, but I don't have enough hardware variety to test it 🙂

{USB_EP_ATTR_ALLOW_ALL | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0},
{0 | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0},
{0 | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0},
Expand All @@ -441,7 +466,9 @@ const usb_ep_table_t *USBPhyHw::endpoint_table()
{0 | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0},
{0 | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0},
{0 | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0},
#if (MBED_CONF_TARGET_USB_SPEED != USE_USB_OTG_HS)
{0 | USB_EP_ATTR_DIR_IN_AND_OUT, 0, 0}
#endif
}
};
return &table;
Expand Down