STM32L4xx_HAL_Driver  1.14.0
Peripheral Control functions

Extended Peripheral Control functions. More...

Functions

HAL_StatusTypeDef HAL_DACEx_SelfCalibrate (DAC_HandleTypeDef *hdac, DAC_ChannelConfTypeDef *sConfig, uint32_t Channel)
 Run the self calibration of one DAC channel. More...
 
HAL_StatusTypeDef HAL_DACEx_SetUserTrimming (DAC_HandleTypeDef *hdac, DAC_ChannelConfTypeDef *sConfig, uint32_t Channel, uint32_t NewTrimmingValue)
 Set the trimming mode and trimming value (user trimming mode applied). More...
 
uint32_t HAL_DACEx_GetTrimOffset (DAC_HandleTypeDef *hdac, uint32_t Channel)
 Return the DAC trimming value. More...
 
uint32_t HAL_DACEx_DualGetValue (DAC_HandleTypeDef *hdac)
 Return the last data output value of the selected DAC channel. More...
 

Detailed Description

Extended Peripheral Control functions.

  ==============================================================================
             ##### Peripheral Control functions #####
  ==============================================================================
    [..]  This section provides functions allowing to:
      (+) Set the specified data holding register value for DAC channel.

Function Documentation

◆ HAL_DACEx_DualGetValue()

uint32_t HAL_DACEx_DualGetValue ( DAC_HandleTypeDef hdac)

Return the last data output value of the selected DAC channel.

Parameters
hdacpointer to a DAC_HandleTypeDef structure that contains the configuration information for the specified DAC.
Return values
Theselected DAC channel data output value.

Definition at line 540 of file stm32l4xx_hal_dac_ex.c.

541 {
542  uint32_t tmp = 0U;
543 
544  tmp |= hdac->Instance->DOR1;
545 
546  tmp |= hdac->Instance->DOR2 << 16U;
547 
548  /* Returns the DAC channel data output register value */
549  return tmp;
550 }

◆ HAL_DACEx_GetTrimOffset()

uint32_t HAL_DACEx_GetTrimOffset ( DAC_HandleTypeDef hdac,
uint32_t  Channel 
)

Return the DAC trimming value.

Parameters
hdacDAC handle
ChannelThe selected DAC channel. This parameter can be one of the following values:
  • DAC_CHANNEL_1: DAC Channel1 selected
  • DAC_CHANNEL_2: DAC Channel2 selected
Return values
Trimmingvalue : range: 0->31

Definition at line 503 of file stm32l4xx_hal_dac_ex.c.

504 {
505  /* Check the parameter */
506  assert_param(IS_DAC_CHANNEL(Channel));
507 
508  /* Retrieve trimming */
509  return ((hdac->Instance->CCR & (DAC_CCR_OTRIM1 << (Channel & 0x10UL))) >> (Channel & 0x10UL));
510 }
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_DACEx_SelfCalibrate()

HAL_StatusTypeDef HAL_DACEx_SelfCalibrate ( DAC_HandleTypeDef hdac,
DAC_ChannelConfTypeDef sConfig,
uint32_t  Channel 
)

Run the self calibration of one DAC channel.

Parameters
hdacpointer to a DAC_HandleTypeDef structure that contains the configuration information for the specified DAC.
sConfigDAC channel configuration structure.
ChannelThe selected DAC channel. This parameter can be one of the following values:
  • DAC_CHANNEL_1: DAC Channel1 selected
  • DAC_CHANNEL_2: DAC Channel2 selected
Return values
UpdatesDAC_TrimmingValue. , DAC_UserTrimming set to DAC_UserTrimming
HALstatus
Note
Calibration runs about 7 ms.

Definition at line 323 of file stm32l4xx_hal_dac_ex.c.

324 {
325  HAL_StatusTypeDef status = HAL_OK;
326 
327  __IO uint32_t tmp;
328  uint32_t trimmingvalue;
329  uint32_t delta;
330 
331  /* store/restore channel configuration structure purpose */
332  uint32_t oldmodeconfiguration;
333 
334  /* Check the parameters */
335  assert_param(IS_DAC_CHANNEL(Channel));
336 
337  /* Check the DAC handle allocation */
338  /* Check if DAC running */
339  if (hdac == NULL)
340  {
341  status = HAL_ERROR;
342  }
343  else if (hdac->State == HAL_DAC_STATE_BUSY)
344  {
345  status = HAL_ERROR;
346  }
347  else
348  {
349  /* Process locked */
350  __HAL_LOCK(hdac);
351 
352  /* Store configuration */
353  oldmodeconfiguration = (hdac->Instance->MCR & (DAC_MCR_MODE1 << (Channel & 0x10UL)));
354 
355  /* Disable the selected DAC channel */
356  CLEAR_BIT((hdac->Instance->CR), (DAC_CR_EN1 << (Channel & 0x10UL)));
357 
358  /* Set mode in MCR for calibration */
359  MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << (Channel & 0x10UL)), 0U);
360 
361  /* Set DAC Channel1 DHR register to the middle value */
362  tmp = (uint32_t)hdac->Instance;
363 
364 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \
365  defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx) || \
366  defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx)
367  if(Channel == DAC_CHANNEL_1)
368  {
369  tmp += DAC_DHR12R1_ALIGNMENT(DAC_ALIGN_12B_R);
370  }
371  else
372  {
373  tmp += DAC_DHR12R2_ALIGNMENT(DAC_ALIGN_12B_R);
374  }
375 #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */
376  /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */
377  /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */
378 #if defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx)
379  tmp += DAC_DHR12R1_ALIGNMENT(DAC_ALIGN_12B_R);
380 #endif /* STM32L451xx STM32L452xx STM32L462xx */
381  *(__IO uint32_t *) tmp = 0x0800U;
382 
383  /* Enable the selected DAC channel calibration */
384  /* i.e. set DAC_CR_CENx bit */
385  SET_BIT((hdac->Instance->CR), (DAC_CR_CEN1 << (Channel & 0x10UL)));
386 
387  /* Init trimming counter */
388  /* Medium value */
389  trimmingvalue = 16U;
390  delta = 8U;
391  while (delta != 0U)
392  {
393  /* Set candidate trimming */
394  MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1 << (Channel & 0x10UL)), (trimmingvalue << (Channel & 0x10UL)));
395 
396  /* tOFFTRIMmax delay x ms as per datasheet (electrical characteristics */
397  /* i.e. minimum time needed between two calibration steps */
398  HAL_Delay(1);
399 
400  if ((hdac->Instance->SR & (DAC_SR_CAL_FLAG1 << (Channel & 0x10UL))) == (DAC_SR_CAL_FLAG1 << (Channel & 0x10UL)))
401  {
402  /* DAC_SR_CAL_FLAGx is HIGH try higher trimming */
403  trimmingvalue -= delta;
404  }
405  else
406  {
407  /* DAC_SR_CAL_FLAGx is LOW try lower trimming */
408  trimmingvalue += delta;
409  }
410  delta >>= 1U;
411  }
412 
413  /* Still need to check if right calibration is current value or one step below */
414  /* Indeed the first value that causes the DAC_SR_CAL_FLAGx bit to change from 0 to 1 */
415  /* Set candidate trimming */
416  MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1 << (Channel & 0x10UL)), (trimmingvalue << (Channel & 0x10UL)));
417 
418  /* tOFFTRIMmax delay x ms as per datasheet (electrical characteristics */
419  /* i.e. minimum time needed between two calibration steps */
420  HAL_Delay(1U);
421 
422  if ((hdac->Instance->SR & (DAC_SR_CAL_FLAG1 << (Channel & 0x10UL))) == 0UL)
423  {
424  /* OPAMP_CSR_OUTCAL is actually one value more */
425  trimmingvalue++;
426  /* Set right trimming */
427  MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1 << (Channel & 0x10UL)), (trimmingvalue << (Channel & 0x10UL)));
428  }
429 
430  /* Disable the selected DAC channel calibration */
431  /* i.e. clear DAC_CR_CENx bit */
432  CLEAR_BIT((hdac->Instance->CR), (DAC_CR_CEN1 << (Channel & 0x10UL)));
433 
434  sConfig->DAC_TrimmingValue = trimmingvalue;
435  sConfig->DAC_UserTrimming = DAC_TRIMMING_USER;
436 
437  /* Restore configuration */
438  MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << (Channel & 0x10UL)), oldmodeconfiguration);
439 
440  /* Process unlocked */
441  __HAL_UNLOCK(hdac);
442  }
443 
444  return status;
445 }
void HAL_Delay(uint32_t Delay)
This function provides minimum delay (in milliseconds) based on variable incremented.
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
return HAL_OK
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_DACEx_SetUserTrimming()

HAL_StatusTypeDef HAL_DACEx_SetUserTrimming ( DAC_HandleTypeDef hdac,
DAC_ChannelConfTypeDef sConfig,
uint32_t  Channel,
uint32_t  NewTrimmingValue 
)

Set the trimming mode and trimming value (user trimming mode applied).

Parameters
hdacpointer to a DAC_HandleTypeDef structure that contains the configuration information for the specified DAC.
sConfigDAC configuration structure updated with new DAC trimming value.
ChannelThe selected DAC channel. This parameter can be one of the following values:
  • DAC_CHANNEL_1: DAC Channel1 selected
  • DAC_CHANNEL_2: DAC Channel2 selected
NewTrimmingValueDAC new trimming value
Return values
HALstatus

Definition at line 460 of file stm32l4xx_hal_dac_ex.c.

462 {
463  HAL_StatusTypeDef status = HAL_OK;
464 
465  /* Check the parameters */
466  assert_param(IS_DAC_CHANNEL(Channel));
467  assert_param(IS_DAC_NEWTRIMMINGVALUE(NewTrimmingValue));
468 
469  /* Check the DAC handle allocation */
470  if (hdac == NULL)
471  {
472  status = HAL_ERROR;
473  }
474  else
475  {
476  /* Process locked */
477  __HAL_LOCK(hdac);
478 
479  /* Set new trimming */
480  MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1 << (Channel & 0x10UL)), (NewTrimmingValue << (Channel & 0x10UL)));
481 
482  /* Update trimming mode */
483  sConfig->DAC_UserTrimming = DAC_TRIMMING_USER;
484  sConfig->DAC_TrimmingValue = NewTrimmingValue;
485 
486  /* Process unlocked */
487  __HAL_UNLOCK(hdac);
488  }
489  return status;
490 }
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))