FreeRTOS library problem

Hi I am trying out a FreeRTOS demo and have done some basic prep in pio.

the Freertos source files are in three separate folders, so I’ve placed them in the projects src folder as below, and placed the .h files in the pio include folder. I also renamed the .c files to .cpp

image

In PIO libraries, I searched for Freertos library and included it , but it doesn’t seem to be found when I inspect the code squiggles.

It’s almost inevitable that I’ve missed something, any help much appreciated. Compiler output below and PIO.ini below that:

Paul

> Executing task: C:\Users\Paul\.platformio\penv\Scripts\platformio.exe run <

Processing megaatmega2560 (platform: atmelavr; board: megaatmega2560; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/megaatmega2560.html
PLATFORM: Atmel AVR (3.2.0) > Arduino Mega or Mega 2560 ATmega2560 (Mega 2560)
HARDWARE: ATMEGA2560 16MHz, 8KB RAM, 248KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES:
 - framework-arduino-avr 5.1.0
 - toolchain-atmelavr 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 8 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <avr-debugger> 1.4.0
|-- <FreeRTOS> 10.4.4-2
Building in release mode
Compiling .pio\build\megaatmega2560\src\main.cpp.o
Compiling .pio\build\megaatmega2560\src\regtest.cpp.o
Compiling .pio\build\megaatmega2560\libd60\avr-debugger\app_api.c.o
Compiling .pio\build\megaatmega2560\libd60\avr-debugger\avr8-stub.c.o
Compiling .pio\build\megaatmega2560\lib6b0\FreeRTOS\event_groups.c.o
Compiling .pio\build\megaatmega2560\lib6b0\FreeRTOS\heap_3.c.o
Compiling .pio\build\megaatmega2560\lib6b0\FreeRTOS\list.c.o
Compiling .pio\build\megaatmega2560\lib6b0\FreeRTOS\port.c.o
src\main.cpp:87:10: fatal error: FreeRTOS.h: No such file or directory

******************************************************************
* Looking for FreeRTOS.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:FreeRTOS.h"
* Web  > https://platformio.org/lib/search?query=header:FreeRTOS.h
*
******************************************************************

 #include "FreeRTOS.h"
          ^~~~~~~~~~~~
compilation terminated.
src\regtest.cpp:29:10: fatal error: FreeRTOS.h: No such file or directory

******************************************************************
* Looking for FreeRTOS.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:FreeRTOS.h"
* Web  > Compiling .pio\build\megaatmega2560\lib6b0\FreeRTOS\queue.c.o
https://platformio.org/lib/search?query=header:FreeRTOS.h
*
******************************************************************

 #include "FreeRTOS.h"
          ^~~~~~~~~~~~
compilation terminated.
Compiling .pio\build\megaatmega2560\lib6b0\FreeRTOS\stream_buffer.c.o
Compiling .pio\build\megaatmega2560\lib6b0\FreeRTOS\tasks.c.o
*** [.pio\build\megaatmega2560\src\main.cpp.o] Error 1
Compiling .pio\build\megaatmega2560\lib6b0\FreeRTOS\timers.c.o
*** [.pio\build\megaatmega2560\src\regtest.cpp.o] Error 1
============================================================================ [FAILED] Took 1.18 seconds ============================================================================The terminal process "C:\Users\Paul\.platformio\penv\Scripts\platformio.exe 'run'" terminated with exit code: 1.

PIO.ini


; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:megaatmega2560]
platform      = atmelavr
board         = megaatmega2560
framework     = arduino
debug_tool    = avr-stub
upload_port   = COM7
monitor_port  = COM7
debug_port    = COM7
monitor_speed = 19200
lib_deps = 
	jdolinay/avr-debugger@^1.1
	feilipu/FreeRTOS@^10.4.4-2

[platformio]
description = A FreeRTOS demo


The library provides Arduino_FreeRTOS.h, not FreeRTOS.h.

1 Like

thanks for pointing that out. When I use the library search facility in PIO’s gui, it doesn’t find FreeRTOS.h so could you give me an idea of how to include the library I need into my pio project?

thanks
Paul

Arduino_FreeRTOS.h is that library’s FreeRTOS.h replacement / version, it works the same. Have you tried the linked example sketch?

Also there is one (older) alternative when I use the search string header:"FreeRTOS.h" platform:atmelavr framework:arduino in the library registry: FreeRTOS-Arduino/libraries/FreeRTOS_AVR at master · greiman/FreeRTOS-Arduino · GitHub. Though it also prefers if you #include <FreeRTOS_AVR.h>.

1 Like

perhaps just importing the project from the FreeRTOS demo file structure may work. I’ll try that.

replies crossed - i’ll try what you’ve indicated. thanks

thanks, so in the code from the FreeRTOS demo port, I can replace FreeRTOS.h with Arduino_FreeRTOS.h I’ll try that and see where it goes. Just seems a bit odd that FreeRTOS examples for a port don’t work out of the box - I appreciate its a different chip I’m trying on a Arduino mega2560 and there are some changes specified by the FreeRTOS folks such as clock speed. Anyway, I’ll give it a go.

I think I must be missing a library path in the pio.ini as there are many more header files not found as per image below and I feel these must be part of the FreeRTOS resources.

image

That feilipu/FreeRTOS library does not have coroutines available (see sources), the one I linked to (which however is based on FreeRTOS 8.2.3 instead of 10.4.4) does. You may be able to expand the feilipu library by copying the original source files for these things and activating them in the config.

As for the other heads not being found, in the

I see that the ParTest and serial folders are not inside src/. If source code is in there, they need to be in either src/ or be modeled as a library in lib/.

Don’t forget to Ctrl+Shift+P → Rebuild IntelliSense after moving files to retrigger the IntelliSense.

thanks for help Max. I’ve reorganised the folders so the ParTest and serial are under src.

Whllst exploring the error I have on the FreeRTOS help forum, it appears that all the headers and lib files are on my local machine here:

image

So I read the README file in PIO lib folder and I understand it, but just one question - rather than copy all the FreeRTOS headers and lib src files into pio’s lib folder, can I specify a path in the lib folder instead?

thanks,
Paul

At first you should just try to copy the croutine.h header and associated .c file from the same FreeRTOS version that port is using in the existing FreeRTOS library folder as a test – if you add this possibly differing FreeRTOS version in the include path it is unlikely to work and likely to conflict. The FreeRTOS library has made AVR specific changes to the port after all.

I’ve made some progress I think, but now have a different kind of error. Any help much appreciated.

main.c line 97 referred to in the compiler errors is this:


#include "print.h"

and the compiler output is:

Processing  FreeRTOS (platform: atmelavr; board: ATmega2560; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/ATmega2560.html
PLATFORM: Atmel AVR (3.2.0) > ATmega2560
HARDWARE: ATMEGA2560 16MHz, 8KB RAM, 256KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES:
 - framework-arduino-avr-megacore 2.1.1
 - toolchain-atmelavr 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 10 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <avr-debugger> 1.4.0
Building in release mode
Compiling .pio\build\ FreeRTOS\src\ParTest\ParTest.c.o
Compiling .pio\build\ FreeRTOS\src\main.c.o
Compiling .pio\build\ FreeRTOS\src\port.c.o
Compiling .pio\build\ FreeRTOS\src\regtest.c.o
Compiling .pio\build\ FreeRTOS\src\serial\serial.c.o
Compiling .pio\build\ FreeRTOS\lib406\avr-debugger\app_api.c.o
Compiling .pio\build\ FreeRTOS\lib406\avr-debugger\avr8-stub.c.o
Archiving .pio\build\ FreeRTOS\libFrameworkArduinoVariant.a
In file included from C:\Users\Paul\.platformio\packages\framework-arduino-avr-megacore\cores\MegaCore/print.h:27:0,
                 from src\main.c:97:
C:\Users\Paul\.platformio\packages\framework-arduino-avr-megacore\cores\MegaCore/Printable.h:25:1: error: unknown type name 'class'; did you mean 'labs'?
 class Print;
 ^~~~~
 labs
C:\Users\Paul\.platformio\packages\framework-arduino-avr-megacore\cores\MegaCore/Printable.h:33:1: error: unknown type name 'class'; did you mean 'labs'?
 class Printable
 ^~~~~
 labs
C:\Users\Paul\.platformio\packages\framework-arduino-avr-megacore\cores\MegaCore/Printable.h:34:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 {
 ^
In file included from src\main.c:97:0:
C:\Users\Paul\.platformio\packages\framework-arduino-avr-megacore\cores\MegaCore/print.h:37:1: error: unknown type name 'class'; did you mean 'labs'?
 class Print
 ^~~~~
 labs
C:\Users\Paul\.platformio\packages\framework-arduino-avr-megacore\cores\MegaCore/print.h:38:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 {
 ^
src\main.c:155:7: warning: return type of 'main' is not 'int' [-Wmain]
 short main( void )
       ^~~~
In file included from src\port.c:32:0:
src\port.c: In function 'prvSetupTimerInterrupt':
include/porthardware.h:54:9: error: 'TCB0' undeclared (first use in this function); did you mean 'ACBG'?
         TCB0.CCMP = configCPU_CLOCK_HZ / configTICK_RATE_HZ; \
         ^
src\port.c:307:5: note: in expansion of macro 'TICK_init'
     TICK_init();
     ^~~~~~~~~
include/porthardware.h:54:9: note: each undeclared identifier is reported only once for each function it appears in
         TCB0.CCMP = configCPU_CLOCK_HZ / configTICK_RATE_HZ; \
         ^
src\port.c:307:5: note: in expansion of macro 'TICK_init'
     TICK_init();
     ^~~~~~~~~
include/porthardware.h:55:24: error: 'TCB_CAPT_bm' undeclared (first use in this function)
         TCB0.INTCTRL = TCB_CAPT_bm;                          \
                        ^
src\port.c:307:5: note: in expansion of macro 'TICK_init'
     TICK_init();
     ^~~~~~~~~
include/porthardware.h:56:22: error: 'TCB_ENABLE_bm' undeclared (first use in this function); did you mean 'TCB_CAPT_bm'?
         TCB0.CTRLA = TCB_ENABLE_bm;                          \
                      ^
src\port.c:307:5: note: in expansion of macro 'TICK_init'
     TICK_init();
     ^~~~~~~~~
In file included from src\port.c:31:0:
src\port.c: In function 'TCB0_INT_vect':
include/porthardware.h:48:30: warning: 'TCB0_INT_vect' appears to be a misspelled 'signal' handler, missing '__vector' prefix [-Wmisspelled-isr]
     #define TICK_INT_vect    TCB0_INT_vect
                              ^
src\port.c:318:10: note: in expansion of macro 'TICK_INT_vect'
     ISR( TICK_INT_vect, ISR_NAKED )
          ^~~~~~~~~Compiling .pio\build\ FreeRTOS\FrameworkArduino\CDC.cpp.o
~~~~
Compiling .pio\build\ FreeRTOS\FrameworkArduino\HardwareSerial.cpp.o
src\main.c: In function 'prvIncrementResetCount':
src\main.c:243:2: warning: implicit declaration of function 'eeprom_read_block' [-Wimplicit-function-declaration]
  eeprom_read_block( &ucCount, mainRESET_COUNT_ADDRESS, sizeof( ucCount ) );
  ^~~~~~~~~~~~~~~~~
src\main.c:245:2: warning: implicit declaration of function 'eeprom_write_byte' [-Wimplicit-function-declaration]
  eeprom_write_byte( mainRESET_COUNT_ADDRESS, ucCount );
Compiling .pio\build\ FreeRTOS\FrameworkArduino\HardwareSerial0.cpp.o
  ^~~~~~~~~~~~~~~~~
src\serial\serial.c: In function 'xSerialPortInitMinimal':
src\serial\serial.c:110:3: error: 'UBRRL' undeclared (first use in this function); did you mean 'UBRR2L'?
   UBRRL = ucByte;
   ^~~~~
   UBRR2L
src\serial\serial.c:110:3: note: each undeclared identifier is reported only once for each function it appears in
src\serial\serial.c:114:3: error: 'UBRRH' undeclared (first use in this function); did you mean 'UBRRL'?
Compiling .pio\build\ FreeRTOS\FrameworkArduino\HardwareSerial1.cpp.o
   UBRRH = ucByte;
   ^~~~~
   UBRRL
src\serial\serial.c:118:3: error: 'UCSRB' undeclared (first use in this function); did you mean 'UCSR0B'?
   UCSRB = ( serRX_INT_ENABLE | serRX_ENABLE | serTX_ENABLE );
   ^~~~~
   UCSR0B
src\serial\serial.c:121:3: error: 'UCSRC' undeclared (first use in this function); did you mean 'UCSRB'?
   UCSRC = ( serUCSRC_SELECT | serEIGHT_DATA_BITS );
   ^~~~~
   UCSRB
src\serial\serial.c: In function 'xSerialPutChar':
src\serial\serial.c:77:11: error: 'UCSRB' undeclared (first use in this function); did you mean 'UCSR0B'?
  ucByte = UCSRB;           \
           ^
src\serial\serial.c:161:2: note: in expansion of macro 'vInterruptOn'
  vInterruptOn();
  ^~~~~~~~~~~~
src\serial\serial.c: In function 'vSerialClose':
src\serial\serial.c:87:13: error: 'UCSRB' undeclared (first use in this function); did you mean 'UCSR0B'?
  ucInByte = UCSRB;          \
             ^
src\serial\serial.c:179:3: note: in expansion of macro 'vInterruptOff'
   vInterruptOff();
   ^~~~~~~~~~~~~
In file included from src\serial\serial.c:52:0:
src\serial\serial.c: In function 'USART_RXC_vect':
src\serial\serial.c:188:9: warning: 'USART_RXC_vect' appears to be a misspelled 'signal' handler, missing '__vector' prefix [-Wmisspelled-isr]
 SIGNAL( USART_RXC_vect )
         ^
src\serial\serial.c:196:10: error: 'UDR' undeclared (first use in this function); did you mean 'UDR0'?
  cChar = UDR;
          ^~~
          UDR0
In file included from src\serial\serial.c:52:0:
src\serial\serial.c: In function 'USART_UDRE_vect':
src\serial\serial.c:207:9: warning: 'USART_UDRE_vect' appears to be a misspelled 'signal' handler, missing '__vector' prefix [-Wmisspelled-isr]
 SIGNAL( USART_UDRE_vect )
         ^
src\serial\serial.c:214:3: error: 'UDR' undeclared (first use in this function); did you mean 'UDR0'?
   UDR = cChar;
   ^~~
   UDR0
src\serial\serial.c:87:13: error: 'UCSRB' undeclared (first use in this function); did you mean 'UCSR0B'?
  ucInByte = UCSRB;          \
             ^
src\serial\serial.c:219:3: note: in expansion of macro 'vInterruptOff'
   vInterruptOff();
   ^~~~~~~~~~~~~
In file included from c:\users\paul\.platformio\packages\toolchain-atmelavr@1.70300.191015\avr\include\avr\io.h:99:0,
                 from c:\users\paul\.platformio\packages\toolchain-atmelavr@1.70300.191015\avr\include\avr\interrupt.h:38,
                 from src\port.c:31:
include/porthardware.h:49:30: error: 'TCB0_INTFLAGS' undeclared (first use in this function); did you mean 'TCB0_INT_vect'?
     #define INT_FLAGS        TCB0_INTFLAGS
                              ^
src\port.c:321:9: note: in expansion of macro 'CLR_INT'
         CLR_INT( INT_FLAGS, INT_MASK );
         ^~~~~~~
src\port.c:321:18: note: in expansion of macro 'INT_FLAGS'
         CLR_INT( INT_FLAGS, INT_MASK );
                  ^~~~~~~~~
In file included from src\port.c:32:0:
include/porthardware.h:50:30: error: 'TCB_CAPT_bm' undeclared (first use in this function)
     #define INT_MASK         TCB_CAPT_bm
                              ^
include/porthardware.h:43:66: note: in definition of macro 'CLR_INT'
         : "i" ( _SFR_MEM_ADDR( FLAG_REG ) ), "i" ( ( uint8_t ) ( FLAG_MASK ) ) \
                                                                  ^~~~~~~~~
src\port.c:321:29: note: in expansion of macro 'INT_MASK'
         CLR_INT( INT_FLAGS, INT_MASK );
                             ^~~~~~~~
*** [.pio\build\ FreeRTOS\src\main.c.o] Error 1
*** [.pio\build\ FreeRTOS\src\serial\serial.c.o] Error 1
*** [.pio\build\ FreeRTOS\src\port.c.o] Error 1
============================================================================ [FAILED] Took 1.20 seconds ===============

PIO.ini :


[env: FreeRTOS]
platform      = atmelavr
board         = ATmega2560
framework     = arduino
debug_tool    = avr-stub
upload_port   = COM7
monitor_port  = COM7
debug_port    = COM7
monitor_speed = 19200
lib_deps = 
	jdolinay/avr-debugger@^1.1
lib_extra_dirs = 
	C:\FreeRTOS\FreeRTOSv202107.00\FreeRTOS\Source\
	C:\FreeRTOS\FreeRTOSv202107.00\FreeRTOS\Demo\Common\include

[platformio]
description = A FreeRTOS demo

I’ve posted this to the FreeRTOS support community as I don’t think it’s a relevant PIO problem.

thanks for suggestions,
Paul

I’m wondering if the Arduino framework file “print.h” is the one you mean? If so, you appear to be including it from a file with extension .c and that makes the gcc C compiler the compiler of choice. You need the G++ compiler, for C++, to be able to compile classes.

The Print.h file, with a capital ‘P’, declares the Print class – also eith a capital ‘P’ :grin:.

C code cannot use classes, you need C++ for that. Note the file name – it has a capital ‘P’ – this will (usually) work fine on a Windows system where the filenames are case insensitive, but if your code is ever copied onto a Linux or Mac box, for example, the application will fail to compile as those systems are case sensitive.

Of course, it’s possible that you have created your own “print.h” file and want to use that one, however, looking at the error messages about the Print class, it seems that the Arduino one has been included instead.

HTH

Cheers,
Norm.

Thanks for helping with this Norm. All the code is from the FreeRTOS download link for the AVR323 port of FreRTOS. They reckon it will compile ‘as is’. I haven’t changed anything. So if their files have the extension.c (as they do), from what you’ve said they should compile with the Atmel AVR toolchain I’m currently using. They don’t compile as there are missing header files and I’ve gradually acquired these from the FreeRTOS site as I’ve come across compile errors. I’ve posted on the FreeRTOS support site too and they’ve pointed at ‘inclusion of incorrect code’, so I’ve laid out what I’ve done (downloaded the demo and tried to compile it, got errors because of missing files, tried to find those files and include them - it’s a mess !) So whilst realistically, I wasn’t expecting it to be perfect, it seems quite a long way away from a clean compile.

thanks,
Paul

Ok, thanks for the update Paul. Good luck getting something sorted out!

Cheers,
Norm.

Hi Norm, the FreeRTOS guys have asked me if I can share my makefile. Is there an equivalent in PIO I could share?

thanks
Paul

There isn’t an equivalent to a make file that I’m aware of, no. The closest to a makefile would be the platformio.ini file, but that would not be any good I’m afraid.

Some frameworks do create a cmakeLists.txt file, but not the Arduino framework.

You might be pushed to get support without a makefile, but you may try to explain that you are using PlatformIO which doesn’t use a makefile.

Sorry, not much help I’m afraid. :frowning:

Cheers,
Norm.

ok Norm, no probs, I’ll see what they say at FreeRTOS and if anything useful comes out, I’ll report back.

thanks,
Paul

Hi Norm,

below is an extract from the makefile supplied with the FreeRTOS port. Is there a way to model this in PIO?
Or, is it best if I goto the places specified in the makefile, gather all the code files into pio src and all the header files into pio include ?

thanks for any thoughts on this,
Paul

extract:

# List C source files here. (C dependencies are automatically generated.)
DEMO_DIR = ../Common/Minimal
SOURCE_DIR = ../../Source
PORT_DIR = ../../Source/portable/GCC/ATMega323

SRC	= \
main.c \
ParTest/ParTest.c \
serial/serial.c \
regtest.c \
$(SOURCE_DIR)/tasks.c \
$(SOURCE_DIR)/queue.c \
$(SOURCE_DIR)/list.c \
$(SOURCE_DIR)/croutine.c \
$(SOURCE_DIR)/portable/MemMang/heap_1.c \
$(PORT_DIR)/port.c \
$(DEMO_DIR)/crflash.c \
$(DEMO_DIR)/integer.c \
$(DEMO_DIR)/PollQ.c \
$(DEMO_DIR)/comtest.c

# If there is more than one source file, append them above, or modify and
# uncomment the following:
#SRC += foo.c bar.c

Hi @paulskirk53,

I could have sworn that I saw an option named something like src_extra_dirs which would let a project compile sources from outside the src directory. I checked the docs and can only find lib_extra_dirs for libraries! :frowning:

I’m wondering how FreeRTOS compiles? If it compiles into a static (*.a) library, then you might be able to link your code to it – you wiuld probably need the lib_extra_dirs option pointing at the source directories in the make file.

If not, then, I’m still not convinced this will work though. Unless these FreeRTOS files are extern C... your main.cpp will invoke the C++ compiler and link errors will result due to name mangling.

Maybe copying the files into src might work, but it might end up being a somewhat recursive process to get everything in thr correct place.

Sorry for the doom and gloom there, but I’ve found when I say things like that, someone jumps in and proves me wrong! :wink:

Cheers,
Norm.