2020-11-03 8:51 PM
I’m very much still learning the STM32 and all my work so far starts with examples. I can get the ST provided RTC example STM32F413ZH-Nucleo -> Examples -> RTC -> RTC_Calendar running and it seems to work fine. But when I put the code from that example into a larger app that started from the STM32F413ZH-Nucleo->Examples->UART->UART_TwoBoards_ComDMA, it doesn’t. I've single stepped through HAL_Init() and SystemClock_Config and they appear to do exactly the same think in both the working RTC example and my larger app but the larger app gets stuck in /* initialization error */ at line 29 below.
int main(void)
{
StateBase *stateArray[numStates];
stateArray[recovery] = new Recovery("Recovery State", -1);
stateArray[findNeutral] = new FindNeutral("Find Neutral State", 10 * 60 * 1000);
stateArray[descend] = new Descend("Descend State", 2 * 3600 * 1000);
bool runMission = true;
bool doStateEntry = true;
StateNames currentState = recovery;
StateNames nextState;
cout << " HAL_Init()" << endl;
HAL_Init();
SystemClock_Config();
RtcHandle.Instance = RTC;
RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
RtcHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
RtcHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
__HAL_RTC_RESET_HANDLE_STATE(&RtcHandle);
if (HAL_RTC_Init(&RtcHandle) != HAL_OK)
{
/* Initialization Error */
cout << "RTC_Init Error_Handler();" << endl;
}
RTC_CalendarConfig();
RTC_CalendarShow(aShowTime, aShowDate);
cout << "time: " << aShowTime << endl;
cout << "date: " << aShowDate << endl;
... more code
HAL_RTC_Init call a bunch of stuff and I think I’ve tracked it down to the RTC_EnterInitMode subroutine in stm32F4xx_hal_rtc.c. It looks like HAL_GetTick isn’t incrementing the tickstart value below even though the HALl-GetTick() method is the same in the working example and my non-working app.
tickstart = HAL_GetTick();
/* Wait till RTC is in INIT state and if Time out is reached exit */
while((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
{
if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}
I’ve been trying to figure out what the STM32 HAL RTC example might be doing to make HAL_GetTick work that I’m not doing in the app I wrote from the VisualGDB UART example. I don’t know if it makes any difference but my app is C++ and the HAL RTC example is straight C. My code does have a SysTick_Handler in main.cpp as shown below. The HAL example seems to bury the SysTick_Handler in various other files but it does seem to do the same thing.
void SysTick_Handler(void)
{
HAL_IncTick();
HAL_SYSTICK_IRQHandler();
}
Seems like I'm not enabling some interrupt handler or something but I've looked in the reference manual and at lots of examples and tutorials on the web but haven't found anything yet. Any suggestions will be greatly appreciated.