muyichuan2012 发表于 2024-8-15 16:55

AT32 WorkBench常用功能14—USB Device CustomHID

本帖最后由 muyichuan2012 于 2024-8-15 17:24 编辑

AT32WorkBench常用功能14—USB Device CustomHID
AT32 WorkBench最新版下载地址:https://www.arterytek.com/file/download/1710

USB CustomHID工程建立
本文主要介绍如何基于AT32 WorkBench配置USB CustomHID硬件环境lAT-START-F405lUSB线缆
软件环境lAT32 WorkbenchlMDK5lUSB HID Demo上位机软件
配置步骤:1.    打开AT32 WorkBench新建AT32F405RCT7工程
2.    在外设中打开USB_OTGHS1并选择设备,视情况选择是否勾选相关信号,本案例不勾选
3.    可以看到时钟配置菜单栏打了红叉,这是因为缺少12M外部晶振为OTGHS PHY提供时钟,所以需要在外设CRM中打开高速外部晶振。
4.    在中间件USB_DEVICE中选择OTGHS1设备类为Custom hid,HS设备描述符和端点FIFO可根据需要修改,本案例使用默认数值。
5.    点击生成代码,然后生成MDK_V5工程即可完成CustomHID基础工程的建立
6.    使用MDK_V5打开项目,对wk_usb_app_task()函数做如下修改,编译并下载到开发板
void wk_usb_app_task(void){/* add user code beginusb_app_task 0 */
/* add user code endusb_app_task 0 */
/* add user code beginusb_app_task 1 */
/* add user code endusb_app_task 1 */
/* hs device custom hid *//*after the the usbconnected, user can use the 'custom_hid_class_send_report' functionto report keyboard events,for example,to report a char ledon/off event as follows:
ALIGNED_HEAD staticuint8_t report_buf ALIGNED_TAIL;   if(usbd_connect_state_get(&otg_core_struct_hs.dev) ==USB_CONN_STATE_CONFIGURED){    report_buf =HID_REPORT_ID_5;    report_buf = 0;   custom_hid_class_send_report(&otg_core_struct_hs.dev, report_buf,64);    usb_delay_ms(100);    report_buf =HID_REPORT_ID_5;    report_buf = 1;   custom_hid_class_send_report(&otg_core_struct_hs.dev, report_buf,64);    usb_delay_ms(100);}*/
/* add user code beginusb_app_task 2 */ALIGNED_HEAD static uint8_t report_buf ALIGNED_TAIL;   if(usbd_connect_state_get(&otg_core_struct_hs.dev) ==USB_CONN_STATE_CONFIGURED){    report_buf = HID_REPORT_ID_5;    report_buf = 0;   custom_hid_class_send_report(&otg_core_struct_hs.dev, report_buf,64);    usb_delay_ms(100);    report_buf = HID_REPORT_ID_5;    report_buf = 1;   custom_hid_class_send_report(&otg_core_struct_hs.dev, report_buf,64);    usb_delay_ms(100);}/* add user code endusb_app_task 2 */}


7.    将开发板HS_Device口连接到PC并复位,打开USB HID Demo上位机软件,可以看到Button 1 Report ID 5所指示的灯泡图标在不停的闪烁,这是因为CustomHID设备在不停的给上位机软件发送指令。
注意:USBHID Demo上位机软件下载方法是:雅特力官网->产品讯息->任一MCU详情界面->USBTool and Driver->USB HID Demo 上位机软件
注意:对于USB_OTGFS来说,步骤相似,但可以不开启12M高速外部时钟,且输入到OTGFS控制器的时钟必须是48MHz。若选择hick to usbfs则可以解锁外设AAC功能,可以在AT32 WorkBench时钟配置界面进行确认。


页: [1]
查看完整版本: AT32 WorkBench常用功能14—USB Device CustomHID