UART

The STM32F401RE has three USART controllers. USART2 is the slowest of the three with a maximum baud-rate of 5.25 Mbps and the USART-controller connected to the nucleo board’s built-in ST-link/V2, which allows us to use the nucleo’s USB-to-serial.

The ST-link itself is powered by an STM32F103CB which also has three USARTs, one with a max baud-rate of 4.5 Mbps, and two with 2.25 Mbps. The max baud-rate I’ve been able to achieve without dropping any¹ data is 115.2 kBps.

In the firmware the USART2 is connected to two DMA-streams to handle transmission and reception, which unlike with SPI can have different lengths. Another difference from SPI is that there’s no master or slave, so the STM32F401 can transmit the collected data whenever it’s ready.

The protocol is 8-bit, so to send the 12-bit data from the ADC we run into the same problem with endianness as with SPI.


On *NIX-systems the USART is handled as a terminal, and on Wheezy the nucleo board is present as:

/dev/ttyACM0

Your user must have access to this file!

There’s a wealth of information on the internet about what a terminal is and how you read and write from it, so take a look for yourself.²

It takes ten bits to send one byte over UART, so with a data-rate of 115.2 kbps we get a minimum transfer-time of:

73880 bits / 115.2 kbps = 642 ms

and with a collection time from the CCD of 7.4 ms it should be possible to read the CCD at 1 Hz. Fast enough for simple chemical kinetic measurements 🙂

If you can live with a subset of the CCD’s pixels, it can of course be much faster. This is a feature I’m working on.


¹ A baudrate of 230.4 kbps is possible, but every once in a while a frame is dropped leading to hangups and data corruption. On my computer (a 12 year old IBM X40) it’s someywhere between 1:5 – 1:30. YMMV.

² Recommended reading for understanding tty’s:
http://tldp.org/HOWTO/Serial-Programming-HOWTO/index.html
The Serial Programming Guide for POSIX Operating Systems
POSIX-compliant example-code


The original posts at erossel.wordpress.com
The A is for asynchronous