USB固件程序设计初步

本文介绍了USB固件程序设计的基础知识,包括使用Keil51编程环境和CY7C68013A USB最小系统。作者强调了设备请求号在固件程序中的重要性,并展示了如何通过switch-case语句处理设备请求,特别是数据发送和接收的设备请求。通过定义SendData和ReceiveData常量,实现了控制传输方式通信的数据发送和接收功能。在固件程序正确运行后,下一步计划是在Linux下编写USB驱动,以控制LED灯。
摘要由CSDN通过智能技术生成

前阵子一直忙着复习考试,都没没有时间学习USB,还好,现在考完了,终于有时间了.好好学习我USB了.预计是先把固件程序用控制传输发送数据调试成功.然后在Linux下编写相应的USB驱动,先点亮LED灯.下面说说USB的固件程序是怎样设计的.
    编程环境是:Keil51.板子是用CY7C68013A做的USB最小系统.下载软件是:CYconsole.
首 先说程序框架:在主函数中定义自己的设备请求号,在请求号中有相应的设备请求处理函数,在设备请求处理函数中可以对端点,进行设置.USB端点是最基本 的,端点的集合就是接口,而接口的集合就是配置.设备请求在固件程序中是被放在一个叫做SETUPDAT的八字节数组中的第2位, 即:SETUPDAT[1]中.驱动程序通过给该结构中发送设备请求来控制响应的USB设备.在USB固件程序的框架中通常是通过switch-case 语句来处理USB设备请求的.以下是一个定义一个数据发送和接收的设备请求,通过端点0以及使用控制传输方式通信:
#define SendData  0xB1             
#define ReceiveData 0xB2

switch(SETUPDAT[1])
 case SendData:
                            DR_Send();
 case ReceiveData:
                            DR_Receive();
/*******************两个函数具体实现如下********************/
BOOL DR_Send(void)
{
  EP0BUF[0]=0XB1;       /*使用端点0来处理0xB1请求*/
  EP0BCH=0;
  EP0BCL=2;                   /*数据长度*/
  EZUSB_Delay(100);    /*延时,等待处理*/

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
AN039 - USB Firmware Programmer's Guide v1.1 Last updated 16 JUL 2003 To exercise the example firmware: 1. Extract the contents of the AN039.zip file (if using WinZip, use the "Extract" function to retain sub-directory information). 2. Open the Cygnal IDE (v1.72 or later). 3. From IDE menu Options->Debug Interface, select Cygnal 2-Wire. 4. Connect to the target C8051F32x device (Alt+C, or IDE menu Debug->Connect). 5. From the Project menu, select "Open Project" (a warning dialogue may appear; this is expected). 6. Browse to directory \AN039\Firmware and select file FirmwareProgramGuide.wsp. 7. Through IDE menu Project->Tool Chain Integration, select the path to your compiler and linker. The default is C:\Cygnal\IDEFiles\C51\Bin\. 8. Build the project (F7, or through IDE menu Project->Build/Make Project). 9. Download the firmware (Alt+D). 10. Connect a USB cable between the target device and the host PC. 11. Run (F5, or IDE menu Debug->Go). 12. When Windows detects the device and the driver installation wizard opens: a. Choose "Search for a suitable driver for my device", and click Next. b. Check the box "Specify a location", and click Next. c. Browse to directory \AN039\Application and select the file CygnalInt.inf, and click OK. d. Follow the dialogue to finish driver installation. 13. After the driver has been installed, run the USBTest.exe application from directory \AN039\Application. Notes: - Firmware works with the Cygnal IDE v1.71 or later and the Keil C51 tool chain. Project and code modifications will be necessary for use with different tool chains. - Compiler optimization emphasis is selected as "favor small code". This selection is necessary for the project to be compiled with the trial version of the Keil C51 Compiler (under 4k code space). - If using the C8051F320TB target board, jumper J2 should be installed if the board is wall-powered; jumper J11 should be installed if bus-powered. - Windows application and driver supports Win2K and XP only.
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值