Post Go back to editing

[ARM] Enabling newlib on FREERTOS

Category: Software
Software Version: FreeRTOS 10.4.6

Hi Team,


Context:

  • Using SC573 ezkit
  • Using FreeRTOS10.4.6 with CCES 2.10.1 ARM toolchain running on SC573 ARM core.
  • Using Clion rather than CCES IDE (pre-defined requirement)
  • Have migrated the FreeRTOS port provided in https://www.analog.com/en/design-center/evaluation-hardware-and-software/software/freertos.html#software-overview to Clion
    • FreeRTOS standard demo building and running successfully on SC573 ezkit
  • Using Cmake with ninja generator and ADI arm-none-eabi-gcc to build the bsp and application
  • Using ADI arm-none-eabi-gdb and OpenOCD for debugging (in Clion)
    • using the following cfg files for OpenOCD
      • source [find interface/ice1000.cfg]
      • source [find board/adspsc573_ezkit.cfg]
  • Using linker script provided by ADI for linker script
    • /opt/analog/cces/2.10.1/ARM/arm-none-eabi/arm-none-eabi/lib/ldscripts/adsp-sc573-l3.ld
    • let me know if I should be using adsp-sc573-l2.ld instead
  • Cmake flags
    • -g
    • -gdwarf-2
    • -mcpu=cortex-a5

Problem:

Trying to use newlib_reentrant with #define configUSE_NEWLIB_REENTRANT              1
Which works in CCES2.10.1 and compiles properly, but not working in CLion because for some reason the preprocessor header _ADI_THREADS is enabled by default in the ADI ARM compiler?

This can be seen in the file include/sys/lock.h, with configUSE_NEWLIB_REENTRANT defined as 1. CCES automatically recognises that _ADI_THREADS is not defined and imports <newlib>.

While in CLion, with the same freertosconfig.h, _ADI_THREADS is defined and thus doesn't import <newlib.h>

In a old sharc compiler documentation (VisualDSP++ 5.0 C/C++ Compiler Manual for SHARC Processors) it shows that by defining -threads switch in compiler option, it also defines _ADI_THREADS macro to 1 at compile time. Not sure if this was carried on to the CCES 2.10.1 compiler.

  • Rest of the compiler flags

    -mabi=aapcs
    -mfloat-abi=hard
    -MMD # same as above but only uses user header files
    -MP # Emits dummy dependency rules
    -MF # specifies file name for the makefile dependency rule (MMD)
    -msi-revision=any #silicon revision
    -mproc=ADSP-SC573
    -D__ADI_FREERTOS #enables the freeRTOS version of osal functions, which are used by BSP libraries
    -DADI_DEBUG
    -mdebug-libs
    -lm
    -D__ADSP215xx__
    -DCORE0
    -Wl,--gc-sections -madi-threads -mdebug-libs -lm
    --specs=${CMAKE_CURRENT_LIST_DIR}/third_party/bsp/SC573/FreeRTOS/portable/ARM_CA5/freertos.specs
    -fdata-sections # Generates one ELF section for each variable
    -ffunction-sections # Generates one ELF section for each function
  • Note also that using rand() in main.c doesn't crash.

  • Hi, 

    so there could a couple of things at play here.

    First up, don't rely on anything that is provided in the VDSP help when it comes to CrossCore Embedded Studio. They are entirely different beast under the hood. A lot of the functionality was re-engineered so the manual statements regarding threads are not likely correct.

    When compiling FreeRTOS projects I would strongly recommend using CCES and starting with the example projects that we provide. We are not resources to support customers using Clion (as nice as it is). Any issues you encounter would need to be reproduced under CCES in order for us to investigate them.

    With that being said, I do have advice that might help you.

    There were some changes made to the threadsafe libraries in CCES 2.9.x that resolved some issues with FreeRTOS. The result of this was that you cannot use the pre-build threadsafe libraries. Instead we recommended that customers used the relevant add-ins within CCES to include drivers in source form.

    Additional to this we added new CCES project options, LD changes and FreeRTOS example options to ensure that we did not link against the pre-built threadsafe libraries (since these target uC/OS not FreeRTOS, and are not compatible with FreeRTOS). The changes are documented in the FreeRTOS release note from ADI and I suggest reviewing that.

    In terms of compiler options, you should not need to pass arch etc to the compiler. If you use the -mproc switch this should take care of all the architectectural configuration required for building sources for a given processor.

    When building for FreeRTOS projects, you will also need to define the appropriate FreeRTOS pre-processor macros for all compile, assemble and link operations. The macros are also discussed in the ADI FreeRTOS release note.

    Again, I would strongly recommend that you stick with CCES. My instincts suggest that trying to get things working under another IDE will take a lot of time.

    Also, we have just announced a FreeRTOS Add-In for CCCES that is currently available as a beta.
    This will provide additional CCES features for creating and configuring FreeRTOS projects under CCES.
    As we move to using this add-in as our default method of delivering FreeRTOS it will likely mean that your current efforts no longer work.

    Regards,

    Dave