RTC Clock Nightmare - STM32F103
Posted: Sun Feb 09, 2014 6:41 pm
Hi All,
My code and the tesHAL RTC sample do not work on my board (chibistudio latest preview) + custom stmf103c8t6 board. everything just locked up. The RTC clock was ticking (clock callback once per second working) as long as I didn't call rtcGetTime(&RTCD1, ×pec);
I've not been able to get the debugger environment up on my machine, so have spent the best part of 10 hours trying to make the debugger work and get RTC working.
So traced the failing call down into rtc_lld.c from rtcv1 folder and tweeked away.
I have it working now, but no idea why the original doesn't - must be a compiler option, a bad cast operation or something.
The following works:
The following doesn't:
The difference is just the use of the temptime value placed into the 'while loop' instead of the expression being used as comparison directly in the while clause.
Anyone give me any ideas of whats going on here. - Its been 20 years since I wrote any C code, so am more than a little rusty on the syntax structure etc.
PS - The above code isn't the original RTC lld code as I've swapped out the + for an OR operation during tweeking - but the same issue with the original code.
Thanks in advance as always.
My code and the tesHAL RTC sample do not work on my board (chibistudio latest preview) + custom stmf103c8t6 board. everything just locked up. The RTC clock was ticking (clock callback once per second working) as long as I didn't call rtcGetTime(&RTCD1, ×pec);
I've not been able to get the debugger environment up on my machine, so have spent the best part of 10 hours trying to make the debugger work and get RTC working.
So traced the failing call down into rtc_lld.c from rtcv1 folder and tweeked away.
I have it working now, but no idea why the original doesn't - must be a compiler option, a bad cast operation or something.
The following works:
Code: Select all
/* Loops until two consecutive read returning the same value.*/
do {
timespec->tv_sec = (uint32_t)RTC->CNTH << 16 | (uint32_t)RTC->CNTL;
time_frac = (uint32_t)RTC->DIVH << 16 | (uint32_t)RTC->DIVL;
temptime = (uint32_t)RTC->CNTH << 16 | (uint32_t)RTC->CNTL;
} while (timespec->tv_sec != temptime);
timespec->tv_msec = (uint16_t)(((STM32_RTCCLK - 1 - time_frac) * 1000) / STM32_RTCCLK);The following doesn't:
Code: Select all
do {
timespec->tv_sec = (uint32_t)RTC->CNTH << 16 | (uint32_t)RTC->CNTL;
time_frac = (uint32_t)RTC->DIVH << 16 | (uint32_t)RTC->DIVL;
} while (timespec->tv_sec != (uint32_t)RTC->CNTH << 16 | (uint32_t)RTC->CNTL);
timespec->tv_msec = (uint16_t)(((STM32_RTCCLK - 1 - time_frac) * 1000) / STM32_RTCCLK);The difference is just the use of the temptime value placed into the 'while loop' instead of the expression being used as comparison directly in the while clause.
Anyone give me any ideas of whats going on here. - Its been 20 years since I wrote any C code, so am more than a little rusty on the syntax structure etc.
PS - The above code isn't the original RTC lld code as I've swapped out the + for an OR operation during tweeking - but the same issue with the original code.
Thanks in advance as always.