当前位置:网站首页>GD32E103 USB official library + STM32CubeMX
GD32E103 USB official library + STM32CubeMX
2022-08-06 12:25:00 【dancebit】
GD32E103 USB库和STM32是不兼容的,GD32E103是M4核,STM32F103是M3核.
在STM32 HAL库的基础上,如何加入GD32的USB库程序,This seems a bit cumbersome.
经过尝试,Thought of a lazy way.
将GD32的USB工程生成一个lib库文件,including initialization alreadyOUT事件,INJust provide the event.
目录
1.1、在libThe library is modified as neededGD的USB配置
2.2、Associate interrupt callback function
1.lib库配置
1.1、在libThe library is modified as neededGD的USB配置
1.2、封装lib接口函数
int ccid_usb_init(void) //int main()
{
usb_rcu_config();
usb_timer_init();
// custom_hid_itfop_register(&custom_hid, &fop_handler);
usbd_init (&custom_hid, USB_CORE_ENUM_FS, &custom_hid_desc, &usbd_custom_hid_cb);
usb_intr_config();
/* CTC peripheral clock enable */
rcu_periph_clock_enable(RCU_CTC);
/* CTC configure */
ctc_config();
return 0;
}
ccid_usb_init就是原来的mian函数,生成lib库之后main函数就不需要,启动文件*.s也不需要,所以libThe library will not actively associate the interrupt vector table,Interrupt needs to be calledlibassociated in the project.
//USBAccept the data callback interface function
extern void ccid_usb_command(uint8_t *request,int len);
//提供USB数据发送接口
void ccid_usb_respond(uint8_t *respond,int len)
{
usbd_ep_send(&custom_hid,CUSTOMHID_IN_EP,respond, len);
}
static uint8_t custom_hid_data_out (usb_dev *udev, uint8_t ep_num)
{
custom_hid_handler *hid = (custom_hid_handler *)udev->dev.class_data[CUSTOM_HID_INTERFACE];
int datalen = usbd_rxcount_get(udev,ep_num);
ccid_usb_command(hid->data,datalen);
usbd_ep_recev (udev, CUSTOMHID_OUT_EP, hid->data, 64);
return USBD_OK;
}1.3、Event interrupt interface
原来 gd32e10x_it.cAll interrupt events in are masked out,Reserve the required interrupt functions and rename them to provide external calls
void TIMER2_IRQHandler_lib(void)
{
usb_timer_irq();
}
void USBFS_IRQHandler_lib (void)
{
usbd_isr (&custom_hid);
}
void USBFS_WKUP_IRQHandler_lib(void)
{
//....
}生成lib文件

2、程序调用lib
STM32Use your own project normally,I use it directly for testingSTM32CubeMx生成STM32F103C8T6的工程.
GD32E103是M4内核,USBPart of the vector configuration sumSTM32F103不一致,启动文件*.s就直接拷贝GD32E103库lib里面的文件
2.1、添加lib库文件

2.2、Associate interrupt callback function
void TIMER2_IRQHandler(void)
{
TIMER2_IRQHandler_lib();
}
void USBFS_IRQHandler (void)
{
USBFS_IRQHandler_lib();
}
void USBFS_WKUP_IRQHandler(void)
{
USBFS_WKUP_IRQHandler_lib();
}
2.3、初始化
extern int ccid_usb_init(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
ccid_usb_init();
print_x("main start\r\n");
/* USER CODE END 2 */
while(1)
{
LED_GPIO_Port->ODR ^= LED_Pin;
HAL_Delay(200);
}
}2.4、收发测试
extern void ccid_usb_respond(uint8_t *respond,int len);
void ccid_usb_command(uint8_t *request,int len)
{
ccid_usb_respond(request,len);
}所以,Join directly in the projectlib库,Just a few pieces of codeUSB串联起来,Send and receive so clearly.

边栏推荐
- OPENCV学习DAY10
- PHP fopen写入文件内容
- PS6603-USB PD protocol SINK terminal output controller chip
- Kubernetes 运维经验分享
- 【cookie&&session】
- OpenFeign【与Feign关系 OpenFeign详解】
- stp simple configuration
- Teach you to draw pixel art and share 195 issues every week
- GD32E103 USB官方库 + STM32CubeMX
- 从没见过能把高并发拆解的这么详细!阿里巴巴这份堪称神级的“高并发”教程太香了
猜你喜欢
随机推荐
Disadvantages of Kubernetes Virtual Machine Deployment
顶象首期业务安全月报来了!
【云原生 · Kubernetes】Kubernetes容器云平台部署与运维
PS6603 代理直销Type-C PD 电源传输接收 SINK 端控制器芯片
mayavi可视化kitti
stp简单配置
Kubernetes 开源未来
分布式架构网络通信
1408. String Matching in Arrays: Simple Simulation Questions
【SSL集训DAY1】B【动态规划】
A Brief Introduction to Type Assertion in Go
severlet运行原理
绝了!阿里人用7部分讲明白百亿级高并发系统(全彩版小册开源)
Hu-cang integrated e-commerce project (1): project background and structure introduction
Absolutely!Ali people explain tens of billions of high-concurrency systems in 7 parts (full-color booklet open source)
Ansible自动化运维、ZABBIX监控
解析隐式类型转换操作operator double() const,带你了解隐式转换危害有多大
PS6652+JD6606S_2C 35W双C口PD协议方案
Link Aggregation Brief
leetcode.10 正则表达式








