Porting to a Nucleo F446ZE board. App: Ping Pong. Transport: serial uart3
alsaibie opened this issue · 6 comments
Setup
Board: Nucleo 446ZE
RTOS: FreeRTOS
App: Ping Pong
Flash Utility: ST-Flash
Debug Utility: OpenOCD
Freertos_apps fork branch
Micro_ros_setup config branch
Porting Stage
- builds
- flashes
- connects and is registered via the linux host microros agent.
- register ros topic
- ping pong
Issue
A call to allocator->deallocate in node.c line 412, during ping_pong app node initialization results in a HardFault.
allocator->deallocate(node_secure_root, allocator->state);
The following is a snapshot of the callstack & local variables at the above call
previous calls to allocator->deallocate
during node init are executed fine.
Any idea where/what to look for?
Could you check what is the behavior when deallocating an already deallocated memory? I'm not sure right now. Anyways it shouldnt be deallocating an non-allocated (or already deallocated) memory chunk... Let me check meanwhile
node_secure_root is null. The call to deallocate(node_secure_root =0,0) fails, specifically at the later call to pxLink->xBlockSize
in custom_memory_manager.c
size_t getBlockSize( void *pv ) {
uint8_t *puc = ( uint8_t * ) pv;
BlockLink_t *pxLink;
puc -= xHeapStructSize;
pxLink = ( void * ) puc;
size_t count = pxLink->xBlockSize & ~xBlockAllocatedBit; <---------
return count;
}
Well we have to avoid this deallocation. You can fix it by checking the null pointer here: https://github.com/alsaibie/freertos_apps/blob/24c342029110fc2f96ff6e78883ea01e60122117/microros_nucleo_f446ze_extensions/Src/allocators.c#L14
But for sure I'm going to check what is happening in the RCL with this node_secure_root
.
Thanks. Indeed, checking for NULL on node_secure_root in rcl node.c
or during call to deallocate works. The app moves forward and I get the ping and pong topics on the agent, but no messages sent or echoed. I get another HardFault during call to pxLink->xBlockSize
at reallocate call shown by the following callstack, the xBlockSize is again equal to 0. Bypassing this reallocation call doesn't initialize the wait_set
I notice the puc ptr underflows after puc -= xHeapStructSize;
as well, doesn't seem right. I'm still trying to wrap my head around the memory manager.
Update:
When reallocating and the ptr = 0, I added a condition to allocate instead:
void * __freertos_reallocate(void * pointer, size_t size, void * state){
(void) state;
// printf("-- Realloc %d -> %d (prev: %d B)\n",getBlockSize(pointer),size, xPortGetFreeHeapSize());
if (NULL != pointer){
absoluteUsedMemory += size;
usedMemory += size;
usedMemory -= getBlockSize(pointer);
return pvPortRealloc(pointer,size);
}
else {
absoluteUsedMemory += size;
usedMemory += size;
return pvPortMalloc(size);
}
}
And that did the trick and I finally pinged and ponged successfully. Not sure if this is the proper fix though. I'm good on my end so far.
Ok, so I will check this all in the RCL. Could you PR these memory management changes to our repo? Also, when you have a final version of the port to your board, could you PR the build system and freeRTOS apps changes to our repos? That would be awesome to increase our board support.
Thanks!