How to use the serial interface to communicate with an FRDM-KL25Z in Linux

This short guide will show how to communicate with the FRDM-KL25Z using the Serial and USBSerial classes from the mbed library in Linux.

Serial and USBSerial are two different methods for creating serial connections using mbed. USBSerial creates an emulated serial port over a normal USB port while Serial uses the built in serial port (if there is one). In the case of the FRDM-KL25Z this can be done through the virtual serial port provided by OpenSDA.

This small example will create two serial connections; one using the serial port built into OpenSDA, and one over the normal USB port. It will pass everything given to either interface on to the other interface.

Each of these device files are connected to one of the serial interfaces on the FRDM-KL25Z. To use them you will first have to add your user to the dialout group.

sudo usermod -a -G dialout USERNAME

You can use any terminal emulator of your choice to connect to these serial ports. I will be using minicom for this example.

Open two terminals. On the first run:

minicom -b 9600 -D /dev/ttyACM0

And in the second:

minicom -b 9600 -D /dev/ttyACM1

‘-b 9600’ sets the baud rate. The default value used by mbed is 9600.

If everything is working correctly whatever you write in one terminal should now appear on the other, and vice versa. If it doesn’t create new lines when you press ‘enter’ and it instead jumps to the beginning of the current line, tell minicom to add linefeeds by pressing ‘Ctrl-a a’.