Compile error on Arduino with configUSE_MALLOC_FAILED_HOOK=0

roxy3d wrote on Thursday, April 26, 2018:

Hello! I’m trying to slip FreeRTOS under Marlin (the 3D Printing firmware) and have run into a problem. I want to keep trying to xCreateTask() with decreasing amounts of stack memory until the task starts successfully. In order to do that, I need configUSE_MALLOC_FAILED_HOOK=0 (or else the malloc() routines will lock up with the board’s LED blinking).

I can’t do that because vTaskStartScheduler() makes a call to vApplicationMallocFailedHook();

Can we make a small change in the release version of FreeRTOS as described below? It is easy enough to make the change, but the distribution of the needed change is difficult. Marlin uses the GNU license and it would be messy for use to distribute a modified version of FreeRTOS.

void initVariant(void)
#if defined(USBCON)

	setup();		// the normal Arduino setup() function is run here.

	vTaskStartScheduler(); // initialise and run the freeRTOS scheduler. Execution should never return here.

#if ( configUSE_MALLOC_FAILED_HOOK == 1 )
	vApplicationMallocFailedHook(); // Probably we've failed trying to initialise heap for the scheduler. Let someone know.
HANG: goto HANG;

rtel wrote on Friday, April 27, 2018:

You can implement vApplicationMallocFailedHook() to do whatever you
want. It sounds like you have default debug configuration that is just
halting execution if it is called, but normally in production code an
allocation failure would be handled gracefully (as you are trying to do)
rather than be considered a fatal error.

The call to vApplicationMallocFailedHook() after vTaskStartScheduler()
appears to be obsolete as if the scheduler can’t start, then it failed
to create the stack for either the idle or timer task, in which case
vApplicationMallocFailedHook() will already have been called.

roxy3d wrote on Friday, April 27, 2018:

May I request we delete the obsolete call to vApplicationMallocFailedHook() after vTaskStartScheduler() for the next release? I’m hoping I can get everything working with no code changes to the FreeRTOS library for Arduino! :slight_smile:

rtel wrote on Friday, April 27, 2018:

That main file is not something we provided :o) Please submit this
request to whomever supplied it.