PSoC Creator provides a simple way to implement certain type of USB devices including a USB composite device that has two CDC device. Thus you can turn a $10 PSoC 5LP stick into a FT2232 like device or you can build a UART sniffer with few lines of code.
Open up the configuration dialog by double clicking on the component. At the Device Descriptor page, select the Import Descriptor Root (green down arrow) button. It will show up a file selection dialog box that allows you to import templates (xml files) from handful number of predefined settings. For the purpose of this post, choose USBUART_TwoComPorts.root.xml.
You will find that all the descriptors and items necessary for dual CDC are nicely populated. You can delete any existing device descriptors.
Finally populate two UART components and set their parameters such as baud, number of data bits, parity types to suit your purpose.
// initialize USB module
USB_Start(0, USB_3V_OPERATION);
Likewise, there is no changes in all the other USB API functions except that you need to choose the COM port before calling any of those.
// choose COM port
USB_SetComPort(port_no);
Dual UART in looback connection |
PSoC Creator Component Setup
Start a new PSoC project with the selection of appropriate PSoC device. Then pick a USBFS from the Cypress Component Catalog on the right.Open up the configuration dialog by double clicking on the component. At the Device Descriptor page, select the Import Descriptor Root (green down arrow) button. It will show up a file selection dialog box that allows you to import templates (xml files) from handful number of predefined settings. For the purpose of this post, choose USBUART_TwoComPorts.root.xml.
You will find that all the descriptors and items necessary for dual CDC are nicely populated. You can delete any existing device descriptors.
Finally populate two UART components and set their parameters such as baud, number of data bits, parity types to suit your purpose.
Coding
In the main.c you can initialize the USB component with the same way as any other USB component.// initialize USB module
USB_Start(0, USB_3V_OPERATION);
Likewise, there is no changes in all the other USB API functions except that you need to choose the COM port before calling any of those.
// choose COM port
USB_SetComPort(port_no);
<<Source Code>>
UART Sniffer
You can turn this dual COM device into a UART sniffer by wiring two RX lines of the device to the UART channel of interest.
The wxPython terminal panel introduced in the other post then can be used to create a dual pane terminal emulator by simply creating two panel objects and populate them in a frame window:
self.pnlTerm1 = TermPanel(self, serial.Serial())
self.pnlTerm2 = TermPanel(self, serial.Serial())
Note that each panel has its own instance of PySerial object. Resulting screen should look like this:
<<source code>>
Comments
Post a Comment