Loading Application Files via UART Print

 

This note explains how to load files such as binary applications from Linux running on the target via UART. This is a useful procedure for those targets that do not provide an Ethernet link and have the serial console as the only communication channel.

On the host, activate the Cortex-M cross-development environment:

-bash-3.2$ pwd
/home/vlad/test/linux-cortexm-1.14.1
-bash-3.2$ . ./ACTIVATE.sh
-bash-3.2$

Create a simple "Hello, world" C application:

[host] $ cd /tmp
[host] $ vi test.c
#include <stdio.h>

void main(void)
{ printf
("Hello, STM32F7\n");
}
~

Build the application for the Cortex-M target:

[host] $ arm-uclinuxeabi-gcc -o test test.c -I ${INSTALL_ROOT}/A2F/root/usr/include -mcpu=cortex-m3 -mthumb

Encode the application binary into an ASCII-only presentation so that the file can be transmitted over a serial line:

[host] $ uuencode test < test > test.encoded

You will require the uudecode application on the target in order to convert the ASCII-only file back into the application binary. Go to your project directory and enable uudecode in the target busybox:

[host] $ cd /home/vlad/test/linux-cortexm-1.14.1/projects/networking/
[host] $ make bmenuconfig

Go to Coreutils and enable uudecode:

Build the updated project:

[host] $ make
...

Load the resultant uImage (networking.uImage in the above example) to the target.

On the host, make sure that the serial port you use for the target console is configured for 115.2 Bps:

[host] $ stty -F /dev/ttyUSB1
speed 115200 baud; line = 0;
eof = ^A; min = 1; time = 0;
ignbrk -brkint -icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe

Start the target console:

[host] $ ./console-stm32f7.script
Connecting to /dev/ttyUSB1, speed 115200
Escape character: Ctrl-\ (ASCII 28, FS): enabled
Type the escape character followed by C to get back,
or followed by ? to see other options.
----------------------------------------------------

From the target, run the following to read a file from the serial console:

~ # cat > /test < /dev/ttyS5

Exit the target console (Ctrl-\ and then q in kermit).

On the host, send the encoded ASCII file to the serial port used for the target console:

[host] $ cd /tmp
[host] $ cat test.encoded > /dev/ttyUSB1

When the transfer command finishes, enter the target console again:

[host] $ ./console-stm32f7.script
Connecting to /dev/ttyUSB1, speed 115200
Escape character: Ctrl-\ (ASCII 28, FS): enabled
Type the escape character followed by C to get back,
or followed by ? to see other options.
----------------------------------------------------

Type Ctrl-C to interrupt the cat command:

^C

Run uudecode to convert the ASCII file back to the binary file:

~ # busybox uudecode /test.encoded

Change mode to allow running the application binary:

~ # chmod u+x test

Finally, run the application:

~ # ./test
Hello, STM32F7
~ #