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

Please include the following information, in order for us to help you as effectively as possible.

  • What product do you wish to discuss? RAK4631

  • What firmware are you using? VSCode/Platformio

  • What firmware version? it is Arduino BSP

  • Computer OS? (MacOS, Linux, Windows) Windows

  • What Computer OS version? Windows 11

  • How often does the problem happen? it is not a problem, it is a memory management best practice

  • How can we replicate the problem? it is not a problem, it is a memory management best practice

  • Provide source code if custom firmware is used or link to example if RAKwireless example code is used.

I have a code working fine for 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

Hello Claudio,

Quick answer for both questions.
With the Arduino BSP, the FreeRTOS is not touched by us, we did not do any changes to it.

There are some functions in FreeRTOS to get available memory size, I used some of them in the past with an ESP32, but forgot their syntax.
We do not have any guides for FreeRTOSConfig. With the Arduino BSP I think it is better not to touch it. In your case, you might be able to changes things there, but I can’t help with that.

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: FreeRTOSConfig.h for Nordic nRF52840

Have a good day.

Claudio

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.