Skip to content

Commit 1f259b3

Browse files
authored
Merge pull request #2392 from Krasutski/bugfix/ch32-hs-dcd
bugfix(ch32-hs-dcd): fix ch32 DATAx managment and long packet transmit
2 parents a1abbd7 + 4a5b190 commit 1f259b3

File tree

4 files changed

+318
-293
lines changed

4 files changed

+318
-293
lines changed

hw/bsp/ch32v307/debug_uart.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <ch32v30x.h>
2929

3030

31-
#define UART_RINGBUFFER_SIZE_TX 64
31+
#define UART_RINGBUFFER_SIZE_TX 128
3232
#define UART_RINGBUFFER_MASK_TX (UART_RINGBUFFER_SIZE_TX-1)
3333

3434
static char tx_buf[UART_RINGBUFFER_SIZE_TX];

hw/bsp/ch32v307/family.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void board_init(void) {
7272
SysTick_Config(SystemCoreClock / 1000);
7373
#endif
7474

75-
usart_printf_init(115200);
75+
usart_printf_init(CFG_BOARD_UART_BAUDRATE);
7676

7777
#if CFG_TUD_MAX_SPEED == OPT_MODE_HIGH_SPEED
7878
// Use Highspeed USB
@@ -150,10 +150,11 @@ int board_uart_read(uint8_t* buf, int len) {
150150

151151
int board_uart_write(void const* buf, int len) {
152152
int txsize = len;
153+
const char* bufc = (const char*) buf;
153154
while (txsize--) {
154-
uart_write(*(uint8_t const*) buf);
155-
buf++;
155+
uart_write(*bufc++);
156156
}
157+
uart_sync();
157158
return len;
158159
}
159160

src/portable/wch/ch32_usbhs_reg.h

+19-12
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,13 @@
6363

6464
// USB DEV AD
6565
#define USBHS_DEV_AD_OFFSET 0x03
66+
6667
// USB FRAME_NO
6768
#define USBHS_FRAME_NO_OFFSET 0x04
69+
#define USBHS_FRAME_NO_NUM_MASK (0x7FF)
70+
#define USBHS_FRAME_NO_MICROFRAME_SHIFT (11)
71+
#define USBHS_FRAME_NO_MICROFRAME_MASK (0x7 << USBHS_FRAME_NO_MICROFRAME_SHIFT)
72+
6873
// USB SUSPEND
6974
#define USBHS_SUSPEND_OFFSET 0x06
7075
#define USBHS_DEV_REMOTE_WAKEUP (1 << 2)
@@ -74,7 +79,10 @@
7479

7580
// USB SPEED TYPE
7681
#define USBHS_SPEED_TYPE_OFFSET 0x08
77-
#define USBSPEED_MASK (0x03)
82+
#define USBHS_SPEED_TYPE_MASK 0x03
83+
#define USBHS_SPEED_TYPE_FULL 0
84+
#define USBHS_SPEED_TYPE_HIGH 1
85+
#define USBHS_SPEED_TYPE_LOW 2
7886

7987
// USB_MIS_ST
8088
#define USBHS_MIS_ST_OFFSET 0x09
@@ -99,12 +107,16 @@
99107
#define USBHS_ISO_ACT_FLAG (1 << 6)
100108

101109
// INT_ST
102-
#define USBHS_INT_ST_OFFSET 0x0B
103-
#define USBHS_DEV_UIS_IS_NAK (1 << 7)
104-
#define USBHS_DEV_UIS_TOG_OK (1 << 6)
105-
#define MASK_UIS_TOKEN (3 << 4)
106-
#define MASK_UIS_ENDP (0x0F)
107-
#define MASK_UIS_H_RES (0x0F)
110+
#define USBHS_INT_ST_OFFSET 0x0B
111+
#define USBHS_DEV_UIS_IS_NAK (1 << 7)
112+
#define USBHS_DEV_UIS_TOG_OK (1 << 6)
113+
#define MASK_UIS_TOKEN (3 << 4)
114+
#define USBHS_TOKEN_PID_OUT (0 << 4)
115+
#define USBHS_TOKEN_PID_SOF (1 << 4)
116+
#define USBHS_TOKEN_PID_IN (2 << 4)
117+
#define USBHS_TOKEN_PID_SETUP (3 << 4)
118+
#define MASK_UIS_ENDP (0x0F)
119+
#define MASK_UIS_H_RES (0x0F)
108120

109121
#define USBHS_TOGGLE_OK (0x40)
110122
#define USBHS_HOST_RES (0x0f)
@@ -367,10 +379,5 @@
367379
#define USBHS_UH_T_TOG_AUTO (1 << 5)
368380
#define USBHS_UH_T_DATA_NO (1 << 6)
369381

370-
// 00: OUT, 01:SOF, 10:IN, 11:SETUP
371-
#define PID_OUT 0
372-
#define PID_SOF 1
373-
#define PID_IN 2
374-
#define PID_SETUP 3
375382

376383
#endif

0 commit comments

Comments
 (0)