Skip to content

STM32 LPTICKER : Fix tickless and LPTICKER_DELAY_TICKS #8242

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

Merged
merged 3 commits into from
Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions targets/TARGET_STM/lp_ticker.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ void lp_ticker_init(void)

__HAL_LPTIM_ENABLE_IT(&LptimHandle, LPTIM_IT_CMPM);
HAL_LPTIM_Counter_Start(&LptimHandle, 0xFFFF);

/* Need to write a compare value in order to get LPTIM_FLAG_CMPOK in set_interrupt */
__HAL_LPTIM_COMPARE_SET(&LptimHandle, 0);
}

static void LPTIM1_IRQHandler(void)
Expand Down Expand Up @@ -194,21 +191,22 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
LptimHandle.Instance = LPTIM1;
irq_handler = (void (*)(void))lp_ticker_irq_handler;

__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK);
__HAL_LPTIM_COMPARE_SET(&LptimHandle, timestamp);
/* CMPOK is set by hardware to inform application that the APB bus write operation to the LPTIM_CMP register has been successfully completed */
/* Any successive write before the CMPOK flag be set, will lead to unpredictable results */
while (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK) == RESET) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this bring back the blocking behavior?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is the same behavior as you have done in #8129

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change in #8129 caused blocking behavior as mentioned by @LMESTM.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@c1728p9 my mistake - Jérôme explained to me and I actually misunderstood CMPOK (programing ok) with CMPM (comparator match) - looks ok to me now

}

__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK);
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPM);
__HAL_LPTIM_COMPARE_SET(&LptimHandle, timestamp);
lp_ticker_clear_interrupt();

NVIC_EnableIRQ(LPTIM1_IRQn);
}

void lp_ticker_fire_interrupt(void)
{
lp_Fired = 1;
irq_handler = (void (*)(void))lp_ticker_irq_handler;
NVIC_SetPendingIRQ(LPTIM1_IRQn);
NVIC_EnableIRQ(LPTIM1_IRQn);
}
Expand All @@ -217,9 +215,6 @@ void lp_ticker_disable_interrupt(void)
{
NVIC_DisableIRQ(LPTIM1_IRQn);
LptimHandle.Instance = LPTIM1;
/* Waiting last write operation completion */
while (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK) == RESET) {
}
}

void lp_ticker_clear_interrupt(void)
Expand Down Expand Up @@ -263,7 +258,6 @@ uint32_t lp_ticker_read(void)

void lp_ticker_set_interrupt(timestamp_t timestamp)
{
lp_ticker_disable_interrupt();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any details on how this fixes the test in #8129?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I should add the details you have added in #8129

rtc_set_wake_up_timer(timestamp);
}

Expand Down
6 changes: 2 additions & 4 deletions targets/TARGET_STM/rtc_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ void rtc_set_wake_up_timer(timestamp_t timestamp)
}

RtcHandle.Instance = RTC;
HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
if (HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, WakeUpCounter, RTC_WAKEUPCLOCK_RTCCLK_DIV4) != HAL_OK) {
error("rtc_set_wake_up_timer init error\n");
}
Expand All @@ -410,10 +411,7 @@ void rtc_fire_interrupt(void)
void rtc_deactivate_wake_up_timer(void)
{
RtcHandle.Instance = RTC;
__HAL_RTC_WRITEPROTECTION_DISABLE(&RtcHandle);
__HAL_RTC_WAKEUPTIMER_DISABLE(&RtcHandle);
__HAL_RTC_WAKEUPTIMER_DISABLE_IT(&RtcHandle, RTC_IT_WUT);
__HAL_RTC_WRITEPROTECTION_ENABLE(&RtcHandle);
HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
NVIC_DisableIRQ(RTC_WKUP_IRQn);
}

Expand Down
Loading