Skip to content
chuck-h edited this page May 17, 2015 · 13 revisions

Cypress PSoC4 Microcontroller

"System on a Chip" with configurable analog and digital logic, in addition to ARM Cortex-M0 processor.

Using http://www.cypress.com/?rID=92146 $4 prototyping kit to start.

PSoC configuration as of 13-May-2015

Serial Communications

The prototyping kit implements a standard USB serial interface which will enumerate as a COM port (or on linux, as /dev/ttyACM0). This COM port allows input from and output to the device

  1. via a terminal program (e.g. Hyperterminal)
  2. via Cypress Bridge Control Panel (see below)
  3. via Cypress Bootloader Host application to install new firmware

Update 24-Feb-2015: There is also a ROS message-based version (project HivoStatRos.cydsn in the PSoC Creator workspace) described later on this page. The simple serial commands described here are implemented in project MiniStat.cydsn)

As of 7-Feb-2015, you can send a limited number of commands to the microcontroller from the terminal interface; these are defined in main.c in the area beginning thus:

        // watch for serial input
        // simple serial command protocol, single-letter commands:
        //    [<numeric parameter>]<command letter>
        // e.g. '150s' sets stir speed to 150
        //
        if (Host_UART_SpiUartGetRxBufferSize() != 0) {
  [...]

Commands:

  • nnns -- set stir motor PWM value to nnn (range 0 - 1023)
  • nnnp -- set pump motor PWM running value to nnn (range 0 - 1023)
  • nnnP -- run pump for nnn steps (counted from pump feedback sensor)
  • nnnR -- start RX8 data reporting mode, publish nnn samples, then stop

Cypress Bridge Control Panel

This free application provided by Cypress gives a basic real-time plotting interface ("strip chart") for values sent out by the microcontroller over its serial port. Here is a plot of photodiode signal (arbitrary units), as a drop of milk is stirred into a testube:

Variables are defined in a dialog:

The data format is defined with an "RX8 command string", e.g.: RX8 [ H = 52 ] @0photo @1photo @2photo @3photo X @0pump @1pump @2pump @3pump X @0volt @1volt @2volt @3volt X @0corr @1corr @2corr @3corr X @0count @1count that must correspond with the print statements in the firmware.

ROS integration

Microcontroller firmware routines access the ROS communications through source files and message header files in the include/ros_lib subdirectory in the PSoC Creator workspace. Source files are copied from rosserial/rosserial_client and rosserial/rosserial_psoc4 directories into include/ros_lib, and message header files are generated automatically. The whole process of copying and message generation is handled by the make_libraries.py script.

Building message headers

The message headers are built programmatically based on *.msg files. At this time the build operation is only supported on a linux host in a somewhat awkward fashion. To be improved!

  1. Create a catkin environment in the linux filesystem and link to the PSoC Creator subdirectories. (Directory locations are for Chuck's laptop, edit as necessary)
    mkdir-p ~/catkin_hb/src
    cd ~/catkin_hb/src
    catkin_init_workspace
    cd ..
    catkin_make install
    source install/setup.sh
    ln -s '/media/C/Documents and Settings/Chuck/My Documents/PSoC Creator/ministat-1/HivoStatRos.cydsn/rosserial' rosserial
    ln -s '/media/C/Documents and Settings/Chuck/My Documents/PSoC Creator/ministat-1/HivoStatRos.cydsn/include' ros_lib_include
    

1. Build ros_lib.
 1. If there is stale information in the ros_lib subdirectory, you must first remove it:
    ```
    rm -rf ~/catkin_hb/ros_lib_include/ros_lib
  1. Then
    rosrun rosserial_psoc4 make_libraries.py ros_lib_include
    

#### Developing HivoStatRos Code

It is convenient to develop PSoC code for ROS in C++ in the PSoC Creator environment on Windows. The Cypress toolkit is oriented primarily toward C (rather than C++) development, so there are certain workarounds
* `*.cpp` source code files must be manually marked as "C_FILE" type using the right-click Properties tab
* C++ - specific compiler flags are used, which cause warnings when C files are processed. These warnings can be ignored.

Application source files (*.cpp, *.h) are usually placed at "top level", in the `HivoStatRos.cydsn` directory.

If you decide to add a new message type (i.e. write a `xxx.msg` file), you will need to re-run the ros_lib build process, described above, on a linux machine.