Re: How use LPTIM
Posted: Tue Oct 18, 2022 9:42 am
Everything relating to using STM32 boards with the Arduino IDE and alternatives
https://www.stm32duino.com/
Code: Select all
#define HAL_LPTIM_MODULE_ENABLED
A big thanks for the answerfpiSTM wrote: ↑Tue Oct 18, 2022 5:16 pm In fact HAL_LPTIM_MODULE_ENABLED is not enabled by default. you can add an hal_conf_extra.h file with:
to enable it.Code: Select all
#define HAL_LPTIM_MODULE_ENABLED
In this archive, you will get a port of a STM32Cube project for L4:
https://github.com/STMicroelectronics/S ... lseCounter
LPTIM_PusleCounter.zip
I've tested and it works as expected.
Code: Select all
if (HAL_LPTIM_Init(&LptimHandle) != HAL_OK)
{
Error_Handler();
}
HAL_LPTIM_MspInit(&LptimHandle);
in the run mode, lots of ways to do this.try the normal Hardware Timers
Code: Select all
calculate the desired number of cycles to achive your duration
calculate the number of wake-ups required (essentially desired cycle mod timer width)
compare register = current timer value + desired cycle
put the chip to sleep
//in the interrupt
if (wake-up counter--) {blink the led; reset wake-up counter / compare register}
else go back to sleep
HAL_LPTIM_MspInit is called by HAL_LPTIM_Init so I don't see why you need to call it again.hamady91 wrote: ↑Tue Oct 18, 2022 7:23 pmA big thanks for the answerfpiSTM wrote: ↑Tue Oct 18, 2022 5:16 pm In fact HAL_LPTIM_MODULE_ENABLED is not enabled by default. you can add an hal_conf_extra.h file with:
to enable it.Code: Select all
#define HAL_LPTIM_MODULE_ENABLED
In this archive, you will get a port of a STM32Cube project for L4:
https://github.com/STMicroelectronics/S ... lseCounter
LPTIM_PusleCounter.zip
I've tested and it works as expected.
I tested it (Nucleo L432KC) but there is a small issue.
To see the led toogle i need to add the MspInit
but i see no change in the frequency of the LED blinking when i whange the div of the prescalerCode: Select all
if (HAL_LPTIM_Init(&LptimHandle) != HAL_OK) { Error_Handler(); } HAL_LPTIM_MspInit(&LptimHandle);
Do you have an idea ?