Heap 4C in extended memory; use bug

I’m using an F469I Disco board. F469 processor, 128 Mb external SDRAM.
It’s properly mapped, setup, functions, and has regions defined in the linker for LTDC, XXHEAP (memory manager related to the graphics tree), and FreeRTOS.

The FreeRTOS is where the problem is:
It can be mapped, Heap4.c (since I only want the FreeRTOS heap in this extended 32 bit memory) deals with it, everything gets placed where it needs to be.
However:
in CubeMXIDE, there is no way to select the configAPPLICATION_ALLOCATED_HEAP as an option in CubeMX. This is a topic that ST is going to have to address.
However, if I go into FreeRTOS.h, I can find the set point for the variable and change it to a 1. This of course is reset each time CubeMX regenerates code. Again, an ST fix.

Now for heap4c, which ST does not control:

The relevant section of code that I have to change is followed by the original code which is commented out:

/* Allocate the memory for the heap. */
 #if( configAPPLICATION_ALLOCATED_HEAP == 1 )
	 /* The application writer has already defined the array used for the RTOS heap - probably so it can be placed in a special segment or address. */
	extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
	 uint8_t ucHeap[ configTOTAL_HEAP_SIZE ] __attribute__ ((section (".freertos_data")));
 #else
	 static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
 #endif /* configAPPLICATION_ALLOCATED_HEAP */

//#if( configAPPLICATION_ALLOCATED_HEAP == 1 )
//	/* The application writer has already defined the array used for the RTOS
//	heap - probably so it can be placed in a special segment or address. */
//	extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
//#else
//	static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
//#endif /* configAPPLICATION_ALLOCATED_HEAP */
//

The problem I have (and so will anyone) is that this section of code is not placed in the “user code” area. So every time I regenerate code, it needs to be fixed.

If you could place this in the user code (or just link to a user section (i.e. add as standard)

#if( configAPPLICATION_ALLOCATED_HEAP == 1 )
// user code n
// user adds code
// end user code n
#endif

That, or add as a _weak_ variable the option of calling the config routine in a location where it won't be changed.

It would be appreciated.  This is a valid setup when using heap4c, since it allows using the entire processor RAM while placing the FreeRTOS heap in extended memory.

I may have missed a detail, but couldn’t this statement be placed somewhere in code that you control? In one of your own code files?

From the name, it is supposed to be defined inFreeRTOSconfig.h, which is a application file and should not get overwritten.

FreeRTOS.h will have a definition bracketed by an ifndef

I tried that, and the code choice in the config file does not seem to be reflected in FreeRTOS.h. Changing FreeRTOS.h was a workaround.

I can check to see if the change is really there, but it doesn’t seem to be. Not a scalability issue, since scalability problems remove the highlighting around the #ifdef/#endif, and this has highlighting as if the option weren’t set.

Odd.

As I read the code, the part of heap4c would overwrite the definition that I’d add in my code (elsewhere), or conflict with it, since the ucHeap apparently needs to be defined in heap4c. Note that their code is an either/or definition depending on whether or not the memory definition is user supplied or not. Since I don’t see a weak attribute, I don’t think the compiler would override that definition with my own.

Have I missed something?

How would you suggest this change be made?

I would probably define configAPPLICATION_ALLOCATED_HEAP to 1 in a user-controlled section of FreeRTOSConfig.h. Then I would declare the heap in a user-controlled section of main.c. No need to modify heap4.c because it has an extern definition which will effectively go find your definition in main.c at link time.

Heap4 TESTS if this is set to one and then either creates the heap there or makes an external reference to a heap defined elsewhere.

If it isn’t seeing the definition in your FreeRTOSconfig.h, you may need to see if you have two of them. Put an obvious error and see if that gets caught, or check where you IDE thinks the file is.

OK, just checked, and that part is working. Changes made in FreeRTOSconfig.h are properly reflected in heap4c. No idea what was going on, so that part is sorted. However, I still have the problem of heap4c being changed.

I had the user configuration flag also set in main.h in a user section. No, it didn’t appear to be working, and now it is.

On the other hand, I still have a problem with keeping the heap4c code intact with the instruction to create the variable in user space.

and now, I’ve got that working. I looked at the initial definition (which was local) and copied that (local) as you can see by the code I attached. Should have been left alone and the definition of the memory region in main.c in a user section.

I was looking for a complex solution and missed the simple one.

Thanks, it all works properly.

I still have a problem with ST not giving the option to set the flag, but that’s their problem and I can always define the flag in the user section of FreeRTOSconfig.h

PS: can only give one solution and both posts were needed. Thanks again.