-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
STM32: Fix RTC test issue on targets using a 16-bit timer for us_ticker #7352
Conversation
targets/TARGET_STM/hal_tick_common.c
Outdated
return ticker_read_us(get_us_ticker_data()) / 1000; // 1 ms tick is required for ST HAL | ||
// 1 ms tick is required for ST HAL driver | ||
if (mbed_sdk_inited) { | ||
return (ticker_read_us(get_us_ticker_data()) / 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to start counting from 0 so there will likely be a time jump after the SDK is initialized. As a workaround you may want to record the time returned by us_ticker_read
just before mbed_sdk_inited is set and use it as an offset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit f785c23
return (ticker_read_us(get_us_ticker_data()) / 1000); | ||
} | ||
else { | ||
return (us_ticker_read() / 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the 16 bit timer this will overflow in ~66ms. If anything in the SDK init takes longer than this it may get stuck as HAL_GetTick will never count higher than this during init. As a potential solution you could accumulate elapsed time rather than reading it directly. Something like:
uint32_t new_time = us_ticker_read();
elapsed_time += (new_time - prev_time) & 0xFFFF; // Only use the lower 16 bits
prev_time = new_time;
return elapsed_time / 1000;
Note - You'll need to make sure prev_time
is reset in HAL_InitTick
since this resets the timer count.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit f785c23
Hi |
Today's status:
|
With commit fcdd529 (thanks @jeromecoutant ), the time, rtc, sleep, tick tests are OK on NUCLEO_L073RZ, NUCLEO_F070RB boards. We are going to perform more tests on more boards but it looks good now. |
targets/TARGET_STM/sleep.c
Outdated
@@ -161,6 +161,7 @@ void hal_deepsleep(void) | |||
// Disable IRQs | |||
core_util_critical_section_enter(); | |||
|
|||
// Save the timer counter value in order to reprogram it after deepsleep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer a new function in hal_tick_common.c which saves TIM_MST needed registers before going into deepsleep:
- CNT
- CCR1
- DIER
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in commit a838cb2
targets/TARGET_STM/sleep.c
Outdated
TIM_HandleTypeDef TimMasterHandle; | ||
TimMasterHandle.Instance = TIM_MST; | ||
__HAL_TIM_SET_COUNTER(&TimMasterHandle, EnterTimeUS); | ||
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call here a function to restore TIM_MST registers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in commit a838cb2
else { | ||
new_time = us_ticker_read(); | ||
elapsed_time += (new_time - prev_time) & 0xFFFF; // Only use the lower 16 bits | ||
prev_time = new_time; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really needed ?
What about 32b targets ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commit 9523bcf do this only for 16bits timer
Tests are OK now. |
/morph build |
Build : ABORTEDBuild number : 2534 |
Weird. Trying again. /morph build |
Build : ABORTEDBuild number : 2537 |
/morph build |
Build : SUCCESSBuild number : 2547 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 2191 |
Test : SUCCESSBuild number : 2302 |
STM32: Fix RTC test issue on targets using a 16-bit timer for us_ticker
Description
This is a fix for Issue #7316
As proposed by @c1728p9 the us_ticker_read() must be used while the SDK is not ready.
Tests:
Pull request type