Sunday 3 September 2017

Bare Metal RPi Intro

Bare Metal programming allows programs to be run on hardware without the need for an Operating System. It is the norm for microprocessor chips such as Atmel and PIC.  The Arduino IDE makes this particularly easy for Atmel chips by providing a mechanism to load programs and many sample working programs which can easily be executed on an Arduino.
By contrast more powerful hardware systems run Windows, MacOSX, GNU/linux or other OS variants.  Raspberry Pi (RPi) comes under this heading, it is often loaded with Raspbian which is a full featured version of Linux tailored for RPi hardware.
It is interesting to consider how to use an RPi without an OS, in particular to better understand how a system starts up, how the components in an RPi communicate with each other, what tools are needed to build basic systems and discover what the different components do.  It would be a huge amount of work to write an OS myself although this was an objective of the nandtotetris tutorials (which I will write about sometime).
Googling gives a good range of information available for RPi.
 Baking Pi - OS development by Alex Chadwick from the Cambridge University Computer Laboratory provides an excellent starting point.  Lesson 1 guides you through writing an assembler program to light the LED on RPi.  Further lessons expand knowledge of assembly language programming and move on to writing to the screen.
Valvers provides a four-step tutorial based on the content of the Baking Pi project which allows you to write C programs and uses a much simpler platform to cross-compile programs.
David Welch appears to have a variety of bare metal programs including  serial port (UART) programming which should be interesting.
Circle appears to provide 30 steps / examples which I will investigate.
OSDev.org  is a serious bare metal development site which appears to provide a small but proper kernel for development.

A number of unusual challenges face us when starting bare metal programming.
  1. How to compile a program to run on a different computer?
    Compilers are usually designed to compile programs on the computer you are using so what environment allows you to develop programs to run directly on an RPi.
  2. How to load and run an executable?
    The basic approach is to load the program onto an SD card and use the same procedure used to load linux, but it is also possible to load via a serial port (David Welch).
  3. How to write programs that don't need an OS?
    It is possible to use the special version of C used for writing the linux kernel and low level assembler libraries can be used.
  4. Where can the information on the relevant hardware, interfaces and libraries be found?
    This is crucial information which the tutorials and forum posters can help to provide.


No comments:

Post a Comment