danhouldsworth / helloBareMetal

A follow on from helloLanguages, dedicated to bare metal programming of embedded devices (Atmel AVR & ARM Cortex)
1 stars 0 forks source link

helloBareMetal

A follow on from helloLanguages, dedicated to bare metal programming of embedded devices (Atmel AVR & ARM Cortex)

Background

While I've been programming various AVRs for drone building (both Flight Controllers and Electronic Speed Controllers), and also back when tinkering with Arduino, I've come unstuck with various projects in a way that makes me realise I don't have a deep understanding of the underlying principles of embedded MCUs. I'm left with questions like :

Additionally, while big projects go slowly in Assembler, I always feel I learn more deeply what is actually going on, and so would like to tackle like for like projects in both C and assembler.

Arduino

This deserves a special mention, as while I've learned a lot at first from working through Arduino projects, and also benefited from the compatabitliy as everyone makes drives and libraries for it. I find the IDE a pig, that slows down development of all but the most trivial project, and blocks me from actually understanding what is going on when we compile or flash a project.

ARM-cortex

This also deserves a special mention, as ultimately my target projects will inevitabilty take me in the direction of a 32-bit CPU with built in float support. But - and it's a big but - as I've tried to move over to the ARM-cortex, I realise I'm even more in the dark on all the issues raised above. Getting just the Blink program to load onto the Teensy3.1 ARM-CortexM4 seemed too hard, without using the Teensduino plugin for Arduino IDE. And so this has kickstarted my desire to get back to first principles and truely understand what's going on under the hood. Using nothing more than a text editor, and simple command line tools that I will install myself. I am then anticipating, that a deep knowledge of the 8-bit AVR MCUs will then speed my transition into the 32-bit ARM world.

Operating Systems

Approaching from a further angle still. Another motive for this project is my desire to understand more about what is actually going on with an operating system and a schedular. And while helloLanguages is a fascinating exploration of different langauges, they are all sitting on top of an operating system which is abstracting away the hardware. What better way to learn about operating systems than to get of them completely, and then build back their services as and when needed - eg. multi tasking, scheduling etc

Build environments

AVR 8-bit

    brew install avrdude avra
    brew tap osx-cross/avr
    brew install avr-libc // avr-gcc is a dependancy of avr-libc

ARM-cortex

    brew tap PX4/homebrew-px4
    brew install gcc-arm-none-eabi

Approach structure

For each task I will attempt a solution in (generally this order):

  1. Assembly - device targetted but using register/definitions include header (eg m328Pdef.inc)
  2. C using standard libs (eg <avr/io.h> and <avr/eeprom.h>)
  3. Standalone - either C or ASM. No included libraries, definitions or macros. This should really reinforce the learning the task in hand.
  4. Different device - This will check we're understanding general principles and not nuances of particular hardware.

Approach style

Questions / Miscallaneous

Developer environment quirks / notes

TBC - whether to include RasberryPi?

On the one hand most of the challenges of helloLanguages could be tackled on a RasberryPi running Rasbian. However, when compiling and running assembler, we would have to do it on the machine (rather than develop on an Intel Mac for instance). On the other hand, if we scrapped the Linux OS, we have a great piece of physical kit with loads of GPIO and connected peripherals (LEDs / GPU / USB / Camera) to experiment with directly from bare metal programming. eg see this tutorial to blink the RaspberryPI LEDs.

Helpful resources :

http://www.avrbeginners.net/ http://maxembedded.com/ http://www.societyofrobots.com/programming_timers.shtml http://www.avr-asm-tutorial.net/avr_en/beginner/index.html Explanation of register bit settings - http://www.societyofrobots.com/member_tutorials/book/export/html/228 Useful tutorials - http://maxembedded.com/2011/07/14/avr-timers-ctc-mode/ Pin mapping - http://arduino.cc/en/Hacking/PinMapping32u4 http://www.engineersgarage.com/embedded/avr-microcontroller-projects/How-to-Use-SPM-for-Flash-to-Flash-Programming