Skip to content

Commit

Permalink
update bulk to have 512 for highspeed usb, tested usbhs with v307 usi…
Browse files Browse the repository at this point in the history
…ng 144mhz hse
  • Loading branch information
hathach committed Jun 13, 2024
1 parent 1b9e433 commit 468f720
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 17 deletions.
6 changes: 4 additions & 2 deletions src/arduino/Adafruit_USBD_CDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#define TINYUSB_API_VERSION 0
#endif

#define BULK_PACKET_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)

// SerialTinyUSB can be macro expanding to "Serial" on supported cores
Adafruit_USBD_CDC SerialTinyUSB;

Expand Down Expand Up @@ -69,8 +71,8 @@ uint16_t Adafruit_USBD_CDC::getInterfaceDescriptor(uint8_t itfnum_deprecated,
uint8_t _strid = 0;
#endif

uint8_t const desc[] = {
TUD_CDC_DESCRIPTOR(itfnum, _strid, ep_notif, 8, ep_out, ep_in, 64)};
uint8_t const desc[] = {TUD_CDC_DESCRIPTOR(itfnum, _strid, ep_notif, 8,
ep_out, ep_in, BULK_PACKET_SIZE)};

uint16_t const len = sizeof(desc);

Expand Down
6 changes: 3 additions & 3 deletions src/arduino/midi/Adafruit_USBD_MIDI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
#define EPSIZE 64
#define BULK_PACKET_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)

// TODO multiple instances
static Adafruit_USBD_MIDI *_midi_dev = NULL;
Expand Down Expand Up @@ -103,7 +103,7 @@ uint16_t Adafruit_USBD_MIDI::getInterfaceDescriptor(uint8_t itfnum_deprecated,

// Endpoint OUT + jack mapping
{
uint8_t desc[] = {TUD_MIDI_DESC_EP(ep_out, EPSIZE, _n_cables)};
uint8_t desc[] = {TUD_MIDI_DESC_EP(ep_out, BULK_PACKET_SIZE, _n_cables)};
memcpy(buf + len, desc, sizeof(desc));
len += sizeof(desc);
}
Expand All @@ -116,7 +116,7 @@ uint16_t Adafruit_USBD_MIDI::getInterfaceDescriptor(uint8_t itfnum_deprecated,

// Endpoint IN + jack mapping
{
uint8_t desc[] = {TUD_MIDI_DESC_EP(ep_in, EPSIZE, _n_cables)};
uint8_t desc[] = {TUD_MIDI_DESC_EP(ep_in, BULK_PACKET_SIZE, _n_cables)};
memcpy(buf + len, desc, sizeof(desc));
len += sizeof(desc);
}
Expand Down
4 changes: 2 additions & 2 deletions src/arduino/msc/Adafruit_USBD_MSC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#include "Adafruit_USBD_MSC.h"

#define EPSIZE 64 // TODO must be 512 for highspeed device
#define BULK_PACKET_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)

static Adafruit_USBD_MSC *_msc_dev = NULL;

Expand All @@ -52,7 +52,7 @@ uint16_t Adafruit_USBD_MSC::getInterfaceDescriptor(uint8_t itfnum_deprecated,
uint8_t const ep_out = TinyUSBDevice.allocEndpoint(TUSB_DIR_OUT);

uint8_t const desc[] = {
TUD_MSC_DESCRIPTOR(itfnum, _strid, ep_out, ep_in, EPSIZE)};
TUD_MSC_DESCRIPTOR(itfnum, _strid, ep_out, ep_in, BULK_PACKET_SIZE)};
uint16_t const len = sizeof(desc);

if (bufsize < len) {
Expand Down
10 changes: 10 additions & 0 deletions src/arduino/ports/ch32/Adafruit_TinyUSB_ch32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ void TinyUSB_Port_InitDevice(uint8_t rhport) {
#endif
#endif

#if CFG_TUD_WCH_USBIP_USBHS
// High speed USB: currently require 144MHz HSE, update later
RCC_USBCLK48MConfig(RCC_USBCLK48MCLKSource_USBPHY);
RCC_USBHSPLLCLKConfig(RCC_HSBHSPLLCLKSource_HSE);
RCC_USBHSConfig(RCC_USBPLL_Div2);
RCC_USBHSPLLCKREFCLKConfig(RCC_USBHSPLLCKREFCLK_4M);
RCC_USBHSPHYPLLALIVEcmd(ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_USBHS, ENABLE);
#endif

tud_init(rhport);
}

Expand Down
17 changes: 10 additions & 7 deletions src/arduino/ports/ch32/tusb_config_ch32.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ extern "C" {
//--------------------------------------------------------------------
#if defined(CH32V20x)
#define CFG_TUSB_MCU OPT_MCU_CH32V20X

#elif defined(CH32V30x)
#define CFG_TUSB_MCU OPT_MCU_CH32V307

#endif

#define CFG_TUSB_OS OPT_OS_NONE
Expand Down Expand Up @@ -105,8 +107,8 @@ extern "C" {
#define CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE 256

// CDC FIFO size of TX and RX
#define CFG_TUD_CDC_RX_BUFSIZE 256
#define CFG_TUD_CDC_TX_BUFSIZE 256
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 256)
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 256)

// MSC Buffer size of Device Mass storage
#define CFG_TUD_MSC_EP_BUFSIZE 512
Expand All @@ -120,17 +122,17 @@ extern "C" {

// Vendor FIFO size of TX and RX
#ifndef CFG_TUD_VENDOR_RX_BUFSIZE
#define CFG_TUD_VENDOR_RX_BUFSIZE 64
#define CFG_TUD_VENDOR_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
#endif

#ifndef CFG_TUD_VENDOR_TX_BUFSIZE
#define CFG_TUD_VENDOR_TX_BUFSIZE 64
#define CFG_TUD_VENDOR_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
#endif

//--------------------------------------------------------------------
// Host Configuration
//--------------------------------------------------------------------

#if 0
// Size of buffer to hold descriptors and other data used for enumeration
#define CFG_TUH_ENUMERATION_BUFSIZE 256

Expand Down Expand Up @@ -158,8 +160,8 @@ extern "C" {
#define CFG_TUH_CDC_CH34X 1

// RX & TX fifo size
#define CFG_TUH_CDC_RX_BUFSIZE 64
#define CFG_TUH_CDC_TX_BUFSIZE 64
#define CFG_TUH_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
#define CFG_TUH_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)

// Set Line Control state on enumeration/mounted:
// DTR ( bit 0), RTS (bit 1)
Expand All @@ -170,6 +172,7 @@ extern "C" {
// This need Pico-PIO-USB at least 0.5.1
#define CFG_TUH_CDC_LINE_CODING_ON_ENUM \
{ 115200, CDC_LINE_CONDING_STOP_BITS_1, CDC_LINE_CODING_PARITY_NONE, 8 }
#endif

#ifdef __cplusplus
}
Expand Down
4 changes: 3 additions & 1 deletion src/arduino/video/Adafruit_USBD_Video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#include "Adafruit_USBD_Video.h"

#define BULK_PACKET_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)

Adafruit_USBD_Video::Adafruit_USBD_Video(void) {
_vc_id = 0;
memset(&_camera_terminal, 0, sizeof(_camera_terminal));
Expand Down Expand Up @@ -231,7 +233,7 @@ uint16_t Adafruit_USBD_Video::getInterfaceDescriptor(uint8_t itfnum_deprecated,

.bEndpointAddress = ep_in,
.bmAttributes = {.xfer = TUSB_XFER_BULK, .sync = 0, .usage = 0},
.wMaxPacketSize = 64,
.wMaxPacketSize = BULK_PACKET_SIZE,
.bInterval = 1}};

uint16_t const len_iad = sizeof(desc_iad);
Expand Down
4 changes: 2 additions & 2 deletions src/arduino/webusb/Adafruit_USBD_WebUSB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
#define EPSIZE 64
#define BULK_PACKET_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)

enum { VENDOR_REQUEST_WEBUSB = 1, VENDOR_REQUEST_MICROSOFT = 2 };

Expand Down Expand Up @@ -163,7 +163,7 @@ uint16_t Adafruit_USBD_WebUSB::getInterfaceDescriptor(uint8_t itfnum_deprecated,
uint8_t const ep_out = TinyUSBDevice.allocEndpoint(TUSB_DIR_OUT);

uint8_t desc[] = {
TUD_VENDOR_DESCRIPTOR(itfnum, _strid, ep_out, ep_in, EPSIZE)};
TUD_VENDOR_DESCRIPTOR(itfnum, _strid, ep_out, ep_in, BULK_PACKET_SIZE)};
uint16_t const len = sizeof(desc);

// null buffer for length only
Expand Down

0 comments on commit 468f720

Please sign in to comment.