FreeRTOS - memory management best practices - Where could I find it?

Good afternoon,

I have a code working fine for RAKWireless sensors RAK1904, RAK1906, RAK5801 and RAK12500. Now I became to create a RTOS (FreeRTOS) version.

Now I am looking for some kind of “memory management Best Practice”. Why? Because I spent a good time to find the root cause about a strange behavior right after to create a task. Well, the problem it was the amount of memory that I was reserving, it wasn´t enough. I began with the minimum described in the FreeRTOSConfig.h (configMINIMAL_STACK_SIZE = 100), and I was increasing step-by-step and now the behavior is normal with 512 manually configured.

FreeRTOSConfig.h

#define configMAX_PRIORITIES                                     ( 5 )
#define configMINIMAL_STACK_SIZE                                 ( 100 )
#define configTOTAL_HEAP_SIZE                                    ( 4096 ) /* not used since we use malloc */
#define configMAX_TASK_NAME_LEN                                  ( 8 )

main.cpp

#include <main.h>
 
void setup()
{
	  xTaskCreate(IniciaRAK4631,"IniciaRAK4631",configMINIMAL_STACK_SIZE,NULL,1,&OperadorIniciaRAK4631);

	 IniciaRAK1906(); 	// Inicia RAK1906 BME680 sensor de variáveis ambientais

	 IniciaRAK12500(); 		// Inicia RAK12500 sensor de geo-posicionamento

	 IniciaRAK1904(); 		// Inidiq RAK1904 sensor de movimento
		
	 IniciaRAK5801(); 	// Inicial o sensor de variação de corrente 4-20Ma  WisBLOCK 5801
}

Now “xTaskCreate(IniciaRAK4631,“IniciaRAK4631”,512,NULL,1,&OperadorIniciaRAK4631);”

A quick question:

  1. The path for FreeRTOSConfig.h is C:\Users\Claudio Rosa.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\config\FreeRTOSConfig.h. Is the FreeRTOSConfig.h configured for capacity/performance for Nordic nRF52840 inside of RAK4631? If it is not optimized, does RAKWireless has a guide with these numbers?

I am looking a better way to do Memory Management to help in some questions:

  1. How to know the memory size required for a task?
  2. How to know how much free memory the nRF52840 has available to be allocated for a task?
  3. Where could I have a “guide” for the FreeRTOSConfig parameters?

Regards,

Cláudio

I can’t answer your first question as you have got the code from somebody else. I’m not familiar with it.

For your other three questions:

  1. The easiest way to know the memory required by a task is to experiment. Oversize the stack, let the code run for a while, making sure you go through the paths that require the most stack, then look at the task’s stack high water mark to see how much stack the task used. (sorry, the formatting on that linked page is all messed up).

  2. This is a generic question. You configure the total amount of memory available to the heap when you build the application. Most likely in a linker script. You said you are using malloc(), which is provided by you C library, so you would need a way of querying that to see how much memory is left. Are you using heap_3.c to wrap malloc() to make it thread safe? You can also consider using static memory allocation.

https://www.freertos.org/a00110.html
https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/examples/template_configuration/FreeRTOSConfig.h

1 Like

Thank you by the response.

In fact, the first question Thank you.

I asked for a friend of mine in AWS and he sent to me the followed link with the customization for Nordic nRF52840 in the AWS Github: FreeRTOSConfig.h for Nordic nRF52840

For other three questions:

  1. I was thinking to work with xPortGetHeapSize. What do you think?
  2. The memory allocation model available is heap_3.c, but I would like to try heap_4.c. What do you think?
  3. I am looking for a guide/best practice for Memory Allocation. Do you know any one?

Regards,

Cláudio

Are you looking for more examples on how to use different heap management scheme?
Here is a link to the FreeRTOS book, heap management section: FreeRTOS-Kernel-Book/ch03.md at main · FreeRTOS/FreeRTOS-Kernel-Book · GitHub

It has more information on different memory allocation schemes and also some utilities that you are looking for.

xPortGetHeapSize will provide you the unallocated memory in heap. Richard described the way to find the optimal stack size for a task. Those 2 are different things.

This page describes all of our heaps and their properties - FreeRTOS - Memory management options for the FreeRTOS small footprint, professional grade, real time kernel (scheduler).

Can you elaborate on why you mean by best practice for Memory Allocation? What kind of memory allocation are you talking about?

Hi aggarg,

Thank by your answers!

When I do a vTaskCreate, I would like to specify the right size of memory required. Today I don´t know how to calculate the memory size for each task. Then, I am using the vTaskList to see how much memory is being used for each task:

I am think that every time that I have a task that I will use just one time, it should be better, in the end of the task, I set a vTaskDelete to release the resources that I won´t need anymore. But this release process can create a memory fragmentation that it could be a problem using heap3.c (the default for Nordic nRF52840 from RAKWireless implementation). Then I would like to try to use heap4.c, but I don´t know where that I need to configure for heap4.c Scheme.

Could you help me with some suggestions?

Regards,

Cláudio

You need to compile heap_4.c instead of heap_3.c in your project and define configTOTAL_HEAP_SIZE in your FreeRTOSConfig.h.

You may want to reconsider the choice of deleting and re-creating tasks. If you describe the problem you are trying to solve, we may try to see if there is a better solution.

Maybe I didn´t understand your instructions, but I did and I am receiving error in the compiling process:

Here they are the error messages:

Executing task in folder RastAtivos: C:\Users\Claudio Rosa\.platformio\penv\Scripts\platformio.exe run 

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 32 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
|-- ArduinoJson @ 7.0.4
|-- CayenneLPP @ 1.1.0
|-- PackPayload
|-- RAK12500
|-- RAK15007
|-- RAK1904
|-- RAK1906
|-- RAK4631
|-- RAK5801
|-- Wire @ 1.0
Building in release mode
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\portable\MemMang\heap_4.c.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\pulse.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\rtos.cpp.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\sysview\Config\SEGGER_SYSVIEW_Config_FreeRTOS.c.o
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\portable\MemMang\heap_4.c:45:
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\config/FreeRTOSConfig.h:59:84: error: 'heap_4' undeclared here (not in a function)
 #define configTOTAL_HEAP_SIZE                                                     (heap_4.c) /* valor original ( 175000 ) */
                                                                                    ^
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\portable\MemMang\heap_4.c:92:44: note: in expansion of macro 'configTOTAL_HEAP_SIZE'
     PRIVILEGED_DATA static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
                                            ^~~~~~~~~~~~~~~~~~~~~
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\sysview\SEGGER_SYSVIEW_FreeRTOS.c.o
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\portable\MemMang\heap_4.c: In function 'pvPortMalloc':
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\portable\MemMang\heap_4.c:275:13: warning: implicit declaration of function 'vApplicationMallocFailedHook' [-Wimplicit-function-declaration]
             vApplicationMallocFailedHook();
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\portable\MemMang\heap_4.c: At top level:
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\portable\MemMang\heap_4.c:487:25: error: unknown type name 'HeapStats_t'; did you mean 'TaskStatus_t'?
 void vPortGetHeapStats( HeapStats_t * pxHeapStats )
                         ^~~~~~~~~~~
                         TaskStatus_t
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\portable\MemMang\heap_4.c:92:36: warning: 'ucHeap' defined but not used [-Wunused-variable]
     PRIVILEGED_DATA static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
                                    ^~~~~~
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\utility\AdaCallback.c.o
*** [.pio\build\wiscore_rak4631\FrameworkArduino\freertos\portable\MemMang\heap_4.c.o] Error 1

Well, I am not sure that a correct definition of ConfigTotal_HEAP_SIZE, in the FreeRTOSConfig file. Take a look in my screenshot and code in the end of this post

I saw that I had the heap3.c in the other directory: “C:\Users\Claudio Rosa.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\Source\portable\MemMang” , then I renamed the heap3.c as heap3.c.old and I added the heap4.c in this directory, and error messages were reduced, take a look:

The error messages:

Executing task in folder RastAtivos: C:\Users\Claudio Rosa\.platformio\penv\Scripts\platformio.exe run 

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 32 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
|-- ArduinoJson @ 7.0.4
|-- CayenneLPP @ 1.1.0
|-- PackPayload
|-- RAK12500
|-- RAK15007
|-- RAK1904
|-- RAK1906
|-- RAK4631
|-- RAK5801
|-- Wire @ 1.0
Building in release mode
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\Source\portable\MemMang\heap_4.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\portable\MemMang\heap_4.c.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_SYSVIEW_FreeRTOS.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\utility\AdaCallback.c.o
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\Source\portable\MemMang\heap_4.c:92:44: warning: character constant too long for its type
     PRIVILEGED_DATA static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
                                            ^~~~~~~~~~~~~~~~~~~~~
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\utility\SoftwareTimer.cpp.o
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\Source\portable\MemMang\heap_4.c: In function 'pvPortMalloc':
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\Source\portable\MemMang\heap_4.c:275:13: warning: implicit declaration of function 'vApplicationMallocFailedHook' [-Wimplicit-function-declaration]
             vApplicationMallocFailedHook();
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\Source\portable\MemMang\heap_4.c: In function 'prvHeapInit':       
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\Source\portable\MemMang\heap_4.c:384:29: warning: character constant too long for its type
     size_t xTotalHeapSize = configTOTAL_HEAP_SIZE;
                             ^~~~~~~~~~~~~~~~~~~~~
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\Source\portable\MemMang\heap_4.c: At top level:
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\Source\portable\MemMang\heap_4.c:487:25: error: unknown type name 'HeapStats_t'; did you mean 'TaskStatus_t'?
 void vPortGetHeapStats( HeapStats_t * pxHeapStats )
                         ^~~~~~~~~~~
                         TaskStatus_t
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\utility\adafruit_fifo.cpp.o
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\portable\MemMang\heap_4.c:92:44: warning: character constant too long for its type
     PRIVILEGED_DATA static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
                                            ^~~~~~~~~~~~~~~~~~~~~
*** [.pio\build\wiscore_rak4631\FrameworkArduino\freertos\Source\portable\MemMang\heap_4.c.o] Error 1
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\portable\MemMang\heap_4.c: In function 'pvPortMalloc':
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\portable\MemMang\heap_4.c:275:13: warning: implicit declaration of function 'vApplicationMallocFailedHook' [-Wimplicit-function-declaration]
             vApplicationMallocFailedHook();
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\portable\MemMang\heap_4.c: In function 'prvHeapInit':
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\portable\MemMang\heap_4.c:384:29: warning: character constant too long for its type
     size_t xTotalHeapSize = configTOTAL_HEAP_SIZE;
                             ^~~~~~~~~~~~~~~~~~~~~
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\portable\MemMang\heap_4.c: At top level:
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\portable\MemMang\heap_4.c:487: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\portable\MemMang\heap_4.c.o] Error 1

FreeRTOSConfig.h

#define configTICK_SOURCE                                                         FREERTOS_USE_RTC
#define configUSE_PREEMPTION                                                      1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION                                   0
#define configUSE_TICKLESS_IDLE                                                   0
#define configUSE_TICKLESS_IDLE_SIMPLE_DEBUG                                      1 /* See into vPortSuppressTicksAndSleep source code for explanation */
#define configCPU_CLOCK_HZ                                                        ( SystemCoreClock )
#define configTICK_RATE_HZ                                                        100
#define configMAX_PRIORITIES                                                      ( 15 )
#define configMINIMAL_STACK_SIZE                                                  ( 600 )
#define configTOTAL_HEAP_SIZE                                                     'heap_4.c' /* valor original ( 175000 ) */
#define configMAX_TASK_NAME_LEN                                                   ( 15 )
#define configUSE_16_BIT_TICKS                                                    0
#define configIDLE_SHOULD_YIELD                                                   1
#define configUSE_MUTEXES                                                         1
#define configUSE_RECURSIVE_MUTEXES                                               1
#define configUSE_COUNTING_SEMAPHORES                                             1
#define configUSE_ALTERNATIVE_API                                                 0    /* Deprecated! */
#define configQUEUE_REGISTRY_SIZE                                                 2
#define configUSE_QUEUE_SETS                                                      0
#define configUSE_TIME_SLICING                                                    0
#define configUSE_NEWLIB_REENTRANT                                                0
#define configENABLE_BACKWARD_COMPATIBILITY                                       1

// Erro na compila��o #define configUSE_DAEMON_TASK_STARTUP_HOOK                       1
#define configSUPPORT_STATIC_ALLOCATION                          0
#define configUSE_APPLICATION_TASK_TAG                                            1
#define configUSE_POSIX_ERRNO                                                     1

#define configSUPPORT_DYNAMIC_ALLOCATION                         1

/* Hook function related definitions. */
#define configUSE_IDLE_HOOK                                      1
#define configUSE_TICK_HOOK                                      0
#define configCHECK_FOR_STACK_OVERFLOW                           1
#define configUSE_MALLOC_FAILED_HOOK                             1

You have to define the heap size as a number e.g.
#define configTOTAL_HEAP_SIZE 65536
and add the appropriate (one of) heap_1/2/3/4/5.c file to your source file list to compile and link.

Thank you by your reply, but in fact, I am trying to work with dynamic allocation, instead of static. For this purpose, I am trying to config FreeRTOS to work with heap4.c, but I don´t know how :slight_smile:

Could you help me?

Claudio

Yes, the heap is for dynamic allocation.
So you simply have to add heap_4.c to your build and define a suitable heap size (used by the heap_4.c implementation) in FreeRTOSConfig.h as mentioned as number and NOT the source file name as you did.
That’s wrong:
#define configTOTAL_HEAP_SIZE 'heap_4.c'
That’s right (as example):
#define configTOTAL_HEAP_SIZE 65536

Thank you by your suport.

I know what is the memory management scheme heap4.c, but I didnt find a document How to implement It.

Claudio

Seems you did it already mostly right. The desired heap_4.c is included in your build:

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\portable\MemMang\heap_4.c:45:

You only have to define the desired heap size correctly (again: a number) in your FreeRTOSConfig.h. That should be easy to fix.
The size mainly depends on your needs and of course the available free RAM. But the linker will tell you if it the heap doesn’t fit :slight_smile:

Well, the heap4.c configuration it is fine now. The FreeRTOSConfig.h come from a AWS FreeRTOS configuration for the Nordic nRF52840-SDK:

/*
 * FreeRTOS Kernel V10.0.0
 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software. If you wish to use our Amazon
 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * http://www.FreeRTOS.org
 * http://aws.amazon.com/freertos
 *
 * 1 tab == 4 spaces!
 */


#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

#ifdef SOFTDEVICE_PRESENT
#include "nrf_soc.h"
#endif

// This port of nrf52 use RTC for freeRTOS tick

/*-----------------------------------------------------------
 * Application specific definitions.
 *
 * These definitions should be adjusted for your particular hardware and
 * application requirements.
 *
 * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
 * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
 *
 * See http://www.freertos.org/a00110.html.
 *----------------------------------------------------------*/
#define configTICK_SOURCE                                                         FREERTOS_USE_RTC
#define configUSE_PREEMPTION                                                      1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION                                   0
#define configUSE_TICKLESS_IDLE                                                   0
#define configUSE_TICKLESS_IDLE_SIMPLE_DEBUG                                      1 /* See into vPortSuppressTicksAndSleep source code for explanation */
#define configCPU_CLOCK_HZ                                                        ( SystemCoreClock )
#define configTICK_RATE_HZ                                                        100
#define configMAX_PRIORITIES                                                      ( 15 )
#define configMINIMAL_STACK_SIZE                                                  ( 600 )
#define configTOTAL_HEAP_SIZE                                                     ( 175000 )
#define configMAX_TASK_NAME_LEN                                                   ( 15 )
#define configUSE_16_BIT_TICKS                                                    0
#define configIDLE_SHOULD_YIELD                                                   1
#define configUSE_MUTEXES                                                         1
#define configUSE_RECURSIVE_MUTEXES                                               1
#define configUSE_COUNTING_SEMAPHORES                                             1
#define configUSE_ALTERNATIVE_API                                                 0    /* Deprecated! */
#define configQUEUE_REGISTRY_SIZE                                                 2
#define configUSE_QUEUE_SETS                                                      0
#define configUSE_TIME_SLICING                                                    0
#define configUSE_NEWLIB_REENTRANT                                                0
#define configENABLE_BACKWARD_COMPATIBILITY                                       1

// Erro na compila��o #define configUSE_DAEMON_TASK_STARTUP_HOOK                       1
#define configSUPPORT_STATIC_ALLOCATION                          0
#define configUSE_APPLICATION_TASK_TAG                                            1
#define configUSE_POSIX_ERRNO                                                     1

#define configSUPPORT_DYNAMIC_ALLOCATION                         1

/* Hook function related definitions. */
#define configUSE_IDLE_HOOK                                      1
#define configUSE_TICK_HOOK                                      0
#define configCHECK_FOR_STACK_OVERFLOW                           1
#define configUSE_MALLOC_FAILED_HOOK                             1

But I am still have some problems:

Compiling .pio\build\wiscore_rak4631\lib920\RAK5801\RAK5801.cpp.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\HardwarePWM.cpp.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\IPAddress.cpp.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\Print.cpp.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\Stream.cpp.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\Tone.cpp.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\Uart.cpp.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\WInterrupts.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\delay.c.o
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
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\Source\portable\MemMang\heap_4.c: In function 'pvPortMalloc':
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\Source\portable\MemMang\heap_4.c:275:13: warning: implicit declaration of function 'vApplicationMallocFailedHook' [-Wimplicit-function-declaration]
             vApplicationMallocFailedHook();
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\Source\portable\MemMang\heap_4.c: At top level:
C:\Users\Claudio Rosa\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\freertos\Source\portable\MemMang\heap_4.c:487:25: error: unknown type name 'HeapStats_t'; did you mean 'TaskStatus_t'?
 void vPortGetHeapStats( HeapStats_t * pxHeapStats )
                         ^~~~~~~~~~~
                         TaskStatus_t
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\Source\tasks.c.o
Compiling .pio\build\wiscore_rak4631\FrameworkArduino\freertos\Source\timers.c.o
*** [.pio\build\wiscore_rak4631\FrameworkArduino\freertos\Source\portable\MemMang\heap_4.c.o] Error 1
============================================================ [FAILED] Took 38.44 seconds ============================================================

If you
#define configUSE_MALLOC_FAILED_HOOK 1
you or your Nordic SDK have to provide a vApplicationMallocFailedHook implementation as documented e.g. here FreeRTOS - RTOS hook (callback) functions for task stack overflows, tick interrupts, idle task, daemon task startup, and malloc failure (pvPortMalloc() returning NULL).
You could either #define configUSE_MALLOC_FAILED_HOOK 0 or implement it.
Also HeapStats_t is defined in FreeRTOS include/portable.h.
I wonder why this seems missing in your (custom/Nordic ?) FreeRTOS include/portable.h ?

This is a good question, but just to remember that I am using the FreeRTOS that it comes inside of Platformio Arduino Framework, if I am not wrong, it is a FreeRTOS Vanilla Version.

When I fixed the portable.h missed, other item missed in the heap4.c, it was found. Well, It can work, but probably I will have problems soon, because it isn´t a official version.

I opened a new post where I am asking how to install the FreeRTOS in the VSCode/Platformio, instead to work with the version inside of Arduino Framework. Is it possible? I didn´t find a documentation about it.

Could you help me?

Claudio

Unfortunately I can’t help. I’m not using any SDK. Sorry !
You might compare the FreeRTOS source tree of your SDK with the real vanilla FreeRTOS sources with the matching version from GitHub when in doubt. Or maybe better ask Nordic / in their forum how to configure/use one of the FreeRTOS memory managers.
I guess this is support somehow because it’s common, pretty basic configuration/setup.
Good luck !