Loading Application Files via UART

Loading Application Files via UART

This note explains how to transfer files, such as application binaries, to a target running Linux over the serial console. 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.

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

    [host] $ . ./ACTIVATE.sh
  2. Create a simple "Hello, world" C application:

    [host] $ cd /tmp [host] $ vi test.c #include <stdio.h> int main(int argc, char *argv[]) { printf("Hello, i.MX RTxxxx\n"); return 0; }
  3. Build the application for the Cortex-M target:

    [host] $ ${CROSS_COMPILE_APPS}gcc -o test test.c
  4. If you have no uuencode installed in your system, then install it:

    [host] $ sudo apt-get install sharutils
  5. 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

    The uudecode application on the target (in order to convert the ASCII-only file back into the application binary) is provided with busybox by default in the rootfs project.

  6. If you have no picocom installed in your system, the install it:

    [host] $ sudo apt-get install picocom
  7. Start the target console:

    [host] $ picocom -b 115200 /dev/ttyACM0
  8. From the target, run the following to read a file from the serial console:

    / # cat > /test.encoded < /dev/ttyLP0
  9. On the host, exit the target console (Ctrl-A and then Ctrl-X in picocom).

  10. On the host, configure the serial port for raw 115200 bps operation, so that the terminal line discipline passes the encoded file through unmodified:

    [host] $ stty -F /dev/ttyACM0 115200 raw -echo -echoe -echoctl -echok
  11. On the host, send the encoded ASCII file to the serial port used for the target console:

    [host] $ cat /tmp/test.encoded > /dev/ttyACM0
  12. When the transfer command finishes, enter the target console again:

    [host] $ picocom -b 115200 /dev/ttyACM0
  13. Type Ctrl-C to interrupt the cat command:

    ^C / #
  14. Run uudecode to convert the ASCII file back to the binary file:

    / # uudecode /test.encoded -o /test
  15. Change mode to allow running the application binary:

    / # chmod a+x /test
  16. Finally, run the application:

    / # /test Hello, i.MX RTxxxx / #