This is a migrated version of my Wordpress post, written on : 27 February 2015
I had some Raspberries Pi A+ available on the toolbox, and i've just got idea to use one of them in my programmable car toy project. The point is that the Pi will be connected to a circuit based on the LPC1114FN28, in which, the ARM cortex M0 chip is used to collect sensor datas (IR sensor, sonar sensor, etc.) and control the motors on the car. The Pi talks to the LPC1114FN28 via a serial connection (UART or SPI), and takes care of some high level calculations based on the datas provided by the LPC chip, it then can analyse the environment's context and send commands to the slave chip to control the car. With the Pi, i can build an API to program the car's behaviour from distance via the network (using TCP protocol or HTTP protocol, via web). It's quite an interesting sujet for me.
So the first thing comes to my mind is that during the experiments, i will need to frequently update the firmware on the LPC1114FN28, so why not use the PI as a programmer for the LPC chip. The firmware is written and compiled on your PC and then is updated on the slave chip by sending it to the PI, no need to used the USB-serial adapter anymore. In this post, i'll show you how to do it, this is a part of my actual project.
To make the PI to be able to program the LPC chip, you need connect the UART (TX/RX) pins on the PI to the serial pins (RX/TX) on the LPC1114. Additionally, we use two others GPIOs as the ISP and RESET control line, as shown in the diagram below :
Raspberry as ARM programmer - wiring
PI LPC1114 Note =============================================== RX - TX(dp16) TX - RX(dp15) GPIO24 - RESET (dp23) Reset line GPIO23 - PIO0_1(dp24) ISP mode control
With this configuration, we can program the LPC chip using the lpc21isp command, so you need to install it first on the PI. You can find more information of how the software programmer works from this post.
I wrote a simple shell script which help automatically program the slave chip from the PI using the lpc21isp command :
#!/bin/sh isp="23" rst="24" delay=1 echo $isp > /sys/class/gpio/unexport echo $rst > /sys/class/gpio/unexport # first put the chip to ISP mode, GPIO23 echo "Put the chip to ISP mode" echo $isp > /sys/class/gpio/export echo out > /sys/class/gpio/gpio$isp/direction echo "0" > /sys/class/gpio/gpio$isp/value # then run the programmer echo "Running programmer" lpc21isp -hex $1 /dev/ttyAMA0 115200 48000 & # reset the chip echo "Resetting the chip" sleep $delay echo $rst > /sys/class/gpio/export echo out > /sys/class/gpio/gpio$rst/direction echo "0"> /sys/class/gpio/gpio$rst/value sleep $delay echo "1" > /sys/class/gpio/gpio$rst/value #wait for the background command finish wait $! # disable the ISPmode echo "1"> /sys/class/gpio/gpio$isp/value echo $isp > /sys/class/gpio/unexport sleep $delay # run the program echo "Run the program" echo "0"> /sys/class/gpio/gpio$rst/value sleep $delay echo "1"> /sys/class/gpio/gpio$rst/value sleep $delay echo $rst > /sys/class/gpio/unexport
Let's save the script as rpi_arm_prog.sh, to program the chip, say i have a main.hex file, you just need to type :
And the script will do the rest for you. Now to send the compiled file from your PC to the PI (via ssh), you can use the scp command (the PI and the PC must be on the same network), for example :
scp blinky.hex firstname.lastname@example.org:/home/pi/blinky.hex #and then from the pi run ./rpi_arm_prog.sh /home/pi/blinky.hex
If you have any problem with the lpc21isp command, try to change the baud-rate value (e.g. 115200 to 19200, etc) in the script file.