STM32L4xx_HAL_Driver  1.14.0
Extended Timer Hall Sensor functions

Timer Hall Sensor functions. More...

Functions

HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init (TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef *sConfig)
 Initializes the TIM Hall Sensor Interface and initialize the associated handle. More...
 
HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit (TIM_HandleTypeDef *htim)
 DeInitializes the TIM Hall Sensor interface. More...
 
void HAL_TIMEx_HallSensor_MspInit (TIM_HandleTypeDef *htim)
 Initializes the TIM Hall Sensor MSP. More...
 
void HAL_TIMEx_HallSensor_MspDeInit (TIM_HandleTypeDef *htim)
 DeInitializes TIM Hall Sensor MSP. More...
 
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start (TIM_HandleTypeDef *htim)
 Starts the TIM Hall Sensor Interface. More...
 
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop (TIM_HandleTypeDef *htim)
 Stops the TIM Hall sensor Interface. More...
 
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT (TIM_HandleTypeDef *htim)
 Starts the TIM Hall Sensor Interface in interrupt mode. More...
 
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT (TIM_HandleTypeDef *htim)
 Stops the TIM Hall Sensor Interface in interrupt mode. More...
 
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA (TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length)
 Starts the TIM Hall Sensor Interface in DMA mode. More...
 
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA (TIM_HandleTypeDef *htim)
 Stops the TIM Hall Sensor Interface in DMA mode. More...
 

Detailed Description

Timer Hall Sensor functions.

  ==============================================================================
                      ##### Timer Hall Sensor functions #####
  ==============================================================================
  [..]
    This section provides functions allowing to:
    (+) Initialize and configure TIM HAL Sensor.
    (+) De-initialize TIM HAL Sensor.
    (+) Start the Hall Sensor Interface.
    (+) Stop the Hall Sensor Interface.
    (+) Start the Hall Sensor Interface and enable interrupts.
    (+) Stop the Hall Sensor Interface and disable interrupts.
    (+) Start the Hall Sensor Interface and enable DMA transfers.
    (+) Stop the Hall Sensor Interface and disable DMA transfers.

Function Documentation

◆ HAL_TIMEx_HallSensor_DeInit()

HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit ( TIM_HandleTypeDef htim)

DeInitializes the TIM Hall Sensor interface.

Parameters
htimTIM Hall Sensor Interface handle
Return values
HALstatus

Definition at line 224 of file stm32l4xx_hal_tim_ex.c.

225 {
226  /* Check the parameters */
227  assert_param(IS_TIM_INSTANCE(htim->Instance));
228 
229  htim->State = HAL_TIM_STATE_BUSY;
230 
231  /* Disable the TIM Peripheral Clock */
232  __HAL_TIM_DISABLE(htim);
233 
234 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
235  if (htim->HallSensor_MspDeInitCallback == NULL)
236  {
237  htim->HallSensor_MspDeInitCallback = HAL_TIMEx_HallSensor_MspDeInit;
238  }
239  /* DeInit the low level hardware */
240  htim->HallSensor_MspDeInitCallback(htim);
241 #else
242  /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
244 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
245 
246  /* Change TIM state */
247  htim->State = HAL_TIM_STATE_RESET;
248 
249  /* Release Lock */
250  __HAL_UNLOCK(htim);
251 
252  return HAL_OK;
253 }
void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim)
DeInitializes TIM Hall Sensor MSP.
__HAL_UNLOCK(hrtc)
return HAL_OK
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIMEx_HallSensor_Init()

HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init ( TIM_HandleTypeDef htim,
TIM_HallSensor_InitTypeDef sConfig 
)

Initializes the TIM Hall Sensor Interface and initialize the associated handle.

Parameters
htimTIM Hall Sensor Interface handle
sConfigTIM Hall Sensor configuration structure
Return values
HALstatus

Definition at line 132 of file stm32l4xx_hal_tim_ex.c.

133 {
134  TIM_OC_InitTypeDef OC_Config;
135 
136  /* Check the TIM handle allocation */
137  if (htim == NULL)
138  {
139  return HAL_ERROR;
140  }
141 
142  /* Check the parameters */
143  assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
144  assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
145  assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
146  assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
147  assert_param(IS_TIM_IC_POLARITY(sConfig->IC1Polarity));
148  assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler));
149  assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter));
150 
151  if (htim->State == HAL_TIM_STATE_RESET)
152  {
153  /* Allocate lock resource and initialize it */
154  htim->Lock = HAL_UNLOCKED;
155 
156 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
157  /* Reset interrupt callbacks to legacy week callbacks */
158  TIM_ResetCallback(htim);
159 
160  if (htim->HallSensor_MspInitCallback == NULL)
161  {
162  htim->HallSensor_MspInitCallback = HAL_TIMEx_HallSensor_MspInit;
163  }
164  /* Init the low level hardware : GPIO, CLOCK, NVIC */
165  htim->HallSensor_MspInitCallback(htim);
166 #else
167  /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
169 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
170  }
171 
172  /* Set the TIM state */
173  htim->State = HAL_TIM_STATE_BUSY;
174 
175  /* Configure the Time base in the Encoder Mode */
176  TIM_Base_SetConfig(htim->Instance, &htim->Init);
177 
178  /* Configure the Channel 1 as Input Channel to interface with the three Outputs of the Hall sensor */
179  TIM_TI1_SetConfig(htim->Instance, sConfig->IC1Polarity, TIM_ICSELECTION_TRC, sConfig->IC1Filter);
180 
181  /* Reset the IC1PSC Bits */
182  htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
183  /* Set the IC1PSC value */
184  htim->Instance->CCMR1 |= sConfig->IC1Prescaler;
185 
186  /* Enable the Hall sensor interface (XOR function of the three inputs) */
187  htim->Instance->CR2 |= TIM_CR2_TI1S;
188 
189  /* Select the TIM_TS_TI1F_ED signal as Input trigger for the TIM */
190  htim->Instance->SMCR &= ~TIM_SMCR_TS;
191  htim->Instance->SMCR |= TIM_TS_TI1F_ED;
192 
193  /* Use the TIM_TS_TI1F_ED signal to reset the TIM counter each edge detection */
194  htim->Instance->SMCR &= ~TIM_SMCR_SMS;
195  htim->Instance->SMCR |= TIM_SLAVEMODE_RESET;
196 
197  /* Program channel 2 in PWM 2 mode with the desired Commutation_Delay*/
198  OC_Config.OCFastMode = TIM_OCFAST_DISABLE;
199  OC_Config.OCIdleState = TIM_OCIDLESTATE_RESET;
200  OC_Config.OCMode = TIM_OCMODE_PWM2;
201  OC_Config.OCNIdleState = TIM_OCNIDLESTATE_RESET;
202  OC_Config.OCNPolarity = TIM_OCNPOLARITY_HIGH;
203  OC_Config.OCPolarity = TIM_OCPOLARITY_HIGH;
204  OC_Config.Pulse = sConfig->Commutation_Delay;
205 
206  TIM_OC2_SetConfig(htim->Instance, &OC_Config);
207 
208  /* Select OC2REF as trigger output on TRGO: write the MMS bits in the TIMx_CR2
209  register to 101 */
210  htim->Instance->CR2 &= ~TIM_CR2_MMS;
211  htim->Instance->CR2 |= TIM_TRGO_OC2REF;
212 
213  /* Initialize the TIM state*/
214  htim->State = HAL_TIM_STATE_READY;
215 
216  return HAL_OK;
217 }
void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim)
Initializes the TIM Hall Sensor MSP.
void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, uint32_t TIM_ICFilter)
Configure the TI1 as Input.
void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure)
Time Base configuration.
void TIM_ResetCallback(TIM_HandleTypeDef *htim)
Reset interrupt callbacks to the legacy weak callbacks.
return HAL_OK
TIM Output Compare Configuration Structure definition.
void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
Timer Output Compare 2 configuration.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIMEx_HallSensor_MspDeInit()

__weak void HAL_TIMEx_HallSensor_MspDeInit ( TIM_HandleTypeDef htim)

DeInitializes TIM Hall Sensor MSP.

Parameters
htimTIM Hall Sensor Interface handle
Return values
None

Definition at line 275 of file stm32l4xx_hal_tim_ex.c.

276 {
277  /* Prevent unused argument(s) compilation warning */
278  UNUSED(htim);
279 
280  /* NOTE : This function should not be modified, when the callback is needed,
281  the HAL_TIMEx_HallSensor_MspDeInit could be implemented in the user file
282  */
283 }

◆ HAL_TIMEx_HallSensor_MspInit()

__weak void HAL_TIMEx_HallSensor_MspInit ( TIM_HandleTypeDef htim)

Initializes the TIM Hall Sensor MSP.

Parameters
htimTIM Hall Sensor Interface handle
Return values
None

Definition at line 260 of file stm32l4xx_hal_tim_ex.c.

261 {
262  /* Prevent unused argument(s) compilation warning */
263  UNUSED(htim);
264 
265  /* NOTE : This function should not be modified, when the callback is needed,
266  the HAL_TIMEx_HallSensor_MspInit could be implemented in the user file
267  */
268 }

◆ HAL_TIMEx_HallSensor_Start()

HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start ( TIM_HandleTypeDef htim)

Starts the TIM Hall Sensor Interface.

Parameters
htimTIM Hall Sensor Interface handle
Return values
HALstatus

Definition at line 290 of file stm32l4xx_hal_tim_ex.c.

291 {
292  uint32_t tmpsmcr;
293 
294  /* Check the parameters */
295  assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
296 
297  /* Enable the Input Capture channel 1
298  (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
299  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
300 
301  /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
302  tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
303  if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
304  {
305  __HAL_TIM_ENABLE(htim);
306  }
307 
308  /* Return function status */
309  return HAL_OK;
310 }
return HAL_OK
void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
Enables or disables the TIM Capture Compare Channel x.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIMEx_HallSensor_Start_DMA()

HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA ( TIM_HandleTypeDef htim,
uint32_t *  pData,
uint16_t  Length 
)

Starts the TIM Hall Sensor Interface in DMA mode.

Parameters
htimTIM Hall Sensor Interface handle
pDataThe destination Buffer address.
LengthThe length of data to be transferred from TIM peripheral to memory.
Return values
HALstatus

Definition at line 394 of file stm32l4xx_hal_tim_ex.c.

395 {
396  uint32_t tmpsmcr;
397 
398  /* Check the parameters */
399  assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
400 
401  if ((htim->State == HAL_TIM_STATE_BUSY))
402  {
403  return HAL_BUSY;
404  }
405  else if ((htim->State == HAL_TIM_STATE_READY))
406  {
407  if (((uint32_t)pData == 0U) && (Length > 0U))
408  {
409  return HAL_ERROR;
410  }
411  else
412  {
413  htim->State = HAL_TIM_STATE_BUSY;
414  }
415  }
416  else
417  {
418  /* nothing to do */
419  }
420  /* Enable the Input Capture channel 1
421  (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
422  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
423 
424  /* Set the DMA Input Capture 1 Callbacks */
425  htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
426  htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
427  /* Set the DMA error callback */
428  htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
429 
430  /* Enable the DMA channel for Capture 1*/
431  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length) != HAL_OK)
432  {
433  return HAL_ERROR;
434  }
435  /* Enable the capture compare 1 Interrupt */
436  __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
437 
438  /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
439  tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
440  if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
441  {
442  __HAL_TIM_ENABLE(htim);
443  }
444 
445  /* Return function status */
446  return HAL_OK;
447 }
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
Start the DMA Transfer with interrupt enabled.
void TIM_DMAError(DMA_HandleTypeDef *hdma)
TIM DMA error callback.
return HAL_OK
void TIM_DMACaptureHalfCplt(DMA_HandleTypeDef *hdma)
TIM DMA Capture half complete callback.
void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma)
TIM DMA Capture complete callback.
void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
Enables or disables the TIM Capture Compare Channel x.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIMEx_HallSensor_Start_IT()

HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT ( TIM_HandleTypeDef htim)

Starts the TIM Hall Sensor Interface in interrupt mode.

Parameters
htimTIM Hall Sensor Interface handle
Return values
HALstatus

Definition at line 338 of file stm32l4xx_hal_tim_ex.c.

339 {
340  uint32_t tmpsmcr;
341 
342  /* Check the parameters */
343  assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
344 
345  /* Enable the capture compare Interrupts 1 event */
346  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
347 
348  /* Enable the Input Capture channel 1
349  (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
350  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
351 
352  /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
353  tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
354  if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
355  {
356  __HAL_TIM_ENABLE(htim);
357  }
358 
359  /* Return function status */
360  return HAL_OK;
361 }
return HAL_OK
void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
Enables or disables the TIM Capture Compare Channel x.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIMEx_HallSensor_Stop()

HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop ( TIM_HandleTypeDef htim)

Stops the TIM Hall sensor Interface.

Parameters
htimTIM Hall Sensor Interface handle
Return values
HALstatus

Definition at line 317 of file stm32l4xx_hal_tim_ex.c.

318 {
319  /* Check the parameters */
320  assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
321 
322  /* Disable the Input Capture channels 1, 2 and 3
323  (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
324  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
325 
326  /* Disable the Peripheral */
327  __HAL_TIM_DISABLE(htim);
328 
329  /* Return function status */
330  return HAL_OK;
331 }
return HAL_OK
void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
Enables or disables the TIM Capture Compare Channel x.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIMEx_HallSensor_Stop_DMA()

HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA ( TIM_HandleTypeDef htim)

Stops the TIM Hall Sensor Interface in DMA mode.

Parameters
htimTIM Hall Sensor Interface handle
Return values
HALstatus

Definition at line 454 of file stm32l4xx_hal_tim_ex.c.

455 {
456  /* Check the parameters */
457  assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
458 
459  /* Disable the Input Capture channel 1
460  (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
461  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
462 
463 
464  /* Disable the capture compare Interrupts 1 event */
465  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
466 
467  (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
468  /* Disable the Peripheral */
469  __HAL_TIM_DISABLE(htim);
470 
471  /* Return function status */
472  return HAL_OK;
473 }
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
Aborts the DMA Transfer in Interrupt mode.
return HAL_OK
void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
Enables or disables the TIM Capture Compare Channel x.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIMEx_HallSensor_Stop_IT()

HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT ( TIM_HandleTypeDef htim)

Stops the TIM Hall Sensor Interface in interrupt mode.

Parameters
htimTIM Hall Sensor Interface handle
Return values
HALstatus

Definition at line 368 of file stm32l4xx_hal_tim_ex.c.

369 {
370  /* Check the parameters */
371  assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
372 
373  /* Disable the Input Capture channel 1
374  (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
375  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
376 
377  /* Disable the capture compare Interrupts event */
378  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
379 
380  /* Disable the Peripheral */
381  __HAL_TIM_DISABLE(htim);
382 
383  /* Return function status */
384  return HAL_OK;
385 }
return HAL_OK
void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
Enables or disables the TIM Capture Compare Channel x.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))