Search code examples
arduinoembeddedavrrtosatmega

Writing to flash ROM for an embedded OS on atmega328p (h8write equivalent for avr)


I'm currently reading a Japanese book on embedded OS/RTOS es except that I am not using the recommended hardware as I already had a seeeduino microcontroller.(atmega328p) The book is about KOZOS "12 steps to making your own embedded OS" by Sakai Hiroaki(It's hiro-something)

I'm stuck at the part where I need to write into the flash ROM of the atmega328p because the author is using a different chip called H8. He uses a software called h8write and uses that in his OS, but I honestly have no idea what is going on at this point, and what the avr replacement for h8write would be. I've looked around to no avail as there is minimal documentation on what h8write does aside from the "it helps you write to flash ROM" that shows up in the book.

This is the first time I'm doing lower layer stuff and it's frankly terrifying...

I'm using ubuntu 14.04 if that helps.


Solution

  • If I understand correctly, the h8write program is supposed to run on your computer and transfer the compiled to the microcontroller. You are using a seeeduino, which is an Arduino compatible board, with Ubuntu. The standard way of programming on this environment is with the arduino software:

    • install the arduino package (sudo apt-get install aruino)
    • type the command arduino from a terminal emulator: this brings an IDE where you can type your code
    • connect the seeeduino to an USB port
    • click on the button with a right-pointing arrow: this will take care of everything (compiling, linking and uploading to the seeeduino)

    Once you are comfortable with this workflow, you can try to get your hands dirty with low-level stuff. The Arduino IDE is built on top of smaller utilities like avr-gcc, avr-libc, avr-as and avrdude. Avrdude is the program used to transfer the compiled program to the Arduino/seeeduino, i.e. write to the flash. You can use these utilities directly, from the command line. This is however complicated by the fact that you will need to pass many command-line arguments, so I recommend you automate the process using a Makefile. Thankfully there is a generic Arduino Makefile available that makes this quite easy:

    • install the generic Arduino Makefile: sudo apt-get install arduino-mk
    • read the instructions in the comments at the top (the Makefile is at /usr/share/arduino/Arduino.mk)
    • write your own project-specific Makefile as per these instructions
    • type make to compile your program
    • type make upload to upload to the seeeduino (i.e. write the flash).