Configuring CYW943907AEVAL1F as USB device
This post discusses about how to configure CYW943907AEVAL1F board as USB device and PC/laptop as USB host. After programming the device, CYW943907AEVAL1F acts as HID keyboard. It prints alphabets ‘a’ to ‘z’ after pressing USER_1 and prints digits ‘1’ to ‘0’ after pressing USER_2 on any text editor on PC/laptop.
To evaluate USB operation on CYW943907AEVAL1F board, some hardware modifications are needed. Refer to blog post Hardware connections for USB evaluation on CYW943907AEVAL1F for the required changes.
Make the hardware connections to connect Olimex ARM-USB-TINY-H debugger with CYW943907AEVAL1F board as discussed in post OpenOCD -WICED.
For initializing device as HID keyboard, wiced_usb_device_hid_keyboard_init() function is called. There are different APIs and functions used within this function to initialize the USB device stack, USB DCI (Device Controller Interface) resources and USBX device controller. hid_keyboard_callback() is the function used to define HID class parameters for keyboard. In function wiced_usb_device_usbx_evt_callback(), different callback events are defined based on the state of the USB device like reset, attached, configured, etc.
The APIs available to configure CYW43907 as USB device are as follows:
1. ux_system_initialize (VOID *non_cached_memory_pool_start, ULONG non_cached_memory_size, VOID *cached_memory_pool_start, ULONG cached_memory_size)
USBX has its own memory manager. The memory needs to be allocated to USBX before the host or device side of USBX is initialized. USBX memory manager can accommodate systems where memory can be cached. This API initializes USBX memory resources with non-cached and cached memory pool.
a. non_cached_memory pool start - Beginning of non-cached memory
b. non_cached_memory_size - size of memory needed
c. cached_memory_pool_start - Beginning of cached memory
d. cached_memory_size - size of memory needed
2. ux_device_stack_initialize (UCHAR * device_framework_high_speed, ULONG device_framework_length_high_speed, UCHAR * device_framework_full_speed, ULONG device_framework_length_full_speed, UCHAR * string_framework, ULONG string_framework_length, UCHAR * language_id_framework, ULONG language_id_framework_length, UINT (*ux_system_slave_change_function)(ULONG), UX_USER_CONFIG_DEVICE *user_config_device)
This API is used to initialize the USB device stack. It mainly provides the stack with the device framework for the USB function
a. device_framework_high_speed - pointer to high speed framework
b. device_framework_length_high_speed - Length of the high speed framework
c. device_framework_full_speed - pointer to full speed framework
d. device_framework_length_full_speed - Length of the full speed framework
e. string_framework - pointer to string framework
f. string_framework_length - Length of the string framework
g. language_id_framework - pointer to string language framework
h. language_id_framework_length - Length of the string language framework
i. ux_system_slave_change_function - function to be called when the device state changes
j. user_config_device - user configured device data
3. ux_dcd_bcm4390x_initialize (ULONG dcd_io, ULONG parameter)
This API is used to define USB Device Controller Interface (DCI) resource.
a. dcd_io - DCI resource address
b. parameter - information about DCI resource
Download the usb_device application attached with this blog post. Extract and add the downloaded folder in apps folder of WICED Studio 6.0 or later.
To program your device using JTAG, install the drivers using zadig. Connect Olimex debugger and CYW943907AEVAL1F board to your PC/laptop. You can see JTAG device detected in Device Manager as follows.
Create the make target as follows:
usb_device-CYW943907AEVAL1F JTAG=Olimex_ARM-USB-TINY-H download run
Download the program to CYW43907 by double clicking on above make target. After you download the program, you will see WICED device acting as HID keyboard in Device Manager.
Open any text editor in your PC/laptop. You should see alphabets or digits getting printed after pressing USER_1 or USER_2.
Note: The USB Device functionality does not work for device classes (For instance, mass storage class) that use a transfer data length which is a multiple of the maximum packet size. Currently there is no workaround for this issue. The issue is being investigated and will be updated once there is a solution or workaround identified.