CY7C68013开发之一:固件开发_总结
(2014-02-25 16:46:53)
标签:
cy7c68013cyusbfx2usb固件 |
固件,指的是本来存在EEPROM,上电之后cpy到RAM里面去的那段程序.
cseg at
90H
;; TODO: this needs to be changed before
release
db
DSCR_DEVICE_LEN
;; Descriptor length
db
DSCR_DEVICE
;; Decriptor type
dw
0002H
;;
Specification Version (BCD)
db
00H
;; Device class
db
00H
;; Device sub-class
db
00H
;; Device sub-sub-class
db
64
;; Maximum packet size
dw
4705H
;; Vendor
ID
dw
0210H
;; Product
ID (Sample Device)
dw
0000H
;; Product
version ID
db
1
;; Manufacturer string
index
db
2
;; Product string index
db
0
;; Serial number string
index
db
1
;; Number of
configurations
db
DSCR_DEVQUAL_LEN
;; Descriptor length
db
DSCR_DEVQUAL
;;
Decriptor type
dw
0002H
;;
Specification Version (BCD)
db
00H
;; Device class
db
00H
;; Device sub-class
db
00H
;; Device sub-sub-class
db
64
;; Maximum packet size
db
1
;; Number of
configurations
db
0
;; Reserved
db
DSCR_CONFIG_LEN
;; Descriptor length
db
DSCR_CONFIG
;; Descriptor type
db
(HighSpeedConfigDscrEnd-HighSpeedConfigDscr) mod
256 ;; Total Length (LSB)
db
(HighSpeedConfigDscrEnd-HighSpeedConfigDscr)
/ 256 ;; Total Length
(MSB)
db
1
;; Number of interfaces
db
1
;; Configuration number
db
0
;; Configuration string
db
10100000b
;; Attributes (b7 - buspwr, b6 - selfpwr, b5 -
rwu)
db
50
;; Power requirement (div 2 ma)
db
DSCR_INTRFC_LEN
;; Descriptor length
db
DSCR_INTRFC
;; Descriptor type
db
0
;; Zero-based index of this
interface
db
0
;; Alternate setting
db
2
;; Number of end points
db
0ffH
;;
Interface class
db
00H
;; Interface sub class
db
00H
;; Interface sub sub class
db
0
;; Interface descriptor string
index
db
DSCR_ENDPNT_LEN
;; Descriptor length
db
DSCR_ENDPNT
;; Descriptor type
db
02H
;; Endpoint number, and direction
db
ET_BULK
;; Endpoint type
db
00H
;; Maximun packet size (LSB)
db
02H
;; Max packect size (MSB)
db
00H
;; Polling interval
db
DSCR_ENDPNT_LEN
;; Descriptor length
db
DSCR_ENDPNT
;; Descriptor type
db
86H
;; Endpoint number, and direction
db
ET_BULK
;; Endpoint type
db
00H
;; Maximun packet size (LSB)
db
02H
;; Max packect size (MSB)
db
00H
;; Polling interval
db
DSCR_CONFIG_LEN
;; Descriptor length
db
DSCR_CONFIG
;; Descriptor type
db
(FullSpeedConfigDscrEnd-FullSpeedConfigDscr) mod
256 ;; Total Length (LSB)
db
(FullSpeedConfigDscrEnd-FullSpeedConfigDscr)
/ 256 ;; Total Length
(MSB)
db
1
;; Number of interfaces
db
1
;; Configuration number
db
0
;; Configuration string
db
10100000b
;; Attributes (b7 - buspwr, b6 - selfpwr, b5 -
rwu)
db
50
;; Power requirement (div 2 ma)
db
DSCR_INTRFC_LEN
;; Descriptor length
db
DSCR_INTRFC
;; Descriptor type
db
0
;; Zero-based index of this
interface
db
0
;; Alternate setting
db
2
;; Number of end points
db
0ffH
;;
Interface class
db
00H
;; Interface sub class
db
00H
;; Interface sub sub class
db
0
;; Interface descriptor string
index
db
DSCR_ENDPNT_LEN
;; Descriptor length
db
DSCR_ENDPNT
;; Descriptor type
db
02H
;; Endpoint number, and direction
db
ET_BULK
;; Endpoint type
db
40H
;; Maximun packet size (LSB)
db
00H
;; Max packect size (MSB)
db
00H
;; Polling interval
db
DSCR_ENDPNT_LEN
;; Descriptor length
db
DSCR_ENDPNT
;; Descriptor type
db
86H
;;
Endpoint number, and direction
db
ET_BULK
;; Endpoint type
db
40H
;; Maximun
packet size (LSB)
db
00H
;; Max
packect size (MSB)
db
00H
;; Polling
interval
db
StringDscr0End-StringDscr0
;; String descriptor
length
db
DSCR_STRING
db
09H,04H
db
StringDscr1End-StringDscr1
;; String descriptor
length
db
DSCR_STRING
db
'S',00
db
'R',00
db
'C',00
db
'O',00
db
'U',00
db
'T',00
db
'_',00
db
'S',00
db
' ',00
db
'v',00
db
'0',00
db
'.',00
db
'2',00
db
'.',00
db
'0',00
db
'0',00
db
'0',00
db
'0',00
db
StringDscr2End-StringDscr2
;; Descriptor length
db
DSCR_STRING
db
'E',00
db
'Z',00
db
'-',00
db
'U',00
db
'S',00
db
'B',00
db
' ',00
db
'F',00
db
'X',00
db
'2',00
db
' ',00
db
'D',00
db
'K',00
db
' ',00
db
'B',00
db
'O',00
db
'A',00
db
'R',00
db
'D',00
db
' ',00
db
'W',00
db
'/',00
db
'L',00
db
'O',00
db
'G',00
db
'I',00
db
'C',00
db
' ',00
db
'A',00
db
'N',00
db
'A',00
db
'L',00
db
'Y',00
db
'Z',00
db
'E',00
db
'R',00
dw
0000H
end
_________________________________________________________________
// set the CPU clock to 48MHz
CPUCS = ((CPUCS & ~bmCLKSPD) |
bmCLKSPD1) ;
// SYNCDELAY;
// REVCTL = 0x03;
SYNCDELAY;
IFCONFIG |= 0x43;
//外部时钟(IFCLK pin),48MHz(产生的内部时钟,没用),内部时钟不输出,IFCLK signal不反转,同步方式
sync,接口方式:Slave FIFO
SYNCDELAY;
EP2CFG = 0xA0; // 有效,EP2 is DIR=OUT,
TYPE=BULK, SIZE=512bytes, BUF=4x
SYNCDELAY;
EP6CFG = 0xE0; // 有效,EP6 is DIR=IN,
TYPE=BULK,SIZE=512bytes,BUF=4x
//必须按照这个顺序来RESET FIFO的endpoint
SYNCDELAY;
FIFORESET = 0x80; // reset all FIFOs
SYNCDELAY;
FIFORESET = 0x02;
SYNCDELAY;
FIFORESET = 0x04;
SYNCDELAY;
FIFORESET = 0x06;
SYNCDELAY;
FIFORESET = 0x08;
SYNCDELAY;
FIFORESET = 0x00;
SYNCDELAY;
EP6AUTOINLENH = 2; // EP6
auto in length: 512
SYNCDELAY;
EP6AUTOINLENL = 0;
SYNCDELAY;
// and sets the slave FIFO
data interface to 16-bits
SYNCDELAY;
EP4FIFOCFG = 0x00;
SYNCDELAY;
EP8FIFOCFG = 0x00;
SYNCDELAY;
//FLAG控制寄存器全部置为0,FLAGA=PF,FLAGB=FF,FLAGC=EF, 具体FPAG
ABCD由addr[1:0]选定,此处ADDR[1:0]=10 选中EP6
PINFLAGSAB = 0x00;
SYNCDELAY;
PINFLAGSCD = 0x00;
SYNCDELAY;
PORTACFG |= 0x01;
// configures PORTA.0 as
INT0
SYNCDELAY;
FIFOPINPOLAR = 0x04;
// all signals active low
,SLWR(slave write) signal active high
EP2FIFOPFH = 0x80;
//FIFO的programmable flag控制寄存器组
设置当FIFO多于(DECIS=1)或者少于(DECIS=0)一个值(PFC)
默认为半满半空的时候pf置位
EP2FIFOPFL = 0x10; //EP2:
FIFO多于(DECIS=1) 8Byte时 PF置位
EP6FIFOPFH = 0x13; //EP6:
FIFO少于 2PKT+1024+512Byte时 PF置位
EP6FIFOPFL = 0x00;
OEA = 0x08; //port A output Enable
阻止进入低功耗模式?
固件开发过程的输入是一个keil工程,输出是一个.hex或者.iic文件
keil工程模版为:
C:\Cypress\Cypress Suite USB 3.4.7\Firmware\Bulkloop
其中要改的地方有两处,一个是dscr.a51文件,一个是fw.c文件中的TD_Init();和 TD_Poll();俩函数.
其中dscr.a51是usb设备描述符的配置,描述符的定义和概念与usb2.0协议相关,这个还没有看,不过显然这个.a51程序分成三部分HighSpeedConfigDscr/FullSpeedConfigDscr/StringDscr.我主要是修改了EPx的配置,抄了一篇网上的翻译:
___________________________________________下面是对dscr.a51文件的分析_________________________________________________
该文件主要是一个USB设备的描述符配置表
;;-----------------------------------------------------------------------------
;; File:
dscr.a51
;; Contents: This file
contains descriptor data tables.
;;
;; Copyright (c) 1997 AnchorChips, Inc. All
rights reserved
;;-----------------------------------------------------------------------------
;;下面是USB设备的设备描述符类型
;; 设备描述符
;; 配置描述符
;; 接口描述符
;; 端口描述符
;; String字串描述符
;; 装置认可描述符(新添加的,暂时未查到详细信息)
DSCR_DEVICE
equ 1
;;
Descriptor type: Device
DSCR_CONFIG
equ 2
;;
Descriptor type: Configuration
DSCR_STRING
equ 3
;;
Descriptor type: String
DSCR_INTRFC
equ 4
;;
Descriptor type: Interface
DSCR_ENDPNT
equ 5
;;
Descriptor type: Endpoint
DSCR_DEVQUAL
equ 6
;;
Descriptor type: Device Qualifier
;;下面是各描述符的长度
;;设备描述符的长度为18个字节
;;配置描述符的长度为9个字节
;;接口描述符的长度为9个字节
;;端口描述符的长度为7个字节
;;(暂时省略)
DSCR_DEVICE_LEN equ
18
DSCR_CONFIG_LEN equ
9
DSCR_INTRFC_LEN equ
9
DSCR_ENDPNT_LEN equ
7
DSCR_DEVQUAL_LEN equ
10
;;下面应该是事务格式,也即传输类型
;;控制传输方式
;;同步
;;批处理
;;中断
ET_CONTROL
equ
0
;; Endpoint type: Control
ET_ISO
equ 1
;; Endpoint
type: Isochronous
ET_BULK
equ
2
;; Endpoint type: Bulk
ET_INT
equ 3
;; Endpoint
type: Interrupt
public
DeviceDscr, DeviceQualDscr, HighSpeedConfigDscr,
FullSpeedConfigDscr, StringDscr, UserDscr
;; TGE DSCR SEGMENT
CODE
;;-----------------------------------------------------------------------------
;; Global Variables
;;-----------------------------------------------------------------------------
;; TGE
rseg DSCR
;; locate
the descriptor table in on-part memory.
;;设备描述符的结构
DeviceDscr:
;;装置认可描述符的结构
DeviceQualDscr:
;;高速描述符的结构介绍开始
;;高速配置描述符结构
HighSpeedConfigDscr:
;;高速接口描述符结构
;; Interface Descriptor
;;高速端口描述符结构(出端点)
;; Endpoint Descriptor
;;高速端口描述符结构(入端点)
;; Endpoint Descriptor
HighSpeedConfigDscrEnd:
;;高速描述符结构介绍完毕
;;全速描述符结构介绍开始
;;全速配置描述符
FullSpeedConfigDscr:
;;全速接口描述符
;; Interface Descriptor
;;全速端点描述符(出端点)
;; Endpoint Descriptor
;;全速端点描述符(入端点)
;; Endpoint Descriptor
FullSpeedConfigDscrEnd:
;;全速描述符介绍完毕
;;下面是字串描述符介绍
StringDscr:
StringDscr0:
StringDscr0End:
StringDscr1:
StringDscr1End:
StringDscr2:
StringDscr2End:
UserDscr:
疑问:
在分析dscr,a51文件时,得知该文件是一个USB设备固件描述符表,有一个疑问就是里面只列出了高速设备和全速设备的描述符,而且这两种描述符中还只包括了ET-BULK(应该批处理传输)的方式,其它(中断、控制、同步)的在哪里定义了啊,而且对于低速设备不用做描述吗
第二部分就是两个函数了,函数就是直接配置寄存器,寄存器定义参考
FX2 TechRefManual.pdf @C:\Cypress\USB\Doc\FX2
由于slaveFIFO不需要void TD_Poll(void)
进行操作,这里只分析void TD_Init( void )
代码之前是寄存器说明,在手册里面寄存器一章一开始:
Most registers deal with endpoints. The general register
format is DDDnFFF, where:
DDD is endpoint direction, IN or OUT with respect to the USB
host.
n is the endpoint number, where:
•“ISO” indicates isochronous endpoints as a group.
FFF is the function, where:
• CS is a control and status register
• IRQ is an Interrupt Request bit
• IE is an Interrupt Enable bit
• BC, BCL, and BCH are byte count registers. BC is used for
single byte counts, and
BCH/BCL are used as the high and low bytes of 16-bit byte
counts.
• DATA is a single-register access to a FIFO.
• BUF is the start address of a buffer.
void TD_Init( void )
{ // Called once at startup
// BYTE i;
// IFCONFIG = 0x03; //
slave fifo, internal clk, async
// IFCONFIG = 0xc3; //
slave fifo, external clk, sync
// EP2CFG = 0xA2; // EP2 is DIR=OUT,
TYPE=BULK, SIZE=512, BUF=2x
SYNCDELAY;
EP2FIFOCFG = 0x00; // EP2 is AUTOOUT=0, AUTOIN=0, ZEROLEN=0,
WORDWIDE=0
SYNCDELAY;
EP2FIFOCFG = 0x11; // EP2 is 不 满之前1个clk出现flag,不
空之前一个clk出现flag,AUTOOUT=1 usb有数据以后立即放入FIFO的endpoint 不需要cpu处理,
AUTOIN=0, ZEROLEN=0, WORDWIDE=1应该是指word
SYNCDELAY;
OUTPKTEND = 0x82; //跳过一个out packet 在EP1
SYNCDELAY;
OUTPKTEND = 0x82;
// EP6FIFOCFG = 0x08; //8-bits
EP6FIFOCFG = 0x09; //EP6 is 不 满之前1个clk出现flag,不
空之前一个clk出现flag,AUTOIN=1.不允许空数据包, WORDWIDE=1应该是指word
// this lets the EP6 auto commit IN packets,
}
估计还是看不懂,那么就读一读EZ-USB FX2 Technical
Reference Manual的Chapter 9 Slave FIFOs