STM32L4xx_HAL_Driver  1.14.0

Extended IO operation functions. More...

Functions

HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate (DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude)
 Enable or disable the selected DAC channel wave generation. More...
 
HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate (DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude)
 Enable or disable the selected DAC channel wave generation. More...
 
HAL_StatusTypeDef HAL_DACEx_DualSetValue (DAC_HandleTypeDef *hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2)
 Set the specified data holding register value for dual DAC channel. More...
 
__weak void HAL_DACEx_ConvCpltCallbackCh2 (DAC_HandleTypeDef *hdac)
 Conversion complete callback in non-blocking mode for Channel2. More...
 
__weak void HAL_DACEx_ConvHalfCpltCallbackCh2 (DAC_HandleTypeDef *hdac)
 Conversion half DMA transfer callback in non-blocking mode for Channel2. More...
 
__weak void HAL_DACEx_ErrorCallbackCh2 (DAC_HandleTypeDef *hdac)
 Error DAC callback for Channel2. More...
 
__weak void HAL_DACEx_DMAUnderrunCallbackCh2 (DAC_HandleTypeDef *hdac)
 DMA underrun DAC callback for Channel2. More...
 
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...
 

Detailed Description

Extended IO operation functions.

  ==============================================================================
                 ##### Extended features functions #####
  ==============================================================================
    [..]  This section provides functions allowing to:
      (+) Start conversion.
      (+) Stop conversion.
      (+) Start conversion and enable DMA transfer.
      (+) Stop conversion and disable DMA transfer.
      (+) Get result of conversion.
      (+) Get result of dual mode conversion.

Function Documentation

◆ HAL_DACEx_ConvCpltCallbackCh2()

__weak void HAL_DACEx_ConvCpltCallbackCh2 ( DAC_HandleTypeDef hdac)

Conversion complete callback in non-blocking mode for Channel2.

Parameters
hdacpointer to a DAC_HandleTypeDef structure that contains the configuration information for the specified DAC.
Return values
None

Definition at line 248 of file stm32l4xx_hal_dac_ex.c.

249 {
250  /* Prevent unused argument(s) compilation warning */
251  UNUSED(hdac);
252 
253  /* NOTE : This function should not be modified, when the callback is needed,
254  the HAL_DACEx_ConvCpltCallbackCh2 could be implemented in the user file
255  */
256 }

◆ HAL_DACEx_ConvHalfCpltCallbackCh2()

__weak void HAL_DACEx_ConvHalfCpltCallbackCh2 ( DAC_HandleTypeDef hdac)

Conversion half DMA transfer callback in non-blocking mode for Channel2.

Parameters
hdacpointer to a DAC_HandleTypeDef structure that contains the configuration information for the specified DAC.
Return values
None

Definition at line 264 of file stm32l4xx_hal_dac_ex.c.

265 {
266  /* Prevent unused argument(s) compilation warning */
267  UNUSED(hdac);
268 
269  /* NOTE : This function should not be modified, when the callback is needed,
270  the HAL_DACEx_ConvHalfCpltCallbackCh2 could be implemented in the user file
271  */
272 }

◆ HAL_DACEx_DMAUnderrunCallbackCh2()

__weak void HAL_DACEx_DMAUnderrunCallbackCh2 ( DAC_HandleTypeDef hdac)

DMA underrun DAC callback for Channel2.

Parameters
hdacpointer to a DAC_HandleTypeDef structure that contains the configuration information for the specified DAC.
Return values
None

Definition at line 296 of file stm32l4xx_hal_dac_ex.c.

297 {
298  /* Prevent unused argument(s) compilation warning */
299  UNUSED(hdac);
300 
301  /* NOTE : This function should not be modified, when the callback is needed,
302  the HAL_DACEx_DMAUnderrunCallbackCh2 could be implemented in the user file
303  */
304 }

◆ HAL_DACEx_DualSetValue()

HAL_StatusTypeDef HAL_DACEx_DualSetValue ( DAC_HandleTypeDef hdac,
uint32_t  Alignment,
uint32_t  Data1,
uint32_t  Data2 
)

Set the specified data holding register value for dual DAC channel.

Parameters
hdacpointer to a DAC_HandleTypeDef structure that contains the configuration information for the specified DAC.
AlignmentSpecifies the data alignment for dual channel DAC. This parameter can be one of the following values: DAC_ALIGN_8B_R: 8bit right data alignment selected DAC_ALIGN_12B_L: 12bit left data alignment selected DAC_ALIGN_12B_R: 12bit right data alignment selected
Data1Data for DAC Channel1 to be loaded in the selected data holding register.
Data2Data for DAC Channel2 to be loaded in the selected data holding register.
Note
In dual mode, a unique register access is required to write in both DAC channels at the same time.
Return values
HALstatus

Definition at line 212 of file stm32l4xx_hal_dac_ex.c.

213 {
214  uint32_t data;
215  uint32_t tmp;
216 
217  /* Check the parameters */
218  assert_param(IS_DAC_ALIGN(Alignment));
219  assert_param(IS_DAC_DATA(Data1));
220  assert_param(IS_DAC_DATA(Data2));
221 
222  /* Calculate and set dual DAC data holding register value */
223  if (Alignment == DAC_ALIGN_8B_R)
224  {
225  data = ((uint32_t)Data2 << 8U) | Data1;
226  }
227  else
228  {
229  data = ((uint32_t)Data2 << 16U) | Data1;
230  }
231 
232  tmp = (uint32_t)hdac->Instance;
233  tmp += DAC_DHR12RD_ALIGNMENT(Alignment);
234 
235  /* Set the dual DAC selected data holding register */
236  *(__IO uint32_t *)tmp = data;
237 
238  /* Return function status */
239  return HAL_OK;
240 }
return HAL_OK
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_DACEx_ErrorCallbackCh2()

__weak void HAL_DACEx_ErrorCallbackCh2 ( DAC_HandleTypeDef hdac)

Error DAC callback for Channel2.

Parameters
hdacpointer to a DAC_HandleTypeDef structure that contains the configuration information for the specified DAC.
Return values
None

Definition at line 280 of file stm32l4xx_hal_dac_ex.c.

281 {
282  /* Prevent unused argument(s) compilation warning */
283  UNUSED(hdac);
284 
285  /* NOTE : This function should not be modified, when the callback is needed,
286  the HAL_DACEx_ErrorCallbackCh2 could be implemented in the user file
287  */
288 }

◆ 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_NoiseWaveGenerate()

HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate ( DAC_HandleTypeDef hdac,
uint32_t  Channel,
uint32_t  Amplitude 
)

Enable or disable the selected DAC channel wave generation.

Parameters
hdacpointer to a DAC_HandleTypeDef structure that contains the configuration information for the specified DAC.
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
AmplitudeUnmask DAC channel LFSR for noise wave generation. This parameter can be one of the following values:
  • DAC_LFSRUNMASK_BIT0: Unmask DAC channel LFSR bit0 for noise wave generation
  • DAC_LFSRUNMASK_BITS1_0: Unmask DAC channel LFSR bit[1:0] for noise wave generation
  • DAC_LFSRUNMASK_BITS2_0: Unmask DAC channel LFSR bit[2:0] for noise wave generation
  • DAC_LFSRUNMASK_BITS3_0: Unmask DAC channel LFSR bit[3:0] for noise wave generation
  • DAC_LFSRUNMASK_BITS4_0: Unmask DAC channel LFSR bit[4:0] for noise wave generation
  • DAC_LFSRUNMASK_BITS5_0: Unmask DAC channel LFSR bit[5:0] for noise wave generation
  • DAC_LFSRUNMASK_BITS6_0: Unmask DAC channel LFSR bit[6:0] for noise wave generation
  • DAC_LFSRUNMASK_BITS7_0: Unmask DAC channel LFSR bit[7:0] for noise wave generation
  • DAC_LFSRUNMASK_BITS8_0: Unmask DAC channel LFSR bit[8:0] for noise wave generation
  • DAC_LFSRUNMASK_BITS9_0: Unmask DAC channel LFSR bit[9:0] for noise wave generation
  • DAC_LFSRUNMASK_BITS10_0: Unmask DAC channel LFSR bit[10:0] for noise wave generation
  • DAC_LFSRUNMASK_BITS11_0: Unmask DAC channel LFSR bit[11:0] for noise wave generation
Return values
HALstatus

Definition at line 168 of file stm32l4xx_hal_dac_ex.c.

169 {
170  /* Check the parameters */
171  assert_param(IS_DAC_CHANNEL(Channel));
172  assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
173 
174  /* Process locked */
175  __HAL_LOCK(hdac);
176 
177  /* Change DAC state */
178  hdac->State = HAL_DAC_STATE_BUSY;
179 
180  /* Enable the noise wave generation for the selected DAC channel */
181  MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1) | (DAC_CR_MAMP1)) << (Channel & 0x10UL), (DAC_CR_WAVE1_0 | Amplitude) << (Channel & 0x10UL));
182 
183  /* Change DAC state */
184  hdac->State = HAL_DAC_STATE_READY;
185 
186  /* Process unlocked */
187  __HAL_UNLOCK(hdac);
188 
189  /* Return function status */
190  return HAL_OK;
191 }
__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))

◆ 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))

◆ HAL_DACEx_TriangleWaveGenerate()

HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate ( DAC_HandleTypeDef hdac,
uint32_t  Channel,
uint32_t  Amplitude 
)

Enable or disable the selected DAC channel wave generation.

Parameters
hdacpointer to a DAC_HandleTypeDef structure that contains the configuration information for the specified DAC.
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
AmplitudeSelect max triangle amplitude. This parameter can be one of the following values:
  • DAC_TRIANGLEAMPLITUDE_1: Select max triangle amplitude of 1
  • DAC_TRIANGLEAMPLITUDE_3: Select max triangle amplitude of 3
  • DAC_TRIANGLEAMPLITUDE_7: Select max triangle amplitude of 7
  • DAC_TRIANGLEAMPLITUDE_15: Select max triangle amplitude of 15
  • DAC_TRIANGLEAMPLITUDE_31: Select max triangle amplitude of 31
  • DAC_TRIANGLEAMPLITUDE_63: Select max triangle amplitude of 63
  • DAC_TRIANGLEAMPLITUDE_127: Select max triangle amplitude of 127
  • DAC_TRIANGLEAMPLITUDE_255: Select max triangle amplitude of 255
  • DAC_TRIANGLEAMPLITUDE_511: Select max triangle amplitude of 511
  • DAC_TRIANGLEAMPLITUDE_1023: Select max triangle amplitude of 1023
  • DAC_TRIANGLEAMPLITUDE_2047: Select max triangle amplitude of 2047
  • DAC_TRIANGLEAMPLITUDE_4095: Select max triangle amplitude of 4095
Return values
HALstatus

Definition at line 119 of file stm32l4xx_hal_dac_ex.c.

120 {
121  /* Check the parameters */
122  assert_param(IS_DAC_CHANNEL(Channel));
123  assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
124 
125  /* Process locked */
126  __HAL_LOCK(hdac);
127 
128  /* Change DAC state */
129  hdac->State = HAL_DAC_STATE_BUSY;
130 
131  /* Enable the triangle wave generation for the selected DAC channel */
132  MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1) | (DAC_CR_MAMP1)) << (Channel & 0x10UL), (DAC_CR_WAVE1_1 | Amplitude) << (Channel & 0x10UL));
133 
134  /* Change DAC state */
135  hdac->State = HAL_DAC_STATE_READY;
136 
137  /* Process unlocked */
138  __HAL_UNLOCK(hdac);
139 
140  /* Return function status */
141  return HAL_OK;
142 }
__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))