@@ -20,56 +20,56 @@ manufacturer: WCH
2020#include "bsp/board_api.h"
2121#include "board.h"
2222
23- /* CH32v203 depending on variants can support 2 USB IPs: FSDEV and USBFS.
23+ /* CH32v203 depending on variants can support 2 USB IPs: FSDEV (port0) and USBFS (port1) .
2424 * By default, we use FSDEV, but you can explicitly select by define:
2525 * - CFG_TUD_WCH_USBIP_FSDEV
2626 * - CFG_TUD_WCH_USBIP_USBFS
2727 */
2828
29- // USBFS
30- __attribute__((interrupt )) __attribute__((used ))
31- void USBHD_IRQHandler (void ) {
32- #if CFG_TUD_WCH_USBIP_USBFS
29+ // Port0: USBD (fsdev)
30+ __attribute__((interrupt )) __attribute__((used )) void USB_LP_CAN1_RX0_IRQHandler (void ) {
31+ #if CFG_TUD_WCH_USBIP_FSDEV
3332 tud_int_handler (0 );
3433 #endif
3534}
3635
37- __attribute__((interrupt )) __attribute__((used ))
38- void USBHDWakeUp_IRQHandler (void ) {
39- #if CFG_TUD_WCH_USBIP_USBFS
36+ __attribute__((interrupt )) __attribute__((used )) void USB_HP_CAN1_TX_IRQHandler (void ) {
37+ #if CFG_TUD_WCH_USBIP_FSDEV
4038 tud_int_handler (0 );
4139 #endif
40+
4241}
4342
44- // USBD (fsdev)
45- __attribute__((interrupt )) __attribute__((used ))
46- void USB_LP_CAN1_RX0_IRQHandler (void ) {
43+ __attribute__((interrupt )) __attribute__((used )) void USBWakeUp_IRQHandler (void ) {
4744 #if CFG_TUD_WCH_USBIP_FSDEV
4845 tud_int_handler (0 );
4946 #endif
5047}
5148
52- __attribute__(( interrupt )) __attribute__(( used ))
53- void USB_HP_CAN1_TX_IRQHandler (void ) {
54- #if CFG_TUD_WCH_USBIP_FSDEV
55- tud_int_handler (0 );
49+ // Port1: USBFS
50+ __attribute__(( interrupt )) __attribute__(( used )) void USBHD_IRQHandler (void ) {
51+ #if CFG_TUD_ENABLED && CFG_TUD_WCH_USBIP_USBFS
52+ tud_int_handler (1 );
5653 #endif
5754
55+ #if CFG_TUH_ENABLED
56+ tuh_int_handler (1 );
57+ #endif
5858}
5959
60- __attribute__((interrupt )) __attribute__((used ))
61- void USBWakeUp_IRQHandler (void ) {
62- #if CFG_TUD_WCH_USBIP_FSDEV
60+ __attribute__((interrupt )) __attribute__((used )) void USBHDWakeUp_IRQHandler (void ) {
61+ #if CFG_TUD_WCH_USBIP_USBFS
6362 tud_int_handler (0 );
6463 #endif
6564}
6665
67-
66+ //--------------------------------------------------------------------+
67+ // Board API
68+ //--------------------------------------------------------------------+
6869#if CFG_TUSB_OS == OPT_OS_NONE
6970volatile uint32_t system_ticks = 0 ;
7071
71- __attribute__((interrupt ))
72- void SysTick_Handler (void ) {
72+ __attribute__((interrupt )) void SysTick_Handler (void ) {
7373 SysTick -> SR = 0 ;
7474 system_ticks ++ ;
7575}
@@ -108,7 +108,7 @@ void board_init(void) {
108108#ifdef UART_DEV
109109 UART_CLOCK_EN ();
110110 GPIO_InitTypeDef usart_init = {
111- .GPIO_Pin = UART_TX_PIN ,
111+ .GPIO_Pin = UART_TX_PIN | UART_RX_PIN ,
112112 .GPIO_Speed = GPIO_Speed_50MHz ,
113113 .GPIO_Mode = GPIO_Mode_AF_PP ,
114114 };
@@ -119,7 +119,7 @@ void board_init(void) {
119119 .USART_WordLength = USART_WordLength_8b ,
120120 .USART_StopBits = USART_StopBits_1 ,
121121 .USART_Parity = USART_Parity_No ,
122- .USART_Mode = USART_Mode_Tx ,
122+ .USART_Mode = USART_Mode_Tx | USART_Mode_Rx ,
123123 .USART_HardwareFlowControl = USART_HardwareFlowControl_None ,
124124 };
125125 USART_Init (UART_DEV , & usart );
@@ -189,9 +189,19 @@ size_t board_get_unique_id(uint8_t id[], size_t max_len) {
189189}
190190
191191int board_uart_read (uint8_t * buf , int len ) {
192- (void ) buf ;
193- (void ) len ;
192+ #ifdef UART_DEV
193+ int count ;
194+ for (count = 0 ; count < len ; count ++ ) {
195+ if (USART_GetFlagStatus (UART_DEV , USART_FLAG_RXNE ) == RESET ) {
196+ break ;
197+ }
198+ buf [count ] = USART_ReceiveData (UART_DEV );
199+ }
200+ return count ;
201+ #else
202+ (void ) buf ; (void ) len ;
194203 return 0 ;
204+ #endif
195205}
196206
197207int board_uart_write (void const * buf , int len ) {
@@ -207,7 +217,3 @@ int board_uart_write(void const *buf, int len) {
207217
208218 return len ;
209219}
210-
211- //--------------------------------------------------------------------
212- // Neopixel
213- //--------------------------------------------------------------------
0 commit comments