2019-01-17 06:08 AM
I call this function a very large amount of times through out my entire program however in just one spot I reliably get a Hard Fault when it's called.
When this line is executed, the fault occurs.
(*hi2c->pBuffPtr++) = hi2c->Instance->RXDR;
I called this function from other higher level functions which are also used a very high number of times in the program so memory allocation should not be a problem. Any one have can suggestions?
Thanks
George
2019-01-17 06:50 AM
Check the value of hi2c->pBuffPtr, is it in its supposed range? Most likely you have a buffer overflow problem.
2019-01-17 06:52 AM
The CM0 is highly sensitive to unaligned memory access, ie 16-bit wide to an ODD address.
Check the alignment of the pointer, and special case the unaligned cases.
2019-01-17 07:07 AM
hi2c->pBuffPtr is a pointer to uint8_t. Arent't 1-byte accesses always valid?
2019-01-17 08:43 AM
Perhaps, but the OP has already discounted using the wrong buffer/memory.
Sanity check the pointer involved, then we'd know.
2019-01-18 01:50 AM
Thank for the replies.
The pData parameter passed to HAL_I2C_Mem_Read has the value 0x20001d88 however the value of hi2c->pBuffPtr is 0x0. How can this be?
In the function the pointer is tested:
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}
And then assigned:
hi2c->pBuffPtr = pData;
Any pointers (no pun intended) would be great, thanks.