Steverino
Posts: 23
Joined: Sun Aug 19, 2012 2:44 pm

ChibiOS/RT Port

Sun Sep 30, 2012 6:01 pm

If anybody is interested in a real-time operating system for the Raspberry PI, I've done an initial port of ChibiOS/RT.

So far, the port has drivers for the GPIO ports, mini-UART I/O, system timers (supports preemptive task scheduling) and counters (supports code performance measurement, for example). I've also created an initial implementation of an I2C driver but it hasn't been tested with hardware yet. I'd like to create (or work with some collaborators to create) drivers for SPI, PWM, SD/MMC and some level of USB support.

I created an example application to that demonstrates a thread runnning a command shell (using the mini-UART) with another thread flashing the onboard LED. The ChibiOS/RT shell-based tests are all passing. The source code is on GitHub at https://github.com/steve-bate/ChibiOS-RPi. See the wiki there for more information (not much more at this point, but I'll be adding more to it soon).

Special thanks to David Welch (dwelch67) for his valuable examples at https://github.com/dwelch67/raspberrypi. I've used much of that information in my port.

I'm new to ChibiOS/RT, to the Raspberry PI and to ARM programming so any help or feedback is greatly appreciated. After the SPI and PWM drivers are complete, I'd like to submit this to ChibiOS/RT project for inclusion in their code base.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: ChibiOS/RT Port

Sun Sep 30, 2012 7:07 pm

Good news!

I would like to help test the I2C drivers as I currently have I2C hardware working via C under linux.

I know nothing about ChibiOS though, so it might take me a while to figure out how to go about that - am starting here: http://www.chibios.org/dokuwiki/doku.ph ... troduction

....well done!
Ostendo ignarus addo scientia.

Steverino
Posts: 23
Joined: Sun Aug 19, 2012 2:44 pm

Re: ChibiOS/RT Port

Mon Oct 01, 2012 12:42 am

Although starting to look at the ChibiOS docs is a good idea, I wouldn't recommend doing anything with the I2C driver until I have it working with at least one device. I have a TMP102 temperature sensor connected to the Pi and I'll be doing more development and testing on the driver this week. I'll let you know when it's working with that device so you can do your own testing with it.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: ChibiOS/RT Port

Mon Oct 01, 2012 1:03 am

Thanks - if you get it working on that device, it would help people with like me with a basic understanding if you could link to your code and a basic chibios how-to so that we can test on different devices...
Ostendo ignarus addo scientia.

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: ChibiOS/RT Port

Tue Oct 02, 2012 6:05 am

Excellent work. I'd crosspost (if you haven't already) into the "other" section of the operating systems bit, too. Having a decent RTOS up and running has been asked for for quite a while.

Simon

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: ChibiOS/RT Port

Tue Oct 02, 2012 11:42 am

I agree. Any links to basic tutorials explaining how to get up and running with ChibiOS would be appreciated. I have been hunting for one without success and have only come accross other posters on other forums complaining about a lack of the same thing. It would be such a shame if people were deterred from using this due to a lack of a good introduction.

The most informative part of chibios.org that I have found so far is the example code part of the forum: http://forum.chibios.org/phpbb/viewtopic.php?f=4&t=474. It seems that ChibiOS is just functions you access from C (API's) and some kernelesque files - perfect.

I am guessing one just bungs the boot files and compiled code on an SD card, power-up, and away you go.....?

Does the C code have to be compiled on another machine with a specific 'toolchain' ?

Is any additional hardware required to plug the Pi into a PC as with other development boards mentioned on the chibios forum?

It seems that people already comfortable with C(++) will have to learn how to ues the APIs and also about threading. An API cheat sheet and overview of threading could be handy....

Edit: found this: http://chibios.org/dokuwiki/doku.php?id ... e&s[]=apis
Ostendo ignarus addo scientia.

Steverino
Posts: 23
Joined: Sun Aug 19, 2012 2:44 pm

Re: ChibiOS/RT Port

Tue Oct 02, 2012 12:32 pm

I have an initial version of the I2C driver working now. I'm using a TMP102 temperature sensor as an input device and a MCP4725 Digital to Analog Converter (DAC) as an output device. I've added a little demo program on GitHub that will read the TMP102 and output the temperature in Fahrenheit as millivolts from the DAC. You can then use a digital voltmeter as a digital temperature display. Not particulary useful or accurate but it demonstrates the I2C reading/writing APIs.

I agree about the documentation. It was a little intimidating when I started doing the port. However, it's actually easier than it seems at first. I'll try to find some time this week to write some "getting started" documentation for the Pi port.

To answer a few of your questions. You can deploy the OS using the technique of installing it as the kernel.img on the SD card or you can use David Welch's bootloader and a serial interface to load it. Using the first technique, not special cables are required. To compile, you'll need a suitable tool chain on a separate computer. I'm using the Yagarto gcc toolchain on a Mac. The ChibiOS documentation describes and Eclipse-based development environment. Although I'm familiar with Eclipse from Java programming I've been doing all my development at the command line with no problems.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: ChibiOS/RT Port

Tue Oct 02, 2012 2:23 pm

Thanks - Im reading this: http://www.chibios.org/dokuwiki/doku.ph ... s:eclipse1.

I'm hoping it's possible to compile under Raspbian via GCC/Geany onto a second SD card via USB card read/writer without extra hardware - and that there is a 'sudo apt-get install' command to unpack the ChibiOS/RT archive into the Pi/Raspbian projects directory ...?

Think I might wait for your how-to ... thanks again and in advance ...
Ostendo ignarus addo scientia.

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: ChibiOS/RT Port

Tue Oct 02, 2012 4:27 pm

I would imagine that compilation on the Raspi (under Linux) for deployment to a second card would be more than possible. apt-get is far less likely.

Simon

Steverino
Posts: 23
Joined: Sun Aug 19, 2012 2:44 pm

Re: ChibiOS/RT Port

Mon Oct 15, 2012 2:47 pm

https://github.com/steve-bate/ChibiOS-RPi

I've implemented several new Pi device drivers in the ChibiOS/RT port. It now supports GPIO (PAL), I2C, SPI and PWM and timers. I've added examples (under testhal/BCM2825) showing how to use Chibi to access various devices (temperature sensor, ADC, DAC, RTC, GPIO in/out, PWM). There's much more than can be done, but the port is very usable as it is for many projects.

An introduction and getting started guide is at http://www.stevebate.net/chibios-rpi/Ge ... arted.html (also accessible via the GitHub wiki).

Steve

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: ChibiOS/RT Port

Mon Oct 15, 2012 2:50 pm

Thanks :D

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: ChibiOS/RT Port

Mon Oct 15, 2012 10:57 pm

Just started with Eclipse as recommended - it seems over complicated. I can follow the instructions on the ChibiOS website, but I don't understand what Im doing or why I'm doing it and it seems there are many steps to compiling a simple program.

I might go against your advice and try using Geany on the Pi.

I do understand the advantages of using a second machine, but if I can't understand and internalise what I'm doing with eclipse, it might be quicker for me to try a physically longer route.

Steverino
Posts: 23
Joined: Sun Aug 19, 2012 2:44 pm

Re: ChibiOS/RT Port

Mon Oct 15, 2012 11:24 pm

I'm not sure if you are responding to me, but I'm not recommending Eclipse. I might try it later but so far I've been using text editors (Vi and Emacs) and a bash shell for my development. If you have a cross compiler toolchain (arm-none-eabi-...) installed, the build steps are to clone the git repository, cd into the demos/ARM11-BCM2835-GCC directory and type 'make'. That should give you a build/ch.bin file that you can load onto the Pi using the instructions on my getting started page.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: ChibiOS/RT Port

Mon Oct 15, 2012 11:37 pm

Thanks, I was refering to the Chibios website rather than your website as that mostly focused on Eclipse.

I followed your simple steps on the Pi but I got an error containing the words 'arm-none-eabi-' and the makefile did not make.

To be honest, 'arm-none-eabi-' doesn't mean anything to me. I suspect its to do with cross-compiling (?) which I'm not doing if I'm trying to make on the Pi - I intend eventually to get a 2nd Pi to use as a 'development machine' as this one will eventually be fastened into a project.

Your instructions are clear and I expect its me making a stupid nooby mistake - I'll retry when I'm less tired - I expect other people instantly understand the cross-compiling process you describe.

I am wondering whether I need to remove an 'arm-none-eabi-' reference from the makefile if I'm native rather than cross-compiling?

dwelch67
Posts: 954
Joined: Sat May 26, 2012 5:32 pm

Re: ChibiOS/RT Port

Tue Oct 16, 2012 12:41 am

arm-none-eabi- is for cross compiling. If you are native then just go without the arm-none-eabi-. I think I added a small example using one raspi with linux to develop for another bare metal raspi. You likely still need to control the linker though and not use the stock (linux) linker script and bootstrap code.

David

Steverino
Posts: 23
Joined: Sun Aug 19, 2012 2:44 pm

Re: ChibiOS/RT Port

Tue Oct 16, 2012 1:20 am

Sorry. I didn't realize you we using a Pi to build the code. You can try adding a TRGT= to the make command line. I haven't tried it myself but that should remove the cross compiler prefix.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: ChibiOS/RT Port

Tue Oct 16, 2012 4:37 pm

Thanks - it gets further:

Code: Select all

[email protected]:/home/pi/Desktop/chibios/steve-bate-ChibiOS-RPi-0f57bdf/demos/ARM11-BCM2835-GCC# make
Compiling ../../os/ports/GCC/ARM/crt0.s
Compiling ../../os/ports/GCC/ARM/chcoreasm.s
Compiling ../../os/ports/GCC/ARM/BCM2835/vectors.s
Compiling ../../os/ports/GCC/ARM/chcore.c
../../os/ports/GCC/ARM/chcore.c:1:0: sorry, unimplemented: -mfloat-abi=hard and VFP
make: *** [build/obj/chcore.o] Error 1
[email protected]:/home/pi/Desktop/chibios/steve-bate-ChibiOS-RPi-0f57bdf/demos/ARM11-BCM2835-GCC# 

could this be anything to do with $PATH ?

Regardless of this, I'm looking forward to spending some quality time with the link you posted to the GNU make command...

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: ChibiOS/RT Port

Tue Oct 16, 2012 5:37 pm

Nah, that looks like chibios doesn't do hardfloat.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: ChibiOS/RT Port

Tue Oct 16, 2012 6:35 pm

shame - I wonder if I can opt for soft-float insted?

With multiple Pi's becomming de reguer, I expect others might like to try a 2 pi set-up.

Steverino
Posts: 23
Joined: Sun Aug 19, 2012 2:44 pm

Re: ChibiOS/RT Port

Wed Oct 17, 2012 1:59 am

Strange. If you add USE_VERBOSE_COMPILE=yes to the make command line, you'll see the actual gcc options. Those gcc options aren't there but I see the same error when I compile on the Pi. Maybe someone will have an idea where those originate. It doesn't appear to be directly related to ChibiOS.

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: ChibiOS/RT Port

Wed Oct 17, 2012 7:25 am

My guess would be that you're (both) running raspbian. When you start doing a make, you're going to pick up the default CFLAGS for your distribution, and as Raspbian is hardfloat / vfp, that's what you get.

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: ChibiOS/RT Port

Wed Oct 17, 2012 8:09 am

First thing to do is to work out exactly what your CFLAGS are set to, /before compile/, as follows.

Code: Select all

env | grep CFLAGS
You'll probably get something like this:

Code: Select all

...-mfpu=vfp -mfloat-abi=hard
You'll be wanting to remove *at least* the hardfloat option before running make. Obviously, remove the ellipses and replace them with the rest of your original CFLAGS.

Code: Select all

export CFLAGS=....-mfloat-abi=softfp
make
Alternatively, of course, you could work out why it doesn't like hardfloat, and fix that instead.

Simon

Steverino
Posts: 23
Joined: Sun Aug 19, 2012 2:44 pm

Re: ChibiOS/RT Port

Wed Oct 17, 2012 11:20 am

I'm running Adafruit's Occidentalist distribution. CFLAGS is a make variable. It's not set in my environment and I've also run gcc manually from the command line without specifying any float options and I see the same error. The following are the command line options I gave to gcc (without using make)...

Code: Select all

gcc -c -mcpu=arm1176jz-s -O2 -ggdb -fomit-frame-pointer -mabi=apcs-gnu -ffunction-sections -fdata-sections  -Wall -Wextra -Wstrict-prototypes -Wa,-alms=build/lst/chcore.lst   -mno-thumb-interwork -MD -MP -MF .dep/chcore.o.d  -I. -I../../os/ports/GCC/ARM -I../../os/ports/GCC/ARM/BCM2835 -I../../os/kernel/include -I../../test -I../../os/hal/include -I../../os/hal/platforms/BCM2835 -I../../boards/RASPBERRYPI_MODB -I../../os/various ../../os/ports/GCC/ARM/chcore.c -o build/obj/chcore.o
Maybe gcc is compiled in a way that is uses this option internally? I did find some information yesterday that said the combination of -mfpu=vfp -mfloat-abi=hard is invalid for some versions of gcc.

Steverino
Posts: 23
Joined: Sun Aug 19, 2012 2:44 pm

Re: ChibiOS/RT Port

Wed Oct 17, 2012 11:36 am

I found through experimentation that it's the -mabi=apcs-gnu that is indirectly causing the problem. I'll do more research on this sometime today.

Steverino
Posts: 23
Joined: Sun Aug 19, 2012 2:44 pm

Re: ChibiOS/RT Port

Wed Oct 17, 2012 2:14 pm

The apcs-gnu ABI is the "old ABI". I initially copied the make file from one of the other ARM demonstrations so I'm not sure why the option is there.

After removing the -mabi=apcs-gnu from the USE_OPT variable in the demo Makefile I was able to compile the source on a Pi. However, the link phase failed. I haven't had time to investigate that issue yet.

Return to “Bare metal, Assembly language”