Summary of kaOS operating system and loader using ATmega32
kaOS is a real-time, multithreaded operating system for the Atmel Mega32 that dynamically loads programs from SD/MMC cards without reprogramming the chip. It features up to 8 prioritized threads and inter-thread messaging. The project includes a custom card reader circuit utilizing SPI interfaces and voltage regulation, alongside software components like a bootloader-based loader and a .ROM file programmer.
Parts used in kaOS:
- Atmel Mega32 microcontroller
- STK500 development board
- Secure Digital or MMC card
- SD/MMC card connector with ejector
- SPI interface on PORTB
- Pushbutton reset switch
- Pull-up resistor
- Step-down circuits (voltage regulators)
- Step-up circuits
- 10-pin jumper cable
The operating system is real-time, multithreaded, and preemptive. It supports creation of up to 8 threads, which can be prioritized. Threads with the same priority are alternately preempted to give both equal processing time. kaOS also supports messaging between threads as a means of inter-thread communication.
While the idea for this project was born out of the lack of a true OS for the Mega32 that dynamically loads programs, we must give some credit to aOS, created by Anssi Ylätalo. In particular, we used his context-switching code to swap processor states when changing threads. Also, portions of our code used to read from SD/MMC cards were adapted from code written by Radig Ulrich. Additional information about SD card communication and the SPI protocol were obtained from SanDisk’s SD card manual.
In designing the operating system, we considered various library functions that we could add to increase functionality, such as LCD and keypad drivers, events, and support for multiple programs on a single card with a menu system to choose between them. These features, although useful bells and whistles, were cut from the design because they were extraneous to our core vision of creating a dynamically-loading OS, added unnecessary complexity, and consumed extra flash and RAM, which might be needed for some user programs.
We had 3 unused pins on PORTB after connecting to the card reader, so we added a pushbutton with a pull-up resistor and connected it to pin 1. This button is used as a reset, which causes the OS to load the program from an SD/MMC card, if one is inserted, and run it.
The SD connector we used included an ejector, which makes inserting and removing cards easy. Pushing the card into the slot clicks it into place. Pushing it again ejects it with a spring.
The real complexity of our design of kaOS is in the software. The biggest software challenge we faced was getting the bootloading to work. All programs on the Atmel have to be contained in flash memory, but only the bootloader can write to flash memory. Thus, we decided to put our OS in the bootloader section of flash. This decision also helped us avoid address conflicts with user programs because the bootloader resides at the highest addresses of flash memory.
We emailed Atmel several times with bootloader questions, asking about the feasibility of some of our ideas. The maximum bootloader size is 2048 instructions. kaOS is too big to fit in this space, so we fixed some functions in high flash addresses next to the bootloader, keeping the functions that program the flash actually in the bootloader.
Card Programmer
The Atmel programs created in our class have been coded and compiled in CodeVision AVR Studio. CodeVision creates .ROM files when it makes a project, which are lists of 16-bit words. These files define what the contents of flash memory should be when the chip is programmed. Rather than programming the MCU, however, we took these .ROM files and used them to program our SD card. We wrote a Win32 programmer and an Atmel programmer, separate from the OS, which programs the contents of a .ROM file to our SD card, also through the circuit we built. The .ROM files consist of hundreds or thousands of lines like the following:
For more detail: kaOS operating system and loader using ATmega32
-
What is the primary function of kaOS?
It is a real-time, multithreaded, preemptive operating system that loads and executes programs from an SD/MMC card. -
How many threads does kaOS support?
The operating system supports the creation of up to 8 threads which can be prioritized. -
Where does the program loader reside in flash memory?
The program loader resides in the Mega32's bootloader section of flash to gain write access to other portions of memory. -
Why were LCD and keypad drivers removed from the design?
These features were cut because they added unnecessary complexity and consumed extra flash and RAM needed for user programs. -
How are input pins connected to the SD card?
Clock, DataIn, and ChipSelect pins connect to PORTB pins 7, 5, and 0, while DataOut connects to PORTB pin 6. -
What voltage level is required by the SD card?
The SD card requires 3.3V, which is achieved using step-down circuits and a voltage regulator to handle load current. -
How do users trigger the OS to load a new program?
A reset button is pressed after inserting a card, causing the OS to load the program from the card and run it. -
What file format is used to store programs on the SD card?
.ROM files created by CodeVision AVR Studio containing lists of 16-bit words are used to program the SD card.

