Haakon Skar, Director AVR Microcontrollers at Atmel Corporation explores how embedded software development tools are evolving to keep pace with MCU advances.
Software engineers have typically been known to favor writing every line of source code personally, but are aware that good quality source code can only be achieved by working for long periods of time. This work has to be laboriously carried out over the keyboard until every single line of source code is optimised, verified and certified. Luckily, there are design engineers out there who are prepared to disclose and compare the results of their working efforts with others cutting the amount of work required by fellow engineers.
There are many sources of high-quality code out there, of both a free and commercial nature. In response to market demands Atmel has released its AVR Software Framework for the company’s AVR microcontrollers. This is a library of source code for common tasks such as communications, analogue and digital I/O, environment sensors, integer-, fixed-, and floating-point math libraries, DSP libraries, audio and video multimedia, graphics and graphical user interfaces, file systems, RTOS, and more.
Understanding the stack is best done from the bottom. In the lower ‘board definition’ layer, digital and analogue peripherals are assigned to each I/O pin. This gives a convenient way to control which peripheral is assigned to each pin. For example, users may choose that their application will use one USB device port, 4 ADC channels, two I2C ports, one SPI port, 6 inputs for buttons, and 3 outputs for LEDs. This is also the layer where logical names are assigned, such as “ANALOG_FILTER_INPUT”, “PLAY_BUTTON” and “GREEN_LED1” to each I/O pin. Assigning logical names has no effect on the code generated on the higher levels, but will make code on higher layers a lot easier to read and understand.
The board definition layer consists mainly of macros, so the code size is negligible.
Layer 2 is known as the “peripherals” layer and this is the only layer that speaks directly to the on-chip hardware. The driver layer is responsible for initiating and managing each of the on-chip peripherals, providing an upwards API interface that allows the higher levels to control the board and speak to external components. For example, the peripherals layer configures the USB, ADC, I2C, SPI and GPIO peripherals and lets the higher levels know they are ready for use. The peripheral layer also controls the interrupt-, peripheral event-, and DMA controllers.
The code in the peripheral layer is written with a focus on providing the functionality that a typical user will need in each of the on-chip peripherals. This gives a significantly smaller code size compared to offering full flexibility in each driver. If the application calls for a peripheral to operate in a ‘non-typical’ mode, it is easy for the user to modify the existing source code, or add an extra function call to the API.
Above the peripherals layer sits the ‘components’ layer, which is responsible for communicating with external components such as displays, keyboards, memories, board controllers, and sensors (light, gyroscope, accelerometer, compass). This layer contains the code that initiates, calibrates and communicates with the external components. This communication is stripped off and hidden from the higher level layers.
The fourth layer in the AVR Software Framework is the ‘services’ layer. This is the layer that holds the USB and TCP/IP communication stacks, DSP and math libraries, audio codecs, graphic decoders, graphical user interfaces, and a whole lot more. The common denominator for all this code is that it takes a long time to write, optimise, test and certify. This ‘commodity’ code has great value to the developer because of the time it will shave off the design cycle.
At the very top of the AVR Software Framework sits the ‘applications’ layer. This is the code that manages everything, by analysing the data collected from internal and external components and feeding it through the libraries and communication stacks of the services layer. In other words, this is where the true magic happens, and what makes your application ‘truly unique’.
Atmel