cancel
Showing results for 
Search instead for 
Did you mean: 

LPTIM Disable Behavior and Interrupt Masking

Makk
Associate II

We are currently using LPTIM1 to measure the time period. As this operation needs to be performed frequently, we are using the following APIs:

 

  • HAL_LPTIM_TimeOut_Stop_IT(&hlptim1)
  • HAL_LPTIM_TimeOut_Start_IT(&hlptim1, 0xXXXX, 0xXXXX)

 

During this process, the LPTIM_Disable() function temporarily disables all interrupts using PRIMASK while waiting for the LPTIM_FLAG_ARROK and LPTIM_FLAG_CMPOK flags.

 

This global interrupt masking is causing data loss on LPUART1, which is operating at 115200 baud. As a result, we are encountering ORE (Overrun Error) due to missed UART interrupts.

 

Given this behaviour, we would like your guidance on the following:

 

  • Is it safe to modify the LPTIM_Disable() implementation by removing or commenting out the PRIMASK-based global interrupt disable?
  • Alternatively, is there a recommended approach to avoid this blocking behaviour while still ensuring correct LPTIM operation?

 

We are concerned about maintaining real-time UART reception alongside frequent LPTIM reconfiguration.

2 REPLIES 2
waclawek.jan
Super User

Normally, it should be enough to clear LPTIM_CR.ENABLE.

Looking at LPTIM_Disable(), it cites the "Device may remain stuck in LPTIM interrupt when entering Stop mode" erratum as the reason for the complex procedure involving resetting the whole LPTIM and then painstakingly (and due to asynchronous clocks domains, potentially slowly) restoring its registers' content.

In other words, if you don't use STOP mode, you are probably OK with simply clearing LPTIM_CR.ENABLE instead of calling LPTIM_Disable() as it is now.

I am not ST.

JW

T_Hamdi
ST Employee

Hello @Makk 

For the first question, we do not recommend removing the PRIMASK protection in LPTIM_Disable(). It is safer to keep the HAL behavior unchanged.

Recommended solution:
Use LPUART1 reception in circular DMA mode to avoid UART data loss during the brief interrupt-masked sections caused by frequent LPTIM reconfiguration.

Thank you!

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Hamdi Teyeb