About
Based on this, I have written a small program for the STM32F4 Discovery that uses the USB-CDC class to show up as an virtual serial port. I’m using the USB stack provided by ST, however, there is also another project that uses libopencm3 that can be found here. I have routed the write system call to use this port, so the stdio printf function will print directly to this serial port.
How to use it
If you don’t have the necessary toolchain to build and upload programs to the STM32F4, you can have a look at this post. Otherwise, the following steps should be sufficient:
- Download the source code complete with all libraries and makefiles here.
- Unpack the program and run make from its root directory. The binary file that can be uploaded should appear in the build directory.
- Upload the program to the STM32F4 discovery (again, this post explains how) and plug in a micro-USB cable to the port next to the audio jack.
- The serial port should show up as /dev/ttyACM0 on most GNU/Linux distributions, such as Ubuntu.
- Start a serial port terminal, such as gtkterm (sudo apt-get install gtkterm on Debian/Ubuntu), and open ttyACM0. The baudrate does not matter as it currently is ignored by the program (see usbd_cdc_vcp.c).
The current program runs some floating point operations and prints the elapsed time on the USB-CDC serial port. The float parameters in the makefile can be changed to see how the FPU affects the speed (and there is a lot of difference). Remember to run clean after changing the float parameters, as the object files are not compatible between hardfloat and softfloat builds.