“Bare Metal” Raspberry Pi Synth

The Raspberry Pi is an “SBC” – a single board computer, whilst the Arduino (and the Raspberry Pi Pico for that matter) is a microcontroller.  Simplistically a single board computer is, well, what most people would think of when they think about a computer – a board (with or without a case!) that you plug a keyboard and display into, that runs an operating system, connects to the Internet, and will let you interact with it somehow to get things done.

A microcontroller on the other hand typically does not run an operating system, but instead runs code that makes it dedicated to a specific purpose – often involving some kind of interaction with the physical world using input and output mechanisms connected to sensors and actuators.  They are particularly good for real-time applications as you can code to specific timing constraints and use bespoke hardware for things like pulse-width modulation and waveform generation using dedicated timers.

But the lines are quite blurry.  MT32-Pi is interesting as it runs as a “bare metal” installation on the Raspberry Pi – i.e. it doesn’t require an operating system; it is dedicated to the purpose of being an MT-32 synthesizer.  Contrast this with Zynthian which does have an underlying operating system and the synthesizers are applications you install over the top.

But MT32-Pi needs a Raspberry Pi v3 or v4.  Now I have a number of v1 Raspberry Pis in my collection, so I thought it might be nice to find some kind of “bare metal” musical applications of my own that might run on a v1 Raspberry Pi.

This is part one of a series exploring the art of the possible.  Here is the full index of posts in this series:

Warning! I strongly recommend using old or second hand equipment for your experiments.  I am not responsible for any damage to expensive instruments!

These are the key tutorials for the main concepts used in this project:

If you are new to microcontrollers and single board computers, see the Getting Started pages.

Parts list

  • Raspberry Pi v1 (in my case)
  • 128Mb or greater SDHC SD Card
  • Linux installation (I use Ubuntu in a virtual machine on my Windows PC)
  • Optional HDMI monitor (for testing)
  • Amplification and lead for the headphone socket on the Pi

IMG_5501

Building The Build Environment

The “bare metal” environment used by MT32-Pi is called Circle and can be found here: https://github.com/rsta2/circle. The readme contains some fairly high-level instructions on how to build it, but unfortunately it doesn’t spell out what someone like me, who is new to all this, has to do.

I initially started looking at the following article: Cross-compiling for the Raspberry Pi.  The problem is that this is setting up an environment to build code to run on a Raspberry Pi Linux system, not a “bare metal” installation, so after a few false starts I realised that rather than the g++-arm-linux-gnueabihf tool chain recommended by the article, I actually needed the gcc-arm-none-eabi toolchain.

So on my Ubuntu, these are the commands I needed to get all the bits I needed.

:~$ sudo apt-get install build-essential
:~$ sudo apt-get install gcc-arm-none-eabi
:~$ sudo apt-get install git
:~$ mkdir src
:~$ cd src
:~/src$ git clone https://github.com/rsta2/circle

At this point I have a tool chain and the circle code, so I started trying to build some of the sample applications.

:~$ cd src/circle
:~/src/circle$ ./configure -r 1 -p arm-none-eabi-
:~/src/circle$ ./makeall
:~/src/circle$ cd sample
:~/src/circle/sample$ ./makeall

This will result in a kernel.img file that should allow the RPi to boot.  To actually make that happen requires a couple of additional steps though.  First, an SD card is required.  I’ve used an 8Gb SDHC card, but in reality you only need 128Mb to boot.

Optional: I cleared and formatting the card to create a boot partition as follows.

WARNING: ONLY DO THIS IF YOU KNOW WHAT YOU ARE DOING.  GET THIS WRONG AND YOU COULD OVERWRITE ALMOST ANYTHING ON YOUR COMPUTER.

  • Clear the existing SD card using the “dd” command.  Alternatively you can use “fdisk” to remove existing partitions.
  • Create a new partition using “fdisk” with the following properties:
    • Primary partition
    • Size 128M
    • Type C – W95 FAT32 (LBA)
  • Format the partition using “mkfs -t msdos”.

The the partition can be mounted and files transferred over.  The Raspberry Pi is a little unusual in that it requires a number of “binary blobs” to actually boot.  These are all available from the Raspberry Pi foundation, but can be grabbed from the boot area in the circle source tree.

:~/src$ cd circle/boot
:~/src/circle/boot$ make

Full instructions can be found in the boot/README here.

Then once the SD card is mounted, the files from the boot area need copying over along with the kernel.img you want to actually boot.

:~$ cp ~/src/circle/boot/* /media/path/to/sd/card/root
:~$ cp ~/src/circle/sample/02-screenpixel/kernel.img /media/path/to/sd/card/root

Then unmount the SD card, transfer it over to your RPi, plug in a HDMI screen and see if it boots.  If all goes well you’ll see a black screen with a rectangle and corner to corner cross!

Raspberry Pi Mini Organ

All along my initial aim was to attempt to get some code running natively on the Raspberry Pi that could do some basic audio via the GPIO.  Well as it happens, there is already the perfect application in the Circle sample set: Sample “29-miniorgan“.

From the readme:

This sample is a simple monophonic mini organ. You have to attach an USB PC keyboard to your Raspberry Pi to use it. The output signal is available on the 3.5mm headphones jack.

If you have a MIDI keyboard with USB interface, you can also use it to play. It has to support the USB Audio Class MIDI device specification. This sample does not support the MIDI velocity parameter.

Perfect – USB MIDI, PWM audio. Just the job!

IMG_5494

Closing Thoughts

This is fantastic.  I have a few v1 RPis and wanted to find a use for them, and running “bare metal” is a pretty good answer.  So what now?  There are a number of options.

  • Rene Stange has another code repository for a “minisynth” in it that I can’t wait to try.
  • I want to see if I can configure the environment to recognise the serial MIDI and audio DAC on my Clumsy MIDI board.
  • Then I want to start seeing if I can get some MIDI polyphony going.  Specifically, I have a stacking set of v1 RPis that I would like to get working in parallel on something musical.
  • And of course, I want to see if any of my existing Arduino projects can be ported over somehow, especially adding some controllable parameters and synthesis options.

Kevin

Leave a comment