|Hint: Use the tree menu to navigate groups of related pages|
Atmel AVR (MegaAVR) / WinAVR Port
The AVR WinAVR demo application is configured to run on an Atmel STK500 prototyping board using an AVR ATMega323 embedded processor running at 8MHz (instructions are provided should you wish to use an alternative development board). If an ATMega32 is used the frequency can be increased to 16MHz. The port is also being used with ATMega128 processors.
The 2KBytes of RAM on the ATMega323 is enough to run 10 real time tasks – including the idle task.
From V4.1.0 the AVR demo application demonstrates the use of co-routines.
IMPORTANT! Notes On Using The AVR/WinAVR RTOS Port:Please read all the following points before using this port.
My application does not run, what could be wrong?
Source Code OrganizationThe FreeRTOS download contains the source code for all the FreeRTOS ports.
See the Source Code Organization section for a description of the downloaded files and information on creating a new project.
The AVR WinAVR demo application makefile is located in the Demo/AVR_ATMega323_WinAVR directory.
The Demo ApplicationThe FreeRTOS source code download includes a fully preemptive multitasking demo application for the Mega AVR GCC RTOS port.
Demo application hardware setupThe demo application includes tasks that send and receive characters over the serial port. The characters sent by one task need to be received by another – if any character is missed or received out of sequence an error condition is flagged. A loopback connector is required on the serial port for this mechanism to operate (simply connect pins 2 and 3 together on the serial port connector).
For best effect LEDs should be connected to the eight data lines on the standard PC parallel port. Omitting these LEDs will not cause the RTOS demo application to fail, but will remove some visual feedback that everything is working as expected.
The following links must be in place on the STK500 prototyping board for the demo application to operate – these can be seen on the photograph above:
- PORTB to LEDS
- PORTD bits 0 and 1 to RS
- SPROG3 to ISP6PIN (correct link to program an AVR ATMega323
The demo application includes tasks that send and receive characters over the serial port. The characters sent by one task need to be received by another – if any character is missed or received out of sequence an error condition is flagged. A loopback connector is required on the serial port for this mechanism to operate (simply connect pins 2 and 3 together on the serial port connector).
Building the RTOS demo applicationFreeRTOS V3.0.0 has replaced the batch files previously used to build the demo application with a single makefile. This was made possible by improvements in ELF and COFF format support in the later versions of WinAVR.
To build the demo application:
- Ensure that WinAVR is correctly installed and accessible from your PATH environment.
- Open a command prompt and navigate to the Demo/AVR_ATMega323_WinAVR directory.
- Type ‘make’ to build the project. The project should build with no errors or warnings.
- To force a complete rebuild type ‘make clean’
- The optimisation level (option -O) and debug level (option -g) can be adjusted within the makefile to suit your application requirements.
Ensure the -g option is used within the makefile when generating files for debug and simulation.
FunctionalityThe RTOS demo application creates 10 of the standard demo tasks.
- LEDs 0 to 2 are under control of the standard ‘flash’ co-routines and flash at a regular rate. Each LED is flashed by a separate task.
- LEDs 4 and 5 are under control of the standard ‘comtest’ tasks. LED 4 toggles every time an RS232 character is transmitted. LED 5 toggles every time an RS232 character is received and verified.
- Not all the tasks update an LED so have no visible indication that they are operating correctly.
Therefore a ‘Check’ task is created whose job it is to ensure that no errors have been detected in any of the
LED 7 is under control of the ‘check’ task. LED 7 will flash every few seconds provided no errors have been detected in any of the other real time tasks. If an error is detected in any other task then LED 7 will stop flashing.
See the standard demo application section for full details of the demo application tasks.
RTOS port specific configurationConfiguration items specific to this port are contained in Demo/AVR_ATMega323_WinAVR/FreeRTOSConfig.h. The constants defined in this file can be edited to suit your application. In particular – the definition configTICK_RATE_HZ is used to set the frequency of the RTOS tick. The supplied value of 1000Hz is useful for testing the RTOS kernel functionality but is faster than most applications require. Lowering this value will improve efficiency.
Each port #defines ‘BaseType_t’ to equal the most efficient data type for that processor. This port defines BaseType_t to be of type char.
To use a microcontroller other than an AVR ATMega323
- Change the MCU definition at the top of the makefile.
- Set the correct clock frequency in Demo/AVR_ATMega323_WinAVR/FreeRTOSConfig.h
- Ensure the configTOTAL_HEAP_SIZE definition is set to fit within the available RAM.
- The tick ISR is generated from a compare match on timer 1. Timer configuration is not identical across all AVR devices. Check the function prvSetupTimerInterrupt() in Source/portable/GCC/ATMega323/port.c to see if any modifications are required for your chosen device.
Switching between the pre-emptive and co-operative RTOS kernels
Set the definition configUSE_PREEMPTION within Demo/AVR_ATMega323_WinAVR/FreeRTOSConfig.h to 1 to use pre-emption or 0 to use co-operative.
Memory managementSource/Portable/MemMang/heap_1.c is included in the MegaAVR demo application makefile to provide the memory allocation required by the RTOS kernel. Please refer to the Memory Management section of the API documentation for full information.
Development tool options
As with all the ports, it is essential that the correct compiler options are used. The best way to ensure this is to base your application on the provided demo application makefile.
RTOS Demo application serial port driver
The serial port driver included with the demo application uses the calculation detailed in the AVR ATMega323 manual to set the baud rate registers. At some baud rates I have found it necessary to adjust the calculated setting slightly. I suspect this is due to an inaccuracy in the 8MHz crystal installed in my prototyping board and rounding errors in the baud calculation.
It should also be noted that the serial drivers are written to test some of the RTOS kernel features – and they are not intended to represent an optimised solution.
Notes for Linux users
I have only tested the makefile from a Win2K host but hopefully it is also compatible with Linux builds of GCC.