cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L0xx LPTIM with STM32L0CUBE

thierry2
Associate
Posted on October 28, 2014 at 06:58

Hello,

I have some problems to initialise the Low power timer correctly. I'm using the STM32Cube firmware and a STM32L053R8 chip. To start with the LPTIM, I will only toggle a GPIO but I'll never enter the interrupt handler of the LPTIM.

Probably someone has any ideas what's wrong with my code...

int main()

{

HAL_Init();

__GPIOA_CLK_ENABLE();

GPIO_InitTypeDef gpioOutputStructure1;

gpioOutputStructure1.Pin = GPIO_PIN_8;

gpioOutputStructure1.Mode = GPIO_MODE_OUTPUT_PP;

gpioOutputStructure1.Pull = GPIO_PULLDOWN;

gpioOutputStructure1.Speed = GPIO_SPEED_FAST;

HAL_GPIO_Init( GPIOA, &gpioOutputStructure1 );

HAL_GPIO_WritePin( GPIOA, GPIO_PIN_8, GPIO_PIN_SET );

initLPTIM();

while( 1 );

}

void initLPTIM( void )

{

uint32_t lptimTicks = 327;

/* Enable External Low Speed Clock (LSE) */

RCC_OscInitTypeDef RCC_OscInitStructure;

RCC_OscInitStructure.OscillatorType = RCC_OSCILLATORTYPE_LSE;

RCC_OscInitStructure.LSEState = RCC_LSE_ON;

HAL_RCC_OscConfig( &RCC_OscInitStructure );

/* Select the LSE clock as LPTIM peripheral clock */

RCC_PeriphCLKInitTypeDef RCC_PeriphCLKInitStructure;

RCC_PeriphCLKInitStructure.PeriphClockSelection = RCC_PERIPHCLK_LPTIM1;

RCC_PeriphCLKInitStructure.LptimClockSelection = RCC_LPTIM1CLKSOURCE_LSE;

HAL_RCCEx_PeriphCLKConfig( &RCC_PeriphCLKInitStructure );

/* Initialise LPTIM peripheral */

LPTIM_InitStructure.Init.Clock.Source = LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC;

LPTIM_InitStructure.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV1;

LPTIM_InitStructure.Init.CounterSource = LPTIM_COUNTERSOURCE_INTERNAL;

LPTIM_InitStructure.Init.Trigger.Source = LPTIM_TRIGSOURCE_SOFTWARE;

LPTIM_InitStructure.Init.OutputPolarity = LPTIM_OUTPUTPOLARITY_HIGH;

LPTIM_InitStructure.Init.UpdateMode = LPTIM_UPDATE_IMMEDIATE;

/* Initialise LPTIM peripheral according to the passed paramters */

if( HAL_LPTIM_Init( &LPTIM_InitStructure ) != HAL_OK )

{

while( 1 );

}

/* Start the Timeout function in interrupt mode */

if( HAL_LPTIM_COUNTER_Start_IT( &LPTIM_InitStructure, 99, 49 ) != HAL_OK )

{

while( 1 );

}

}

void LPTIM1_IRQHandler(void)

{

/* Autoreload match interrupt */

if( __HAL_LPTIM_GET_FLAG( &LPTIM_InitStructure, LPTIM_FLAG_ARRM ) != RESET )

{

if( __HAL_LPTIM_GET_ITSTATUS( &LPTIM_InitStructure, LPTIM_IT_ARRM ) != RESET )

{

/* Clear Autoreload match flag */

__HAL_LPTIM_CLEAR_FLAG( &LPTIM_InitStructure, LPTIM_FLAG_ARRM );

HAL_GPIO_TogglePin( GPIOA, GPIO_PIN_8 );

//timer.interruptServiceMethod();

}

}

}

#lptim #stm32cube-stm32l0xx
0 REPLIES 0