打印
[AT32 WorkBench]

AT32 WorkBench常用功能14—USB Device CustomHID

[复制链接]
422|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 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
硬件环境
l  AT-START-F405
l  USB线缆

软件环境
l  AT32 Workbench
l  MDK5
l  USB 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 begin  usb_app_task 0 */
  
  
  /* add user code end  usb_app_task 0 */
  
  
  /* add user code begin  usb_app_task 1 */
  
  
  /* add user code end  usb_app_task 1 */
  
  
  /* hs device custom hid */
  
  /*
  
  after the the usb  connected, user can use the 'custom_hid_class_send_report' function
  
  to report keyboard events,  for example,  to report a char led  on/off event as follows:
  
  
  ALIGNED_HEAD static  uint8_t report_buf[64] ALIGNED_TAIL;
  
   if(usbd_connect_state_get(&otg_core_struct_hs.dev) ==  USB_CONN_STATE_CONFIGURED)
  
  {
  
    report_buf[0] =  HID_REPORT_ID_5;
  
    report_buf[1] = 0;
  
     custom_hid_class_send_report(&otg_core_struct_hs.dev, report_buf,  64);
  
    usb_delay_ms(100);
  
    report_buf[0] =  HID_REPORT_ID_5;
  
    report_buf[1] = 1;
  
     custom_hid_class_send_report(&otg_core_struct_hs.dev, report_buf,  64);
  
    usb_delay_ms(100);
  
  }
  
  */
  
  
  /* add user code begin  usb_app_task 2 */
  
ALIGNED_HEAD static uint8_t report_buf[64] ALIGNED_TAIL;
  
   if(usbd_connect_state_get(&otg_core_struct_hs.dev) ==  USB_CONN_STATE_CONFIGURED)
  
  {
  
    report_buf[0] = HID_REPORT_ID_5;
  
    report_buf[1] = 0;
  
     custom_hid_class_send_report(&otg_core_struct_hs.dev, report_buf,  64);
  
    usb_delay_ms(100);
  
    report_buf[0] = HID_REPORT_ID_5;
  
    report_buf[1] = 1;
  
     custom_hid_class_send_report(&otg_core_struct_hs.dev, report_buf,  64);
  
    usb_delay_ms(100);
  
  }
  
  /* add user code end  usb_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时钟配置界面进行确认。



使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

189

主题

1864

帖子

27

粉丝