File transfer between a PC and an embedded system over the serial port
I was playing with the Elektor Linux board and needed to tranfer code compiled on a “host” system to the SD card of the embedded Linux board. Following the tutorial off the magazine I read:
“To test whether the above process has been successful, we can copy
the file ‘hello’ that the compiler has created to the Elektor Linux
board’s SD card. Make sure the board is off and remove the card.
Insert it into the PC’s card reader, and plug the reader into the PC.”
I did not have a card reader with me and I did not like to halt the system, remove the card, etc. etc.
Back in the days of modems it was not unusual to transfer files over the serial ports.
This is what you need to do in order to transfer your files between your Linux PC and your Linux embedded system using the serial port.
Picocom can transfer files using several protocols that, whomever used to use modems, will be familiar with.
Specifically you can use ZModmem which is the best choice compared to XModem and YModem.
Enough with the yada yada, let’s cut to the chase.
Let’s say that you are either using Ubuntu or Mint for what matters.
You will need to install rz and sz. Check here for more.
apt-get install lrzsz
Your serial port is ttyUSB0.
Run: picocom -b 115200 /dev/ttyUSB0
Note the output especially:
send_cmd is : sz -vv
receive_cmd is : rz -vv
This means that your board can talk ZModem!
Hit ^a (ctrl+a) then ^s (ctrl+s). Read the man page for picocom to know more.
This will set picocom in file transfer mode. You will be prompted for a file name as follows:
Write the full path of the file e.g. /root/hello (being the compiled version of hello.c)
Sure enough your next ls command should show the file now on your Elektor Linux board.