1 /**
2 ******************************************************************************
3 * @file stm32l4xx_hal_dac_ex.c
4 * @author MCD Application Team
5 * @brief DAC HAL module driver.
6 * This file provides firmware functions to manage the extended
7 * functionalities of the DAC peripheral.
8 *
9 *
10 ******************************************************************************
11 * @attention
12 *
13 * Copyright (c) 2017 STMicroelectronics.
14 * All rights reserved.
15 *
16 * This software is licensed under terms that can be found in the LICENSE file
17 * in the root directory of this software component.
18 * If no LICENSE file comes with this software, it is provided AS-IS.
19 *
20 ******************************************************************************
21 @verbatim
22 ==============================================================================
23 ##### How to use this driver #####
24 ==============================================================================
25 [..]
26 *** Dual mode IO operation ***
27 ==============================
28 (+) When Dual mode is enabled (i.e. DAC Channel1 and Channel2 are used simultaneously) :
29 Use HAL_DACEx_DualGetValue() to get digital data to be converted and use
30 HAL_DACEx_DualSetValue() to set digital value to converted simultaneously in
31 Channel 1 and Channel 2.
32
33 *** Signal generation operation ***
34 ===================================
35 (+) Use HAL_DACEx_TriangleWaveGenerate() to generate Triangle signal.
36 (+) Use HAL_DACEx_NoiseWaveGenerate() to generate Noise signal.
37
38 (+) HAL_DACEx_SelfCalibrate to calibrate one DAC channel.
39 (+) HAL_DACEx_SetUserTrimming to set user trimming value.
40 (+) HAL_DACEx_GetTrimOffset to retrieve trimming value (factory setting
41 after reset, user setting if HAL_DACEx_SetUserTrimming have been used
42 at least one time after reset).
43
44 @endverbatim
45 ******************************************************************************
46 */
47
48
49 /* Includes ------------------------------------------------------------------*/
50 #include "stm32l4xx_hal.h"
51
52 /** @addtogroup STM32L4xx_HAL_Driver
53 * @{
54 */
55
56 #ifdef HAL_DAC_MODULE_ENABLED
57
58 #if defined(DAC1)
59
60 /** @defgroup DACEx DACEx
61 * @brief DAC Extended HAL module driver
62 * @{
63 */
64
65 /* Private typedef -----------------------------------------------------------*/
66 /* Private define ------------------------------------------------------------*/
67 /* Private macro -------------------------------------------------------------*/
68 /* Private variables ---------------------------------------------------------*/
69 /* Private function prototypes -----------------------------------------------*/
70 /* Exported functions --------------------------------------------------------*/
71
72 /** @defgroup DACEx_Exported_Functions DACEx Exported Functions
73 * @{
74 */
75
76 /** @defgroup DACEx_Exported_Functions_Group2 IO operation functions
77 * @brief Extended IO operation functions
78 *
79 @verbatim
80 ==============================================================================
81 ##### Extended features functions #####
82 ==============================================================================
83 [..] This section provides functions allowing to:
84 (+) Start conversion.
85 (+) Stop conversion.
86 (+) Start conversion and enable DMA transfer.
87 (+) Stop conversion and disable DMA transfer.
88 (+) Get result of conversion.
89 (+) Get result of dual mode conversion.
90
91 @endverbatim
92 * @{
93 */
94
95 /**
96 * @brief Enable or disable the selected DAC channel wave generation.
97 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
98 * the configuration information for the specified DAC.
99 * @param Channel The selected DAC channel.
100 * This parameter can be one of the following values:
101 * @arg DAC_CHANNEL_1: DAC Channel1 selected
102 * @arg DAC_CHANNEL_2: DAC Channel2 selected
103 * @param Amplitude Select max triangle amplitude.
104 * This parameter can be one of the following values:
105 * @arg DAC_TRIANGLEAMPLITUDE_1: Select max triangle amplitude of 1
106 * @arg DAC_TRIANGLEAMPLITUDE_3: Select max triangle amplitude of 3
107 * @arg DAC_TRIANGLEAMPLITUDE_7: Select max triangle amplitude of 7
108 * @arg DAC_TRIANGLEAMPLITUDE_15: Select max triangle amplitude of 15
109 * @arg DAC_TRIANGLEAMPLITUDE_31: Select max triangle amplitude of 31
110 * @arg DAC_TRIANGLEAMPLITUDE_63: Select max triangle amplitude of 63
111 * @arg DAC_TRIANGLEAMPLITUDE_127: Select max triangle amplitude of 127
112 * @arg DAC_TRIANGLEAMPLITUDE_255: Select max triangle amplitude of 255
113 * @arg DAC_TRIANGLEAMPLITUDE_511: Select max triangle amplitude of 511
114 * @arg DAC_TRIANGLEAMPLITUDE_1023: Select max triangle amplitude of 1023
115 * @arg DAC_TRIANGLEAMPLITUDE_2047: Select max triangle amplitude of 2047
116 * @arg DAC_TRIANGLEAMPLITUDE_4095: Select max triangle amplitude of 4095
117 * @retval HAL status
118 */
HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef * hdac,uint32_t Channel,uint32_t Amplitude)119 HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude)
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 }
143
144 /**
145 * @brief Enable or disable the selected DAC channel wave generation.
146 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
147 * the configuration information for the specified DAC.
148 * @param Channel The selected DAC channel.
149 * This parameter can be one of the following values:
150 * @arg DAC_CHANNEL_1: DAC Channel1 selected
151 * @arg DAC_CHANNEL_2: DAC Channel2 selected
152 * @param Amplitude Unmask DAC channel LFSR for noise wave generation.
153 * This parameter can be one of the following values:
154 * @arg DAC_LFSRUNMASK_BIT0: Unmask DAC channel LFSR bit0 for noise wave generation
155 * @arg DAC_LFSRUNMASK_BITS1_0: Unmask DAC channel LFSR bit[1:0] for noise wave generation
156 * @arg DAC_LFSRUNMASK_BITS2_0: Unmask DAC channel LFSR bit[2:0] for noise wave generation
157 * @arg DAC_LFSRUNMASK_BITS3_0: Unmask DAC channel LFSR bit[3:0] for noise wave generation
158 * @arg DAC_LFSRUNMASK_BITS4_0: Unmask DAC channel LFSR bit[4:0] for noise wave generation
159 * @arg DAC_LFSRUNMASK_BITS5_0: Unmask DAC channel LFSR bit[5:0] for noise wave generation
160 * @arg DAC_LFSRUNMASK_BITS6_0: Unmask DAC channel LFSR bit[6:0] for noise wave generation
161 * @arg DAC_LFSRUNMASK_BITS7_0: Unmask DAC channel LFSR bit[7:0] for noise wave generation
162 * @arg DAC_LFSRUNMASK_BITS8_0: Unmask DAC channel LFSR bit[8:0] for noise wave generation
163 * @arg DAC_LFSRUNMASK_BITS9_0: Unmask DAC channel LFSR bit[9:0] for noise wave generation
164 * @arg DAC_LFSRUNMASK_BITS10_0: Unmask DAC channel LFSR bit[10:0] for noise wave generation
165 * @arg DAC_LFSRUNMASK_BITS11_0: Unmask DAC channel LFSR bit[11:0] for noise wave generation
166 * @retval HAL status
167 */
HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef * hdac,uint32_t Channel,uint32_t Amplitude)168 HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude)
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 }
192
193 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \
194 defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx) || \
195 defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \
196 defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx)
197
198 /**
199 * @brief Set the specified data holding register value for dual DAC channel.
200 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
201 * the configuration information for the specified DAC.
202 * @param Alignment Specifies the data alignment for dual channel DAC.
203 * This parameter can be one of the following values:
204 * DAC_ALIGN_8B_R: 8bit right data alignment selected
205 * DAC_ALIGN_12B_L: 12bit left data alignment selected
206 * DAC_ALIGN_12B_R: 12bit right data alignment selected
207 * @param Data1 Data for DAC Channel1 to be loaded in the selected data holding register.
208 * @param Data2 Data for DAC Channel2 to be loaded in the selected data holding register.
209 * @note In dual mode, a unique register access is required to write in both
210 * DAC channels at the same time.
211 * @retval HAL status
212 */
HAL_DACEx_DualSetValue(DAC_HandleTypeDef * hdac,uint32_t Alignment,uint32_t Data1,uint32_t Data2)213 HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef *hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2)
214 {
215 uint32_t data;
216 uint32_t tmp;
217
218 /* Check the parameters */
219 assert_param(IS_DAC_ALIGN(Alignment));
220 assert_param(IS_DAC_DATA(Data1));
221 assert_param(IS_DAC_DATA(Data2));
222
223 /* Calculate and set dual DAC data holding register value */
224 if (Alignment == DAC_ALIGN_8B_R)
225 {
226 data = ((uint32_t)Data2 << 8U) | Data1;
227 }
228 else
229 {
230 data = ((uint32_t)Data2 << 16U) | Data1;
231 }
232
233 tmp = (uint32_t)hdac->Instance;
234 tmp += DAC_DHR12RD_ALIGNMENT(Alignment);
235
236 /* Set the dual DAC selected data holding register */
237 *(__IO uint32_t *)tmp = data;
238
239 /* Return function status */
240 return HAL_OK;
241 }
242
243 /**
244 * @brief Conversion complete callback in non-blocking mode for Channel2.
245 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
246 * the configuration information for the specified DAC.
247 * @retval None
248 */
HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef * hdac)249 __weak void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef *hdac)
250 {
251 /* Prevent unused argument(s) compilation warning */
252 UNUSED(hdac);
253
254 /* NOTE : This function should not be modified, when the callback is needed,
255 the HAL_DACEx_ConvCpltCallbackCh2 could be implemented in the user file
256 */
257 }
258
259 /**
260 * @brief Conversion half DMA transfer callback in non-blocking mode for Channel2.
261 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
262 * the configuration information for the specified DAC.
263 * @retval None
264 */
HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef * hdac)265 __weak void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef *hdac)
266 {
267 /* Prevent unused argument(s) compilation warning */
268 UNUSED(hdac);
269
270 /* NOTE : This function should not be modified, when the callback is needed,
271 the HAL_DACEx_ConvHalfCpltCallbackCh2 could be implemented in the user file
272 */
273 }
274
275 /**
276 * @brief Error DAC callback for Channel2.
277 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
278 * the configuration information for the specified DAC.
279 * @retval None
280 */
HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef * hdac)281 __weak void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef *hdac)
282 {
283 /* Prevent unused argument(s) compilation warning */
284 UNUSED(hdac);
285
286 /* NOTE : This function should not be modified, when the callback is needed,
287 the HAL_DACEx_ErrorCallbackCh2 could be implemented in the user file
288 */
289 }
290
291 /**
292 * @brief DMA underrun DAC callback for Channel2.
293 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
294 * the configuration information for the specified DAC.
295 * @retval None
296 */
HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef * hdac)297 __weak void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef *hdac)
298 {
299 /* Prevent unused argument(s) compilation warning */
300 UNUSED(hdac);
301
302 /* NOTE : This function should not be modified, when the callback is needed,
303 the HAL_DACEx_DMAUnderrunCallbackCh2 could be implemented in the user file
304 */
305 }
306 #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */
307 /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */
308 /* STM32L4P5xx STM32L4Q5xx */
309 /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */
310
311 /**
312 * @brief Run the self calibration of one DAC channel.
313 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
314 * the configuration information for the specified DAC.
315 * @param sConfig DAC channel configuration structure.
316 * @param Channel The selected DAC channel.
317 * This parameter can be one of the following values:
318 * @arg DAC_CHANNEL_1: DAC Channel1 selected
319 * @arg DAC_CHANNEL_2: DAC Channel2 selected
320 * @retval Updates DAC_TrimmingValue. , DAC_UserTrimming set to DAC_UserTrimming
321 * @retval HAL status
322 * @note Calibration runs about 7 ms.
323 */
324
HAL_DACEx_SelfCalibrate(DAC_HandleTypeDef * hdac,DAC_ChannelConfTypeDef * sConfig,uint32_t Channel)325 HAL_StatusTypeDef HAL_DACEx_SelfCalibrate(DAC_HandleTypeDef *hdac, DAC_ChannelConfTypeDef *sConfig, uint32_t Channel)
326 {
327 HAL_StatusTypeDef status = HAL_OK;
328
329 __IO uint32_t tmp;
330 uint32_t trimmingvalue;
331 uint32_t delta;
332
333 /* store/restore channel configuration structure purpose */
334 uint32_t oldmodeconfiguration;
335
336 /* Check the parameters */
337 assert_param(IS_DAC_CHANNEL(Channel));
338
339 /* Check the DAC handle allocation */
340 /* Check if DAC running */
341 if (hdac == NULL)
342 {
343 status = HAL_ERROR;
344 }
345 else if (hdac->State == HAL_DAC_STATE_BUSY)
346 {
347 status = HAL_ERROR;
348 }
349 else
350 {
351 /* Process locked */
352 __HAL_LOCK(hdac);
353
354 /* Store configuration */
355 oldmodeconfiguration = (hdac->Instance->MCR & (DAC_MCR_MODE1 << (Channel & 0x10UL)));
356
357 /* Disable the selected DAC channel */
358 CLEAR_BIT((hdac->Instance->CR), (DAC_CR_EN1 << (Channel & 0x10UL)));
359
360 /* Set mode in MCR for calibration */
361 MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << (Channel & 0x10UL)), 0U);
362
363 /* Set DAC Channel1 DHR register to the middle value */
364 tmp = (uint32_t)hdac->Instance;
365
366 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \
367 defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx) || \
368 defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \
369 defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx)
370 if(Channel == DAC_CHANNEL_1)
371 {
372 tmp += DAC_DHR12R1_ALIGNMENT(DAC_ALIGN_12B_R);
373 }
374 else
375 {
376 tmp += DAC_DHR12R2_ALIGNMENT(DAC_ALIGN_12B_R);
377 }
378 #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */
379 /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */
380 /* STM32L4P5xx STM32L4Q5xx */
381 /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */
382 #if defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx)
383 tmp += DAC_DHR12R1_ALIGNMENT(DAC_ALIGN_12B_R);
384 #endif /* STM32L451xx STM32L452xx STM32L462xx */
385 *(__IO uint32_t *) tmp = 0x0800U;
386
387 /* Enable the selected DAC channel calibration */
388 /* i.e. set DAC_CR_CENx bit */
389 SET_BIT((hdac->Instance->CR), (DAC_CR_CEN1 << (Channel & 0x10UL)));
390
391 /* Init trimming counter */
392 /* Medium value */
393 trimmingvalue = 16U;
394 delta = 8U;
395 while (delta != 0U)
396 {
397 /* Set candidate trimming */
398 MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1 << (Channel & 0x10UL)), (trimmingvalue << (Channel & 0x10UL)));
399
400 /* tOFFTRIMmax delay x ms as per datasheet (electrical characteristics */
401 /* i.e. minimum time needed between two calibration steps */
402 HAL_Delay(1);
403
404 if ((hdac->Instance->SR & (DAC_SR_CAL_FLAG1 << (Channel & 0x10UL))) == (DAC_SR_CAL_FLAG1 << (Channel & 0x10UL)))
405 {
406 /* DAC_SR_CAL_FLAGx is HIGH try higher trimming */
407 trimmingvalue -= delta;
408 }
409 else
410 {
411 /* DAC_SR_CAL_FLAGx is LOW try lower trimming */
412 trimmingvalue += delta;
413 }
414 delta >>= 1U;
415 }
416
417 /* Still need to check if right calibration is current value or one step below */
418 /* Indeed the first value that causes the DAC_SR_CAL_FLAGx bit to change from 0 to 1 */
419 /* Set candidate trimming */
420 MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1 << (Channel & 0x10UL)), (trimmingvalue << (Channel & 0x10UL)));
421
422 /* tOFFTRIMmax delay x ms as per datasheet (electrical characteristics */
423 /* i.e. minimum time needed between two calibration steps */
424 HAL_Delay(1U);
425
426 if ((hdac->Instance->SR & (DAC_SR_CAL_FLAG1 << (Channel & 0x10UL))) == 0UL)
427 {
428 /* Check trimming value below maximum */
429 if (trimmingvalue < 0x1FU)
430 {
431 /* Trimming is actually one value more */
432 trimmingvalue++;
433
434 /* Set right trimming */
435 MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1 << (Channel & 0x10UL)), (trimmingvalue << (Channel & 0x10UL)));
436 }
437 }
438
439 /* Disable the selected DAC channel calibration */
440 /* i.e. clear DAC_CR_CENx bit */
441 CLEAR_BIT((hdac->Instance->CR), (DAC_CR_CEN1 << (Channel & 0x10UL)));
442
443 sConfig->DAC_TrimmingValue = trimmingvalue;
444 sConfig->DAC_UserTrimming = DAC_TRIMMING_USER;
445
446 /* Restore configuration */
447 MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << (Channel & 0x10UL)), oldmodeconfiguration);
448
449 /* Process unlocked */
450 __HAL_UNLOCK(hdac);
451 }
452
453 return status;
454 }
455
456 /**
457 * @brief Set the trimming mode and trimming value (user trimming mode applied).
458 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
459 * the configuration information for the specified DAC.
460 * @param sConfig DAC configuration structure updated with new DAC trimming value.
461 * @param Channel The selected DAC channel.
462 * This parameter can be one of the following values:
463 * @arg DAC_CHANNEL_1: DAC Channel1 selected
464 * @arg DAC_CHANNEL_2: DAC Channel2 selected
465 * @param NewTrimmingValue DAC new trimming value
466 * @retval HAL status
467 */
468
HAL_DACEx_SetUserTrimming(DAC_HandleTypeDef * hdac,DAC_ChannelConfTypeDef * sConfig,uint32_t Channel,uint32_t NewTrimmingValue)469 HAL_StatusTypeDef HAL_DACEx_SetUserTrimming(DAC_HandleTypeDef *hdac, DAC_ChannelConfTypeDef *sConfig, uint32_t Channel,
470 uint32_t NewTrimmingValue)
471 {
472 HAL_StatusTypeDef status = HAL_OK;
473
474 /* Check the parameters */
475 assert_param(IS_DAC_CHANNEL(Channel));
476 assert_param(IS_DAC_NEWTRIMMINGVALUE(NewTrimmingValue));
477
478 /* Check the DAC handle allocation */
479 if (hdac == NULL)
480 {
481 status = HAL_ERROR;
482 }
483 else
484 {
485 /* Process locked */
486 __HAL_LOCK(hdac);
487
488 /* Set new trimming */
489 MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1 << (Channel & 0x10UL)), (NewTrimmingValue << (Channel & 0x10UL)));
490
491 /* Update trimming mode */
492 sConfig->DAC_UserTrimming = DAC_TRIMMING_USER;
493 sConfig->DAC_TrimmingValue = NewTrimmingValue;
494
495 /* Process unlocked */
496 __HAL_UNLOCK(hdac);
497 }
498 return status;
499 }
500
501 /**
502 * @brief Return the DAC trimming value.
503 * @param hdac DAC handle
504 * @param Channel The selected DAC channel.
505 * This parameter can be one of the following values:
506 * @arg DAC_CHANNEL_1: DAC Channel1 selected
507 * @arg DAC_CHANNEL_2: DAC Channel2 selected
508 * @retval Trimming value : range: 0->31
509 *
510 */
511
HAL_DACEx_GetTrimOffset(DAC_HandleTypeDef * hdac,uint32_t Channel)512 uint32_t HAL_DACEx_GetTrimOffset(DAC_HandleTypeDef *hdac, uint32_t Channel)
513 {
514 /* Check the parameter */
515 assert_param(IS_DAC_CHANNEL(Channel));
516
517 /* Retrieve trimming */
518 return ((hdac->Instance->CCR & (DAC_CCR_OTRIM1 << (Channel & 0x10UL))) >> (Channel & 0x10UL));
519 }
520
521 /**
522 * @}
523 */
524
525 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \
526 defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx) || \
527 defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \
528 defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx)
529
530 /** @defgroup DACEx_Exported_Functions_Group3 Peripheral Control functions
531 * @brief Extended Peripheral Control functions
532 *
533 @verbatim
534 ==============================================================================
535 ##### Peripheral Control functions #####
536 ==============================================================================
537 [..] This section provides functions allowing to:
538 (+) Set the specified data holding register value for DAC channel.
539
540 @endverbatim
541 * @{
542 */
543
544 /**
545 * @brief Return the last data output value of the selected DAC channel.
546 * @param hdac pointer to a DAC_HandleTypeDef structure that contains
547 * the configuration information for the specified DAC.
548 * @retval The selected DAC channel data output value.
549 */
HAL_DACEx_DualGetValue(DAC_HandleTypeDef * hdac)550 uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef *hdac)
551 {
552 uint32_t tmp = 0U;
553
554 tmp |= hdac->Instance->DOR1;
555
556 tmp |= hdac->Instance->DOR2 << 16U;
557
558 /* Returns the DAC channel data output register value */
559 return tmp;
560 }
561
562 /**
563 * @}
564 */
565
566 #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */
567 /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */
568 /* STM32L4P5xx STM32L4Q5xx */
569 /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */
570
571 /**
572 * @}
573 */
574
575 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \
576 defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx) || \
577 defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \
578 defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx)
579
580 /* Private functions ---------------------------------------------------------*/
581 /** @defgroup DACEx_Private_Functions DACEx private functions
582 * @brief Extended private functions
583 * @{
584 */
585
586 /**
587 * @brief DMA conversion complete callback.
588 * @param hdma pointer to a DMA_HandleTypeDef structure that contains
589 * the configuration information for the specified DMA module.
590 * @retval None
591 */
DAC_DMAConvCpltCh2(DMA_HandleTypeDef * hdma)592 void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma)
593 {
594 DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
595
596 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
597 hdac->ConvCpltCallbackCh2(hdac);
598 #else
599 HAL_DACEx_ConvCpltCallbackCh2(hdac);
600 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
601
602 hdac->State = HAL_DAC_STATE_READY;
603 }
604
605 /**
606 * @brief DMA half transfer complete callback.
607 * @param hdma pointer to a DMA_HandleTypeDef structure that contains
608 * the configuration information for the specified DMA module.
609 * @retval None
610 */
DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef * hdma)611 void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma)
612 {
613 DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
614 /* Conversion complete callback */
615 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
616 hdac->ConvHalfCpltCallbackCh2(hdac);
617 #else
618 HAL_DACEx_ConvHalfCpltCallbackCh2(hdac);
619 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
620 }
621
622 /**
623 * @brief DMA error callback.
624 * @param hdma pointer to a DMA_HandleTypeDef structure that contains
625 * the configuration information for the specified DMA module.
626 * @retval None
627 */
DAC_DMAErrorCh2(DMA_HandleTypeDef * hdma)628 void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma)
629 {
630 DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
631
632 /* Set DAC error code to DMA error */
633 hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
634
635 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
636 hdac->ErrorCallbackCh2(hdac);
637 #else
638 HAL_DACEx_ErrorCallbackCh2(hdac);
639 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
640
641 hdac->State = HAL_DAC_STATE_READY;
642 }
643
644 /**
645 * @}
646 */
647 #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */
648 /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */
649 /* STM32L4P5xx STM32L4Q5xx */
650 /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */
651
652 /**
653 * @}
654 */
655
656 #endif /* DAC1 */
657
658 #endif /* HAL_DAC_MODULE_ENABLED */
659
660 /**
661 * @}
662 */
663
664