網頁

顯示具有 EZ-USB 標籤的文章。 顯示所有文章
顯示具有 EZ-USB 標籤的文章。 顯示所有文章

2015年7月25日 星期六

[Note][EZ-USB]


快要被 Eclipse 搞瘋掉之前, 找到了解決方法, 但是應該不算正解, 不過先記下來, 可以用先.
加入 static library ( .a)
要加入 libcyu3mipicsi.a, 先把它複製到相對應的 debug/release 目錄下, 然後在 project property 的 C/C++ General 下面的 Paths and Symbols 的 Libraies 的地方, 加入去掉前面 lib, 後面 .a 的 cyu3mipicsi, 就可以了
image

2014年9月14日 星期日

[EZ-USB FX3] Added descriptor in USB 2.0


在 USB descriptor 的規格中, 定義了從 device/configuration/interface/endpoint, 從上而下的樹狀結構. 一個 device 可以有數個 configurtion, 一個 configuration 可以有數個 interface, 一個 interface 可以有數個 endpoint, 可以很清楚的瞭解到 device 提供了那些互動的方式.
當功能和 interface 是 1:1 對應的時候, 這些看來都沒有問題.
image
然而, 如果一個 device 如果有一個功能, 用到不同的 interface, 這樣主機端就不能由原先 device 傳回來的 descriptor, 看出這兩個 interface 是屬於同一組 (也許驅動程式根本就是同一個).
image

Interface Association Descriptors

因此, 在 USB 2.0 的規格推出後, 又以 ECN (Engineering Change Note) 的形式, 提出一個新的 descriptor, 在 USB 3.0 這是規格的一部份. 這一個 descriptor 就是在描述 interface 彼此之間的關係.
Offset Field Size Value Description
0 bLength 1 Number Size of Descriptor in bytes 0x09
1 bDescriptorType 1 Constant Interface Association Descriptor 0x0B
2 bFirstInterface 1 Number Interface number of the first interface that is associated with this function  
3 bInterfaceCount 1 Number Number of contiguous interfaces that at associated with this function  
4 bFunctionClass 1 Class Class Code (assigned by USB-IF)  
5 bFunctionSubClass 1 SubClass Sub Class Code (asigned by USB-IF)
6 bFunctionProtocol 1 Protocol Protocol Code (assigned by USB-IF)
7 iFunction 1 Index Index of string descriptor describing this function

2014年9月12日 星期五

[EZ-USB FX3] USB 3.0 Additional Descriptors


SuperSpeed USB 3.0 增加兩個新的 descriptors, 用來儲存 technology 及 device function 的特定資訊.

Binary device Object Store (BOS)

BOS descriptor 作為一個或是更多的 device capability descriptor 的基礎的 descriptor, 提供特定的能力和技術的資訊.
所有的 SuperSpeed USB 3.0 設備都必需支援這一個 descriptor, 並且在 high speed 運行時, 支援 Link Power Management (LPM).
Offset Field Size Value Description
0 bLength 1 Number Size of Descriptor in bytes 0x05
1 bDescriptorType 1 Constant BOS Descriptor 0x0F
2 wTotalLength 2 Number The number of bytes in this descriptor and all of its subordinate descriptors include all sub desceiptors
4 bNumDeviceCaps 1 Number The number of device capability descriptors subordinate to this BOS descriptor.

Device Capability Descriptor

Device Capability Descriptor 描述各不同 Device 的 capability
Offset Field Size Value Description
0 bLength 1 Number Size of Descriptor in bytes
1 bDescriptorType 1 Constant DevCapability Descriptor 0x10
2 bDevCapabilityType 1 Number Device Capability Type
3 Capability-Dependent Var Variable Capability-specific data and format
 

Device Capability Types Codes


Capability Code Value Descriptor
Wireless_USB 01H Defines the set of Wireless USB-specific device level capabilities
USB 2.0 Extension 02H USB 2.0 Extension Descriptor
SUPERSPEED_USB 03H Defines the set of SuperSpeed USB specific device level capabilities
CONTAINER_ID 04H Defines the instance unique ID used to identify the instance across all operating modes
PLATFORM 05H Defines a device capability specific to a particular platform/operating system
POWER_DELIVERY_CAPABILITY 06H Defines the various PD Capabilities of this device
BATTERY_INFO_CAPABILITY 07H Provides information on each battery supported by the device
PD_CONSUMER_PORT_CAPABILITY 08H The consumer characteristics of a port on the device
PD_PROVIDER_PORT_CAPABILITY 09H The provider characteristics of a port on the device
SUPERSPEED_PLUS 0AH Defines the set of SuperSpeed Plus USB specific device level capabilities
PRECISION_TIME_MEASUREMENT 0BH Precision Time Measurement (PTM) Capability Descriptor
Wireless_USB_Ext 0CH Defines the set of Wireless USB 1.1-specific device level capabilities
Reserved 00H,
0DH~FFH
Reserved for future use

2014年9月11日 星期四

[EZ-USB FX3] Notes on USB 2.0 descriptors


USB 的 descriptor 是 host 識別 device 的資料. 當一個 USB 的設備插入 USB port 時, USB host 會主動詢問 USB 設備的相關資料, 以載入相對應的驅動程式, 以及供給電源等動作. USB 設備就是透過 USB descriptor 來傳達這些資訊.
USB descriptor 的結構如附圖. 由一個 Device Descriptor, 包含數個 Configuration Descriptor, 每一個 Configurtion Descriptor 又可以包含數個 Interface Descriptor, 每一個 Interface Descriptor 又可以包含數個 Endpoint Descriptor, 字串的部份則放在 String Descriptor 中.
image

Device Descriptor

USB device 只能有一個 device descriptor, 這個 descriptor 提供設備為主的資訊. 譬如說對應到 USB 的規格的版本, 設備供應商的代號, 產品代號, 等等.

Offset

Field

Size

Value

Description

Note

0

bLength

1

Number

size of the descriptor in bytes

0x12

1

bDescriptorType

1

Constant

DeviceDescriptor (0x01)

0x01

2

bcdUSB

2

BCD

USB Sepcification Number

USB 3.0 0x00, 0x03

USB 2.1 0x10, 0x02

4

bDeviceClass

1

Class

Class Code:
0x00: each interface specifies it’s own claas code
0xFF: the class code is vendor specified
Otherwise:
0xEF
Miscellaneous

5

bDeviceSubClass

1

SubClass

Assigned by USB ORG 0x02

6

bDeviceProtocol

1

Protocol

Assigned by USB ORG 0x01

7

bMaxPacketSize

1

Number

Maximum Packet Size for Endpoint 0 8/16/32/64

8

idVendor

2

ID

Assigned by USB ORG

10

idProduct

2

ID

Assigned by Manufacturer

12

bcdDevice

2

BCD

Device Release Number

14

iManufacturer

1

Index

Index of Manufacturer String Descriptor

15

iProduct

1

Index

Index of Product String Descriptor

16

iSerialNumber

1

Index

Index of Serial Number String Descriptor

17

bNumConfigurations

1

Integer

Number of Possible Configurations
Class/SubClass/Protocol 共同指定了 USB device 的類型. 譬如說, Class = 0xEF, SubClass = 0x02, Protocol = 0x01, 指定了這個 device 是一個 Miscelaneous device ( Class = 0xEF), SubClass = 0x02, Protocol = 0x01, 則說明這個 device 的 Class Code, 是由 Interface Association Descriptor 指定. 也就是需參照 Interface Descriptor.

Configuration Descriptor

Configuration Descriptor 指定裝置在這個 configuration 的狀態下的電力設定及所需要的電力供應. 通常一個設備只會用到一個 configuration, 但是如果設備可以支援自我供電以及 USB 供電兩種方式的時候, 可以有兩個以上的 configuration, 以供 host 選擇, 但是同一時間只能有一個作用中的 configurtion.
舉例來說, 可以有一個高功率需求的 bus 供電 configuration, 以及一個自我供電的 configuration. 如果 USB device 被插入一個有電源供應的系統, 驅動程式可以選擇 bus 供電. 如果是被插入沒有電源供給的系統 (以系統的電池供電), 則可以選擇設備自我供電.
Offset Field Size Value Description  
0 bLength 1 Number Size of Descriptor in bytes 0x09
1 bDescriptorType 1 Constant Configuration Descriptor 0x02
2 wTotalLength 2 Number Total Length of Data returned include all sub desceiptors
4 bNumInterfaces 1 Number Number of Interfaces number of interface in this configuration
5 bConfigurationValue 1 Number Value to use as an argument to select this configuration Configuration value to be selected
6 iConfiguration 1 Index Index of String Descriptor Describing this configuration  
7 bmAttributes 1 Bitmap D7: Bus Powered
D6: Self Powered
D5: Remote Wakeup
D4..D0 reserved (0)
 
8 bMaxPower 1 mA Maximum Power Consumption  

 

Interface Descriptor

interface descriptor 可以看成是一組 endpoints 所組成的功能群組, 以達成特定功能. 例如, 一個多功能事務機, 可以用一個 interface descriptor 來描述 fax 功能的 endpoints, 然後用另一個 interface descriptor 來描述 scanner, 再一個來描述 printer. 和 configuration descriptor 不同的是, interface descriptor 沒有在同一時間內只能有一個在運作中的限制. USB 設備可以有一個或更多的 interface 在運作中.
interface descriptors 有一個 bInterfaceNumber 的欄位, 用以指定這一個 interface. 另外, 還有一個 bAlternateSetting 欄位, 這可以讓 interface 達成動態變更的效果.
假設, 我們有一個設備, 它有兩個 interface, interface 1, interface 2. interface 1 的 bInterfaceNumber 設成 0, 表示它是第一個 interface descriptor, 並且 bAlternativeSetting 設成 0. interface 2 的 bInterfaceNumber 設成 1, 表示它是第二個 interface descriptor, 並且 bAlternativeSetting 設成 0. 當我們可以再加入一個 interface descriptor, 並且把 bInterfaceNumber 設成 1, 表示它也是第二個 interface descriptor, 但是這次把 bAlternativeSetting 設定為 1, 表示這一個 interface descriptor 是另一個 interface descriptor 的替代.
Offset Field Size Value Description  
0 bLength 1 Number Size of Descriptor in bytes 0x09
1 bDescriptorType 1 Constant Interface Descriptor 0x04
2 bInterefaceNumber 1 Number Number of Interface zero based interface descriptor
3 bAlternateSetting 1 Number Value used to select alternative setting 0: Not alternative
1: alternative
4 bNumEndpoints 1 Number Number of Endpoints used for this interface  
5 bInterfaceClass 1 Class Assigned by USB ORG  
6 bInterfaceSubClass 1 SubClass Assigned by USB ORG  
7 bInterfaceProtocol 1 Protocol Protocol Code  
8 iInterface 1 Index Index of String Descriptor  

 

Endpoint Descriptor

每一個 endpoint descriptor 都是用來指定傳輸的型態, 方向, 輪詢間隔, 最大的封包大小. Endpoint 0, 是預設的控制 endpoint, 只會是 control point, 所以不需要 descriptor.
Offset Field Size Value Description  
0 bLength 1 Number Size of Descriptor in bytes 0x07
1 bDescriptorType 1 Constant End Descriptor 0x05
2 bEndpointAddress 1 Endpoint Endpoint Address
0b..3b Endpoint NUmber
4b..6b Reserved ( Zero)
7b Direction
   0 : Out Endpoint
   1 : In Endpoint
zero based interface descriptor
3 bmAttributes 1 Bitmap Bits 0..1 Transfer Type
  00 = Control
  01 = Isochronous
  10 = Bulk
  11 = Interrupt
Bits 5..2 reserved if not Isochronous.
Bits 3..2 Synchronization type
  00 = No Synchronization
  01 = Asynchronous
  10 = Adaptive
  11 = Synchronous
Bits 5..4 Usage type
  00 = Data endpoint
  01 = Feedback endpoint
  10 = Implicit feedback Data endpoint
  11 = Reserved 
0: Not alternative
1: alternative
4 wMaxPacketSize 2 Number Maximum Packet Size .  
6 bInterval 1 Number Polling interval in frame count.
Bulk & Control Endpoint ignored.
Iso must equal 1
Interrupt 1..255
 

 

String Descriptor

string descriptor 提供可讀的資訊. 如果不提供這一個 string descriptor, string index 需要設成 0. string 以 Unicode 編碼, 並且提供多國語言的支援.
String Descriptor Zero, 是用來描述所支持的語言 :
Offset Field Size Value Description
0 bLength 1 Number Size of Descriptor in bytes
1 bDescriptorType 1 Constant String Descriptor 0x03
2 wLANGID[0] 2 Number Supported Language Code Zero ex
0x0409 (English, USA)

wLANGID[1] 2 Number Supported Language Code One ex
0x0C09 (English, Austria)
4 wLANGID[2] 2 Number Supported Language Code X ex
0x0407 (German – Standard)
String Descriptor 1~, 是放置 Unicode 字串的地方.
Offset Field Size Value Description
0 bLength 1 Number Size of Descriptor in bytes
1 bDescriptorType 1 Constant String Descriptor 0x03
2 bString n Unicode Supported Language Code Zero Unicode Encoded String

 

Device Qualifier

device_qualifier descriptor 描述關於高速設備在不同速度下的訊息改變. 例如, 如果設備正在 full-speed 下運作, device_qualifier 傳回它在 high-speed 下運作的資訊. 反之亦然.
Offset Field Size Value Description
0 bLength 1 Number Size of Descriptor in bytes
1 bDescriptorType 1 Constant Device Qualifier Type  
2 bcdUSB 2 BCD USB spec version number.  
4 bDeviceClass 1 Class Class Code
5 bDeviceSubClass 1 SubClass SubClass Code
6 bDeviceProtocol 1 Protocol Protocol Code
7 bMaxPacketSize0 1 Number Maximum packet size for other speed
8 bNumConfigurations 1 Number Number of Other-speed configurations
9 bReserved 1 Zero Reserved for future use, must be zero

2014年9月2日 星期二

[EZ-USB FX3] Debug with J-Link GDB


這邊主要是記錄在使用 J-Link debug 的時候, 需要進行的操作. 因為對每一個 project 都需要設定, 所以只好記錄起來.

Create Debug Configuration

1. 在左邊的 Project Explorer 中, 點選要 debug 的 project, 這個地方是 UartLpDmaMode
image
2. 在上面的 Run 選單中, 選擇 Debug Configurations
image
3. 在左邊的 configurations 中, 選擇 Zylin Embedded debug (Native)
image
4. 在 Zylin Embedded debug (Native) 上按右鍵, 選擇 new

image

 

Modify Debug Configuration

1. 選擇 Debugger 分頁, 把 Main 分頁的 GDB debugger 連結到 C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\ARM GCC\bin\arm-none-eabi-gdb.exe”
image

2. 選擇 Commands 分頁, 在 Initialize commands, 加入以下命令
set prompt (arm-gdb)
# This connects to a target via netsiliconLibRemote
# listening for commands on a TCP port on the local machine.
# 2331 if the Segger J-Link GDB Server is being used
# 3333 if OpenOCD is being used
# If OpenOCD is being used, the CPU should be halted
# using the "monitor halt" command.
# Uncomment the appropriate line below:
target remote localhost:2331
# target remote localhost:3333
# monitor halt
monitor speed 1000
monitor endian little
set endian little
monitor reset
# Set the processor to SVC mode
monitor reg cpsr =0xd3
# Disable all interrupts
monitor memU32 0xFFFFF014 =0xFFFFFFFF
# Enable the TCMs
monitor memU32 0x40000000 =0xE3A00015
monitor memU32 0x40000004 =0xEE090F31
monitor memU32 0x40000008 =0xE240024F
monitor memU32 0x4000000C =0xEE090F11
# Change the FX3 SYSCLK setting based on
# input clock frequency. Update with
# correct value from list below.
# Clock input is 19.2 MHz: Value = 0x00080015
# Clock input is 26.0 MHz: Value = 0x00080010
# Clock input is 38.4 MHz: Value = 0x00080115
# Clock input is 52.0 MHz: Value = 0x00080110
monitor memU32 0xE0052000 = 0x00080015
# Add a delay to let the clock stabilize.
monitor sleep 1000
set $pc =0x40000000
si
si
si
si
3. 選擇 Commands 分頁, 在 Run commands, 加入以下命令
load
按下 “Apply” 儲存設定.
image

Run GDB server

1. 啟動 GDB server.
在開始功能表中, 找到 SEGGER, 執行 SEGGER\J-Link V4.9X.x\J-Link GDB Server. 確認以下的設定. 沒有問題的話, 按下 OK 開始.
image
正常的話, 會顯示未連線.
image

Debug from Eclipse

在專案名稱上按右鍵, 選擇 Debug As\Debug Configurations. 確定在左邊的 debug configuration 選項中, 剛剛建立的 configuration 被選擇. 然後按下 debug.
image
出現切換到 debug view 的提示. Eclipse 的 source code view 及 debug view 是在歸屬在不同的視覺系統中. 所以進到 debug 時, 會切換到 debug view. 這只是提示. 按下 “Yes” 進入 debug view.
進入 debug 後, 系統會先停下來. 看起來會像是這個樣子.
image
按下工具列的 resume 按紐
image
程式會停在 main() 的第一行 , GDB server 也會顯示已連線
image

2014年8月20日 星期三

[EZ-USB FX3] Memory map


FX3 的 memory, 基本上可以分成三類, D-TCM/I-TCM/System memory. TCM 是 Tightly-coupled memory 的縮寫, 它是 low-latency memory, 可以提供快速的記憶體存取.

D-TCM

D-TCM 是資料 (data) 用的 TCM. FX3 有 8 K 的 D-TCM. SDK 預設把這一塊記憶體, 分配給系統的堆疊.
modes address size  
SYS MODE STACK 0x10000000-0x10000800 2 K  
ABT MODE STACK 0x10000800-0x10000900 256 B  
UND MODE STACK 0x10000900-0x10000A00 256 B  
FIQ MODE STACK 0x10000A00-0x10000C00 512 B  
IRQ MODE STACK 0x10000A00-0x10001000 1 K  
SVC MODE STACK 0x10000A00-0x10002000 4 K  

I-TCM

I-TCM 是 instruction TCM. FX3 有 16 K 的 I-TCM. SDK 預設把這一塊記憶體, SDK 主要分配給 Interrupt Handler, 以及 Exception Vector.
usage address size  
Execption  Vector 0x00000000-0x00000100 256 B Fixed
Interrupt Handler 0x00000100-0x00004000 16 K – 256 B  

System memory

不同的 FX3 型號, system memory 的 size 可能有所不同, 有 256K/512K 的差別. 以下以 512 K 作說明.
usage address size  
DMA descriptor 0x40000000-0x40003000 12 K Fixed
Code Area 0x40003000-0x40030000 180 K  
Data Area 0x40030000-0x40037000
0x40030000-0x40038000
28 K
32 K
(with Compiler Heap)
(without Compiler Heap)
Compiler Heap 0x40030000-0x40037000 4 K (if used)
RTOS Heap 0x40038000-0x40040000 32 K  
DMA Buffer Area 0x40040000-0x40080000 256 K  

 

2014年8月19日 星期二

[EZ-USB FX3] firmware framework –1 Initialization


以下說明 FX3 firmware application 的啟動過程.

Hardware reset

在系統重置, 或是上電時, 所有的處理器都會進入一個硬體重置的階段, 雖然硬體重置的動作/順序/需要時間各自有差異, 不過它的目的都是準備處理器, 以進行之後的運算任務. 粗略的來說, 它會有一些任務要執行.
  • register reset : 在電源開始供電之前, 處理器內部的暫存器, 它的內容都應該視為未知. 因此, 它需要一些時間讓它回到預設值.
  • peripheral reset : 處理器需要周邊的元件來進行處理. 譬如, 需要 RAM 來儲存資料, IO 和外界溝通或交換資料. 這些元件也需要進入工作狀態.
  • 載入初始的指令 : 處理器要執行指令, 第一個要執行的指令, 要放在指令暫存器的預設的位址. 也就是說, reset 後,  指令暫存器的內容會還原成預設值. 而這預設值就是第一個要執行的指令的位址.

Device configuration

FX3 在 CPU rest 之後, 第一個執行的指令是在內部的 boot-ROM, 它的位址是 0xFFFF0000. 也可以稱為第一 Boot Loader. 根據文件, 它執行以下動作:
  • 根據 PMODE pin 的設定, 判斷 firmware 的來源. FX3 可以支援 USB Boot/I2C boot/SPI Boot/GPIF Boot.
  • 從 firmware 的來源, download firmware 的映像到系統的記憶體.
  • 從 firmware entry location ( 0x40000000) 指向的地方開始執行
firmware entry location 的位址 ( 0x40000000) , 存放的是 firmware reset address. 也就是 firmware 第一個指令的位置. 通常是在 0x40003000, 也就是 CyU3PFirmwareEntry() 這個程序.
CyU3PFirmwareEntry() 在清除 BSS 段的資料後, 會呼叫 main() 這個 function. 這也是 firmware application 第一個會執行到的指令.  

Clock Setup

通常, 在 main() 中, 首先要設定 clock. 這會呼叫到 CyU3PDeviceInit ()
/* Initialize the device */
CyU3PSysClockConfig_t clockConfig;
clockConfig.setSysClk400  = CyTrue;
clockConfig.cpuClkDiv     = 2;
clockConfig.dmaClkDiv     = 2;
clockConfig.mmioClkDiv    = 2;
clockConfig.useStandbyClk = CyFalse;
clockConfig.clkSrc         = CY_U3P_SYS_CLK;
status = CyU3PDeviceInit (&clockConfig);

MMU and cache management

FX3 不支援 virtual memory. 實體記憶體是和虛擬記憶體是1對1的對應. 這需要設定 MMU. 另外, MMU 也用來 enable 系統的 cache. /* Initialize the caches. Enable both Instruction and Data caches. */
status = CyU3PDeviceCacheControl (CyTrue, CyTrue, CyTrue);
if (status != CY_U3P_SUCCESS)
{
    goto handle_fatal_error;
}


RTOS Kernel

當完成這前述的步驟後, 程式的執行權會交給 RTOS. 也就是透過呼叫 CyU3PKernelEntry (). RTOS 在完成 RTOS 自己的啟始動作後, 會再呼叫 CyFxApplicationDefine 這個 FX3 已經定義的 callback function, application 在這個地方定義自己的 thread, 由 RTOS 分配時間來執行.



2014年8月18日 星期一

[EZ-USB FX3] include/library path


FX3 SDK 預設的 IDE 是 Eclipse. 雖然 Eclipse 很常見, 但是因為它可以客製化, 有些細節的地方還是要摸索一下. 例如說, include 和 library 的路徑設定.

include path

在專案瀏覽畫面, 在要設定的專案名稱上按右鍵, 會跳出專案選單, 選擇最下面的 Properties, 打開專案屬性視窗.image
在以下的專案屬性視窗中, 依序進入 include 設定:
  1. 在左邊的選項中, 選擇 “C/C++ Build”, 以及其下的 “Settings”.
  2. 在中間的 Settings 窗格, 選擇 “Tool Settings” 分頁.
  3. 在“Tool Settings” 分頁中, 選擇 “ARM Sourcery Windows GCC Compiler”, 以及其下的 “Directories”
  4. 按右上角的加號, 加入新的 include path
image

library path

  1. 在左邊的選項中, 選擇 “C/C++ Build”, 以及其下的 “Settings”.
  2. 在中間的 Settings 窗格, 選擇 “Tool Settings” 分頁.
  3. 在“Tool Settings” 分頁中, 選擇 “ARM Sourcery Windows GCC Linker”, 以及其下的 “Miscellaneos”
  4. 在右邊的窗格, 捲到最下面, 可以看到 “Other flags”, 在這邊可以輸入要用到的 library 的路徑及檔名.
image

Notice :

Library 的設定, 似乎要在 ${FX3_INSTALL_PATH} 才可以, 這部份沒有深入去探討, 有問題的時候, 可以試試看放在這個地方.

2014年6月11日 星期三

[EZ-USB FX3] Create new project


雖然 FX3 SDK 提供了很多 example, 但是當要進行自己的工作時, 還是會想要建一個自己的專案, 至少專案名稱是自己想要的.
不過, FX3 在這方面不太好操作, 自己 create 出來的專案, 完全不能用. 以下說明如何以手動的方式建立一個新的專案

建立專案資料夾

在 FX3 的範例目錄下, ex: C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\firmware\basic_examples, 建立一個新的資料夾, 資料夾名稱就是專案名稱. 在這個例子中是 CxTest
image

複製專案檔案

從一個已經存在的專案範本中, 複製專案內容. 以下是從 cyfxbulksrcsink 複製. 將 cyfxbulksrcsink 下的檔案, 都複製到 CxTest 的目錄.
image

重新命名專案檔案

將 cyfxbulksrcsink.c 重新命名成 CxTest.c
將 cyfxbulksrcsink.h 重新命名成 CxTest.h
將 cyfxbulkdscr.c 重新命名成 CxTestDscr.h
其他的檔案是每一個專案都有, 而且內容一樣的.

修改專案檔案內容

1. 修改 CxTest.c
將 #include "cyfxbulksrcsink.h" 修改為 #include "CxTest.h" 
2. 修改 CxTestDscr.c
將 #include "cyfxbulksrcsink.h" 修改為 #include "CxTest.h"
3. 修改 .project
將 cyfxbulksrcsink 全部取代成 CxTest
4. 修改 .cproject
將 cyfxbulksrcsink 全部取代成 CxTest

import 專案範例

在 File/Import/Existing Projects into Workspace
image
瀏覽至 C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\firmware\basic_examples\CxTest
image
然後就可以在 project explorer 中, 看到新增加的專案
image

2014年6月3日 星期二

[EZ-USB FX3] UART on Development Kit


從 Uart 印一些 message 作 debug 用, 是 firmware 常用的開發技巧. FX3 所附的範例中, 也有一些有印出 debug message, 不過, 實際上操作, Uart 卻是一片空白. 以下用一步一步的操作, 來確認 Uart 的問題.

1. 檢查 Uart 裝置.

現在很多電腦都沒有 Uart/RS232/COM port 這樣的介面, 取而代之的, 是 Uart-USB 的裝置很容易取得. 以下就使用 Uart-USB 來代替 UART 的輸出.
在控制台, 裝置管理員, 可以看到連接埠, 下圖中的 COM10, 就是我們要用的 Uart port.
image

2. 開啟 PC 端的終端機.

不管是用 Hyper Terminal, 或是其他隨便什麼軟體, Uart 都有一些設定要做, 不過很簡單.Port name (COM10), Speed/baud rate (115200), Data bits (8), Stop bits (1), Parity (None),Flow control (None )
image

3. 設定 DVK ( developmen kit ) 上面的 jumper.

J101 1 and 2, GPIO_46=UART_RTS, J101 用來設定 GPIO 46 當作 UART_RTS
J102 1 and 2, GPIO_47=UART_CTS, J102 用來設定 GPIO 47 當作 UART_CTS
J103 1 and 2, GPIO_48=UART_TX, J103 用來設定 GPIO 48 當作 UART_TX
J104 1 and 2, GPIO_49=UART_RX, J104 用來設定 GPIO 49 當作 UART_RX 實際上, CTS/RTS 現在已經很少用到, 所以只跳 J103/J104 也是可以的.
image

4. 開啟 USBDebug 範例. Build 完 project.

update 到 DVK 上, 嗯, 還是不 work.
image

5. 修改 USBDebug 範例.

1. cyfxusbdebug.c 的 main()
UART 的 GPIO 的設定應該和以下的程式碼相同. 如果都沒有改過, 應該是一樣的.
/* No LPP or GPIO is being used. */
io_cfg.isDQ32Bit = CyFalse;
io_cfg.s0Mode = CY_U3P_SPORT_INACTIVE;
io_cfg.s1Mode = CY_U3P_SPORT_INACTIVE;
io_cfg.useUart   = CyTrue;
io_cfg.useI2C    = CyFalse;
io_cfg.useI2S    = CyFalse;
io_cfg.useSpi    = CyFalse;
io_cfg.lppMode   = CY_U3P_IO_MATRIX_LPP_UART_ONLY;
/* No GPIOs are enabled. */
io_cfg.gpioSimpleEn[0]  = 0;
io_cfg.gpioSimpleEn[1]  = 0;
io_cfg.gpioComplexEn[0] = 0;
io_cfg.gpioComplexEn[1] = 0;
status = CyU3PDeviceConfigureIOMatrix (&io_cfg);
if (status != CY_U3P_SUCCESS)
{
    goto handle_fatal_error;
}
以上是設定的 Uart 的 IO. 但是 UART 的 config 卻沒有設, 因此要加入一個 function CyFxDebugInit ()
2. 加入 CyFxDebugInit ()
/* This function initializes the debug module. The debug prints
* are routed to the UART and can be seen using a UART console
* running at 115200 baud rate. */
void CyFxDebugInit (void)
{
    CyU3PUartConfig_t uartConfig;
    CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;
    /* Initialize the UART for printing debug messages */
    apiRetStatus = CyU3PUartInit();
    if (apiRetStatus != CY_U3P_SUCCESS)
    {
        /* Error handling */
        CyFxAppErrorHandler(apiRetStatus);
    }
    /* Set UART configuration */
    CyU3PMemSet ((uint8_t *)&uartConfig, 0, sizeof (uartConfig));
    uartConfig.baudRate = CY_U3P_UART_BAUDRATE_115200;
    uartConfig.stopBit = CY_U3P_UART_ONE_STOP_BIT;
    uartConfig.parity = CY_U3P_UART_NO_PARITY;
    uartConfig.txEnable = CyTrue;
    uartConfig.rxEnable = CyFalse;
    uartConfig.flowCtrl = CyFalse;
    uartConfig.isDma = CyTrue;
    apiRetStatus = CyU3PUartSetConfig (&uartConfig, NULL);
    if (apiRetStatus != CY_U3P_SUCCESS)
    {
        CyFxAppErrorHandler(apiRetStatus);
    }
    /* Set the UART transfer to a really large value. */
    apiRetStatus = CyU3PUartTxSetBlockXfer (0xFFFFFFFF);
    if (apiRetStatus != CY_U3P_SUCCESS)
    {
        CyFxAppErrorHandler(apiRetStatus);
    }
    /* Initialize the debug module. */
    apiRetStatus = CyU3PDebugInit (CY_U3P_LPP_SOCKET_UART_CONS, 8);
    if (apiRetStatus != CY_U3P_SUCCESS)
    {
        CyFxAppErrorHandler(apiRetStatus);
    }
    CyU3PDebugPreamble (CyFalse); }
3. 呼叫 CyFxDebugInit()
在 ApplnThread_Entry() 中, 呼叫 CyFxDebugInit () /* Entry function for the AppThread. */
void
ApplnThread_Entry ( uint32_t input)
{
    CyFxDebugInit();
    /* Initialize the logger application */
    CyFxApplnInit();
    for (;;)
    {
        CyU3PThreadSleep (1000);
        if (glIsApplnActive)
        {
            CyU3PDebugPrint (2, "USB Debug logger: time from start in ticks: %d\n", CyU3PGetTime ());
        }
        CyU3PDebugPrint (2, "USB Debug Hello: %d\n", CyU3PGetTime ());
    }
}
到這邊應該就可以在 PC 上看到 debug message 了, 不過, 還有一些地方要注意  

Note

1. FX3 的 Uart 不會立刻顯示. 大約要幾秒鐘之後, PC 上才會開始看到字. 並不是 delay, 而是 Uart 要過幾秒鐘才有作用. 2. 文字偏移, 沒有回到左邊界. 如果 PC 的軟體沒有自動把“\n” 取代成 “\r\n” 就會造成文字一直偏移. 這時可以自己加. 例如 :
CyU3PDebugPrint (2, "USB Debug Hello: %d\n", CyU3PGetTime ());
改成
CyU3PDebugPrint (2, "USB Debug Hello: %d\r\n", CyU3PGetTime ());



















2014年4月27日 星期日

[EZ-USB FX3] USB Transfer modes


不僅僅是 FX3, 所有的 USB device 都可以有 4 種不同的傳輸模式. 這 4 種不同的傳輸模式, 各自有各自的定位和特性,傳輸速度. 在評估 FX3 的傳輸速度前, 先簡單說明這幾個不同的傳輸模式.
參考連結:
http://www.beyondlogic.org/usbnutshell/usb4.shtml#Interrupt
Control Transfer 控制傳輸
Interrupt Transfer 中斷傳輸
Isochronous Transfer 同步傳輸
Bulk Transfer 大量傳輸

 

Control Transfer: 控制傳輸

定位:
Control Transfer 是被設計作為 USB Host 向 USB Device 下達命令及狀態查詢. 它的作用主要是在於和應用無關的 USB 系統控制. 所以, 每個 device 都必需至少提供一組 Control Transfer 來對應.
當然, 要自己定義一組 Control Transfer 來使用也是可以的.
特徵:
由於是對應 USB Host 的命令, 所以對 device 來說, Control Transfer 是突如其來, 但是它又必需以最高優先權傳送, 所以它可以傳送的資料限制也最大. 通常, 它只能傳送 8/16/32/64 個 bytes 的資料.

Interrupt Transfer: 中斷傳輸

定位:
相對於 Control Transfer 是被動的和 USB Host 溝通, Interrupt Transfer 是被設計作為USB device 向 USB Host 傳送非週期的資料. 但是在 USB 的架構下, 傳輸的頻寬是由 USB Host 分配, 因此, Interrupt Transfer 實際上是先向 USB Host 發出頻寬分配的請求, 然後在下一次傳輸時, 才真正的傳遞資料.
特徵:
Interrupt Transfer 傳送的是非週期性的資料, 這代表這資料的重要性比較高. 因此, Interrupt Transfer 傳送的資料, 可以被保證在一段時間內送達, 而且, 如果傳送錯誤, 它可以在下一個 Host/Device 交換資料的時間內重傳.
Guaranteed Latency
Stream Pipe - Unidirectional
Error detection and next period retry

Isochronous Transfer: 同步傳輸

定位:
同步傳輸用來傳送連續, 定期發生, 對時間敏感的資料. 譬如說, 電話/即時影像/視訊電話等應用. 當中間有一小段資料失誤, 對應用來說, 影響不大, 可能只是很短的一個雜音, 或是畫面破損了一下, 停滯了一下. 由於下一個時間點的資料還是會繼續收到, 因此, 這樣的影響是可以被接受的.
Isochronous Transfer 的資料, 及時送達比資料的正確性重要.
特徵:
Isochronous Transfer 保證在傳輸的過程中, 在每一次傳輸時, 保留預先分配的資料頻寬來傳送資料. 因此, 它可以保證在固定時間內傳輸, 它檢查錯誤, 但是不重傳, 也不保證送達.
Guaranteed access to USB bandwidth
Bounded latency
Stream Pipe - Unidirectional
Error detection via CRC, but no retry or guarantee of delivery
Full & high speed modes only
No data toggling

Bulk Transfer: 大量傳輸

定位:
Bulk Transfer 用來傳送大量突發性, 時間不敏感的資料. 例如外接硬碟, 從 scanner/DSC 接收影像資料. 這些資料, 傳輸錯誤不能容許, 但是慢個一秒也沒有太大的關係. 
Bulk Transfer 的時間優先權是最低的, 因此, 在其他 Transfer mode 作用的情況下, 會延遲較長的時間, 資料才能被送出. 但是在傳輸的頻寬分配完之後, Bulk Transfer 又可以吃光所有剩下的頻寬. 因此, 它又具備最大傳輸能力的可能性.
特徵:
Bulk Transfer 的時間優先權是最低的, 因此, 在其他 Transfer mode 作用的情況下, 會延遲較長的時間, 資料才能被送出. 但是在傳輸的頻寬分配完之後, Bulk Transfer 又可以吃光所有剩下的頻寬. 因此, 它又具備最大傳輸能力的可能性.
Used to transfer large bursty data
Error detection via CRC, with guarantee of delivery
No guarantee of bandwidth or minimum latency
Stream Pipe-Unidirectional
Full & high speed modes only

2014年4月23日 星期三

[EZ-USB FX3] FX3 啟動


這部份說明的是, 啟動 Eclipse ( IDE for firmware development), build example project, download firmware code, 以及從 Windows 上的程式去存取.
使用到 USBBulkLoopAuto 這個 example, 及 Bulk Loop 這個 utility.
參考 Application Note AN75705, Getting Started with FX3
1. 啟動 Eclipse. Eclipse 已經在安裝 SDK 的時候, 一併安裝了. 可以在程式集的 Cypress 下面的 Eclipse 找到. 不同的 SDK, 有不同的檔名, SDK 1.3 的檔名是 “EZ USB Suite”
01-Start-Eclipse-IDE
2. Select Workspace. Eclipse 的架構是 Workspace 裡面裝 project. 所以要先選擇一個 workspace. 用 default 的也可以, 或者隨便定義一個空的目錄也行. (避免給自己找麻煩, workspace 的名稱不要有空白字元).
02-Select-Workspace
3. Upload Usage data. Eclipse 會收集一些資訊, 給不給都沒有關係.
03-Upload-Usage-Data
4. Eclipse 說明收集的資料使用目的及限制.
04-Terms-of-use
5. 加入範例專案. SDK 已經包含了一些 example, 現在要把它複製到 Eclipse 的 workspace. 在 Eclipse 的 File 選項, 選擇 Import. import source 選擇 General/Existing Projects into Workspace, 如下圖. 按 Next 繼續.
05-Import-Example-Project
6. 選擇來源專案目錄. 預設的 example project 會放在 “C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\firmware”. 按確定繼續.
06-Select-Source-Folder
7. 複製專案. Eclipse 在這個目錄, 會找到許多專案, 把它們通通 import 進來.
* copy projects into workspace 務必要打勾
07-Import-Projects
8. 設定 Save before Build. 在 Eclipse 的 Window 選項, 選擇 Preferences, 在 General/Workspace, 把 Save automatically before build 打勾. 按 Apply09-Save-Before-Build
9. 建置 USBBulkLoopAuto 專案. 先把 USBBulkLoopAuto 專案選取.
08-Build-USBBulkLoopAuto
10. Build. 可以在 USBBulkLoopAuto 的選項上按右鍵, 選擇 Build Project. 也可以選取專案後, 按工作列的鎚子. 建置的結果, 可以在底下的 Console 視窗看到.
10-Build-Project
11. download firmware. 接下來要用 Control Center download firmware 到 FX3 上, 所以先從程式集中, 叫出 Control Center.
11-Control-Center
12. 選取目前僅有的 Cypress USB BootLoader
12-Select-Device
13. 在 Control Center 的 Program選項中, 選取 FX3/RAM. 然後在選取 file 的對話盒中, 選取剛剛建置完成的 USBBulkLoopAuto.img
13-Select-Image-File
14. Control 自動 download firmware. (這一點不太欣賞). download 完之後, Control Center 的 device 的名稱變成 Cypress USB BulkloopExample
14-Device-Changed
15. 接下來, 要用 PC 端的 Bulk Loop 來和 FX3 試傳資料. 在程式集中, 選取 Cypress/Cypress USBSuite/Bulk Loop
15-Launch-Bulk-Loop
16. BulkloopExample 顯示可用的狀態
16-Bulk-Loop
17. 按下 Start, 開始試傳.
17-Bulk-Loop-run

2014年4月22日 星期二

[EZ-USB FX3] USB driver 安裝記錄


參考 Application Note AN75705, Getting Started with FX3
1. 將板子的電源 ( 5V adapter) 接上. 板子上的 LED 燈會亮起.
2. 將所附的 USB 3.0 cable 連接到電腦的 USB 3.0 port.
3. 過一段時間之後, 右下角的狀態列, 會顯示錯誤的彈出視窗. 點擊之後, 螢幕中央會顯示無法識別的裝置
01-device-not-recognize
4. 依照建議, 拔除 USB cable, 再重新連一次. 右下角的狀態列, 會顯示另一個視窗. 點擊之後, 螢幕中央會顯示找不到驅動程式.
02-device-driver-not-found
5. 關閉此對話盒.
6. 打開控制台/硬體及音效/裝置管理員
03-device-manager
7. 點選 “WestBridge”, 如上圖. 選擇更新驅動程式軟體.
04-update-driver(WestBridge)
8. 選擇"瀏覽電腦上的驅動程式軟體", 如上圖所示. 並指向以下目錄
“C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\driver\bin\win7\x64”, (因為我的電腦是Windows 7 64 位元)
05-manual-update 
9. 安裝完成, 顯示 “Cypress USB BootLoader”
06-update-success
10. 安裝成功後的裝置管理員
07-updated-device-manager
11. 打開程式集/Cypress/Cypress USBSuite/Control Center
08-Control-Center
12. USB Control Center 的畫面, 左邊顯示 "Cypress USB BootLoader”, 右邊顯示 USB device 的相關資訊
09-control-center-view
13. USB driver 安裝完成