2020-10-14 04:16 AM
Target: STM32G473RBTX
IDE: STM32CubeIDE v1.4.2
bool read(STRUCT *devInfo)
{
uint8_t readbuf[len];
STRUCT *tmp = (STRUCT *)calloc(1, sizeof( STRUCT ));
if(EEPRomReadNByte(addr, len, readbuf))
{
tmp = (STRUCT *)&readbuf; //implicit convert
memcpy(devInfo, tmp, sizeof( STRUCT ));//make sure
}
free(tmp); //<- HardFault_Handler occurred
}
1.why happened to call free memory will occur Hard fault interrupt?
2.implicit convert some time is work or not, why?
2020-10-14 04:42 AM
You are trying to free memory that isn't part of the heap.
And the chaining structure contains random junk, which is undefined and unpredictable.