I am using an STM32F103C8T6, STM32CubeIDE with HAL.
During accessing an LCD (1602), with I2C, I get a hard fault.
I try to debug it, but somehow I don't see the stack. See the following screenshot:
The breakpoint happens inside the stm32f1xx_hal_i2c, in this code (==> is break point):
static HAL_StatusTypeDef I2C_WaitOnFlagUntilTimeout(I2C_HandleTypeDef *hi2c, uint32_t Flag, FlagStatus Status, uint32_t Timeout, uint32_t Tickstart)
{
/* Wait until flag is set */
==> while (__HAL_I2C_GET_FLAG(hi2c, Flag) == Status)
{
/* Check for the Timeout */
if (Timeout != HAL_MAX_DELAY)
{
if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
{
hi2c->PreviousState = I2C_STATE_NONE;
hi2c->State = HAL_I2C_STATE_READY;
hi2c->Mode = HAL_I2C_MODE_NONE;
hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
/* Process Unlocked */
__HAL_UNLOCK(hi2c);
==> return HAL_ERROR;
}
}
}
return HAL_OK;
}
This function is called from within many functions inside the same file.
The hard fault occurs after return HAL_ERROR
in the same function, than the next function in the 'while' loop, and when I jump INTO the while
(so calling __HAL_I2C_GET_FLAG
). During the call to that last function, the following stack is shown:
How can I debug what's happening exactly in between the call and the hard fault? Or even better, does anybody have a reason how such hard fault can happen in an STM library inside HAL?