eCos Support for USB Serial like Peripherals Introduction Introduction eCos support for USB Serial like Peripherals Introduction The eCos USB-Serial package provides additional support for USB peripherals that look like a serial port to the host. These can follow the ACM communication device specification or simpler devices which just have two bulk endpoints. Microsoft Windows requires ACM mode. Linux should operate with both modes, however ACM may cause problems since the eCos driver does not implement all the class descriptors, so generic mode is recommended. The USB-Serial package is not tied to any specific hardware. It requires the presence of USB hardware on the target and a suitable device driver to make endpoints available for this code to use. The configuration system cannot load the eCos package automatically for specific targets, in the way that a USB device driver or an ethernet driver can be loaded automatically. Instead, the package has to be added explicitly. When using the command line tools this will involve an operation like the following: $ ecosconfig add usbs_serial Typically, this will automatically cause the USB device driver to become active. Configuration Configuration Configuration USB Serial like Peripherals Configuration The package requires a few basic configurations plus optionally some additional configuration options. The driver needs two or three endpoints, depending if ACM communications or a more generic model is used. This is configured with CYGDAT_IO_USB_SLAVE_CLASS_TYPE which can take the value ACM or generic. The CYGDAT_IO_USB_SLAVE_SERIAL_EP0 must be configured with the control end point of the USB device. When using static endpoint configuration, CYGPKG_IO_USB_SLAVE_SERIAL_STATIC_EP must be enabled, CYGDAT_IO_USB_SLAVE_SERIAL_TX_EP must be configured with the endpoint to be used for transmission and CYGDAT_IO_USB_SLAVE_SERIAL_RX_EP must be configured with the end point used for reception. Associated with these are CYGNUM_IO_USB_SLAVE_SERIAL_RX_EP_NUM and CYGNUM_IO_USB_SLAVE_SERIAL_TX_EP_NUM which are the endpoint numbers and are used during enumeration of the device. The TX and RX endpoints must operate in BULK mode. If operation mode ACM is selected a third endpoint is needed. This must operate in interrupt mode and should be configured in CYGNUM_IO_USB_SLAVE_SERIAL_INTR_EP and CYGNUM_IO_USB_SLAVE_SERIAL_INTR_EP_NUM. The USB serial device will make its vendor:product ID known to the host. This should be configured with CYGNUM_IO_USB_SLAVE_SERIAL_VENDOR_ID and CYGNUM_IO_USB_SLAVE_SERIAL_PRODUCT_ID. NOTE: The default configurations are not valid for products, but should work for testing. The USB enumeration also contains text strings to describe the device. This text string can be set with CYGDAT_IO_USB_SLAVE_SERIAL_PRODUCT_STR. The last configuration option of interest is CYGPKG_IO_USB_SLAVE_SERIAL_EXAMPLES. When true example programs will be built when the eCos tests are built. These are not pass/fail test like other eCos tests, but examples of how the eCos USB serial class can be used. Host Configuration Host Configuration Host Configuration for USB Serial like Peripherals Host Configuration Configuration for two hosts are listed here, Microsoft Windows and Linux. It should also be possible to use the eCos USB serial like peripheral driver with other hosts. Linux The eCos USB serial like peripheral driver can be used in Linux in one of two ways. Using the generic usbserial kernel module passing the vendor and product ID as module parameters. e.g. modprobe usbserial vendor=0xabcd product=0x1234 would load the kernel module so that it would use a USB device abcd:1234 as a serial device. Using the mini driver provided with eCos in the host/linux directory. This driver must be edited and the correct vendor and product ID set to match the vendor and product ID used by the device. Once compiled this driver can be loaded with: modprobe usbserial modprobe ecos_usbserial This driver is known to compile with kernel versions 2.6.18 and probably works fine with other kernels. However it fails to compile with kernels after 2.6.25. Both of these methods will result in the Linux Kernel making a new serial device available. This is typically named /dev/ttyUSB0. Microsoft Windows To install the device in a Microsoft Windows system make use of the INF file in host/windows/eCosUsbSerial.inf. Copy this INF file and usbser.sys from your version of Windows into an empty directory. Then plug in the USB device. When prompted to load a driver navigate to the INF file and select it. API Function usbs_serial_start usbs_serial_init usbs_serial_start usbs_serial_wait_until_configured usbs_serial_is_configured usbs_serial_start_tx usbs_serial_wait_for_tx usbs_serial_tx usbs_serial_start_rx usbs_serial_wait_for_rx usbs_serial_rx usbs_serial_state_change_handler eCos USB Serial like Peripherals API #include <cyg/io/usb/usbs_serial.h> void usbs_serial_start void void usbs_serial_init usbs_serial * ser usbs_tx_endpoint * tx_ep usbs_rx_endpoint * rx_ep void usbs_serial_wait_until_configured void> cyg_bool usbs_serial_is_configured void void usbs_serial_start_tx usbs_serial * ser const void *buf int * n int usbs_serial_wait_for_tx usbs_serial * ser void usbs_serial_start_rx usbs_serial * ser const void *buf int * n int usbs_serial_wait_for_rx usbs_serial * ser int usbs_serial_rx usbs_serial * ser const void *buf int * n void usbs_serial_state_change_handler usbs_control_endpoint * ep void * data usbs_state_change change int prev_state Description For examples of how to use this API see the files .../tests/usbserial_echo.c and .../tests/usb2serial.c The first function that needs calling is usbs_serial_start(). This will initialise the eCos USB slave layer, creating all the enumeration data and then let the host know that the device exists. Once the USB subsystem has been started it is necessary to wait for the host to configure the device using the function usbs_serial_wait_until_configured(). The host will assign the device an ID and then load the appropriate device driver in the host in order to make use the device. Once the device is configured it is then possible to make use of it, i.e. send and receive data. This transfer of data can be accomplished either asynchronously or synchronously. It is also possible to mix asynchronously and synchronously between receiving and sending data. To perform asynchronous operations the functions usbs_serial_start_rx() and usbs_serial_start_tx() is used to start the operation. These functions start the necessary actions and then return immediately. At a later time the functions usbs_serial_wait_for_tx() or usbs_serial_wait_for_rx() should be called. These will, if necessary, block and then return the status and any data for the previously started asynchronous call. To perform synchronous operations the functions usbs_serial_rx() and usbs_serial_tx() are used. These functions will block until the requested action is complete.