RP2040 failing demo build, -Werror=unused-variable

Hello everyone,
After several years of using the Pico, i wanted to try out freeRTOS.

Unfortunately, im failing the demo build.

Cmake gives no error, however, compilation with make stops at 20% due to this error:


[ 17%] Building C object OnEitherCore/CMakeFiles/on_core_zero.dir/home/daniel/Downloads/FreeRTOSv202212.01/FreeRTOS/Demo/ThirdParty/Community-Supported-Demos/pico-sdk/lib/tinyusb/src/common/tusb_fifo.c.obj
[ 17%] Building C object OnEitherCore/CMakeFiles/on_core_zero.dir/home/daniel/Downloads/FreeRTOSv202212.01/FreeRTOS/Demo/ThirdParty/Community-Supported-Demos/pico-sdk/src/rp2_common/pico_fix/rp2040_usb_device_enumeration/rp2040_usb_device_enumeration.c.obj
[ 17%] Building C object OnEitherCore/CMakeFiles/on_core_zero.dir/home/daniel/Downloads/FreeRTOSv202212.01/FreeRTOS/Demo/ThirdParty/Community-Supported-Demos/pico-sdk/src/rp2_common/pico_multicore/multicore.c.obj
[ 18%] Linking CXX executable on_core_zero.elf
[ 18%] Built target on_core_zero
[ 19%] Building C object OnEitherCore/CMakeFiles/on_core_one.dir/main.c.obj
[ 19%] Building C object OnEitherCore/CMakeFiles/on_core_one.dir/home/daniel/Downloads/FreeRTOSv202212.01/FreeRTOS/Source/portable/ThirdParty/GCC/RP2040/port.c.obj
[ 19%] Building C object OnEitherCore/CMakeFiles/on_core_one.dir/home/daniel/Downloads/FreeRTOSv202212.01/FreeRTOS/Source/croutine.c.obj
[ 19%] Building C object OnEitherCore/CMakeFiles/on_core_one.dir/home/daniel/Downloads/FreeRTOSv202212.01/FreeRTOS/Source/event_groups.c.obj
[ 19%] Building C object OnEitherCore/CMakeFiles/on_core_one.dir/home/daniel/Downloads/FreeRTOSv202212.01/FreeRTOS/Source/list.c.obj
[ 20%] Building C object OnEitherCore/CMakeFiles/on_core_one.dir/home/daniel/Downloads/FreeRTOSv202212.01/FreeRTOS/Source/queue.c.obj
[ 20%] Building C object OnEitherCore/CMakeFiles/on_core_one.dir/home/daniel/Downloads/FreeRTOSv202212.01/FreeRTOS/Source/stream_buffer.c.obj
/home/daniel/Downloads/FreeRTOSv202212.01/FreeRTOS/Source/stream_buffer.c: In function 'prvInitialiseNewStreamBuffer':
/home/daniel/Downloads/FreeRTOSv202212.01/FreeRTOS/Source/stream_buffer.c:1375:26: error: unused variable 'xWriteValue' [-Werror=unused-variable]
 1375 |         const BaseType_t xWriteValue = 0x55;
      |                          ^~~~~~~~~~~
cc1: all warnings being treated as errors
make[2]: *** [OnEitherCore/CMakeFiles/on_core_one.dir/build.make:160: OnEitherCore/CMakeFiles/on_core_one.dir/home/daniel/Downloads/FreeRTOSv202212.01/FreeRTOS/Source/stream_buffer.c.obj] Error 1

No I have hunted around in every cmake file i can think of, and also tried to pass the
–compile-no-warnings-as-error flag to cmake to get around it.

Any one have a clue? Is it normal for the source to have unused variables or am i missing something? If normal, how do we get around the error?

EDIT: After setting release manually to “Debug” it compiles cleanly. Is this expected?

Any help is greatly appreciated!

Hello @ObligedTester,

If the following code triggers a -Werror=unused-variable

#if ( configASSERT_DEFINED == 1 )
{
    const BaseType_t xWriteValue = 0x55;
    configASSERT( memset( pucBuffer,
                  ( int ) xWriteValue,
                  xBufferSizeBytes ) == pucBuffer );
}
#endif

then it looks like configASSERT_DEFINED equals 1, and configASSERT() is not properly defined, meaning that xWriteValue is not passed to memset().

Can you please show how configASSERT() is defined in your project? You can normally find in FreeRTOSConfig.h

In the newer kernel sources, the above code has been rewritten to:

#if ( configASSERT_DEFINED == 1 )
{
    #define STREAM_BUFFER_BUFFER_WRITE_VALUE  ( 0x55 )
    configASSERT( memset( pucBuffer,
                  ( int ) STREAM_BUFFER_BUFFER_WRITE_VALUE,
                  xBufferSizeBytes ) == pucBuffer );
}
#endif

As you can see, mentioned warning won’t be triggered anymore.

Hello,

Thank you very much for your assistance.

Checking FreeRTOSConfig.h in both “Standard” & “Standard_smp” it is defined as following:

#define configASSERT(x)                         assert(x)

FreeRTOS is freshly downloaded from github plus the “CORTEX_M0+_RP2040” version, so both should be the latest version.

I was not able to find this mentioned in the demo-document though, is there old version of the documentation maybe?

@ObligedTester wrote:

FreeRTOS is freshly downloaded from github

Apparently it is not the latest version found here, because the latter doesn’t mention xWriteValue at all.

Sorry, I forgot to respond to :

#define configASSERT(x)                         assert(x)

In case you have defined NDEBUG before including assert.h, the assert() macro will do nothing.

I used the official download link that points to FreeRTOS202212.01 so im not really sure what i am missing here :smiley:

Now, if I force my cmake to use a “Debug” build, these errors goes away and it builds and uploads fine.

And you are referring to NDEBUG, which might be this flag maybe?

However, not sure what the best route is here? Because I of course want it to build cleanly without “hiding” anything, so to speak. And a debug build is probably a bit bigger also…

I’m sorry if I confuse anyone with this thread, :upside_down_face:. New to freeRTOS and having hard time to gather all the pieces.

However, I did everything from scratch. Downloaded the “Distribution”-version that includes “all the files” The latest one here is the 202212.01 version, it is directly linked from the website.

Inside of that, I put the RP2040 demo from the github in the thirdparty folder.
No issues here.

To build “cleanly” I need to set cmake to Debug release, otherwise it halts with the above error.

So main question now is. Since I want to be able to compile a non-debug version also of course. What needs to be done? Is there a step I’m missing?

Also are these warnings something to be expected and not harmful?

I’m using the RP2040 guide from freeRTOS website and it does not state any further info unfortunately. (Cannot link to it since I’m a new member of the forum)