The FreeRTOS was prepared by Adafruit for Nordic nRF52840: Adafruit_nRF52_Arduino/cores/nRF5/freertos at master · adafruit/Adafruit_nRF52_Arduino · GitHub
In the link you shared, the scheduler is started here - Adafruit_nRF52_Arduino/cores/nRF5/main.cpp at master · adafruit/Adafruit_nRF52_Arduino · GitHub. So you do not need to start it again.
The loop
function is called from a separate task created for this purpose only - Adafruit_nRF52_Arduino/cores/nRF5/main.cpp at master · adafruit/Adafruit_nRF52_Arduino · GitHub.
Thank you by your support.
I wrote in a Adafruit Forum asking if they can refresh the FreeRTOS version that they embedded in their distributions.
In this link, where did you find the scheduler being started?
In fact, I would like to work with the FreeRTOS downloaded from FreeRTOS.org and it would be installed in the VSCode/Platformio, but I don´t know if it is possible today. Do you know?
It seems like they are maintaining a separate port - Adafruit_nRF52_Arduino/cores/nRF5/freertos/portable at master · adafruit/Adafruit_nRF52_Arduino · GitHub. I guess it would be best to ask them to update. If you still wanna try out, you can try updating the FreeRTOS at this location - Adafruit_nRF52_Arduino/cores/nRF5/freertos/Source at master · adafruit/Adafruit_nRF52_Arduino · GitHub.
I already ask to Adafruit if they have plans to update the FreeRTOS version. I am asking about the update to have availble the Management Memory Scheme heap4.c to support dynamic memory allocation. Today the FreeRTOS version distributed by Adafruit, it has only one scheme, heap3.c, and I know that heap4.c seems to be much better, and maybe in the future, heap5.c
What do you think?
Claudio
You should be able to use heap_4.c by replacing heap_3.c file with heap_4.c. As far as the reason for only shipping heap_3.c is concerned, Adafruit can answer that.
I already tried to get heap_4.c from FreeRTOS download from FreeRTOS.org. I had to do a lot of adjustments because heap_4.c file has a lot of references that heap_3.c doesn´t have. I gave up to do the replacement after 3 days trying to find all references…
I really would like to test heap_4.c, but it can´t be too hard
Claudio
Can you describe the references that are missing?
Doing a comparinson between files, we can see that we have a lot of differences. Then I am sending attached the files:
heap.zip (7.2 KB)
I know the differences. Are those causing any problem?
Yes, the compile process stops by a lot of failures, I mean a lot of “misseds”
Can you share compiler output?
Sure:
As it is a large number of messages, I will cut what is fine:
This is with heap_4.c
Compile messages:
Processing wiscore_rak4631 (platform: nordicnrf52; board: wiscore_rak4631; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/nordicnrf52/wiscore_rak4631.html
PLATFORM: Nordic nRF52 (10.4.0) > WisCore RAK4631 Board
HARDWARE: NRF52840 64MHz, 243KB RAM, 796KB Flash
DEBUG: Current (jlink) External (jlink, stlink)
PACKAGES:
- framework-arduinoadafruitnrf52 @ 1.10600.0 (1.6.0)
- framework-cmsis @ 2.50700.210515 (5.7.0)
- tool-adafruit-nrfutil @ 1.503.0 (5.3)
- tool-sreccat @ 1.164.0 (1.64)
- toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 33 compatible libraries
Scanning dependencies...
Dependency Graph
|-- SparkFun LIS3DH Arduino Library @ 1.0.3
|-- Adafruit BME680 Library @ 2.0.4
|-- SparkFun u-blox GNSS Arduino Library @ 2.2.25
|-- SX126x-Arduino @ 2.0.24
|-- CayenneLPP @ 1.1.0
|-- Interfaces
|-- PackPayload
|-- RAK12500
|-- RAK15007
|-- RAK1904
|-- RAK1906
|-- RAK4631
|-- RAK5801
|-- Wire @ 1.0
Building in release mode
Error messages:
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\Source\croutine.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\Source\event_groups.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\Source\list.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\Source\portable\MemMang\heap_4.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\Source\queue.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\Source\stream_buffer.c.o
In file included from C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\portable\GCC\nrf52/portmacro.h:33:0,
from C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\Source\include/portable.h:52,
from C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\Source\portable\MemMang\heap_4.c:45:
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\portable\CMSIS\nrf52/portmacro_cmsis.h:181:1: error: unknown type name '__STATIC_INLINE'; did you mean '_ELIDABLE_INLINE'?
__STATIC_INLINE uint32_t ulPortRaiseBASEPRI( void )
^~~~~~~~~~~~~~~
_ELIDABLE_INLINE
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\portable\CMSIS\nrf52/portmacro_cmsis.h:181:26: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'ulPortRaiseBASEPRI'
__STATIC_INLINE uint32_t ulPortRaiseBASEPRI( void )
^~~~~~~~~~~~~~~~~~
In file included from C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\Source\portable\MemMang\heap_4.c:45:0:
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\Source\include/portable.h:102:65: error: unknown type name 'TaskFunction_t'
StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters ) PRIVILEGED_FUNCTION;
^~~~~~~~~~~~~~
In file included from C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\Source\include/FreeRTOS.h:56:0,
from C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\Source\portable\MemMang\heap_4.c:47:
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\config/FreeRTOSConfig.h:52:0: warning: "configUSE_PORT_OPTIMISED_TASK_SELECTION" redefined
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
In file included from C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\portable\GCC\nrf52/portmacro.h:33:0,
from C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\Source\include/portable.h:52,
from C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\Source\portable\MemMang\heap_4.c:45:
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\portable\CMSIS\nrf52/portmacro_cmsis.h:141:0: note: this is the location of the previous definition
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\Source\portable\MemMang\heap_4.c:489:25: error: unknown type name 'HeapStats_t'; did you mean 'TaskStatus_t'?
void vPortGetHeapStats( HeapStats_t * pxHeapStats )
^~~~~~~~~~~
TaskStatus_t
*** [.pio\build\wiscore_rak4631\FrameworkArduino\freertos\Source\portable\MemMang\heap_4.c.o] Error 1
====================================================== [FAILED] Took 53.01 seconds ======================================================
* The terminal process "C:\Users\Claudio Rosa\.platformio\penv\Scripts\platformio.exe 'run'" terminated with exit code: 1.
* Terminal will be reused by tasks, press any key to close it.
This is with heap_3.c:
Processing wiscore_rak4631 (platform: nordicnrf52; board: wiscore_rak4631; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/nordicnrf52/wiscore_rak4631.html
PLATFORM: Nordic nRF52 (10.4.0) > WisCore RAK4631 Board
HARDWARE: NRF52840 64MHz, 243KB RAM, 796KB Flash
DEBUG: Current (jlink) External (jlink, stlink)
PACKAGES:
- framework-arduinoadafruitnrf52 @ 1.10600.0 (1.6.0)
- framework-cmsis @ 2.50700.210515 (5.7.0)
- tool-adafruit-nrfutil @ 1.503.0 (5.3)
- tool-sreccat @ 1.164.0 (1.64)
- toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 33 compatible libraries
Scanning dependencies...
Dependency Graph
|-- SparkFun LIS3DH Arduino Library @ 1.0.3
|-- Adafruit BME680 Library @ 2.0.4
|-- SparkFun u-blox GNSS Arduino Library @ 2.2.25
|-- SX126x-Arduino @ 2.0.24
|-- CayenneLPP @ 1.1.0
|-- Interfaces
|-- PackPayload
|-- RAK12500
|-- RAK15007
|-- RAK1904
|-- RAK1906
|-- RAK4631
|-- RAK5801
|-- Wire @ 1.0
Building in release mode
The part related with FreeRTOS:
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\Source\croutine.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\Source\event_groups.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\Source\list.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\Source\portable\MemMang\heap_3.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\Source\queue.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\Source\stream_buffer.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\Source\tasks.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\Source\timers.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\portable\CMSIS\nrf52\port_cmsis.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\portable\CMSIS\nrf52\port_cmsis_systick.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\portable\GCC\nrf52\port.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\hooks.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\itoa.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\linker\gcc_startup_nrf52.S.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\linker\gcc_startup_nrf52840.S.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\main.cpp.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\new.cpp.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\nordic\nrfx\drivers\src\nrfx_gpiote.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\nordic\nrfx\drivers\src\nrfx_power.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\nordic\nrfx\drivers\src\nrfx_pwm.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\nordic\nrfx\drivers\src\nrfx_qspi.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\nordic\nrfx\drivers\src\nrfx_spim.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\nordic\nrfx\drivers\src\nrfx_spis.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\nordic\nrfx\drivers\src\nrfx_temp.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\nordic\nrfx\drivers\src\nrfx_timer.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\nordic\nrfx\mdk\system_nrf52.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\nordic\nrfx\mdk\system_nrf52840.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\pulse.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\pulse_asm.S.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\rtos.cpp.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\sysview\Config\SEGGER_SYSVIEW_Config_FreeRTOS.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\sysview\SEGGER\SEGGER_RTT.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\sysview\SEGGER\SEGGER_RTT_ASM_ARMv7M.S.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\sysview\SEGGER\SEGGER_RTT_printf.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\sysview\SEGGER\SEGGER_SYSVIEW.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\sysview\SEGGER_SYSVIEW_FreeRTOS.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\utility\AdaCallback.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\utility\SoftwareTimer.cpp.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\utility\adafruit_fifo.cpp.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\utility\debug.cpp.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\utility\utilities.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\wiring.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\wiring_analog.cpp.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\wiring_analog_nRF52.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\wiring_digital.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\wiring_private.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\wiring_shift.c.o
Archiving .pio\build\wiscore_rak4631\libFrameworkArduino.a
Linking .pio\build\wiscore_rak4631\firmware.elf
Checking size .pio\build\wiscore_rak4631\firmware.elf
Building .pio\build\wiscore_rak4631\firmware.hex
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [ ] 2.5% (used 6136 bytes from 248832 bytes)
Flash: [= ] 12.3% (used 100284 bytes from 815104 bytes)
Building .pio\build\wiscore_rak4631\firmware.zip
Zip created at .pio\build\wiscore_rak4631\firmware.zip
================================================= [SUCCESS] Took 78.27 seconds =================================================
* Terminal will be reused by tasks, press any key to close it.
I am not sure how can this be introduced by just replacing heap_3.c with heap_4.c.
For this one, you need to update other FrerRTOS files.
One other thing I noticed that the heap_3.c file is not exactly same as the official one but they have modified it.
The only thing that I changed it was the heap version, in other words heap_4.c instead of heap_3.c.
With heap_4.c compilation with errors and with heap_3.c compilations without errors.
You might try the version of heap_4.c from FreeRTOS version 10.0
No promises but at least it would be contemporary to the version of FreeRTOS in your project.
I already tried it. The problem is that I found a lot of difference between heap_3.c and heap_4.c. I invested near to one week only to try to replace by heap_4.c, but the compile process receive a lot of errors because heap_4.c has a lot of references missed when you just replace one by another.
Any ideas?
Cláudio
The current version of heap4.c is not compatible with the version of FreeRTOS in the nrf52 support project. But the OLD version of heap4.c looks like is might work. When I looked in the old code I did not see the symbols that were flagged in your earlier error posting.
That aside, heap3 should work for your testing so long as you don’t need to free memory. In general it is better to use static memory and to avoid deleting tasks in an embedded system. We recommend that you design your task architecture, start them up and let them run forever.
Good news!
Where I can get the OLD heap_4.c version?
In fact, I don´t need heap_4.c yet, but I would like to test how memory management will work to “defrag” memory, when I am using vTaskDelete. Today I have enough memory in the nRF52840. But in the future, maybe it could be a good possibility to have a continue memory area. Just to give a idea, a version of the code that I am using today, using vTaskDelete, I reduced from 22% to 6% of RAM utilization.
Claudio
The link in my previous post should go to the old version. I looked in the github history and found the v10.0 release tag. If you just go to releases you can download the freertos zip that corresponds to the v10.0 release. Here is a link
In C the only way to “defrag” the RAM is to release ALL of it and reallocate it. There is no way to crawl through all the operational pointers and move them around. If your application dynamically creates & frees “random” amounts of memory at “random” intervals then there can be memory free in a variety of small blocks. The largest contiguous block could be too small for your next malloc and cause allocation failures.
Good Luck.