Setting up the Pi software Mar 2017
To turn the Raspberry Pi into a general-purpose uploader / debugger for ARM STM32 chips, we need to set up some software.
First of all - the OS. DietPi is a very practical little distribution these days. It’s minimal, well-supported, offers a simple way to manage lots of popular applications and to configure or update the system itself. All console driven, through simple old-fashioned text menus.
Underneath this all sits a standard Debian 8.0 system, with
apt-get and all
Most conveniently, DietPi is available for a very wide range of RasPi-like boards:
So the first step is to dowload the proper image and put it on an SD card. For
boards which do not have on-board wired LAN, it’s easy to get WiFi started by
/boot/dietpi.cfg before ejecting the SD card from the host machine
(that boot partion is VFAT and can also be mounted in Windows and MacOS).
If all is well, you can login on the box over the network, using
ssh (or Putty
At this point, you’ll be taken to the DietPi “Launcher” (it can also be started manually later):
No need to install extra packages in this first pass through DietPi’s setup. The only confusing part is that even when not installing anything else, you’ll need to go through that last “Install” step in the menu to complete the setup process, and only then should you exit the Launcher.
The entire setup process is well-documented, see DietPi’s Getting
Started page. Once you’re up
and running, and logged in as
root on the RasPi, you will get a greeting
similar to this:
─────────────────────────────────────── DietPi | 13:30 | Mon 06/03/17 ─────────────────────────────────────── V145 | RPi A (armv6l) ─────────────────────────────────────── IP Address | 192.168.188.55 ─────────────────────────────────────── Created by : Daniel Knight Web : http://DietPi.com Twitter : http://twitter.com/dietpi_ Donate : http://goo.gl/pzISt9 DietPi's web hosting is powered by: MyVirtualServer.com dietpi-launcher = All the DietPi programs in one place. dietpi-config = Feature rich configuration tool for your device. dietpi-software = Select optimized software for installation. htop = Resource monitor. cpu = Shows CPU information and stats.
From here on, we’ll always use the
root account to avoid problems with
permissions on GPIO pins, etc. It’s a dedicated board, so it’s no big deal. Just
pick a good password and SSH keys.
First, we need to start up
dietpi-config and adjust a few settings:
- Advanced Options: - serial console disabled, i2c enabled, i2c frequency 400 (kHz)
- Security Options: - adjust your root password and host name to your preference
- Network Options: Adapters - optionally disable ipv6, if not used
Disabling the serial console does not seem to work, but this extra command will do the trick:
systemctl mask serial-getty@ttyAMA0.service
Time to bring everything up to date and install a few more packages:
apt-get update && apt-get upgrade apt-get install aptitude i2c-tools stm32flash picocom vim
Now clean up a bit, reboot to start from a fresh power-up state - then log back in again:
apt-get clean reboot
With these changes, the RasPi will start up with its serial console free for our
own use (no
getty running, no login prompt), and we can start using this for
connecting µC boards - we now have serial, I2C, and SPI at our disposal on the
We can use PicoCom for example:
picocom -b 115200 -imod lfcrlf /dev/ttyAMA0
But we can also download Folie,
unpack and move it to
/usr/local/bin/, and use that:
folie -r -p /dev/ttyAMA0
If the DTR and RTS pins on the FTDI header have been wired up, we can use
stm32flash (installed earlier) to verify their proper operation - here with a
JeeNode Zero inserted:
# stm32flash -i 23,-18,18:-23,-18,18 /dev/ttyAMA0 stm32flash 0.4 http://stm32flash.googlecode.com/ Interface serial_posix: 57600 8E1 Version : 0x31 Option 1 : 0x00 Option 2 : 0x00 Device ID : 0x0417 (L05xxx/06xxx) - RAM : 8KiB (4096b reserved by bootloader) - Flash : 64KiB (sector size: 32x128) - Option RAM : 16b - System RAM : 4KiB
Next, we’ll install OpenOCD. It’s particularly useful on
RasPi, because it can toggle GPIO pins to create a JTAG/SWD programmer and
debugger. It’s highly configurable and supports
The default OpenOCD package in Debian is version 0.8, but 0.10 is a better choice for SWD on RasPi - so we’ll build it ourselves from source. There’s an excellent description of all the steps involved. In summary, we need to enter the following commands - this will take a while:
apt-get install git autoconf libtool make pkg-config libusb-1.0-0-dev telnet mkdir -p ~/src; cd ~/src git clone git://git.code.sf.net/p/openocd/code openocd cd openocd && ./bootstrap ./configure --enable-maintainer-mode --enable-bcm2835gpio --enable-sysfsgpio make && make install # use "make -j4" on RasPi ≥ 2 to speed things up
Once OpenOCD is installed, we can set up some scripts and configuration files to upload a hex firmware image easily to an attached microcontroller. Note that this is not limited to the STM32L052 of the JeeNode Zero or the STM32F103 µC series - OpenOCD is considerably more advanced and generalised than that.
Below are a number of scripts which you can add to the home directory, i.e.
/root/ to create a basic upload structure. The hex firmware images are
expected to be in folders named
images-f1x/, and the 2nd
burns.sh is the image name.
Assuming there’s a file called
$HOME/images-l0/jz4.hex, this will upload it
./burn.sh l0 jz4
And this variant can be used to upload over serial with DTR+RTS pin toggling:
./burns.sh l0 jz4
Best of all, if you have set up SSH access to your RasPi box, then all of this can be done without even logging in, using commands such as:
ssh myraspi ./burn.sh l0 jz4 ssh myraspi ./burns.sh l0 jz4
Below are the scripts which make this possible, shown inline but provided as a Gist by GitHub:
There you go - hook it all up, install the above software, and you’ll be ready for any µC task!