2 ******************************************************************************
\r
3 * @file stm32f7xx_hal_dac.c
\r
4 * @author MCD Application Team
\r
6 * @date 06-March-2015
\r
7 * @brief DAC HAL module driver.
\r
8 * This file provides firmware functions to manage the following
\r
9 * functionalities of the Digital to Analog Converter (DAC) peripheral:
\r
10 * + Initialization and de-initialization functions
\r
11 * + IO operation functions
\r
12 * + Peripheral Control functions
\r
13 * + Peripheral State and Errors functions
\r
17 ==============================================================================
\r
18 ##### DAC Peripheral features #####
\r
19 ==============================================================================
\r
21 *** DAC Channels ***
\r
22 ====================
\r
24 The device integrates two 12-bit Digital Analog Converters that can
\r
25 be used independently or simultaneously (dual mode):
\r
26 (#) DAC channel1 with DAC_OUT1 (PA4) as output
\r
27 (#) DAC channel2 with DAC_OUT2 (PA5) as output
\r
29 *** DAC Triggers ***
\r
30 ====================
\r
32 Digital to Analog conversion can be non-triggered using DAC_TRIGGER_NONE
\r
33 and DAC_OUT1/DAC_OUT2 is available once writing to DHRx register.
\r
35 Digital to Analog conversion can be triggered by:
\r
36 (#) External event: EXTI Line 9 (any GPIOx_Pin9) using DAC_TRIGGER_EXT_IT9.
\r
37 The used pin (GPIOx_Pin9) must be configured in input mode.
\r
39 (#) Timers TRGO: TIM2, TIM4, TIM5, TIM6, TIM7 and TIM8
\r
40 (DAC_TRIGGER_T2_TRGO, DAC_TRIGGER_T4_TRGO...)
\r
42 (#) Software using DAC_TRIGGER_SOFTWARE
\r
44 *** DAC Buffer mode feature ***
\r
45 ===============================
\r
47 Each DAC channel integrates an output buffer that can be used to
\r
48 reduce the output impedance, and to drive external loads directly
\r
49 without having to add an external operational amplifier.
\r
50 To enable, the output buffer use
\r
51 sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
\r
53 (@) Refer to the device datasheet for more details about output
\r
54 impedance value with and without output buffer.
\r
56 *** DAC wave generation feature ***
\r
57 ===================================
\r
59 Both DAC channels can be used to generate
\r
60 (#) Noise wave using HAL_DACEx_NoiseWaveGenerate()
\r
61 (#) Triangle wave using HAL_DACEx_TriangleWaveGenerate()
\r
63 *** DAC data format ***
\r
64 =======================
\r
66 The DAC data format can be:
\r
67 (#) 8-bit right alignment using DAC_ALIGN_8B_R
\r
68 (#) 12-bit left alignment using DAC_ALIGN_12B_L
\r
69 (#) 12-bit right alignment using DAC_ALIGN_12B_R
\r
71 *** DAC data value to voltage correspondence ***
\r
72 ================================================
\r
74 The analog output voltage on each DAC channel pin is determined
\r
75 by the following equation:
\r
76 DAC_OUTx = VREF+ * DOR / 4095
\r
77 with DOR is the Data Output Register
\r
78 VEF+ is the input voltage reference (refer to the device datasheet)
\r
79 e.g. To set DAC_OUT1 to 0.7V, use
\r
80 Assuming that VREF+ = 3.3V, DAC_OUT1 = (3.3 * 868) / 4095 = 0.7V
\r
82 *** DMA requests ***
\r
83 =====================
\r
85 A DMA1 request can be generated when an external trigger (but not
\r
86 a software trigger) occurs if DMA1 requests are enabled using
\r
89 DMA1 requests are mapped as following:
\r
90 (#) DAC channel1 : mapped on DMA1 Stream5 channel7 which must be
\r
92 (#) DAC channel2 : mapped on DMA1 Stream6 channel7 which must be
\r
95 -@- For Dual mode and specific signal (Triangle and noise) generation please
\r
96 refer to Extension Features Driver description
\r
99 ##### How to use this driver #####
\r
100 ==============================================================================
\r
102 (+) DAC APB clock must be enabled to get write access to DAC
\r
103 registers using HAL_DAC_Init()
\r
104 (+) Configure DAC_OUTx (DAC_OUT1: PA4, DAC_OUT2: PA5) in analog mode.
\r
105 (+) Configure the DAC channel using HAL_DAC_ConfigChannel() function.
\r
106 (+) Enable the DAC channel using HAL_DAC_Start() or HAL_DAC_Start_DMA functions
\r
108 *** Polling mode IO operation ***
\r
109 =================================
\r
111 (+) Start the DAC peripheral using HAL_DAC_Start()
\r
112 (+) To read the DAC last data output value, use the HAL_DAC_GetValue() function.
\r
113 (+) Stop the DAC peripheral using HAL_DAC_Stop()
\r
116 *** DMA mode IO operation ***
\r
117 ==============================
\r
119 (+) Start the DAC peripheral using HAL_DAC_Start_DMA(), at this stage the user specify the length
\r
120 of data to be transferred at each end of conversion
\r
121 (+) At The end of data transfer HAL_DAC_ConvCpltCallbackCh1()or HAL_DAC_ConvCpltCallbackCh2()
\r
122 function is executed and user can add his own code by customization of function pointer
\r
123 HAL_DAC_ConvCpltCallbackCh1 or HAL_DAC_ConvCpltCallbackCh2
\r
124 (+) In case of transfer Error, HAL_DAC_ErrorCallbackCh1() function is executed and user can
\r
125 add his own code by customization of function pointer HAL_DAC_ErrorCallbackCh1
\r
126 (+) Stop the DAC peripheral using HAL_DAC_Stop_DMA()
\r
129 *** DAC HAL driver macros list ***
\r
130 =============================================
\r
132 Below the list of most used macros in DAC HAL driver.
\r
134 (+) __HAL_DAC_ENABLE : Enable the DAC peripheral
\r
135 (+) __HAL_DAC_DISABLE : Disable the DAC peripheral
\r
136 (+) __HAL_DAC_CLEAR_FLAG: Clear the DAC's pending flags
\r
137 (+) __HAL_DAC_GET_FLAG: Get the selected DAC's flag status
\r
140 (@) You can refer to the DAC HAL driver header file for more useful macros
\r
143 ******************************************************************************
\r
146 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
\r
148 * Redistribution and use in source and binary forms, with or without modification,
\r
149 * are permitted provided that the following conditions are met:
\r
150 * 1. Redistributions of source code must retain the above copyright notice,
\r
151 * this list of conditions and the following disclaimer.
\r
152 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
153 * this list of conditions and the following disclaimer in the documentation
\r
154 * and/or other materials provided with the distribution.
\r
155 * 3. Neither the name of STMicroelectronics nor the names of its contributors
\r
156 * may be used to endorse or promote products derived from this software
\r
157 * without specific prior written permission.
\r
159 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
160 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
161 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
162 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
\r
163 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
164 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
\r
165 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
\r
166 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
\r
167 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
168 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
170 ******************************************************************************
\r
174 /* Includes ------------------------------------------------------------------*/
\r
175 #include "stm32f7xx_hal.h"
\r
177 /** @addtogroup STM32F7xx_HAL_Driver
\r
181 /** @defgroup DAC DAC
\r
182 * @brief DAC driver modules
\r
186 #ifdef HAL_DAC_MODULE_ENABLED
\r
188 #if defined(STM32F756xx) || defined(STM32F746xx)
\r
189 /* Private typedef -----------------------------------------------------------*/
\r
190 /* Private define ------------------------------------------------------------*/
\r
191 /* Private macro -------------------------------------------------------------*/
\r
192 /* Private variables ---------------------------------------------------------*/
\r
193 /** @addtogroup DAC_Private_Functions
\r
196 /* Private function prototypes -----------------------------------------------*/
\r
197 static void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma);
\r
198 static void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma);
\r
199 static void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma);
\r
204 /* Exported functions --------------------------------------------------------*/
\r
205 /** @defgroup DAC_Exported_Functions DAC Exported Functions
\r
209 /** @defgroup DAC_Exported_Functions_Group1 Initialization and de-initialization functions
\r
210 * @brief Initialization and Configuration functions
\r
213 ==============================================================================
\r
214 ##### Initialization and de-initialization functions #####
\r
215 ==============================================================================
\r
216 [..] This section provides functions allowing to:
\r
217 (+) Initialize and configure the DAC.
\r
218 (+) De-initialize the DAC.
\r
225 * @brief Initializes the DAC peripheral according to the specified parameters
\r
226 * in the DAC_InitStruct.
\r
227 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
\r
228 * the configuration information for the specified DAC.
\r
229 * @retval HAL status
\r
231 HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef* hdac)
\r
233 /* Check DAC handle */
\r
238 /* Check the parameters */
\r
239 assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance));
\r
241 if(hdac->State == HAL_DAC_STATE_RESET)
\r
243 /* Init the low level hardware */
\r
244 HAL_DAC_MspInit(hdac);
\r
247 /* Initialize the DAC state*/
\r
248 hdac->State = HAL_DAC_STATE_BUSY;
\r
250 /* Set DAC error code to none */
\r
251 hdac->ErrorCode = HAL_DAC_ERROR_NONE;
\r
253 /* Initialize the DAC state*/
\r
254 hdac->State = HAL_DAC_STATE_READY;
\r
256 /* Return function status */
\r
261 * @brief Deinitializes the DAC peripheral registers to their default reset values.
\r
262 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
\r
263 * the configuration information for the specified DAC.
\r
264 * @retval HAL status
\r
266 HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef* hdac)
\r
268 /* Check DAC handle */
\r
274 /* Check the parameters */
\r
275 assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance));
\r
277 /* Change DAC state */
\r
278 hdac->State = HAL_DAC_STATE_BUSY;
\r
280 /* DeInit the low level hardware */
\r
281 HAL_DAC_MspDeInit(hdac);
\r
283 /* Set DAC error code to none */
\r
284 hdac->ErrorCode = HAL_DAC_ERROR_NONE;
\r
286 /* Change DAC state */
\r
287 hdac->State = HAL_DAC_STATE_RESET;
\r
290 __HAL_UNLOCK(hdac);
\r
292 /* Return function status */
\r
297 * @brief Initializes the DAC MSP.
\r
298 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
\r
299 * the configuration information for the specified DAC.
\r
302 __weak void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
\r
304 /* NOTE : This function Should not be modified, when the callback is needed,
\r
305 the HAL_DAC_MspInit could be implemented in the user file
\r
310 * @brief DeInitializes the DAC MSP.
\r
311 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
\r
312 * the configuration information for the specified DAC.
\r
315 __weak void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac)
\r
317 /* NOTE : This function Should not be modified, when the callback is needed,
\r
318 the HAL_DAC_MspDeInit could be implemented in the user file
\r
326 /** @defgroup DAC_Exported_Functions_Group2 IO operation functions
\r
327 * @brief IO operation functions
\r
330 ==============================================================================
\r
331 ##### IO operation functions #####
\r
332 ==============================================================================
\r
333 [..] This section provides functions allowing to:
\r
334 (+) Start conversion.
\r
335 (+) Stop conversion.
\r
336 (+) Start conversion and enable DMA transfer.
\r
337 (+) Stop conversion and disable DMA transfer.
\r
338 (+) Get result of conversion.
\r
345 * @brief Enables DAC and starts conversion of channel.
\r
346 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
\r
347 * the configuration information for the specified DAC.
\r
348 * @param Channel: The selected DAC channel.
\r
349 * This parameter can be one of the following values:
\r
350 * @arg DAC_CHANNEL_1: DAC Channel1 selected
\r
351 * @arg DAC_CHANNEL_2: DAC Channel2 selected
\r
352 * @retval HAL status
\r
354 HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel)
\r
356 uint32_t tmp1 = 0, tmp2 = 0;
\r
358 /* Check the parameters */
\r
359 assert_param(IS_DAC_CHANNEL(Channel));
\r
361 /* Process locked */
\r
364 /* Change DAC state */
\r
365 hdac->State = HAL_DAC_STATE_BUSY;
\r
367 /* Enable the Peripheral */
\r
368 __HAL_DAC_ENABLE(hdac, Channel);
\r
370 if(Channel == DAC_CHANNEL_1)
\r
372 tmp1 = hdac->Instance->CR & DAC_CR_TEN1;
\r
373 tmp2 = hdac->Instance->CR & DAC_CR_TSEL1;
\r
374 /* Check if software trigger enabled */
\r
375 if((tmp1 == DAC_CR_TEN1) && (tmp2 == DAC_CR_TSEL1))
\r
377 /* Enable the selected DAC software conversion */
\r
378 hdac->Instance->SWTRIGR |= (uint32_t)DAC_SWTRIGR_SWTRIG1;
\r
383 tmp1 = hdac->Instance->CR & DAC_CR_TEN2;
\r
384 tmp2 = hdac->Instance->CR & DAC_CR_TSEL2;
\r
385 /* Check if software trigger enabled */
\r
386 if((tmp1 == DAC_CR_TEN2) && (tmp2 == DAC_CR_TSEL2))
\r
388 /* Enable the selected DAC software conversion*/
\r
389 hdac->Instance->SWTRIGR |= (uint32_t)DAC_SWTRIGR_SWTRIG2;
\r
393 /* Change DAC state */
\r
394 hdac->State = HAL_DAC_STATE_READY;
\r
396 /* Process unlocked */
\r
397 __HAL_UNLOCK(hdac);
\r
399 /* Return function status */
\r
404 * @brief Disables DAC and stop conversion of channel.
\r
405 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
\r
406 * the configuration information for the specified DAC.
\r
407 * @param Channel: The selected DAC channel.
\r
408 * This parameter can be one of the following values:
\r
409 * @arg DAC_CHANNEL_1: DAC Channel1 selected
\r
410 * @arg DAC_CHANNEL_2: DAC Channel2 selected
\r
411 * @retval HAL status
\r
413 HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef* hdac, uint32_t Channel)
\r
415 /* Check the parameters */
\r
416 assert_param(IS_DAC_CHANNEL(Channel));
\r
418 /* Disable the Peripheral */
\r
419 __HAL_DAC_DISABLE(hdac, Channel);
\r
421 /* Change DAC state */
\r
422 hdac->State = HAL_DAC_STATE_READY;
\r
424 /* Return function status */
\r
429 * @brief Enables DAC and starts conversion of channel.
\r
430 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
\r
431 * the configuration information for the specified DAC.
\r
432 * @param Channel: The selected DAC channel.
\r
433 * This parameter can be one of the following values:
\r
434 * @arg DAC_CHANNEL_1: DAC Channel1 selected
\r
435 * @arg DAC_CHANNEL_2: DAC Channel2 selected
\r
436 * @param pData: The destination peripheral Buffer address.
\r
437 * @param Length: The length of data to be transferred from memory to DAC peripheral
\r
438 * @param Alignment: Specifies the data alignment for DAC channel.
\r
439 * This parameter can be one of the following values:
\r
440 * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
\r
441 * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
\r
442 * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
\r
443 * @retval HAL status
\r
445 HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment)
\r
447 uint32_t tmpreg = 0;
\r
449 /* Check the parameters */
\r
450 assert_param(IS_DAC_CHANNEL(Channel));
\r
451 assert_param(IS_DAC_ALIGN(Alignment));
\r
453 /* Process locked */
\r
456 /* Change DAC state */
\r
457 hdac->State = HAL_DAC_STATE_BUSY;
\r
459 if(Channel == DAC_CHANNEL_1)
\r
461 /* Set the DMA transfer complete callback for channel1 */
\r
462 hdac->DMA_Handle1->XferCpltCallback = DAC_DMAConvCpltCh1;
\r
464 /* Set the DMA half transfer complete callback for channel1 */
\r
465 hdac->DMA_Handle1->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh1;
\r
467 /* Set the DMA error callback for channel1 */
\r
468 hdac->DMA_Handle1->XferErrorCallback = DAC_DMAErrorCh1;
\r
470 /* Enable the selected DAC channel1 DMA request */
\r
471 hdac->Instance->CR |= DAC_CR_DMAEN1;
\r
473 /* Case of use of channel 1 */
\r
476 case DAC_ALIGN_12B_R:
\r
477 /* Get DHR12R1 address */
\r
478 tmpreg = (uint32_t)&hdac->Instance->DHR12R1;
\r
480 case DAC_ALIGN_12B_L:
\r
481 /* Get DHR12L1 address */
\r
482 tmpreg = (uint32_t)&hdac->Instance->DHR12L1;
\r
484 case DAC_ALIGN_8B_R:
\r
485 /* Get DHR8R1 address */
\r
486 tmpreg = (uint32_t)&hdac->Instance->DHR8R1;
\r
494 /* Set the DMA transfer complete callback for channel2 */
\r
495 hdac->DMA_Handle2->XferCpltCallback = DAC_DMAConvCpltCh2;
\r
497 /* Set the DMA half transfer complete callback for channel2 */
\r
498 hdac->DMA_Handle2->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh2;
\r
500 /* Set the DMA error callback for channel2 */
\r
501 hdac->DMA_Handle2->XferErrorCallback = DAC_DMAErrorCh2;
\r
503 /* Enable the selected DAC channel2 DMA request */
\r
504 hdac->Instance->CR |= DAC_CR_DMAEN2;
\r
506 /* Case of use of channel 2 */
\r
509 case DAC_ALIGN_12B_R:
\r
510 /* Get DHR12R2 address */
\r
511 tmpreg = (uint32_t)&hdac->Instance->DHR12R2;
\r
513 case DAC_ALIGN_12B_L:
\r
514 /* Get DHR12L2 address */
\r
515 tmpreg = (uint32_t)&hdac->Instance->DHR12L2;
\r
517 case DAC_ALIGN_8B_R:
\r
518 /* Get DHR8R2 address */
\r
519 tmpreg = (uint32_t)&hdac->Instance->DHR8R2;
\r
526 /* Enable the DMA Stream */
\r
527 if(Channel == DAC_CHANNEL_1)
\r
529 /* Enable the DAC DMA underrun interrupt */
\r
530 __HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR1);
\r
532 /* Enable the DMA Stream */
\r
533 HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length);
\r
537 /* Enable the DAC DMA underrun interrupt */
\r
538 __HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR2);
\r
540 /* Enable the DMA Stream */
\r
541 HAL_DMA_Start_IT(hdac->DMA_Handle2, (uint32_t)pData, tmpreg, Length);
\r
544 /* Enable the Peripheral */
\r
545 __HAL_DAC_ENABLE(hdac, Channel);
\r
547 /* Process Unlocked */
\r
548 __HAL_UNLOCK(hdac);
\r
550 /* Return function status */
\r
555 * @brief Disables DAC and stop conversion of channel.
\r
556 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
\r
557 * the configuration information for the specified DAC.
\r
558 * @param Channel: The selected DAC channel.
\r
559 * This parameter can be one of the following values:
\r
560 * @arg DAC_CHANNEL_1: DAC Channel1 selected
\r
561 * @arg DAC_CHANNEL_2: DAC Channel2 selected
\r
562 * @retval HAL status
\r
564 HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel)
\r
566 HAL_StatusTypeDef status = HAL_OK;
\r
568 /* Check the parameters */
\r
569 assert_param(IS_DAC_CHANNEL(Channel));
\r
571 /* Disable the selected DAC channel DMA request */
\r
572 hdac->Instance->CR &= ~(DAC_CR_DMAEN1 << Channel);
\r
574 /* Disable the Peripheral */
\r
575 __HAL_DAC_DISABLE(hdac, Channel);
\r
577 /* Disable the DMA Channel */
\r
578 /* Channel1 is used */
\r
579 if(Channel == DAC_CHANNEL_1)
\r
581 status = HAL_DMA_Abort(hdac->DMA_Handle1);
\r
583 else /* Channel2 is used for */
\r
585 status = HAL_DMA_Abort(hdac->DMA_Handle2);
\r
588 /* Check if DMA Channel effectively disabled */
\r
589 if(status != HAL_OK)
\r
591 /* Update DAC state machine to error */
\r
592 hdac->State = HAL_DAC_STATE_ERROR;
\r
596 /* Change DAC state */
\r
597 hdac->State = HAL_DAC_STATE_READY;
\r
600 /* Return function status */
\r
605 * @brief Returns the last data output value of the selected DAC channel.
\r
606 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
\r
607 * the configuration information for the specified DAC.
\r
608 * @param Channel: The selected DAC channel.
\r
609 * This parameter can be one of the following values:
\r
610 * @arg DAC_CHANNEL_1: DAC Channel1 selected
\r
611 * @arg DAC_CHANNEL_2: DAC Channel2 selected
\r
612 * @retval The selected DAC channel data output value.
\r
614 uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel)
\r
616 /* Check the parameters */
\r
617 assert_param(IS_DAC_CHANNEL(Channel));
\r
619 /* Returns the DAC channel data output register value */
\r
620 if(Channel == DAC_CHANNEL_1)
\r
622 return hdac->Instance->DOR1;
\r
626 return hdac->Instance->DOR2;
\r
631 * @brief Handles DAC interrupt request
\r
632 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
\r
633 * the configuration information for the specified DAC.
\r
636 void HAL_DAC_IRQHandler(DAC_HandleTypeDef* hdac)
\r
638 /* Check underrun channel 1 flag */
\r
639 if(__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR1))
\r
641 /* Change DAC state to error state */
\r
642 hdac->State = HAL_DAC_STATE_ERROR;
\r
644 /* Set DAC error code to channel1 DMA underrun error */
\r
645 hdac->ErrorCode |= HAL_DAC_ERROR_DMAUNDERRUNCH1;
\r
647 /* Clear the underrun flag */
\r
648 __HAL_DAC_CLEAR_FLAG(hdac,DAC_FLAG_DMAUDR1);
\r
650 /* Disable the selected DAC channel1 DMA request */
\r
651 hdac->Instance->CR &= ~DAC_CR_DMAEN1;
\r
653 /* Error callback */
\r
654 HAL_DAC_DMAUnderrunCallbackCh1(hdac);
\r
656 /* Check underrun channel 2 flag */
\r
657 if(__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR2))
\r
659 /* Change DAC state to error state */
\r
660 hdac->State = HAL_DAC_STATE_ERROR;
\r
662 /* Set DAC error code to channel2 DMA underrun error */
\r
663 hdac->ErrorCode |= HAL_DAC_ERROR_DMAUNDERRUNCH2;
\r
665 /* Clear the underrun flag */
\r
666 __HAL_DAC_CLEAR_FLAG(hdac,DAC_FLAG_DMAUDR2);
\r
668 /* Disable the selected DAC channel1 DMA request */
\r
669 hdac->Instance->CR &= ~DAC_CR_DMAEN2;
\r
671 /* Error callback */
\r
672 HAL_DACEx_DMAUnderrunCallbackCh2(hdac);
\r
677 * @brief Conversion complete callback in non blocking mode for Channel1
\r
678 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
\r
679 * the configuration information for the specified DAC.
\r
682 __weak void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef* hdac)
\r
684 /* NOTE : This function Should not be modified, when the callback is needed,
\r
685 the HAL_DAC_ConvCpltCallback could be implemented in the user file
\r
690 * @brief Conversion half DMA transfer callback in non blocking mode for Channel1
\r
691 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
\r
692 * the configuration information for the specified DAC.
\r
695 __weak void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef* hdac)
\r
697 /* NOTE : This function Should not be modified, when the callback is needed,
\r
698 the HAL_DAC_ConvHalfCpltCallbackCh1 could be implemented in the user file
\r
703 * @brief Error DAC callback for Channel1.
\r
704 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
\r
705 * the configuration information for the specified DAC.
\r
708 __weak void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac)
\r
710 /* NOTE : This function Should not be modified, when the callback is needed,
\r
711 the HAL_DAC_ErrorCallbackCh1 could be implemented in the user file
\r
716 * @brief DMA underrun DAC callback for channel1.
\r
717 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
\r
718 * the configuration information for the specified DAC.
\r
721 __weak void HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef *hdac)
\r
723 /* NOTE : This function Should not be modified, when the callback is needed,
\r
724 the HAL_DAC_DMAUnderrunCallbackCh1 could be implemented in the user file
\r
732 /** @defgroup DAC_Exported_Functions_Group3 Peripheral Control functions
\r
733 * @brief Peripheral Control functions
\r
736 ==============================================================================
\r
737 ##### Peripheral Control functions #####
\r
738 ==============================================================================
\r
739 [..] This section provides functions allowing to:
\r
740 (+) Configure channels.
\r
741 (+) Set the specified data holding register value for DAC channel.
\r
748 * @brief Configures the selected DAC channel.
\r
749 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
\r
750 * the configuration information for the specified DAC.
\r
751 * @param sConfig: DAC configuration structure.
\r
752 * @param Channel: The selected DAC channel.
\r
753 * This parameter can be one of the following values:
\r
754 * @arg DAC_CHANNEL_1: DAC Channel1 selected
\r
755 * @arg DAC_CHANNEL_2: DAC Channel2 selected
\r
756 * @retval HAL status
\r
758 HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel)
\r
760 uint32_t tmpreg1 = 0, tmpreg2 = 0;
\r
762 /* Check the DAC parameters */
\r
763 assert_param(IS_DAC_TRIGGER(sConfig->DAC_Trigger));
\r
764 assert_param(IS_DAC_OUTPUT_BUFFER_STATE(sConfig->DAC_OutputBuffer));
\r
765 assert_param(IS_DAC_CHANNEL(Channel));
\r
767 /* Process locked */
\r
770 /* Change DAC state */
\r
771 hdac->State = HAL_DAC_STATE_BUSY;
\r
773 /* Get the DAC CR value */
\r
774 tmpreg1 = hdac->Instance->CR;
\r
775 /* Clear BOFFx, TENx, TSELx, WAVEx and MAMPx bits */
\r
776 tmpreg1 &= ~(((uint32_t)(DAC_CR_MAMP1 | DAC_CR_WAVE1 | DAC_CR_TSEL1 | DAC_CR_TEN1 | DAC_CR_BOFF1)) << Channel);
\r
777 /* Configure for the selected DAC channel: buffer output, trigger */
\r
778 /* Set TSELx and TENx bits according to DAC_Trigger value */
\r
779 /* Set BOFFx bit according to DAC_OutputBuffer value */
\r
780 tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputBuffer);
\r
781 /* Calculate CR register value depending on DAC_Channel */
\r
782 tmpreg1 |= tmpreg2 << Channel;
\r
783 /* Write to DAC CR */
\r
784 hdac->Instance->CR = tmpreg1;
\r
785 /* Disable wave generation */
\r
786 hdac->Instance->CR &= ~(DAC_CR_WAVE1 << Channel);
\r
788 /* Change DAC state */
\r
789 hdac->State = HAL_DAC_STATE_READY;
\r
791 /* Process unlocked */
\r
792 __HAL_UNLOCK(hdac);
\r
794 /* Return function status */
\r
799 * @brief Set the specified data holding register value for DAC channel.
\r
800 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
\r
801 * the configuration information for the specified DAC.
\r
802 * @param Channel: The selected DAC channel.
\r
803 * This parameter can be one of the following values:
\r
804 * @arg DAC_CHANNEL_1: DAC Channel1 selected
\r
805 * @arg DAC_CHANNEL_2: DAC Channel2 selected
\r
806 * @param Alignment: Specifies the data alignment.
\r
807 * This parameter can be one of the following values:
\r
808 * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
\r
809 * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
\r
810 * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
\r
811 * @param Data: Data to be loaded in the selected data holding register.
\r
812 * @retval HAL status
\r
814 HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data)
\r
816 __IO uint32_t tmp = 0;
\r
818 /* Check the parameters */
\r
819 assert_param(IS_DAC_CHANNEL(Channel));
\r
820 assert_param(IS_DAC_ALIGN(Alignment));
\r
821 assert_param(IS_DAC_DATA(Data));
\r
823 tmp = (uint32_t)hdac->Instance;
\r
824 if(Channel == DAC_CHANNEL_1)
\r
826 tmp += DAC_DHR12R1_ALIGNMENT(Alignment);
\r
830 tmp += DAC_DHR12R2_ALIGNMENT(Alignment);
\r
833 /* Set the DAC channel1 selected data holding register */
\r
834 *(__IO uint32_t *) tmp = Data;
\r
836 /* Return function status */
\r
844 /** @defgroup DAC_Exported_Functions_Group4 Peripheral State and Errors functions
\r
845 * @brief Peripheral State and Errors functions
\r
848 ==============================================================================
\r
849 ##### Peripheral State and Errors functions #####
\r
850 ==============================================================================
\r
852 This subsection provides functions allowing to
\r
853 (+) Check the DAC state.
\r
854 (+) Check the DAC Errors.
\r
861 * @brief return the DAC state
\r
862 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
\r
863 * the configuration information for the specified DAC.
\r
864 * @retval HAL state
\r
866 HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef* hdac)
\r
868 /* Return DAC state */
\r
869 return hdac->State;
\r
874 * @brief Return the DAC error code
\r
875 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
\r
876 * the configuration information for the specified DAC.
\r
877 * @retval DAC Error Code
\r
879 uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac)
\r
881 return hdac->ErrorCode;
\r
889 * @brief DMA conversion complete callback.
\r
890 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
\r
891 * the configuration information for the specified DMA module.
\r
894 static void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma)
\r
896 DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
898 HAL_DAC_ConvCpltCallbackCh1(hdac);
\r
900 hdac->State= HAL_DAC_STATE_READY;
\r
904 * @brief DMA half transfer complete callback.
\r
905 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
\r
906 * the configuration information for the specified DMA module.
\r
909 static void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma)
\r
911 DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
912 /* Conversion complete callback */
\r
913 HAL_DAC_ConvHalfCpltCallbackCh1(hdac);
\r
917 * @brief DMA error callback
\r
918 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
\r
919 * the configuration information for the specified DMA module.
\r
922 static void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma)
\r
924 DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
926 /* Set DAC error code to DMA error */
\r
927 hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
\r
929 HAL_DAC_ErrorCallbackCh1(hdac);
\r
931 hdac->State= HAL_DAC_STATE_READY;
\r
937 #endif /* STM32F756xx || STM32F746xx */
\r
938 #endif /* HAL_DAC_MODULE_ENABLED */
\r
948 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r