I needed to observe the communication between a microcontroller and a modem, but also between the PC (USB-2-Serial) and the microcontroller. Both protocols were not available - so how to find out what is going on?
Reverse-engineering!
My solution:SNIFFly - a simple seriadata logger: Take another microcontroller with at least 4 channel UARTs and additionally a USB function peripheral to make the PC connection (alternatively have a fifth UART and use a USB-2-serial adapter).
Well, working with Cypress' PSoC kits I remembered the KitProg that is part of the most Cypress Pioneer Kits, and works as the programmer unit for those kits. It is based on PSoC5LP.
Sometimes (e.g. Embedded World) Cypress gives that kits for free, or you can order for approx. 10-20USD from distributors.
Some suitable kits having the KitProg2 programmer:
Advantage of the CY8CKIT-149, it has a Micro-USB socket on board, that simpliefies and improves the connection using a standard USB cable to the PC. The older KitProg2 implementation (e.g. CY8CKIT-149) can be connected directly to the PC-USB Host port, but that is somethis a little groggy.
Cypress' KitProg2Many people do not know, that the KitProg2-Firmware, beside of the main purpose ('programmer'), includes additionally a bootloader that allows to add and run user-applications. This is described well in the user-guide that can be found on your computer, when you have installed the PSoC Creator IDE, that anyway is required to develop software for PSoC.
Depending on your installation path (e.g.: C:\Program Files (x86)\Cypress\Programmer\Documents\KitProg2 User Guide.pdf), find the User Guide and see chapter 'Developing Applications for PSoC 5LP' for details how to make a bootloadable application, how to change the KitProg2 from programmer mode to bootloader mode, and how to download the user-software.
Also an example project is provided by Cypress, depending on the installation path, e.g. C:\Program Files (x86)\Cypress\Programmer\Examples\Misc\KitProg2_Custom_App).
Software implementationSNIFFly is based on the KitProg2_Custom_App decribed above. Following components have been added to implement the requirements:
- 4 x UARTs (Receive only) added
- 4 x Interrupts added to the UART-RX interrupt
- 1 x USBFS (CDC mode) added
The PSoC Creator schematic is very clear and more or less self-explaining: Four UARTs will forward (via interrupt handling) the receive-data to the Virtual-Com-Port realised by the USBFS (CDC) component.
NOTE: Before compiling/building the project adjust the right baudrate for each UART channel!!!
As mentioned above, the bootloadable component is still needed to be kept in the project for further updates and not to loose the KitProg.
The custom application must provide a means to switch back to KitProg2 mode, otherwise the programming capability will be lost unless KitProg2 firmware would be reprogrammed. That 'return' is implemented by usage of the mode switch SW available on the board. See file app_switch.c for the implementation.
How to download the software (Bootloader)The CustomApp is not downloaded as normally by the PSoC Creator Programmer! It need to be handled by the Bootloader Host tool that can be invoked from the PSoC Creator Tools menu.
On the KitProg2 the bootloader mode is started by pressing mode switch SW3 while power-up.
In case the sniffer software is running then the bootloader can be entered by pressing SW3 more than 5 sec, the status LED3 will light. Release SW3 and press it again short, the kit will reboot entering the bootloader mode what is indicated within the Bootloader Host tool.
Ensure that Port 'USB Human Interface Device 04B4_F146' is listed correctly.
Browse for the right file: <project>\ KitProg2_Uart_Sniffer.cydsn -> CortexM3\ARM_GCC_541\Debug\KitProg2_Uart_Sniffer_2.cyacd
HardwareJust add to the given KitProg2 some header pins that allows you to connect with the required UART channels with your target system. Don't forget to connect GND as well.
Of course, if required the pin mapping can be changed within the PSoC Creator project.
Run the snifferAfter the project has been downloaded to the KitProg2 it is automatically started. Open your preferred terminal program and select the related Virtual-Com-Port.
Each data that is received by UART #1 to #4 will be routed to the terminal.
Example 1 (Sequential UART activity):
3:Hello World on channel #3
2:My Message on channel #2
Example1 demonstrates a sequential flow: UART#3 has written a complete message. Afterwards UART#2 has written a message.
Example 2 (Parallel UART activity):
3:Send Reque
2:Ans
3:st
2:wer
Example 2 demonstrates that UART communication may takeplace on several channels in parallel. The content is written into the buffer contiguouslyas it arrives, but a channel marker is added each time the channels changes.That helps later to identify the order in time and to re-engineer the sequenceof messages. In this case UART#3 started the communication (‘Send Request’) whilein between UART#2 already started to answer (‘Answer’).
Example 3 (real data):
Reflecting the origin of this project, how to observe four UART channels used within a modem system, the following log was taken after power-on
- Channel #1: PC -> Microcontroller
- Channel #2: Microcontroller -> Modem
- Channel #3: Modem -> Microcontroller
- Channel #4: Microcontroller -> PC
While start-up no PC command was sent, that’s why no data is visible on channel #1.
SNIFFly works fine and helped me to understand the modem communcation.
Summary and OutlookFor more complex tasks the tool will surely not be the right replacement for professional data loggers. But in the given case, the tiny sniffer tool (that’s why I named it ‘SNIFFly’) was very helpful while analyzing the modem protocol that was not very well documented by the supplier. It helped a lot to understand the commands needed to make the connection.
Some additonal ideas came up and could be implemented on demand, e.g.
- RTC time stamp
- CAN interface
Additionally, the possibility of Cypress' KitProg2 to be used as a tiny DevKit for running custom Application might be an interesting value adder for CY kit users. Did you know that?
#END
Comments