Help with serial.h file

Hi I am trying out FreeRTOS for the first time and looking to mod the AVRAtmega323 winAVR port to use it with an arduino mega 2560. I am using the PlatformIO IDE and have made some progress, but the ide/ compiler is complaining about missing headers such as serial.h, partest.h and pollQ.h

Although I found lots of .h files in the FreeRTOS source\ include folder, I couldn’t find the ones mentioned above. More user error :slight_smile:

Many thanks for any help to get this going.

Paul

These are files used by most of the FreeRTOS demos applications. Their header files are in this directory. Note these are not required by the FreeRTOS kernel - only the demo application that accompanies the port. See the following links for more information:

https://www.freertos.org/a00017.html
https://www.freertos.org/a00102.html

many thanks for the reply. I found the headers on my local installation too. Now that I’ve included them, I’m getting other compiler errors as shown in the extract below. Any help much appreciated.

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 11 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <avr-debugger> 1.4.0
|-- <Source> 0.0.0+20210815151739
|   |-- <FreeRTOS> 10.4.4-2
|-- <portable>
|-- <FreeRTOS> 10.4.4-2
Building in release mode
Compiling .pio\build\megaatmega2560\src\ParTest\ParTest.cpp.o
Compiling .pio\build\megaatmega2560\src\main.cpp.o
Compiling .pio\build\megaatmega2560\src\regtest.cpp.o
Compiling .pio\build\megaatmega2560\src\serial\serial.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
src\ParTest\ParTest.cpp:66:45: error: expected ',' or '...' before 'uxLED'
 void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
                                             ^~~~~
src\ParTest\ParTest.cpp: In function 'void vParTestSetLED(unsigned int)':
src\ParTest\ParTest.cpp:70:6: error: 'uxLED' was not declared in this scope
  if( uxLED <= partstMAX_OUTPUT_LED )
      ^~~~~
src\ParTest\ParTest.cpp:76:8: error: 'xValue' was not declared in this scope
Compiling .pio\build\megaatmega2560\lib6b0\FreeRTOS\list.c.o
    if( xValue == pdTRUE )
        ^~~~~~
src\ParTest\ParTest.cpp: At global scope:
Compiling .pio\build\megaatmega2560\lib6b0\FreeRTOS\port.c.o
src\ParTest\ParTest.cpp:93:48: error: expected ',' or '...' before 'uxLED'
Compiling .pio\build\megaatmega2560\lib6b0\FreeRTOS\queue.c.o
 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
                                                ^~~~~
src\ParTest\ParTest.cpp: In function 'void vParTestToggleLED(unsigned int)':
src\ParTest\ParTest.cpp:97:6: error: 'uxLED' was not declared in this scope
  if( uxLED <= partstMAX_OUTPUT_LED )
      ^~~~~
In file included from src\main.cpp:94:0:
Compiling .pio\build\megaatmega2560\lib6b0\FreeRTOS\stream_buffer.c.o
include/serial.h:90:63: error: expected ',' or '...' before 'uxQueueLength'
                                        unsigned portBASE_TYPE uxQueueLength );
                                  

Looks like you are build C++ code, so it is not code from us. I’m going to guess portBASE_TYPE isn’t defined, maybe because of the C++ settings, but I don’t have your project to know - I’m just interpreting the compiler output you posted.

I have probably confused things by renaming the FreeRTOS .c files to .cpp so that they’d ‘work’ in my ide. I probably have some research to do. Sorry if I have wasted your time.
Paul

I reverted the file extensions to .c and recompiled. Iteratively I got closer to solving the .h file issues, but now my compiler output flags other errors as below. Any pointers to a way forward would be much appreciated:

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 12 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <avr-debugger> 1.4.0
|-- <portable>
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
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
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();
     ^~~~~~~~~
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
 {
 ^
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();
     ^~~~~~~~~
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
 {
 ^
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();
     ^~~~~~~~~
src\main.c:155:7: warning: return type of 'main' is not 'int' [-Wmain]
 short main( void )
       ^~~~
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 )
          ^~~~~~~~~~~~~
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 );
                  ^~~~~~~~~
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 ) );
  ^~~~~~~~~~~~~~~~~
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 );
                             ^~~~~~~~
src\main.c:245:2: warning: implicit declaration of function 'eeprom_write_byte' [-Wimplicit-function-declaration]
  eeprom_write_byte( mainRESET_COUNT_ADDRESS, ucCount );
  ^~~~~~~~~~~~~~~~~
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'?
   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;           \
           ^
Compiling .pio\build\ FreeRTOS\lib679\portable\ARMv8M\non_secure\port.c.o
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 )
         ^
Compiling .pio\build\ FreeRTOS\lib679\portable\ARMv8M\non_secure\portable\GCC\ARM_CM23\portasm.c.o
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();
   ^~~~~~~~~~~~~
Compiling .pio\build\ FreeRTOS\lib679\portable\ARMv8M\non_secure\portable\GCC\ARM_CM23_NTZ\portasm.c.o
Compiling .pio\build\ FreeRTOS\lib679\portable\ARMv8M\non_secure\portable\GCC\ARM_CM33\portasm.c.o
*** [.pio\build\ FreeRTOS\src\port.c.o] Error 1
*** [.pio\build\ FreeRTOS\src\main.c.o] Error 1
*** [.pio\build\ FreeRTOS\src\serial\serial.c.o] Error 1
Compiling .pio\build\ FreeRTOS\lib679\portable\ARMv8M\non_secure\portable\GCC\ARM_CM33_NTZ\portasm.c.o
C:\FreeRTOS\FreeRTOSv202107.00\FreeRTOS\Source\portable\ARMv8M\non_secure\portable\GCC\ARM_CM23\portasm.c:37:10: fatal error: portasm.h: No such file or directory

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

 #include "portasm.h"
          ^~~~~~~~~~~
compilation terminated.
C:\FreeRTOS\FreeRTOSv202107.00\FreeRTOS\Source\portable\ARMv8M\non_secure\portable\GCC\ARM_CM23_NTZ\portasm.c:37:10: fatal error: portasm.h: No such file or directory

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

 #include "portasm.h"
          ^~~~~~~~~~~
compilation terminated.
C:\FreeRTOS\FreeRTOSv202107.00\FreeRTOS\Source\portable\ARMv8M\non_secure\port.c:35: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.
C:\FreeRTOS\FreeRTOSv202107.00\FreeRTOS\Source\portable\ARMv8M\non_secure\portable\GCC\ARM_CM33_NTZ\portasm.c:37:10: fatal error: portasm.h: No such file or directory

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

 #include "portasm.h"
          ^~~~~~~~~~~
compilation terminated.
*** [.pio\build\ FreeRTOS\lib679\portable\ARMv8M\non_secure\portable\GCC\ARM_CM23\portasm.c.o] Error 1
C:\FreeRTOS\FreeRTOSv202107.00\FreeRTOS\Source\portable\ARMv8M\non_secure\portable\GCC\ARM_CM33\portasm.c:37:10: fatal error: portasm.h: No such file or directory

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

 #include "portasm.h"
          ^~~~~~~~~~~
compilation terminated.
*** [.pio\build\ FreeRTOS\lib679\portable\ARMv8M\non_secure\portable\GCC\ARM_CM23_NTZ\portasm.c.o] Error 1
*** [.pio\build\ FreeRTOS\lib679\portable\ARMv8M\non_secure\port.c.o] Error 1
*** [.pio\build\ FreeRTOS\lib679\portable\ARMv8M\non_secure\portable\GCC\ARM_CM33_NTZ\portasm.c.o] Error 1
*** [.pio\build\ FreeRTOS\lib679\portable\ARMv8M\non_secure\portable\GCC\ARM_CM33\portasm.c.o] Error 1
============================================================================ [FAILED] Took 2.10 seconds ===========

looks like you are using a C compiler to compile C++ code. C compilers cannot recognize the forward declaration of “class Print”

Why are you building ARMv8M port files that too the ones even the v8M ports are not supposed to build? Read this link to learn about which FreeRTOS files you are supposed to use: Creating a new RTOS project

Thanks.

thank you for replies. It’s a C++ compiler - the Atmel AVR toolchain. I use it extensively in my many MCU applications which as you might expect are peppered with forward declarations. I have read a lot of the FreeRTOS documentation and watched some Renesas youtube vids about FreeRTOS concepts before I decided on the route I would take.
The choice I made (as recommended in the FreeRTOS manual) was to use the FreeRTOS demo code, and once I had that running, I would modify it to my specific needs. The demo I chose was
image

  • the AVR closest to the Mega2560 board I intended to use to check out FreeRTOS

It didn’t compile properly, so I also picked up headers from here

C:\FreeRTOS\FreeRTOSv202107.00\FreeRTOS\Source\portable\GCC\AVR_Mega0 which I thought would be relevant headers for the porthardware and portmacro. Was I wrong in that assumption?

I’m happy to start again if there’s some better way…

thanks
Paul

You should also compile the port files from this directory only. Can you share your makefile?

Thanks.

Thanks for your reply. I use the PlatformIO IDE which does not use a makefile.

I’ve re-read the help page for building the RTOS demo:
I tried to post the link here, but the system does not allow ‘new’ users to post links, so here’s a snip instead:
image

and it looks pretty straightforward, I can’t understand why the compiler flags errors if all the code and header files are present.

Perhaps I’ll review the makefile supplied in the FreeRTOS port demo folder and see what I can find from that. I’ve never used one though as my development has been done in atmel studio and latterly PlatformIO.
thanks for trying to help.
Paul

so from the makefile extract below, it looks like the following places contain the code for the port:

# 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
  • please could anyone who knows confirm if this is the case?
    If the necessary code resides in all the above places, they are not flagged in my IDE and that’ll be the problem.

Thanks
Paul

I have not used Platform IO and I do not know whether or not it uses makefiles. Any build system needs the following two things:

  1. The source files to compile.
  2. Directories to search for header files (aka include search paths).

The Makefile portion that you posted tells you both the above information. You need to pass this information to Platfrom IO in whatever way it requires.

Thanks.

thanks, PlatformIO doesn’t accommodate multiple source directories, so I’ll gather the .c files into a source directory and all the .h into an include directory.

Help from the PlatformIO community has also suggested this link (which I can’t post) which is to a Plaformio specific version of FreeRTOS:

I’ll give that a try and see if I can get it to compile for the Mega2560.

thanks
Paul

@paul - I have increased your privilege level - hopefully you will be able to paste a link now.

Thanks Richard. Someone on the Platformio commnity pages has just pointed out that the registers on the avr323 are different from the mega2560 and so by default the code will not compile.

Could I just go back to the very beginning and reframe my question?
What I want to do is this:
Try out a FreeRTOS demo

What I have at my disposal:
an IDE which uses GCC/G++ compilers
An arduino mega2560 and various other AVR bare chips such as 328P and 4809

Please could someone point me at a freertos demo for one of the above boards/ chips

Thanks.