• Stars
    star
    838
  • Rank 54,406 (Top 2 %)
  • Language
    C
  • License
    MIT License
  • Created almost 9 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A FreeRTOS Library for all Arduino ATmega Devices (Uno R3, Leonardo, Mega, etc).

This is a fork of Richard Barry's freeRTOS, optimised for the Arduino AVR devices.

It has been created to provide access to FreeRTOS capabilities, with full compatibility to the Arduino environment. It does this by keeping hands off almost everything, and only touching the minimum of hardware to be successful.

Usage & Further Reading

Read the short blog post on Arduino FreeRTOS to get started. And there is another much older post on using FreeRTOS with AVR, which may be useful to read too. There are some further posts I've written on Hackster.IO, but they're essentially the same content.

The canonical source for information is the FreeRTOS Web Site. Within this site, the Getting Started page is very useful. This is the source for FreeRTOS usage (as distinct from installing and using this Arduino Library).

My other AVRfreeRTOS Sourceforge Repository or AVRfreeRTOS Github has plenty of examples, ranging from blink through to a synthesiser.

This library was the genesis of generalised support for the ATmega platform within FreeRTOS.

Over the past few years freeRTOS development has become increasingly 32-bit orientated, with little change or improvement for the 8-bit world. As such I'm treating this FreeRTOS V10.5.x (released May 1 2023) as my LTS release.

General

FreeRTOS has a multitude of configuration options, which can be specified from within the FreeRTOSConfig.h file. To keep commonality with all of the Arduino hardware options, some sensible defaults have been selected. Feel free to change these defaults as you gain experience with FreeRTOS.

Normally, the AVR Watchdog Timer is used to generate 15ms time slices (Ticks). For applications requiring high precision timing, the Ticks can be sourced from a hardware timer or external clock. See chapter Scheduler Tick Sources for the configuration details.

Tasks that finish before their allocated time will hand execution back to the Scheduler.

The Arduino delay() function has been redefined to automatically use the FreeRTOS vTaskDelay() function when the delay required is one Tick or longer, by setting configUSE_PORT_DELAY to 1, so that simple Arduino example sketches and tutorials work as expected. If you would like to measure a short millisecond delay of less than one Tick, then preferably use millis() (or with greater granularity use micros()) to achieve this outcome (for example see BlinkWithoutDelay). However, when the delay requested is less than one Tick then the original Arduino delay() function will be automatically selected.

The 8-bit AVR Timer0 has been added as an option for the experienced user. Please examine the source code to figure out how to use it. Reconfiguring Timer0 for FreeRTOS will break Arduino millis() and micros() though, as these functions rely on Timer0.

Stack for the loop() function has been set at 192 Bytes. This can be configured by adjusting the configMINIMAL_STACK_SIZE parameter. If you have stack overflow issues, just increase it. Users should prefer to allocate larger structures, arrays, or buffers using pvPortMalloc(), rather than defining them locally on the stack. Ideally you should not use loop() for your sketches, and then the stack size can be reduced down to 85 Bytes, saving some valuable memory.

Memory for the heap is allocated by the normal malloc() function, wrapped by pvPortMalloc(). This option has been selected because it is automatically adjusted to use the capabilities of each device. Other heap allocation schemes are supported by FreeRTOS, and they can used with some additional configuration.

Upgrading

Errors

  • Stack Overflow: If any stack (for the loop() or) for any Task overflows, there will be a slow LED blink, with 4 second cycle.
  • Heap Overflow: If any Task tries to allocate memory and that allocation fails, there will be a fast LED blink, with 100 millisecond cycle.

Errata

Testing with the Software Serial library shows some incompatibilities at low baud rates (9600), due to the extended time this library disables the global interrupt. Use the hardware USARTs.

Compatibility

  • ATmega328 @ 16MHz : Arduino UNO, Arduino Duemilanove, Arduino Diecimila, etc.
  • ATmega328 @ 16MHz : Adafruit Pro Trinket 5V, Adafruit Metro 328, Adafruit Metro Mini
  • ATmega328 @ 16MHz : Seeed Studio Stalker
  • ATmega328 @ 16MHz : Freetronics Eleven
  • ATmega328 @ 12MHz : Adafruit Pro Trinket 3V
  • ATmega32u4 @ 16MHz : Arduino Leonardo, Arduino Micro, Arduino Yun, Teensy 2.0
  • ATmega32u4 @ 8MHz : Adafruit Flora, Bluefruit Micro
  • ATmega1284p @ 16MHz: Sanguino, WickedDevice WildFire
  • ATmega1284p @ 24.576MHz : Seeed Studio Goldilocks, Seeed Studio Goldilocks Analogue
  • ATmega2560 @ 16MHz : Arduino Mega, Arduino ADK
  • ATmega2560 @ 16MHz : Seeed Studio ADK

The new megaAVR 0-Series devices (eg. ATmega4809) are not fully compatible with this library. Their Timer configuration is substantially different from previous devices, and forms part of a new avr8x architecture. It may be a while until avr-libc is updated to include support for megaAVR devices, but when that happens further work will be added here.

Files & Configuration

  • Arduino_FreeRTOS.h : Must always be #include first. It references other configuration files, and sets defaults where necessary.
  • FreeRTOSConfig.h : Contains a multitude of API and environment configurations.
  • FreeRTOSVariant.h : Contains the AVR specific configurations for this port of freeRTOS.
  • heap_3.c : Contains the heap allocation scheme based on malloc(). Other schemes are available, but depend on user configuration for specific MCU choice.

PlatformIO

Arduino FreeRTOS is available in the PlatformIO library manager for use in a PlatformIO project.

Watchdog period is configurable using build-flags:

build_flags =
  -DportUSE_WDTO=WDTO_15MS

Code of conduct

See the Code of conduct.

Contributors โœจ

All Contributors

Thanks goes to these wonderful people (emoji key):


Phillip Stevens

๐Ÿšง๐Ÿ’ป๐Ÿ‘€๐Ÿ“–

Hector Espert

๐Ÿ’ป

Floessie

๐Ÿ’ป

Derekduke

๐Ÿ’ป

Balaji.V

๐Ÿ’ป๐Ÿ“–

John Y. Pazekha

๐Ÿ’ป๐Ÿ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

More Repositories

1

avrfreertos

AVR ATmega port of freeRTOS
C
185
star
2

miniAVRfreeRTOS

Minimum FreeRTOS implementation - for all AVR ATmega MCU variants.
C
63
star
3

NASCOM_BASIC_4.7

Z80 8085 MS BASIC Version 4.7 - (C) 1978 Microsoft
Assembly
50
star
4

yaz180

YAZ180 - Modern Single Board Z180 Computer
Assembly
50
star
5

z88dk-libraries

A collection of z80 libraries integrated with z88dk
C
24
star
6

LLL-Floating-Point

Floating-Point Package for Intel 8008 and 8080 Microprocessors
Assembly
14
star
7

ux_module

User Experience Module - RC2014
Propeller Spin
11
star
8

ReGIS

ReGIS, short for Remote Graphic Instruction Set, is a vector graphics markup language.
C
10
star
9

Goldilocks_Analogue_DAC_Library

Firmware for the MCP4822 12-bit, dual channel, SPI interface, DAC integrated into the Goldilocks Analogue, a ATmega1284p MCU classic Arduino board.
C
10
star
10

Arduino_RTC_Library

Real Time functions for AVR (Goldilocks Analogue, Arduino Mega). The underlying avr-libc time implementation aspires to conform with ISO/IEC 9899 (C90). However, due to limitations of the target processor and the nature of its development environment, a practical AVR implementation must of necessity deviate from the C90 standard time.h.
C
9
star
11

Arduino_Goldilocks_Variant

Variant files for Goldilocks AVR ATmega1284p Boards under Arduino IDE. STK500v2 boot-loader including debug monitor.
C
7
star
12

Goldilocks_Analogue_SPIRAM_Library

This library implements firmware to control SPI SRAM, FRAM, and EEPROM as implemented in the Goldilocks Analogue, a ATmega1284p MCU classic Arduino board.
C
4
star
13

planet-motion

Graphical planetary motion calculator
C
2
star
14

planets

A rough calculation of planetary motion - to test floating point solutions
C
2
star
15

rcm2024

RabbitCoreยฎ Module - Designed for RC2014 Standard Bus
1
star
16

8085-opcodes

8085 instructions (including undocumented) in Zilog mnemonics
HTML
1
star