User avatar
rin67630
Posts: 551
Joined: Fri Mar 04, 2016 10:15 am

Bare metal à la Arduino...

Tue Oct 08, 2019 4:40 pm

I am used to program Arduinos and ESP32 systems. These controllers are very easy to program "bare metal".
Have we got a similar IDE in the Raspberry Pi world? Probably not, isn't it?
The other fantastic asset of Arduinos and ESP32 is the huge amount of libraries for almost every possible device. Libraries for the Raspberry pi exist, but are they suitable to bare metal programming?

pik33
Posts: 182
Joined: Thu Sep 10, 2015 4:26 pm

Re: Bare metal à la Arduino...

Wed Oct 09, 2019 7:34 am

Yes, we have. With libraries for almost everything (no wifi yet, but vc4/omx/opengl is there)

Works with RPi 0/1/2/3 (no RPi4 yet because of the new hardware - work in progress)

The environment is called Ultibo

"Normal" mode of operation is: install Ultibo on Windows, create a project, compile, copy the result (kernel7.img) to the SD card with firmware files, insert it to the RPi, switch on the RPi

Ultibo can be also installed on Raspbian and you can use a shell script to replace kernel7.img on your SD and reboot the RPi. Your Ultibo program can then restore the original kernel7.img and reboot to Raspbian again - no SD swapping. This is the way I work with Ultibo, as I don't want to use a PC and swap SD cards :)

www.ultibo.org

User avatar
rin67630
Posts: 551
Joined: Fri Mar 04, 2016 10:15 am

Re: Bare metal à la Arduino...

Wed Oct 09, 2019 8:44 am

pik33 wrote:
Wed Oct 09, 2019 7:34 am
The environment is called Ultibo
Thank you, i'll give a try.
but... no C++
I will have to re-learn Pascal like my very first times with the Sharp MZ700 with dual cassette drives in the Eighties...
;-)

Have we at least got a Pascal compiler to run the code on Raspbian for testing?

pik33
Posts: 182
Joined: Thu Sep 10, 2015 4:26 pm

Re: Bare metal à la Arduino...

Wed Oct 09, 2019 9:11 am

Yes, the Ultibo is a customized Lazarus.

You can do sudo apt-get lazarus, but I had some problems with this version on Raspbian (and PC debian too) so I built my own Lazarus for Raspbian from sources.

In Windows, simply get a Lazarus from here https://www.lazarus-ide.org and install it

Lazarus is a "write once, compile everywhere" so you can write, compile and use the same code in Windows, Linux, Mac, RPi etc (of course if not using asm and directly calling system functions)

All this is of course GPL/LGPL stuff

And.. you can still use C with Ultibo: you can write a static library in C and link it in your code.

hippy
Posts: 5970
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Bare metal à la Arduino...

Wed Oct 09, 2019 9:43 am

The Arduino IDE is available for use with the Pi though it is recommended to download and install the latest rather than 'apt-get' what is an ancient version -

Code: Select all

cd~
wget https://downloads.arduino.cc/arduino-1.8.10-linuxarm.tar.xz
tar -xvf arduino-1.8.10-linuxarm.tar.xz
cd arduino-1.8.10
sudo ./install.sh
From the Pi desktop; select the Start Menu, Programming, and click on the Arduino IDE option.

Using the PiDuino framework you can create Pi binaries which run under Raspbian. I don't think that can create true 'bare metal' programs but there might be something similar which can or could be created.

rst
Posts: 409
Joined: Sat Apr 20, 2013 6:42 pm
Location: Germany

Re: Bare metal à la Arduino...

Wed Oct 09, 2019 10:48 am

You may have a look at Circle. It's a collection of C++ bare metal libraries with a build environment for the Raspberry Pi. It allows building bare metal programs on Raspbian too. Try:

Code: Select all

git clone https://github.com/rsta2/circle.git
cd circle
echo "PREFIX =" > Config.mk
echo "RASPPI = 4" >> Config.mk
./makeall clean
./makeall -j
("4" is the number of your target Raspberry Pi model)

This builds the libraries and the latest sample program. You can go to any subdirectory of sample/ afterwards and do make there to build another sample program.

pik33
Posts: 182
Joined: Thu Sep 10, 2015 4:26 pm

Re: Bare metal à la Arduino...

Sat Oct 12, 2019 7:00 am

You may have a look at Circle.
Wow, you have RPi4 supported - to be tested :) although c++ is not my favourite language.
I saw RPi4 audio there at PWM#1... so I have questions (I didn't manage to find it in the code - where to search this?):

- the clock source address for PWM1 - is it the same or another than for PWM0?
- GPIO functions for PWM1 - where can I output PWM1 (GPIO function numbers)

Maybe my noise shaped driver for Ultibo can be implemented here - https://github.com/pik33/SimpleAudio - it is 8-bit, 960 kHz noise shaped audio driver which plays HQ audio at near every sample rate you want up to ~960 kHz

rst
Posts: 409
Joined: Sat Apr 20, 2013 6:42 pm
Location: Germany

Re: Bare metal à la Arduino...

Sat Oct 12, 2019 9:42 am

pik33 wrote:
Sat Oct 12, 2019 7:00 am
I saw RPi4 audio there at PWM#1... so I have questions (I didn't manage to find it in the code - where to search this?):

- the clock source address for PWM1 - is it the same or another than for PWM0?
- GPIO functions for PWM1 - where can I output PWM1 (GPIO function numbers)
The clock source is the same as for PWM0. You have to set GPIO40/41 to ALT0 to direct PWM1 to the headphone jack. I do not know, if can be directed to other GPIO pins. I found the PWM1 MMIO address (0xFE20C800) in a forum article (don't know where any more) and simply tried it out. I do not have other references. The PWM sound driver in Circle is here.

Return to “Bare metal, Assembly language”