HAL_TIMEOUT while trying to combine several STM32L4R9 HAL examples into one project.
I'm building up an app on the STM32L4R9-Discovery board that needs a lot of IO: UARTs, USARTs, I2C, SPI,RTC, FatFS on the SD Card and others. I'm pretty new to the STMCubeIDE and C/C++ world so I've build up several test apps that start for the Discovery board based on examples from the HAL library. Now I'm trying to combine my SD card example with my RTC example. They work find separately but when I try to put them together I get a HAL_Timeout error in the RTC_EnterInitMode method in the STM32L4xx_hal_rtc.c file. This happens with the STMCubeIDE and in VisualGDB.
HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef *hrtc)
{
uint32_t tickstart;
HAL_StatusTypeDef status = HAL_OK;
/* Check if the Initialization mode is set */
#if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
if ((hrtc->Instance->ICSR & RTC_ICSR_INITF) == 0U)
{
/* Set the Initialization mode */
SET_BIT(hrtc->Instance->ICSR, RTC_ICSR_INIT);
tickstart = HAL_GetTick();
/* Wait till RTC is in INIT state and if Time out is reached exit */
while ((READ_BIT(hrtc->Instance->ICSR, RTC_ICSR_INITF) == 0U) && (status != HAL_TIMEOUT))
{
if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
{
status = HAL_TIMEOUT;
hrtc->State = HAL_RTC_STATE_TIMEOUT;
}
}
}
#else /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
if ((hrtc->Instance->ISR & RTC_ISR_INITF) == 0U)
{
/* Set the Initialization mode */
hrtc->Instance->ISR = (uint32_t)RTC_INIT_MASK;
tickstart = HAL_GetTick();
/* Wait till RTC is in INIT state and if Time out is reached exit */
while ((READ_BIT(hrtc->Instance->ISR, RTC_ISR_INITF) == 0U) && (status != HAL_TIMEOUT))
{
if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
{
status = HAL_TIMEOUT;
hrtc->State = HAL_RTC_STATE_TIMEOUT;
}
}
}
#endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
status = HAL_OK; //Temporary fix by Gene Massin 2020Apr25
return status;
}As a test, I just put a status = HAL_OK before the return status at the end of this method and the rest of my little project runs fine. Obviously, this isn't the right way to fix the problem but I can figure out what the difference is between my individual projects and the combined project. Suggestions will be greatly appreciated. Thanks - Gene
BTW - I started the whole project by defining IO functionality (and pins) using the CubeMX functionality in CubeIDE with no obvious conflicts.
