/** * @brief Selects the trigger source for the counter and its polarity. * @param LPTIMx: where x can be 1. * @param LPTIM_ExtTRGSource: the selected external trigger. * This parameter can be: * @arg LPTIM_ExtTRGSource_Trig0 : ext_trig0 * @arg LPTIM_ExtTRGSource_Trig1 : ext_trig1 * @arg LPTIM_ExtTRGSource_Trig2 : ext_trig2 * @arg LPTIM_ExtTRGSource_Trig3 : ext_trig3 * @arg LPTIM_ExtTRGSource_Trig4 : ext_trig4 * @arg LPTIM_ExtTRGSource_Trig5 : ext_trig5 * @arg LPTIM_ExtTRGSource_Trig6 : ext_trig6 * @arg LPTIM_ExtTRGSource_Trig7 : ext_trig7 * @param LPTIM_ExtTRGPolarity: the selected external trigger. * This parameter can be: * @arg LPTIM_ExtTRGPolarity_RisingEdge : Rising edge polarity selected * @arg LPTIM_ExtTRGPolarity_FallingEdge : Falling edge polarity selected * @arg LPTIM_ExtTRGPolarity_BothEdges : Both edges polarity selected * @retval None * * @note It is mandatory to disable the peripheral to use this function. */ void LPTIM_ConfigExternalTrigger(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_ExtTRGSource, uint32_t LPTIM_ExtTRGPolarity) { uint32_t tmpreg1 = 0; /* Check the parameters */ assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx)); assert_param(IS_LPTIM_EXT_TRG_SOURCE(LPTIM_ExtTRGSource)); assert_param(IS_LPTIM_EXT_TRG_POLARITY(LPTIM_ExtTRGPolarity)); /* Get the LPTIMx CFGR value */ tmpreg1 = LPTIMx->CFGR; /* Clear the TRIGEN and TRIGSEL bits */ tmpreg1 &= CFGR_TRIG_AND_POL_CLEAR_MASK; /* Set or Reset the TRIGEN and TRIGSEL bits */ tmpreg1 |= (LPTIM_ExtTRGSource | LPTIM_ExtTRGPolarity); /* Write to LPTIMx CFGR */ LPTIMx->CFGR = tmpreg1; }
/** * @brief Initializes the LPTIM according to the specified parameters in the * LPTIM_InitTypeDef and creates the associated handle. * @param hlptim : LPTIM handle * @retval HAL status */ HAL_StatusTypeDef HAL_LPTIM_Init(LPTIM_HandleTypeDef *hlptim) { uint32_t tmpcfgr = 0; /* Check the LPTIM handle allocation */ if(hlptim == NULL) { return HAL_ERROR; } /* Check the parameters */ assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); assert_param(IS_LPTIM_CLOCK_SOURCE(hlptim->Init.Clock.Source)); assert_param(IS_LPTIM_CLOCK_PRESCALER(hlptim->Init.Clock.Prescaler)); if((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM) { assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity)); assert_param(IS_LPTIM_CLOCK_SAMPLE_TIME(hlptim->Init.UltraLowPowerClock.SampleTime)); } assert_param(IS_LPTIM_TRG_SOURCE(hlptim->Init.Trigger.Source)); if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE) { assert_param(IS_LPTIM_TRIG_SAMPLE_TIME(hlptim->Init.Trigger.SampleTime)); assert_param(IS_LPTIM_EXT_TRG_POLARITY(hlptim->Init.Trigger.ActiveEdge)); } assert_param(IS_LPTIM_OUTPUT_POLARITY(hlptim->Init.OutputPolarity)); assert_param(IS_LPTIM_UPDATE_MODE(hlptim->Init.UpdateMode)); assert_param(IS_LPTIM_COUNTER_SOURCE(hlptim->Init.CounterSource)); if(hlptim->State == HAL_LPTIM_STATE_RESET) { /* Init the low level hardware */ HAL_LPTIM_MspInit(hlptim); } /* Change the LPTIM state */ hlptim->State = HAL_LPTIM_STATE_BUSY; /* Get the LPTIMx CFGR value */ tmpcfgr = hlptim->Instance->CFGR; if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM) { tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKPOL | LPTIM_CFGR_CKFLT)); } if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE) { tmpcfgr &= (uint32_t)(~ (LPTIM_CFGR_TRGFLT | LPTIM_CFGR_TRIGSEL)); } /* Clear CKSEL, PRESC, TRIGEN, TRGFLT, WAVPOL, PRELOAD & COUNTMODE bits */ tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKSEL | LPTIM_CFGR_TRIGEN | LPTIM_CFGR_PRELOAD | LPTIM_CFGR_WAVPOL | LPTIM_CFGR_PRESC | LPTIM_CFGR_COUNTMODE )); /* Set initialization parameters */ tmpcfgr |= (hlptim->Init.Clock.Source | hlptim->Init.Clock.Prescaler | hlptim->Init.OutputPolarity | hlptim->Init.UpdateMode | hlptim->Init.CounterSource); if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM) { tmpcfgr |= (hlptim->Init.UltraLowPowerClock.Polarity | hlptim->Init.UltraLowPowerClock.SampleTime); } if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE) { /* Enable External trigger and set the trigger source */ tmpcfgr |= (hlptim->Init.Trigger.Source | hlptim->Init.Trigger.ActiveEdge | hlptim->Init.Trigger.SampleTime); } /* Write to LPTIMx CFGR */ hlptim->Instance->CFGR = tmpcfgr; /* Change the LPTIM state */ hlptim->State = HAL_LPTIM_STATE_READY; /* Return function status */ return HAL_OK; }