Add USB driver for GD32VF103.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka
2019-12-27 09:42:22 +09:00
parent 167741bdc8
commit 228d1d06ce
5 changed files with 1327 additions and 6 deletions

View File

@@ -1,3 +1,13 @@
2019-12-27 NIIBE Yutaka <gniibe@fsij.org>
* mcu/usb-gd32vf103.c: New.
* mcu/clk_gpio_init-gd32vf103.c (clock_init): Configure USB clock.
* mcu/gd32vf103.h (RCU_CFG0_USBFSPSC_DIV2): New.
* usb_lld.h [MCU_GD32VF1]: Support GD32VF103.
2019-12-27 NIIBE Yutaka <gniibe@fsij.org>
* chopstx.c (chopstx_poll): Call CHECK for condition

View File

@@ -17,6 +17,8 @@ clock_init (void)
RCU->CFG0 |= RCU_CFG0_APB2_CKAHB_DIV1;
/* CK_APB1 = CK_AHB/2 */
RCU->CFG0 |= RCU_CFG0_APB1_CKAHB_DIV2;
/* CK_USBFS = 48MHz */
RCU->CFG0 |= RCU_CFG0_USBFSPSC_DIV2;
/* CK_ADC, CK_TIMER1xxx, CK_TIMER0, CK_I2S */

View File

@@ -33,6 +33,7 @@ static struct RCU *const RCU = (struct RCU *)0x40021000;
#define RCU_CFG0_SCS_MASK 0x00000003
#define RCU_CFG0_SCSS_PLL 0x00000008
#define RCU_CFG0_CKSYSSRC_PLL 0x00000002
#define RCU_CFG0_USBFSPSC_DIV2 0x00c00000
#define RCU_CFG1_PREDV0SEL_MASK 0x00010000
#define RCU_CFG1_PREDV0SEL_HXTAL 0x00000000
@@ -41,6 +42,8 @@ static struct RCU *const RCU = (struct RCU *)0x40021000;
#define RCU_APB2_GPIOB 0x00000008
#define RCU_APB2_GPIOC 0x00000010
#define RCU_AHB_USBFS 0x00001000
/* Semantics is exactly same as STM32F103. */
struct GPIO {
volatile uint32_t CRL;

1268
mcu/usb-gd32vf103.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -38,12 +38,20 @@ enum DESCRIPTOR_TYPE
#define USB_SETUP_GET(req) ((req & REQUEST_DIR) != 0)
struct device_req {
union {
struct {
uint8_t type;
uint8_t request;
uint16_t value;
uint16_t index;
uint16_t len;
};
struct {
uint32_t w0;
uint32_t w1;
};
};
};
struct ctrl_data {
uint8_t *addr;
@@ -51,12 +59,27 @@ struct ctrl_data {
uint8_t require_zlp;
};
#ifdef MCU_GD32VF1
#define USB_REQUIRE_TXRX_INFO 1
#endif
#ifdef USB_REQUIRE_TXRX_INFO
struct epctl {
uint8_t *addr;
uint16_t len;
};
#endif
struct usb_dev {
uint8_t configuration;
uint8_t feature;
uint8_t state;
struct device_req dev_req;
struct ctrl_data ctrl_data;
#ifdef USB_REQUIRE_TXRX_INFO
struct epctl epctl_tx[3];
struct epctl epctl_rx[3];
#endif
};
enum {
@@ -152,7 +175,22 @@ void usb_lld_rx_enable_buf (int ep_num, void *buf, size_t len);
void usb_lld_setup_endp (struct usb_dev *dev, int ep_num, int rx_en, int tx_en);
void usb_lld_stall_tx (int ep_num);
void usb_lld_stall_rx (int ep_num);
#else
#elif defined(MCU_GD32VF1)
#define INTR_REQ_USB 86
#define INTR_REQ_USB_WAKEUP 61
void usb_lld_tx_enable_buf (struct usb_dev *dev, int ep_num, const void *buf, size_t len);
void usb_lld_rx_enable_buf (struct usb_dev *dev, int ep_num, void *buf, size_t len);
/* EP_TYPE[1:0] EndPoint TYPE */
#define EP_CONTROL 0x00
#define EP_ISOCHRONOUS 0x01
#define EP_BULK 0x02
#define EP_INTERRUPT 0x03
void usb_lld_setup_endp (struct usb_dev *dev, int ep_num, int ep_type, int rx_en, int tx_en);
void usb_lld_stall_tx (struct usb_dev *dev, int ep_num);
void usb_lld_stall_rx (struct usb_dev *dev, int ep_num);
#else /* STM32L4 or STM32F103/GD32F103 */
#if defined(MCU_STM32L4)
#define INTR_REQ_USB 67
#else