2022-04-09 12:43 AM
Hi
Project built with TouchGFX not initializing heap properly:
When attempting to allocate a variable to the heap the variable is allocated at 0x00000000 instead of the heap location. This doesn't happen with projects built using cube. Does anyone have any ideas.
The screen shots are attached as my browser kept crashing when I tried to embed the images.
Project Built with CubeMX
Project built with touchGF, but with all TouchGFX code commented out and the MPU initialisation commented out as well:
I have asked this question on the support page.
The two projects are attached.
Best regards
Rob
Solved! Go to Solution.
2022-04-09 06:08 PM
Perhaps have a look at _sbrk()
MallocTestTinyShark_To_STM\MallocTestTinyShark\mallocTest\STM32CubeIDE\Application\User\Core\sysmem.c
2022-04-09 03:41 AM
Too large?
2022-04-09 05:41 PM
Hi TDL
I have cleared out all of the TouchGFX bloat from the zip file so it is now only 6 Mb. I have also attached screen shots of debug sessions with both projects. God I hate graphics!
I tried to embed the screen shots in the post but Firefox kept crashing so I have just attached them.
The problem I have is that I don't know how where malloc gets the base address of the heap from. It would appear that this variable wherever/whatever it is gets zero'd out in the TochGFX build; although as I said, commenting out all of the TouchGFX intitialization and the GUI task doesn't fix the problem so it must be in the linker script or startup or something related.
I don't really need to use dynamic memeory as I have plenty available in this project, but i have a number of utilities that use dynanic ram and I don't want to rewrite them to make them static as I will have to test them all again.
Best regards
Rob
2022-04-09 06:08 PM
Perhaps have a look at _sbrk()
MallocTestTinyShark_To_STM\MallocTestTinyShark\mallocTest\STM32CubeIDE\Application\User\Core\sysmem.c
2022-04-09 06:42 PM
Hi TDL
You've got it baby! The sysmem file for TouchGFX is the problem:
sysmem for cubemx generated version:
void *_sbrk(ptrdiff_t incr)
{
extern uint8_t _end; /* Symbol defined in the linker script */
extern uint8_t _estack; /* Symbol defined in the linker script */
extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */
const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size;
const uint8_t *max_heap = (uint8_t *)stack_limit;
uint8_t *prev_heap_end;
/* Initialize heap end at first call */
if (NULL == __sbrk_heap_end)
{
__sbrk_heap_end = &_end;
}
/* Protect heap from growing into the reserved MSP stack */
if (__sbrk_heap_end + incr > max_heap)
{
errno = ENOMEM;
return (void *)-1;
}
prev_heap_end = __sbrk_heap_end;
__sbrk_heap_end += incr;
return (void *)prev_heap_end;
}
TouchGFX sysmem:
caddr_t _sbrk(int incr)
{
extern char end asm("end");
static char *heap_end;
char *prev_heap_end;
if (heap_end == 0)
heap_end = &end;
prev_heap_end = heap_end;
if (heap_end + incr > stack_ptr)
{
errno = ENOMEM;
return (caddr_t) -1;
}
heap_end += incr;
return (caddr_t) prev_heap_end;
}
I copied the cubemx version over to the TouchGFX project and et voila.
I will now go about testing in the full project with GFX enabled.
Here's hoping!
Best regards
Rob
2022-04-09 06:57 PM
Update:
Put revised CubeMX sysmem.c into main project with TouchGFX operational. It appears to have fixed the issue and not caused problems with touchGFX as expected.
Looks like the Touch GFX auto gen template is missing an "*"
Thanks for you help
Rob.