FreeRTOS on Metro M0 (SAMD21)

Should this work?

lib_deps = PlatformIO-FreeRTOS

I get a result I don’t understand, about libopencm3. There is another package named “FreeRTOS_SAMD” but it gives me the same results.

Processing adafruit_metro_m0 (platform: atmelsam; board: adafruit_metro_m0; framework: arduino; lib_deps: RTCZero, Serial, Adafruit ILI9341, Adafruit GFX Library, Adafruit TouchScreen, Adafruit FT6206 Library, Adafruit Zero DMA Library, Adafruit BusIO, SPI, Wire, FreeRTOS_SAMD21; build_flags: -Ilib/itron_coap_server -DADAFRUIT_METRO_M0_EXPRESS)
------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/atmelsam/adafruit_metro_m0.html
PLATFORM: Atmel SAM (5.0.1) > Adafruit Metro M0 Expresss
HARDWARE: SAMD21G18A 48MHz, 32KB RAM, 256KB Flash
DEBUG: Current (atmel-ice) External (atmel-ice, blackmagic, jlink)
PACKAGES:
 - framework-arduino-samd-adafruit 1.5.14
 - framework-cmsis 1.40500.0 (4.5.0)
 - framework-cmsis-atmel 1.2.0
 - toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Error: No Libopencm3 device defined for FreeRTOS!
============================================== [FAILED] Took 0.75 seconds ==============================================
[platformio]
default_envs = adafruit_metro_m0

[env:adafruit_metro_m0]
platform = atmelsam
board = adafruit_metro_m0
framework = arduino
lib_deps = RTCZero
           Serial
           Adafruit ILI9341
           Adafruit GFX Library
           Adafruit TouchScreen
           Adafruit FT6206 Library
           Adafruit Zero DMA Library
           Adafruit BusIO
           SPI
           Wire
           Arduino_FreeRTOS

build_flags =
    -Ilib/itron_coap_server
    -D ADAFRUIT_METRO_M0_EXPRESS

According to the README page of the library and the Python script, maybe, but only with libopencm3 as the framework, and you’re setting Arduino. As can be seen in the Python builder code

You would need to set -D SAMD in the build flags to attempt a forced inclusion with FreeRTOS. Workings are however not guaranteed then…

So you tried 3 different ones? :sweat_smile:

After searching the library registry with the appropriate string header:"FreeRTOS.h" framework:arduino platform:atmelsam I get the library PlatformIO Registry.

Which works on my Adafruit M0 Express, which has the same MCU as yours. So just try

[env:adafruit_metro_m0]
platform = atmelsam
board = adafruit_metro_m0
framework = arduino
lib_deps = 
    briscoetech/FreeRTOS_SAMD21 @ ^2.3.0
monitor_speed = 115200

with the Basic_RTOS_Example.ino, with the 2 code adaptions to

  • add #include <Arduino.h> at the top
  • comment #define SERIAL SerialUSB and uncomment #define SERIAL Serial

RTOS boots and operates just fine.

I did try three different ones. It seemed like running this with Arduino underneath would be ok. This web page actually suggests it should work without you even having to start the task manager, which is a bit strange. I came to the conclusion that FreeRTOS_SAMD21 was the right one, too. I tried setting SAMD as well as FREERTOS_MCU_FAMILY but I get the same result.

[env:adafruit_metro_m0]
platform = atmelsam
board = adafruit_feather_m0
framework = arduino
lib_deps = RTCZero
           Serial
           Adafruit ILI9341
           Adafruit GFX Library
           Adafruit TouchScreen
           Adafruit FT6206 Library
           Adafruit Zero DMA Library
           Adafruit BusIO
           SPI
           Wire
           briscoetech/FreeRTOS_SAMD21 @ ^2.3.0

build_flags =
    -Ilib/itron_coap_server
    -D ADAFRUIT_METRO_M0_EXPRESS
    -D CMSIS_device_header='"sam.h"'
    -D FREERTOS_HEAP_IMPLEMENTATION=1
    -D FREERTOS_MCU_FAMILY=ARM_CM0
    -D SAMD

I don’t think I’m out-of-date on anything.

C:\work\milli\sunspec-milli>platformio --version
PlatformIO Core, version 5.0.4b1

Let me try building a brand new project with the Basic_RTOS_Example you referenced, and see what happens … unless you’re feeling generous enough to just tar or zip your project up and stuff it somewhere for me.

Interesting. I built a new project from scratch, created one little “Blink” task, and it compiles. I wonder what’s different about my project …

If you have the full project I can have a look at it, or with the error message I can consult my crystal glass balls for guidance.

Remember that wise crack about “You tried three different ones?” That was the problem :slight_smile: It left more than one in .pio/libdeps and it was finding the wrong one - probably finding the first one I found, before I realized I needed the SAMD specific port. It builds now, LEDs are blinking, and I’m on my way.

Actually, the huge help was you telling me “Yeah, it should work” then trying it to confirm. Thanks for the motivation, appreciate it very much.