Computing stuff tied to the physical world

ChibiOS for the Arduino IDE

In AVR, Software on May 25, 2013 at 00:01

A real-time operating system is a fairly tricky piece of software, even with a small RTOS – because of the way it messes with several low-level details of the running code, such as stacks and interrupts. It’s therefore no small feat when everything can be done as a standard add-on library for the Arduino IDE.

But that’s exactly what has been done by Bill Greiman with ChibiOS, in the form of a library called “ChibiOS_AVR” (there’s also an ARM version for the Due & Teensy).

So let’s continue where I left off yesterday and install this thing for use with JeeNodes, eh?

  • download a copy of ChibiOS20130208.zip from this page on Google Code
  • unpack it and inside you’ll find a folder called ChibiOS_AVR
  • move it inside the libraries folder in your IDE sketches folder (next to JeeLib, etc)
  • you might also want to move ChibiOS_ARM and SdFat next to it, for use later
  • other things in that ZIP file are a README file and the HTML documentation
  • that’s it, now re-launch the Arduino IDE to make it recognise the new libraries

That’s really all there is to it. The ChibiOS_AVR folder also contains a dozen examples, each of which is worth looking into and trying out. Keep in mind that there is no LED on a standard JeeNode, and that the blue LED on the JeeNode SMD and JeeNode USB is on pin 9 and has a reverse polarity (“0″ will turn it on, “1″ will turn it off).

Note: I’m using this with Arduino IDE 1.5.2, but it should also work with IDE 1.0.x

Simple things are still relatively simple with a RTOS, but be prepared to face a whole slew of new concepts and techniques when you really start to dive in. Lots of ways to make tasks and interrupts work together – mutexes, semaphores, events, queues, mailboxes…

Luckily, ChibiOS comes with a lot of documentation, including some general guides and how-to’s. The AVR-specific documentation can be found here (as well as in that ZIP file you just downloaded).

Not sure this is the best place for it, but I’ve put yesterday’s example in JeeLib for now.

I’d like to go into RTOS’s and ChibiOS some more in the weeks ahead, if only to see how wireless communication and low-power sleep modes can be fitted in there.

Just one statistic for now: the context switch latency of ChibiOS on an ATmega328 @ 16 MHz appears to be around 15 ┬Ás. Or to put it differently: you can switch between multiple tasks over sixty thousand times a second. Gulp.

  1. Well JC. There’s also FemtoOS by your fellow countryman Ruud V

    http://femtoos.org/

    http://sourceforge.net/p/femtoos/discussion/789278/thread/9cebaab0

    Is AVR Only , but it’s small and tight.

    /Bingo

    • FemtoOS looks to be on par with ChibiOS looking at the functionality.

      However, I see no active development any more for the last years, no Arduino IDE support and no support for the Due / Teensy.

      A pity I think, but I won’t start using it without active development, Arduino support and an active coumminty developing libraries and software for / with it…

    • Small addition: ChibiOS also runs on the rpi, and there are even libraries for the rpi to mimic the Arduino api, so you can run Arduino sketches on the rpi using ChibiOS!.

      (note: I don’t have an rpi, just read it on the internet!)

  2. Femto OS development has certainly not been stopped, but i admit i could have be more communicative to you guys. I will release a kernel running xmega in the summer. And, questions on the forum are always quickly answered by me. If not, send me a mail. By the way, i think ChibiOS and Femto OS target different ‘markets’. From their website: on AVR: ChibiOS kernel size ~7500, mine is more around 2000 and often much less then that (any thing not needed is not included). Also, i can (with tweaking) run 8 preemptive tasks in 64 bytes of ram or less.

    And yes, i agree, i have no Arduino support (although i have seen people run Femto OS on Arduino) and very few drivers. It is simply to much work for me to write (and maintain) it al by myself. Other people have written code too, but as it often goes with open source projects, when time goes by, interest declines …

  3. Any license concerns? I tend to shy away from GPL code. Much happier with MIT and BSD style licenses. Perhaps I am being overly cautious.

    • ChibiOS has GPL with linking exception, for even-numbered releases. Personally, I tend to prefer MIT as well, but like everything, no two programmers are ever going to agree on this sort of stuff…

  4. Anybody wants to skip toying with bunch of toy RTOSes which doesn’t provide much besides bare RTOS stuff reimplemented again and again, and instead work with RTOS which really brings added value, especially for the area of Wireless Sensor Networks – Contiki? Lot’s of WSN functionality (two non-toy wireless stacks), many hardware ports, BSD, active development and community. AVR port needs your love, hackers!

    • What is there to like about Contiki, other than its BSD-license and GitHub hosting?

Comments are closed.