Easy mbed Programming from Linux

If you use mbed you know it is cool not to have to install compilers or build libraries and toolchains. You just enter some code, grab some up to date libraries and press compile. Everything runs in your browser and you download a binary file with your program in it. However, you still have to get it to the board. Most of the Arm boards look like a USB drive and you can simply copy or move the file over to do a program. However, I get tired of manually doing that step. This is especially a problem if you use a GUI. You have to remember to move and not copy (so your browser doesn’t keep renaming the file) and you also need to keep confirming the overwrite on the phantom file still on the “fake” USB drive.
So instead, I write a little command line “script” to do it all for me. You could use inotify, but this is easy and I just do it when I’m developing and stop it when I’m done. Suppose your object file is XXX.bin and you are in the /tmp/mbed directory.

Open a shell and go to the /tmp/mbed directory. In my case, the fake USB drive is at /media/USER/FRDM-KL25Z. Then enter this:

while true
 do if [ - f XXX.bin ]
 then echo Programming
 sleep 1
 mv -f XXX.bin /media/USER/FRDM-KL25Z 
 echo Done
 sleep 2

Now when you save your binary file to /tmp/mbed, it will automatically program the device. Simple!