Skip to content

Commit 468f720

Browse files
committed
update bulk to have 512 for highspeed usb, tested usbhs with v307 using 144mhz hse
1 parent 1b9e433 commit 468f720

File tree

7 files changed

+34
-17
lines changed

7 files changed

+34
-17
lines changed

src/arduino/Adafruit_USBD_CDC.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#define TINYUSB_API_VERSION 0
3939
#endif
4040

41+
#define BULK_PACKET_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
42+
4143
// SerialTinyUSB can be macro expanding to "Serial" on supported cores
4244
Adafruit_USBD_CDC SerialTinyUSB;
4345

@@ -69,8 +71,8 @@ uint16_t Adafruit_USBD_CDC::getInterfaceDescriptor(uint8_t itfnum_deprecated,
6971
uint8_t _strid = 0;
7072
#endif
7173

72-
uint8_t const desc[] = {
73-
TUD_CDC_DESCRIPTOR(itfnum, _strid, ep_notif, 8, ep_out, ep_in, 64)};
74+
uint8_t const desc[] = {TUD_CDC_DESCRIPTOR(itfnum, _strid, ep_notif, 8,
75+
ep_out, ep_in, BULK_PACKET_SIZE)};
7476

7577
uint16_t const len = sizeof(desc);
7678

src/arduino/midi/Adafruit_USBD_MIDI.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
//--------------------------------------------------------------------+
3232
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
3333
//--------------------------------------------------------------------+
34-
#define EPSIZE 64
34+
#define BULK_PACKET_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
3535

3636
// TODO multiple instances
3737
static Adafruit_USBD_MIDI *_midi_dev = NULL;
@@ -103,7 +103,7 @@ uint16_t Adafruit_USBD_MIDI::getInterfaceDescriptor(uint8_t itfnum_deprecated,
103103

104104
// Endpoint OUT + jack mapping
105105
{
106-
uint8_t desc[] = {TUD_MIDI_DESC_EP(ep_out, EPSIZE, _n_cables)};
106+
uint8_t desc[] = {TUD_MIDI_DESC_EP(ep_out, BULK_PACKET_SIZE, _n_cables)};
107107
memcpy(buf + len, desc, sizeof(desc));
108108
len += sizeof(desc);
109109
}
@@ -116,7 +116,7 @@ uint16_t Adafruit_USBD_MIDI::getInterfaceDescriptor(uint8_t itfnum_deprecated,
116116

117117
// Endpoint IN + jack mapping
118118
{
119-
uint8_t desc[] = {TUD_MIDI_DESC_EP(ep_in, EPSIZE, _n_cables)};
119+
uint8_t desc[] = {TUD_MIDI_DESC_EP(ep_in, BULK_PACKET_SIZE, _n_cables)};
120120
memcpy(buf + len, desc, sizeof(desc));
121121
len += sizeof(desc);
122122
}

src/arduino/msc/Adafruit_USBD_MSC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
#include "Adafruit_USBD_MSC.h"
3030

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

3333
static Adafruit_USBD_MSC *_msc_dev = NULL;
3434

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

5454
uint8_t const desc[] = {
55-
TUD_MSC_DESCRIPTOR(itfnum, _strid, ep_out, ep_in, EPSIZE)};
55+
TUD_MSC_DESCRIPTOR(itfnum, _strid, ep_out, ep_in, BULK_PACKET_SIZE)};
5656
uint16_t const len = sizeof(desc);
5757

5858
if (bufsize < len) {

src/arduino/ports/ch32/Adafruit_TinyUSB_ch32.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ void TinyUSB_Port_InitDevice(uint8_t rhport) {
128128
#endif
129129
#endif
130130

131+
#if CFG_TUD_WCH_USBIP_USBHS
132+
// High speed USB: currently require 144MHz HSE, update later
133+
RCC_USBCLK48MConfig(RCC_USBCLK48MCLKSource_USBPHY);
134+
RCC_USBHSPLLCLKConfig(RCC_HSBHSPLLCLKSource_HSE);
135+
RCC_USBHSConfig(RCC_USBPLL_Div2);
136+
RCC_USBHSPLLCKREFCLKConfig(RCC_USBHSPLLCKREFCLK_4M);
137+
RCC_USBHSPHYPLLALIVEcmd(ENABLE);
138+
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_USBHS, ENABLE);
139+
#endif
140+
131141
tud_init(rhport);
132142
}
133143

src/arduino/ports/ch32/tusb_config_ch32.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ extern "C" {
3434
//--------------------------------------------------------------------
3535
#if defined(CH32V20x)
3636
#define CFG_TUSB_MCU OPT_MCU_CH32V20X
37+
3738
#elif defined(CH32V30x)
3839
#define CFG_TUSB_MCU OPT_MCU_CH32V307
40+
3941
#endif
4042

4143
#define CFG_TUSB_OS OPT_OS_NONE
@@ -105,8 +107,8 @@ extern "C" {
105107
#define CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE 256
106108

107109
// CDC FIFO size of TX and RX
108-
#define CFG_TUD_CDC_RX_BUFSIZE 256
109-
#define CFG_TUD_CDC_TX_BUFSIZE 256
110+
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 256)
111+
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 256)
110112

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

121123
// Vendor FIFO size of TX and RX
122124
#ifndef CFG_TUD_VENDOR_RX_BUFSIZE
123-
#define CFG_TUD_VENDOR_RX_BUFSIZE 64
125+
#define CFG_TUD_VENDOR_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
124126
#endif
125127

126128
#ifndef CFG_TUD_VENDOR_TX_BUFSIZE
127-
#define CFG_TUD_VENDOR_TX_BUFSIZE 64
129+
#define CFG_TUD_VENDOR_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
128130
#endif
129131

130132
//--------------------------------------------------------------------
131133
// Host Configuration
132134
//--------------------------------------------------------------------
133-
135+
#if 0
134136
// Size of buffer to hold descriptors and other data used for enumeration
135137
#define CFG_TUH_ENUMERATION_BUFSIZE 256
136138

@@ -158,8 +160,8 @@ extern "C" {
158160
#define CFG_TUH_CDC_CH34X 1
159161

160162
// RX & TX fifo size
161-
#define CFG_TUH_CDC_RX_BUFSIZE 64
162-
#define CFG_TUH_CDC_TX_BUFSIZE 64
163+
#define CFG_TUH_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
164+
#define CFG_TUH_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
163165

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

174177
#ifdef __cplusplus
175178
}

src/arduino/video/Adafruit_USBD_Video.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
#include "Adafruit_USBD_Video.h"
3232

33+
#define BULK_PACKET_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
34+
3335
Adafruit_USBD_Video::Adafruit_USBD_Video(void) {
3436
_vc_id = 0;
3537
memset(&_camera_terminal, 0, sizeof(_camera_terminal));
@@ -231,7 +233,7 @@ uint16_t Adafruit_USBD_Video::getInterfaceDescriptor(uint8_t itfnum_deprecated,
231233

232234
.bEndpointAddress = ep_in,
233235
.bmAttributes = {.xfer = TUSB_XFER_BULK, .sync = 0, .usage = 0},
234-
.wMaxPacketSize = 64,
236+
.wMaxPacketSize = BULK_PACKET_SIZE,
235237
.bInterval = 1}};
236238

237239
uint16_t const len_iad = sizeof(desc_iad);

src/arduino/webusb/Adafruit_USBD_WebUSB.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
//--------------------------------------------------------------------+
3737
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
3838
//--------------------------------------------------------------------+
39-
#define EPSIZE 64
39+
#define BULK_PACKET_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
4040

4141
enum { VENDOR_REQUEST_WEBUSB = 1, VENDOR_REQUEST_MICROSOFT = 2 };
4242

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

165165
uint8_t desc[] = {
166-
TUD_VENDOR_DESCRIPTOR(itfnum, _strid, ep_out, ep_in, EPSIZE)};
166+
TUD_VENDOR_DESCRIPTOR(itfnum, _strid, ep_out, ep_in, BULK_PACKET_SIZE)};
167167
uint16_t const len = sizeof(desc);
168168

169169
// null buffer for length only

0 commit comments

Comments
 (0)