STM32L443xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_hal_dac.c 00004 * @author MCD Application Team 00005 * @brief DAC HAL module driver. 00006 * This file provides firmware functions to manage the following 00007 * functionalities of the Digital to Analog Converter (DAC) peripheral: 00008 * + Initialization and de-initialization functions 00009 * + Peripheral Control functions 00010 * + Peripheral State and Errors functions 00011 * 00012 * 00013 ****************************************************************************** 00014 * @attention 00015 * 00016 * Copyright (c) 2017 STMicroelectronics. 00017 * All rights reserved. 00018 * 00019 * This software is licensed under terms that can be found in the LICENSE file 00020 * in the root directory of this software component. 00021 * If no LICENSE file comes with this software, it is provided AS-IS. 00022 * 00023 ****************************************************************************** 00024 @verbatim 00025 ============================================================================== 00026 ##### DAC Peripheral features ##### 00027 ============================================================================== 00028 [..] 00029 *** DAC Channels *** 00030 ==================== 00031 [..] 00032 STM32L4 devices integrate one or two 12-bit Digital Analog Converters 00033 (i.e. one or 2 channel(s)) 00034 1 channel : STM32L451xx STM32L452xx STM32L462xx 00035 2 channels: STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx 00036 STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx 00037 STM32L4P5xx STM32L4Q5xx 00038 STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx 00039 00040 When 2 channels are available, the 2 converters (i.e. channel1 & channel2) 00041 can be used independently or simultaneously (dual mode): 00042 (#) DAC channel1 with DAC_OUT1 (PA4) as output or connected to on-chip 00043 peripherals. 00044 (#) Whenever present, DAC channel2 with DAC_OUT2 (PA5) as output 00045 or connected to on-chip peripherals. 00046 00047 *** DAC Triggers *** 00048 ==================== 00049 [..] 00050 Digital to Analog conversion can be non-triggered using DAC_TRIGGER_NONE 00051 and DAC_OUT1/DAC_OUT2 is available once writing to DHRx register. 00052 [..] 00053 Digital to Analog conversion can be triggered by: 00054 (#) External event: EXTI Line 9 (any GPIOx_PIN_9) using DAC_TRIGGER_EXT_IT9. 00055 The used pin (GPIOx_PIN_9) must be configured in input mode. 00056 00057 (#) Timers TRGO: TIM2, TIM3, TIM4, TIM5, TIM6 and TIM7 00058 (DAC_TRIGGER_T2_TRGO, DAC_TRIGGER_T3_TRGO...) 00059 00060 (#) Software using DAC_TRIGGER_SOFTWARE 00061 00062 *** DAC Buffer mode feature *** 00063 =============================== 00064 [..] 00065 Each DAC channel integrates an output buffer that can be used to 00066 reduce the output impedance, and to drive external loads directly 00067 without having to add an external operational amplifier. 00068 To enable, the output buffer use 00069 sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE; 00070 [..] 00071 (@) Refer to the device datasheet for more details about output 00072 impedance value with and without output buffer. 00073 00074 *** DAC connect feature *** 00075 =============================== 00076 [..] 00077 Each DAC channel can be connected internally. 00078 To connect, use 00079 sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_ENABLE; 00080 00081 *** GPIO configurations guidelines *** 00082 ===================== 00083 [..] 00084 When a DAC channel is used (ex channel1 on PA4) and the other is not 00085 (ex channel2 on PA5 is configured in Analog and disabled). 00086 Channel1 may disturb channel2 as coupling effect. 00087 Note that there is no coupling on channel2 as soon as channel2 is turned on. 00088 Coupling on adjacent channel could be avoided as follows: 00089 when unused PA5 is configured as INPUT PULL-UP or DOWN. 00090 PA5 is configured in ANALOG just before it is turned on. 00091 00092 *** DAC Sample and Hold feature *** 00093 ======================== 00094 [..] 00095 For each converter, 2 modes are supported: normal mode and 00096 "sample and hold" mode (i.e. low power mode). 00097 In the sample and hold mode, the DAC core converts data, then holds the 00098 converted voltage on a capacitor. When not converting, the DAC cores and 00099 buffer are completely turned off between samples and the DAC output is 00100 tri-stated, therefore reducing the overall power consumption. A new 00101 stabilization period is needed before each new conversion. 00102 00103 The sample and hold allow setting internal or external voltage @ 00104 low power consumption cost (output value can be at any given rate either 00105 by CPU or DMA). 00106 00107 The Sample and hold block and registers uses either LSI & run in 00108 several power modes: run mode, sleep mode, low power run, low power sleep 00109 mode & stop1 mode. 00110 00111 Low power stop1 mode allows only static conversion. 00112 00113 To enable Sample and Hold mode 00114 Enable LSI using HAL_RCC_OscConfig with RCC_OSCILLATORTYPE_LSI & 00115 RCC_LSI_ON parameters. 00116 00117 Use DAC_InitStructure.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_ENABLE; 00118 & DAC_ChannelConfTypeDef.DAC_SampleAndHoldConfig.DAC_SampleTime, 00119 DAC_HoldTime & DAC_RefreshTime; 00120 00121 *** DAC calibration feature *** 00122 =================================== 00123 [..] 00124 (#) The 2 converters (channel1 & channel2) provide calibration capabilities. 00125 (++) Calibration aims at correcting some offset of output buffer. 00126 (++) The DAC uses either factory calibration settings OR user defined 00127 calibration (trimming) settings (i.e. trimming mode). 00128 (++) The user defined settings can be figured out using self calibration 00129 handled by HAL_DACEx_SelfCalibrate. 00130 (++) HAL_DACEx_SelfCalibrate: 00131 (+++) Runs automatically the calibration. 00132 (+++) Enables the user trimming mode 00133 (+++) Updates a structure with trimming values with fresh calibration 00134 results. 00135 The user may store the calibration results for larger 00136 (ex monitoring the trimming as a function of temperature 00137 for instance) 00138 00139 *** DAC wave generation feature *** 00140 =================================== 00141 [..] 00142 Both DAC channels can be used to generate 00143 (#) Noise wave 00144 (#) Triangle wave 00145 00146 *** DAC data format *** 00147 ======================= 00148 [..] 00149 The DAC data format can be: 00150 (#) 8-bit right alignment using DAC_ALIGN_8B_R 00151 (#) 12-bit left alignment using DAC_ALIGN_12B_L 00152 (#) 12-bit right alignment using DAC_ALIGN_12B_R 00153 00154 *** DAC data value to voltage correspondence *** 00155 ================================================ 00156 [..] 00157 The analog output voltage on each DAC channel pin is determined 00158 by the following equation: 00159 [..] 00160 DAC_OUTx = VREF+ * DOR / 4095 00161 (+) with DOR is the Data Output Register 00162 [..] 00163 VEF+ is the input voltage reference (refer to the device datasheet) 00164 [..] 00165 e.g. To set DAC_OUT1 to 0.7V, use 00166 (+) Assuming that VREF+ = 3.3V, DAC_OUT1 = (3.3 * 868) / 4095 = 0.7V 00167 00168 *** DMA requests *** 00169 ===================== 00170 [..] 00171 A DMA1 request can be generated when an external trigger (but not a software trigger) 00172 occurs if DMA1 requests are enabled using HAL_DAC_Start_DMA(). 00173 DMA requests are mapped as following: 00174 (#) When DMAMUX is NOT present: 00175 DMA1 requests are mapped as following: 00176 (+) DAC channel1 mapped on DMA1 request 6 / channel3 00177 (+) DAC channel2 mapped on DMA1 request 5 / channel4 00178 DMA2 requests are mapped as following: 00179 (+) DAC channel1 mapped on DMA2 request 3 / channel4 00180 (+) DAC channel2 mapped on DMA2 request 3 / channel5 00181 (#) When DMAMUX is present: 00182 (+) DAC channel1 mapped on DMA1/DMA2 request 6 (can be any DMA channel) 00183 (+) DAC channel2 mapped on DMA1/DMA2 request 7 (can be any DMA channel) 00184 00185 *** High frequency interface mode *** 00186 ===================================== 00187 [..] 00188 The high frequency interface informs DAC instance about the bus frequency in use. 00189 It is mandatory information for DAC (as internal timing of DAC is bus frequency dependent) 00190 provided thanks to parameter DAC_HighFrequency handled in HAL_DAC_ConfigChannel () function. 00191 Use of DAC_HIGH_FREQUENCY_INTERFACE_MODE_AUTOMATIC value of DAC_HighFrequency is recommended 00192 function figured out the correct setting. 00193 The high frequency mode is same for all converters of a same DAC instance. Either same 00194 parameter DAC_HighFrequency is used for all DAC converters or again self 00195 DAC_HIGH_FREQUENCY_INTERFACE_MODE_AUTOMATIC detection parameter. 00196 00197 [..] 00198 (@) For Dual mode and specific signal (Triangle and noise) generation please 00199 refer to Extended Features Driver description 00200 00201 ##### How to use this driver ##### 00202 ============================================================================== 00203 [..] 00204 (+) DAC APB clock must be enabled to get write access to DAC 00205 registers using HAL_DAC_Init() 00206 (+) Configure DAC_OUTx (DAC_OUT1: PA4, DAC_OUT2: PA5) in analog mode. 00207 (+) Configure the DAC channel using HAL_DAC_ConfigChannel() function. 00208 (+) Enable the DAC channel using HAL_DAC_Start() or HAL_DAC_Start_DMA() functions. 00209 00210 *** Calibration mode IO operation *** 00211 ====================================== 00212 [..] 00213 (+) Retrieve the factory trimming (calibration settings) using HAL_DACEx_GetTrimOffset() 00214 (+) Run the calibration using HAL_DACEx_SelfCalibrate() 00215 (+) Update the trimming while DAC running using HAL_DACEx_SetUserTrimming() 00216 00217 *** Polling mode IO operation *** 00218 ================================= 00219 [..] 00220 (+) Start the DAC peripheral using HAL_DAC_Start() 00221 (+) To read the DAC last data output value, use the HAL_DAC_GetValue() function. 00222 (+) Stop the DAC peripheral using HAL_DAC_Stop() 00223 00224 *** DMA mode IO operation *** 00225 ============================== 00226 [..] 00227 (+) Start the DAC peripheral using HAL_DAC_Start_DMA(), at this stage the user specify the length 00228 of data to be transferred at each end of conversion 00229 First issued trigger will start the conversion of the value previously set by HAL_DAC_SetValue(). 00230 (+) At the middle of data transfer HAL_DAC_ConvHalfCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2() 00231 function is executed and user can add his own code by customization of function pointer 00232 HAL_DAC_ConvHalfCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2() 00233 (+) At The end of data transfer HAL_DAC_ConvCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2() 00234 function is executed and user can add his own code by customization of function pointer 00235 HAL_DAC_ConvCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2() 00236 (+) In case of transfer Error, HAL_DAC_ErrorCallbackCh1() function is executed and user can 00237 add his own code by customization of function pointer HAL_DAC_ErrorCallbackCh1 00238 (+) In case of DMA underrun, DAC interruption triggers and execute internal function HAL_DAC_IRQHandler. 00239 HAL_DAC_DMAUnderrunCallbackCh1() or HAL_DACEx_DMAUnderrunCallbackCh2() 00240 function is executed and user can add his own code by customization of function pointer 00241 HAL_DAC_DMAUnderrunCallbackCh1() or HAL_DACEx_DMAUnderrunCallbackCh2() and 00242 add his own code by customization of function pointer HAL_DAC_ErrorCallbackCh1() 00243 (+) Stop the DAC peripheral using HAL_DAC_Stop_DMA() 00244 00245 *** Callback registration *** 00246 ============================================= 00247 [..] 00248 The compilation define USE_HAL_DAC_REGISTER_CALLBACKS when set to 1 00249 allows the user to configure dynamically the driver callbacks. 00250 00251 Use Functions HAL_DAC_RegisterCallback() to register a user callback, 00252 it allows to register following callbacks: 00253 (+) ConvCpltCallbackCh1 : callback when a half transfer is completed on Ch1. 00254 (+) ConvHalfCpltCallbackCh1 : callback when a transfer is completed on Ch1. 00255 (+) ErrorCallbackCh1 : callback when an error occurs on Ch1. 00256 (+) DMAUnderrunCallbackCh1 : callback when an underrun error occurs on Ch1. 00257 (+) ConvCpltCallbackCh2 : callback when a half transfer is completed on Ch2. 00258 (+) ConvHalfCpltCallbackCh2 : callback when a transfer is completed on Ch2. 00259 (+) ErrorCallbackCh2 : callback when an error occurs on Ch2. 00260 (+) DMAUnderrunCallbackCh2 : callback when an underrun error occurs on Ch2. 00261 (+) MspInitCallback : DAC MspInit. 00262 (+) MspDeInitCallback : DAC MspdeInit. 00263 This function takes as parameters the HAL peripheral handle, the Callback ID 00264 and a pointer to the user callback function. 00265 00266 Use function HAL_DAC_UnRegisterCallback() to reset a callback to the default 00267 weak (surcharged) function. It allows to reset following callbacks: 00268 (+) ConvCpltCallbackCh1 : callback when a half transfer is completed on Ch1. 00269 (+) ConvHalfCpltCallbackCh1 : callback when a transfer is completed on Ch1. 00270 (+) ErrorCallbackCh1 : callback when an error occurs on Ch1. 00271 (+) DMAUnderrunCallbackCh1 : callback when an underrun error occurs on Ch1. 00272 (+) ConvCpltCallbackCh2 : callback when a half transfer is completed on Ch2. 00273 (+) ConvHalfCpltCallbackCh2 : callback when a transfer is completed on Ch2. 00274 (+) ErrorCallbackCh2 : callback when an error occurs on Ch2. 00275 (+) DMAUnderrunCallbackCh2 : callback when an underrun error occurs on Ch2. 00276 (+) MspInitCallback : DAC MspInit. 00277 (+) MspDeInitCallback : DAC MspdeInit. 00278 (+) All Callbacks 00279 This function) takes as parameters the HAL peripheral handle and the Callback ID. 00280 00281 By default, after the HAL_DAC_Init and if the state is HAL_DAC_STATE_RESET 00282 all callbacks are reset to the corresponding legacy weak (surcharged) functions. 00283 Exception done for MspInit and MspDeInit callbacks that are respectively 00284 reset to the legacy weak (surcharged) functions in the HAL_DAC_Init 00285 and HAL_DAC_DeInit only when these callbacks are null (not registered beforehand). 00286 If not, MspInit or MspDeInit are not null, the HAL_DAC_Init and HAL_DAC_DeInit 00287 keep and use the user MspInit/MspDeInit callbacks (registered beforehand) 00288 00289 Callbacks can be registered/unregistered in READY state only. 00290 Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered 00291 in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used 00292 during the Init/DeInit. 00293 In that case first register the MspInit/MspDeInit user callbacks 00294 using HAL_DAC_RegisterCallback before calling HAL_DAC_DeInit 00295 or HAL_DAC_Init function. 00296 00297 When The compilation define USE_HAL_DAC_REGISTER_CALLBACKS is set to 0 or 00298 not defined, the callback registering feature is not available 00299 and weak (surcharged) callbacks are used. 00300 00301 *** DAC HAL driver macros list *** 00302 ============================================= 00303 [..] 00304 Below the list of most used macros in DAC HAL driver. 00305 00306 (+) __HAL_DAC_ENABLE : Enable the DAC peripheral 00307 (+) __HAL_DAC_DISABLE : Disable the DAC peripheral 00308 (+) __HAL_DAC_CLEAR_FLAG: Clear the DAC's pending flags 00309 (+) __HAL_DAC_GET_FLAG: Get the selected DAC's flag status 00310 00311 [..] 00312 (@) You can refer to the DAC HAL driver header file for more useful macros 00313 00314 @endverbatim 00315 ****************************************************************************** 00316 */ 00317 00318 /* Includes ------------------------------------------------------------------*/ 00319 #include "stm32l4xx_hal.h" 00320 00321 /** @addtogroup STM32L4xx_HAL_Driver 00322 * @{ 00323 */ 00324 00325 #ifdef HAL_DAC_MODULE_ENABLED 00326 #if defined(DAC1) 00327 00328 /** @defgroup DAC DAC 00329 * @brief DAC driver modules 00330 * @{ 00331 */ 00332 00333 /* Private typedef -----------------------------------------------------------*/ 00334 /* Private define ------------------------------------------------------------*/ 00335 /* Private constants ---------------------------------------------------------*/ 00336 /** @addtogroup DAC_Private_Constants DAC Private Constants 00337 * @{ 00338 */ 00339 #define TIMEOUT_DAC_CALIBCONFIG 1U /* 1 ms */ 00340 #define HFSEL_ENABLE_THRESHOLD_80MHZ 80000000U /* 80 MHz */ 00341 00342 /** 00343 * @} 00344 */ 00345 00346 /* Private macro -------------------------------------------------------------*/ 00347 /* Private variables ---------------------------------------------------------*/ 00348 /* Private function prototypes -----------------------------------------------*/ 00349 /* Exported functions -------------------------------------------------------*/ 00350 00351 /** @defgroup DAC_Exported_Functions DAC Exported Functions 00352 * @{ 00353 */ 00354 00355 /** @defgroup DAC_Exported_Functions_Group1 Initialization and de-initialization functions 00356 * @brief Initialization and Configuration functions 00357 * 00358 @verbatim 00359 ============================================================================== 00360 ##### Initialization and de-initialization functions ##### 00361 ============================================================================== 00362 [..] This section provides functions allowing to: 00363 (+) Initialize and configure the DAC. 00364 (+) De-initialize the DAC. 00365 00366 @endverbatim 00367 * @{ 00368 */ 00369 00370 /** 00371 * @brief Initialize the DAC peripheral according to the specified parameters 00372 * in the DAC_InitStruct and initialize the associated handle. 00373 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00374 * the configuration information for the specified DAC. 00375 * @retval HAL status 00376 */ 00377 HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef *hdac) 00378 { 00379 /* Check DAC handle */ 00380 if (hdac == NULL) 00381 { 00382 return HAL_ERROR; 00383 } 00384 /* Check the parameters */ 00385 assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance)); 00386 00387 if (hdac->State == HAL_DAC_STATE_RESET) 00388 { 00389 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) 00390 /* Init the DAC Callback settings */ 00391 hdac->ConvCpltCallbackCh1 = HAL_DAC_ConvCpltCallbackCh1; 00392 hdac->ConvHalfCpltCallbackCh1 = HAL_DAC_ConvHalfCpltCallbackCh1; 00393 hdac->ErrorCallbackCh1 = HAL_DAC_ErrorCallbackCh1; 00394 hdac->DMAUnderrunCallbackCh1 = HAL_DAC_DMAUnderrunCallbackCh1; 00395 00396 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \ 00397 defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx) || \ 00398 defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \ 00399 defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx) 00400 hdac->ConvCpltCallbackCh2 = HAL_DACEx_ConvCpltCallbackCh2; 00401 hdac->ConvHalfCpltCallbackCh2 = HAL_DACEx_ConvHalfCpltCallbackCh2; 00402 hdac->ErrorCallbackCh2 = HAL_DACEx_ErrorCallbackCh2; 00403 hdac->DMAUnderrunCallbackCh2 = HAL_DACEx_DMAUnderrunCallbackCh2; 00404 #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */ 00405 /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */ 00406 /* STM32L4P5xx STM32L4Q5xx */ 00407 /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */ 00408 00409 if (hdac->MspInitCallback == NULL) 00410 { 00411 hdac->MspInitCallback = HAL_DAC_MspInit; 00412 } 00413 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ 00414 00415 /* Allocate lock resource and initialize it */ 00416 hdac->Lock = HAL_UNLOCKED; 00417 00418 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) 00419 /* Init the low level hardware */ 00420 hdac->MspInitCallback(hdac); 00421 #else 00422 /* Init the low level hardware */ 00423 HAL_DAC_MspInit(hdac); 00424 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ 00425 } 00426 00427 /* Initialize the DAC state*/ 00428 hdac->State = HAL_DAC_STATE_BUSY; 00429 00430 /* Set DAC error code to none */ 00431 hdac->ErrorCode = HAL_DAC_ERROR_NONE; 00432 00433 /* Initialize the DAC state*/ 00434 hdac->State = HAL_DAC_STATE_READY; 00435 00436 /* Return function status */ 00437 return HAL_OK; 00438 } 00439 00440 /** 00441 * @brief Deinitialize the DAC peripheral registers to their default reset values. 00442 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00443 * the configuration information for the specified DAC. 00444 * @retval HAL status 00445 */ 00446 HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef *hdac) 00447 { 00448 /* Check DAC handle */ 00449 if (hdac == NULL) 00450 { 00451 return HAL_ERROR; 00452 } 00453 00454 /* Check the parameters */ 00455 assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance)); 00456 00457 /* Change DAC state */ 00458 hdac->State = HAL_DAC_STATE_BUSY; 00459 00460 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) 00461 if (hdac->MspDeInitCallback == NULL) 00462 { 00463 hdac->MspDeInitCallback = HAL_DAC_MspDeInit; 00464 } 00465 /* DeInit the low level hardware */ 00466 hdac->MspDeInitCallback(hdac); 00467 #else 00468 /* DeInit the low level hardware */ 00469 HAL_DAC_MspDeInit(hdac); 00470 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ 00471 00472 /* Set DAC error code to none */ 00473 hdac->ErrorCode = HAL_DAC_ERROR_NONE; 00474 00475 /* Change DAC state */ 00476 hdac->State = HAL_DAC_STATE_RESET; 00477 00478 /* Release Lock */ 00479 __HAL_UNLOCK(hdac); 00480 00481 /* Return function status */ 00482 return HAL_OK; 00483 } 00484 00485 /** 00486 * @brief Initialize the DAC MSP. 00487 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00488 * the configuration information for the specified DAC. 00489 * @retval None 00490 */ 00491 __weak void HAL_DAC_MspInit(DAC_HandleTypeDef *hdac) 00492 { 00493 /* Prevent unused argument(s) compilation warning */ 00494 UNUSED(hdac); 00495 00496 /* NOTE : This function should not be modified, when the callback is needed, 00497 the HAL_DAC_MspInit could be implemented in the user file 00498 */ 00499 } 00500 00501 /** 00502 * @brief DeInitialize the DAC MSP. 00503 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00504 * the configuration information for the specified DAC. 00505 * @retval None 00506 */ 00507 __weak void HAL_DAC_MspDeInit(DAC_HandleTypeDef *hdac) 00508 { 00509 /* Prevent unused argument(s) compilation warning */ 00510 UNUSED(hdac); 00511 00512 /* NOTE : This function should not be modified, when the callback is needed, 00513 the HAL_DAC_MspDeInit could be implemented in the user file 00514 */ 00515 } 00516 00517 /** 00518 * @} 00519 */ 00520 00521 /** @defgroup DAC_Exported_Functions_Group2 IO operation functions 00522 * @brief IO operation functions 00523 * 00524 @verbatim 00525 ============================================================================== 00526 ##### IO operation functions ##### 00527 ============================================================================== 00528 [..] This section provides functions allowing to: 00529 (+) Start conversion. 00530 (+) Stop conversion. 00531 (+) Start conversion and enable DMA transfer. 00532 (+) Stop conversion and disable DMA transfer. 00533 (+) Get result of conversion. 00534 00535 @endverbatim 00536 * @{ 00537 */ 00538 00539 /** 00540 * @brief Enables DAC and starts conversion of channel. 00541 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00542 * the configuration information for the specified DAC. 00543 * @param Channel The selected DAC channel. 00544 * This parameter can be one of the following values: 00545 * @arg DAC_CHANNEL_1: DAC Channel1 selected 00546 * @arg DAC_CHANNEL_2: DAC Channel2 selected (when supported) 00547 * @retval HAL status 00548 */ 00549 HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef *hdac, uint32_t Channel) 00550 { 00551 /* Check the parameters */ 00552 assert_param(IS_DAC_CHANNEL(Channel)); 00553 00554 /* Process locked */ 00555 __HAL_LOCK(hdac); 00556 00557 /* Change DAC state */ 00558 hdac->State = HAL_DAC_STATE_BUSY; 00559 00560 /* Enable the Peripheral */ 00561 __HAL_DAC_ENABLE(hdac, Channel); 00562 00563 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx) 00564 if (Channel == DAC_CHANNEL_1) 00565 { 00566 /* Check if software trigger enabled */ 00567 if ((hdac->Instance->CR & (DAC_CR_TEN1 | DAC_CR_TSEL1)) == DAC_TRIGGER_SOFTWARE) 00568 { 00569 /* Enable the selected DAC software conversion */ 00570 SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG1); 00571 } 00572 } 00573 else 00574 { 00575 /* Check if software trigger enabled */ 00576 if ((hdac->Instance->CR & (DAC_CR_TEN2 | DAC_CR_TSEL2)) == (DAC_TRIGGER_SOFTWARE << (Channel & 0x10UL))) 00577 { 00578 /* Enable the selected DAC software conversion*/ 00579 SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG2); 00580 } 00581 } 00582 00583 #endif /* STM32L4P5xx STM32L4Q5xx STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */ 00584 00585 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \ 00586 defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx) 00587 if(Channel == DAC_CHANNEL_1) 00588 { 00589 /* Check if software trigger enabled */ 00590 if ((hdac->Instance->CR & (DAC_CR_TEN1 | DAC_CR_TSEL1)) == DAC_CR_TEN1) 00591 { 00592 /* Enable the selected DAC software conversion */ 00593 SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG1); 00594 } 00595 } 00596 else 00597 { 00598 /* Check if software trigger enabled */ 00599 if ((hdac->Instance->CR & (DAC_CR_TEN2 | DAC_CR_TSEL2)) == DAC_CR_TEN2) 00600 { 00601 /* Enable the selected DAC software conversion*/ 00602 SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG2); 00603 } 00604 } 00605 #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */ 00606 /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */ 00607 00608 00609 #if defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) 00610 /* Check if software trigger enabled */ 00611 if((hdac->Instance->CR & (DAC_CR_TEN1 | DAC_CR_TSEL1)) == (DAC_CR_TEN1 | DAC_CR_TSEL1)) 00612 { 00613 /* Enable the selected DAC software conversion */ 00614 SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG1); 00615 } 00616 #endif /* STM32L451xx STM32L452xx STM32L462xx */ 00617 /* Change DAC state */ 00618 hdac->State = HAL_DAC_STATE_READY; 00619 00620 /* Process unlocked */ 00621 __HAL_UNLOCK(hdac); 00622 00623 /* Return function status */ 00624 return HAL_OK; 00625 } 00626 00627 /** 00628 * @brief Disables DAC and stop conversion of channel. 00629 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00630 * the configuration information for the specified DAC. 00631 * @param Channel The selected DAC channel. 00632 * This parameter can be one of the following values: 00633 * @arg DAC_CHANNEL_1: DAC Channel1 selected 00634 * @arg DAC_CHANNEL_2: DAC Channel2 selected 00635 * @retval HAL status 00636 */ 00637 HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef *hdac, uint32_t Channel) 00638 { 00639 /* Check the parameters */ 00640 assert_param(IS_DAC_CHANNEL(Channel)); 00641 00642 /* Disable the Peripheral */ 00643 __HAL_DAC_DISABLE(hdac, Channel); 00644 00645 /* Change DAC state */ 00646 hdac->State = HAL_DAC_STATE_READY; 00647 00648 /* Return function status */ 00649 return HAL_OK; 00650 } 00651 00652 #if defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) 00653 /** 00654 * @brief Enables DAC and starts conversion of channel. 00655 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00656 * the configuration information for the specified DAC. 00657 * @param Channel The selected DAC channel. 00658 * This parameter can be one of the following values: 00659 * @arg DAC_CHANNEL_1: DAC Channel1 selected 00660 * @param pData The destination peripheral Buffer address. 00661 * @param Length The length of data to be transferred from memory to DAC peripheral 00662 * @param Alignment Specifies the data alignment for DAC channel. 00663 * This parameter can be one of the following values: 00664 * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected 00665 * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected 00666 * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected 00667 * @retval HAL status 00668 */ 00669 HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t *pData, uint32_t Length, 00670 uint32_t Alignment) 00671 { 00672 HAL_StatusTypeDef status; 00673 uint32_t tmpreg = 0U; 00674 00675 /* Check the parameters */ 00676 assert_param(IS_DAC_CHANNEL(Channel)); 00677 assert_param(IS_DAC_ALIGN(Alignment)); 00678 00679 /* Process locked */ 00680 __HAL_LOCK(hdac); 00681 00682 /* Change DAC state */ 00683 hdac->State = HAL_DAC_STATE_BUSY; 00684 00685 /* Set the DMA transfer complete callback for channel1 */ 00686 hdac->DMA_Handle1->XferCpltCallback = DAC_DMAConvCpltCh1; 00687 00688 /* Set the DMA half transfer complete callback for channel1 */ 00689 hdac->DMA_Handle1->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh1; 00690 00691 /* Set the DMA error callback for channel1 */ 00692 hdac->DMA_Handle1->XferErrorCallback = DAC_DMAErrorCh1; 00693 00694 /* Enable the selected DAC channel1 DMA request */ 00695 SET_BIT(hdac->Instance->CR, DAC_CR_DMAEN1); 00696 00697 /* Case of use of channel 1 */ 00698 switch (Alignment) 00699 { 00700 case DAC_ALIGN_12B_R: 00701 /* Get DHR12R1 address */ 00702 tmpreg = (uint32_t)&hdac->Instance->DHR12R1; 00703 break; 00704 case DAC_ALIGN_12B_L: 00705 /* Get DHR12L1 address */ 00706 tmpreg = (uint32_t)&hdac->Instance->DHR12L1; 00707 break; 00708 case DAC_ALIGN_8B_R: 00709 /* Get DHR8R1 address */ 00710 tmpreg = (uint32_t)&hdac->Instance->DHR8R1; 00711 break; 00712 default: 00713 break; 00714 } 00715 00716 /* Enable the DMA channel */ 00717 /* Enable the DAC DMA underrun interrupt */ 00718 __HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR1); 00719 00720 /* Enable the DMA channel */ 00721 status = HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length); 00722 00723 /* Process Unlocked */ 00724 __HAL_UNLOCK(hdac); 00725 00726 if (status == HAL_OK) 00727 { 00728 /* Enable the Peripheral */ 00729 __HAL_DAC_ENABLE(hdac, Channel); 00730 } 00731 else 00732 { 00733 hdac->ErrorCode |= HAL_DAC_ERROR_DMA; 00734 } 00735 00736 /* Return function status */ 00737 return status; 00738 } 00739 #endif /* STM32L451xx STM32L452xx STM32L462xx */ 00740 00741 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \ 00742 defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx) || \ 00743 defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \ 00744 defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx) 00745 00746 /** 00747 * @brief Enables DAC and starts conversion of channel. 00748 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00749 * the configuration information for the specified DAC. 00750 * @param Channel The selected DAC channel. 00751 * This parameter can be one of the following values: 00752 * @arg DAC_CHANNEL_1: DAC Channel1 selected 00753 * @arg DAC_CHANNEL_2: DAC Channel2 selected 00754 * @param pData The destination peripheral Buffer address. 00755 * @param Length The length of data to be transferred from memory to DAC peripheral 00756 * @param Alignment Specifies the data alignment for DAC channel. 00757 * This parameter can be one of the following values: 00758 * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected 00759 * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected 00760 * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected 00761 * @retval HAL status 00762 */ 00763 HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t *pData, uint32_t Length, 00764 uint32_t Alignment) 00765 { 00766 HAL_StatusTypeDef status; 00767 uint32_t tmpreg = 0U; 00768 00769 /* Check the parameters */ 00770 assert_param(IS_DAC_CHANNEL(Channel)); 00771 assert_param(IS_DAC_ALIGN(Alignment)); 00772 00773 /* Process locked */ 00774 __HAL_LOCK(hdac); 00775 00776 /* Change DAC state */ 00777 hdac->State = HAL_DAC_STATE_BUSY; 00778 00779 if (Channel == DAC_CHANNEL_1) 00780 { 00781 /* Set the DMA transfer complete callback for channel1 */ 00782 hdac->DMA_Handle1->XferCpltCallback = DAC_DMAConvCpltCh1; 00783 00784 /* Set the DMA half transfer complete callback for channel1 */ 00785 hdac->DMA_Handle1->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh1; 00786 00787 /* Set the DMA error callback for channel1 */ 00788 hdac->DMA_Handle1->XferErrorCallback = DAC_DMAErrorCh1; 00789 00790 /* Enable the selected DAC channel1 DMA request */ 00791 SET_BIT(hdac->Instance->CR, DAC_CR_DMAEN1); 00792 00793 /* Case of use of channel 1 */ 00794 switch (Alignment) 00795 { 00796 case DAC_ALIGN_12B_R: 00797 /* Get DHR12R1 address */ 00798 tmpreg = (uint32_t)&hdac->Instance->DHR12R1; 00799 break; 00800 case DAC_ALIGN_12B_L: 00801 /* Get DHR12L1 address */ 00802 tmpreg = (uint32_t)&hdac->Instance->DHR12L1; 00803 break; 00804 case DAC_ALIGN_8B_R: 00805 /* Get DHR8R1 address */ 00806 tmpreg = (uint32_t)&hdac->Instance->DHR8R1; 00807 break; 00808 default: 00809 break; 00810 } 00811 } 00812 else 00813 { 00814 /* Set the DMA transfer complete callback for channel2 */ 00815 hdac->DMA_Handle2->XferCpltCallback = DAC_DMAConvCpltCh2; 00816 00817 /* Set the DMA half transfer complete callback for channel2 */ 00818 hdac->DMA_Handle2->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh2; 00819 00820 /* Set the DMA error callback for channel2 */ 00821 hdac->DMA_Handle2->XferErrorCallback = DAC_DMAErrorCh2; 00822 00823 /* Enable the selected DAC channel2 DMA request */ 00824 SET_BIT(hdac->Instance->CR, DAC_CR_DMAEN2); 00825 00826 /* Case of use of channel 2 */ 00827 switch (Alignment) 00828 { 00829 case DAC_ALIGN_12B_R: 00830 /* Get DHR12R2 address */ 00831 tmpreg = (uint32_t)&hdac->Instance->DHR12R2; 00832 break; 00833 case DAC_ALIGN_12B_L: 00834 /* Get DHR12L2 address */ 00835 tmpreg = (uint32_t)&hdac->Instance->DHR12L2; 00836 break; 00837 case DAC_ALIGN_8B_R: 00838 /* Get DHR8R2 address */ 00839 tmpreg = (uint32_t)&hdac->Instance->DHR8R2; 00840 break; 00841 default: 00842 break; 00843 } 00844 } 00845 00846 /* Enable the DMA channel */ 00847 if (Channel == DAC_CHANNEL_1) 00848 { 00849 /* Enable the DAC DMA underrun interrupt */ 00850 __HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR1); 00851 00852 /* Enable the DMA channel */ 00853 status = HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length); 00854 } 00855 else 00856 { 00857 /* Enable the DAC DMA underrun interrupt */ 00858 __HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR2); 00859 00860 /* Enable the DMA channel */ 00861 status = HAL_DMA_Start_IT(hdac->DMA_Handle2, (uint32_t)pData, tmpreg, Length); 00862 } 00863 00864 /* Process Unlocked */ 00865 __HAL_UNLOCK(hdac); 00866 00867 if (status == HAL_OK) 00868 { 00869 /* Enable the Peripheral */ 00870 __HAL_DAC_ENABLE(hdac, Channel); 00871 } 00872 else 00873 { 00874 hdac->ErrorCode |= HAL_DAC_ERROR_DMA; 00875 } 00876 00877 /* Return function status */ 00878 return status; 00879 } 00880 #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */ 00881 /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */ 00882 /* STM32L4P5xx STM32L4Q5xx */ 00883 /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */ 00884 00885 /** 00886 * @brief Disables DAC and stop conversion of channel. 00887 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00888 * the configuration information for the specified DAC. 00889 * @param Channel The selected DAC channel. 00890 * This parameter can be one of the following values: 00891 * @arg DAC_CHANNEL_1: DAC Channel1 selected 00892 * @arg DAC_CHANNEL_2: DAC Channel2 selected 00893 * @retval HAL status 00894 */ 00895 HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef *hdac, uint32_t Channel) 00896 { 00897 /* Check the parameters */ 00898 assert_param(IS_DAC_CHANNEL(Channel)); 00899 00900 /* Disable the selected DAC channel DMA request */ 00901 hdac->Instance->CR &= ~(DAC_CR_DMAEN1 << (Channel & 0x10UL)); 00902 00903 /* Disable the Peripheral */ 00904 __HAL_DAC_DISABLE(hdac, Channel); 00905 00906 /* Disable the DMA channel */ 00907 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \ 00908 defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx) || \ 00909 defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \ 00910 defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx) 00911 /* Channel1 is used */ 00912 if (Channel == DAC_CHANNEL_1) 00913 { 00914 /* Disable the DMA channel */ 00915 (void)HAL_DMA_Abort(hdac->DMA_Handle1); 00916 00917 /* Disable the DAC DMA underrun interrupt */ 00918 __HAL_DAC_DISABLE_IT(hdac, DAC_IT_DMAUDR1); 00919 } 00920 else /* Channel2 is used for */ 00921 { 00922 /* Disable the DMA channel */ 00923 (void)HAL_DMA_Abort(hdac->DMA_Handle2); 00924 00925 /* Disable the DAC DMA underrun interrupt */ 00926 __HAL_DAC_DISABLE_IT(hdac, DAC_IT_DMAUDR2); 00927 } 00928 #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */ 00929 /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */ 00930 /* STM32L4P5xx STM32L4Q5xx */ 00931 /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */ 00932 00933 #if defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) 00934 /* Disable the DMA channel */ 00935 (void)HAL_DMA_Abort(hdac->DMA_Handle1); 00936 00937 /* Disable the DAC DMA underrun interrupt */ 00938 __HAL_DAC_DISABLE_IT(hdac, DAC_IT_DMAUDR1); 00939 #endif /* STM32L451xx STM32L452xx STM32L462xx */ 00940 00941 /* Return function status */ 00942 return HAL_OK; 00943 } 00944 00945 /* DAC channel 2 is available on top of DAC channel 1 in */ 00946 /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */ 00947 /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */ 00948 00949 /** 00950 * @brief Handles DAC interrupt request 00951 * This function uses the interruption of DMA 00952 * underrun. 00953 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00954 * the configuration information for the specified DAC. 00955 * @retval None 00956 */ 00957 void HAL_DAC_IRQHandler(DAC_HandleTypeDef *hdac) 00958 { 00959 if (__HAL_DAC_GET_IT_SOURCE(hdac, DAC_IT_DMAUDR1)) 00960 { 00961 /* Check underrun flag of DAC channel 1 */ 00962 if (__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR1)) 00963 { 00964 /* Change DAC state to error state */ 00965 hdac->State = HAL_DAC_STATE_ERROR; 00966 00967 /* Set DAC error code to chanel1 DMA underrun error */ 00968 SET_BIT(hdac->ErrorCode, HAL_DAC_ERROR_DMAUNDERRUNCH1); 00969 00970 /* Clear the underrun flag */ 00971 __HAL_DAC_CLEAR_FLAG(hdac, DAC_FLAG_DMAUDR1); 00972 00973 /* Disable the selected DAC channel1 DMA request */ 00974 CLEAR_BIT(hdac->Instance->CR, DAC_CR_DMAEN1); 00975 00976 /* Error callback */ 00977 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) 00978 hdac->DMAUnderrunCallbackCh1(hdac); 00979 #else 00980 HAL_DAC_DMAUnderrunCallbackCh1(hdac); 00981 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ 00982 } 00983 } 00984 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \ 00985 defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx) || \ 00986 defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \ 00987 defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx) 00988 if(__HAL_DAC_GET_IT_SOURCE(hdac, DAC_IT_DMAUDR2)) 00989 { 00990 /* Check underrun flag of DAC channel 2 */ 00991 if (__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR2)) 00992 { 00993 /* Change DAC state to error state */ 00994 hdac->State = HAL_DAC_STATE_ERROR; 00995 00996 /* Set DAC error code to channel2 DMA underrun error */ 00997 SET_BIT(hdac->ErrorCode, HAL_DAC_ERROR_DMAUNDERRUNCH2); 00998 00999 /* Clear the underrun flag */ 01000 __HAL_DAC_CLEAR_FLAG(hdac, DAC_FLAG_DMAUDR2); 01001 01002 /* Disable the selected DAC channel2 DMA request */ 01003 CLEAR_BIT(hdac->Instance->CR, DAC_CR_DMAEN2); 01004 01005 /* Error callback */ 01006 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) 01007 hdac->DMAUnderrunCallbackCh2(hdac); 01008 #else 01009 HAL_DACEx_DMAUnderrunCallbackCh2(hdac); 01010 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ 01011 } 01012 } 01013 #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */ 01014 /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */ 01015 /* STM32L4P5xx STM32L4Q5xx */ 01016 /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */ 01017 } 01018 01019 /** 01020 * @brief Set the specified data holding register value for DAC channel. 01021 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 01022 * the configuration information for the specified DAC. 01023 * @param Channel The selected DAC channel. 01024 * This parameter can be one of the following values: 01025 * @arg DAC_CHANNEL_1: DAC Channel1 selected 01026 * @arg DAC_CHANNEL_2: DAC Channel2 selected 01027 * @param Alignment Specifies the data alignment. 01028 * This parameter can be one of the following values: 01029 * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected 01030 * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected 01031 * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected 01032 * @param Data Data to be loaded in the selected data holding register. 01033 * @retval HAL status 01034 */ 01035 HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data) 01036 { 01037 __IO uint32_t tmp = 0; 01038 01039 /* Check the parameters */ 01040 assert_param(IS_DAC_CHANNEL(Channel)); 01041 assert_param(IS_DAC_ALIGN(Alignment)); 01042 assert_param(IS_DAC_DATA(Data)); 01043 01044 tmp = (uint32_t)hdac->Instance; 01045 if (Channel == DAC_CHANNEL_1) 01046 { 01047 tmp += DAC_DHR12R1_ALIGNMENT(Alignment); 01048 } 01049 else 01050 { 01051 tmp += DAC_DHR12R2_ALIGNMENT(Alignment); 01052 } 01053 01054 /* Set the DAC channel selected data holding register */ 01055 *(__IO uint32_t *) tmp = Data; 01056 01057 /* Return function status */ 01058 return HAL_OK; 01059 } 01060 01061 /** 01062 * @brief Conversion complete callback in non-blocking mode for Channel1 01063 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 01064 * the configuration information for the specified DAC. 01065 * @retval None 01066 */ 01067 __weak void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef *hdac) 01068 { 01069 /* Prevent unused argument(s) compilation warning */ 01070 UNUSED(hdac); 01071 01072 /* NOTE : This function should not be modified, when the callback is needed, 01073 the HAL_DAC_ConvCpltCallbackCh1 could be implemented in the user file 01074 */ 01075 } 01076 01077 /** 01078 * @brief Conversion half DMA transfer callback in non-blocking mode for Channel1 01079 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 01080 * the configuration information for the specified DAC. 01081 * @retval None 01082 */ 01083 __weak void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef *hdac) 01084 { 01085 /* Prevent unused argument(s) compilation warning */ 01086 UNUSED(hdac); 01087 01088 /* NOTE : This function should not be modified, when the callback is needed, 01089 the HAL_DAC_ConvHalfCpltCallbackCh1 could be implemented in the user file 01090 */ 01091 } 01092 01093 /** 01094 * @brief Error DAC callback for Channel1. 01095 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 01096 * the configuration information for the specified DAC. 01097 * @retval None 01098 */ 01099 __weak void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac) 01100 { 01101 /* Prevent unused argument(s) compilation warning */ 01102 UNUSED(hdac); 01103 01104 /* NOTE : This function should not be modified, when the callback is needed, 01105 the HAL_DAC_ErrorCallbackCh1 could be implemented in the user file 01106 */ 01107 } 01108 01109 /** 01110 * @brief DMA underrun DAC callback for channel1. 01111 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 01112 * the configuration information for the specified DAC. 01113 * @retval None 01114 */ 01115 __weak void HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef *hdac) 01116 { 01117 /* Prevent unused argument(s) compilation warning */ 01118 UNUSED(hdac); 01119 01120 /* NOTE : This function should not be modified, when the callback is needed, 01121 the HAL_DAC_DMAUnderrunCallbackCh1 could be implemented in the user file 01122 */ 01123 } 01124 01125 /** 01126 * @} 01127 */ 01128 01129 /** @defgroup DAC_Exported_Functions_Group3 Peripheral Control functions 01130 * @brief Peripheral Control functions 01131 * 01132 @verbatim 01133 ============================================================================== 01134 ##### Peripheral Control functions ##### 01135 ============================================================================== 01136 [..] This section provides functions allowing to: 01137 (+) Configure channels. 01138 (+) Set the specified data holding register value for DAC channel. 01139 01140 @endverbatim 01141 * @{ 01142 */ 01143 01144 /** 01145 * @brief Returns the last data output value of the selected DAC channel. 01146 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 01147 * the configuration information for the specified DAC. 01148 * @param Channel The selected DAC channel. 01149 * This parameter can be one of the following values: 01150 * @arg DAC_CHANNEL_1: DAC Channel1 selected 01151 * @arg DAC_CHANNEL_2: DAC Channel2 selected 01152 * @retval The selected DAC channel data output value. 01153 */ 01154 uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef *hdac, uint32_t Channel) 01155 { 01156 /* Check the parameters */ 01157 assert_param(IS_DAC_CHANNEL(Channel)); 01158 01159 /* Returns the DAC channel data output register value */ 01160 #if defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) 01161 /* Prevent unused argument(s) compilation warning if no assert_param check */ 01162 UNUSED(Channel); 01163 01164 return hdac->Instance->DOR1; 01165 #endif /* STM32L451xx STM32L452xx STM32L462xx */ 01166 01167 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \ 01168 defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx) || \ 01169 defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \ 01170 defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx) 01171 if(Channel == DAC_CHANNEL_1) 01172 { 01173 return hdac->Instance->DOR1; 01174 } 01175 else 01176 { 01177 return hdac->Instance->DOR2; 01178 } 01179 #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */ 01180 /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */ 01181 /* STM32L4P5xx STM32L4Q5xx */ 01182 /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */ 01183 } 01184 01185 /** 01186 * @brief Configures the selected DAC channel. 01187 * @note By calling this function, the high frequency interface mode (HFSEL bits) 01188 * will be set. This parameter scope is the DAC instance. As the function 01189 * is called for each channel, the @ref DAC_HighFrequency of @arg sConfig 01190 * must be the same at each call. 01191 * (or DAC_HIGH_FREQUENCY_INTERFACE_MODE_AUTOMATIC self detect). 01192 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 01193 * the configuration information for the specified DAC. 01194 * @param sConfig DAC configuration structure. 01195 * @param Channel The selected DAC channel. 01196 * This parameter can be one of the following values: 01197 * @arg DAC_CHANNEL_1: DAC Channel1 selected 01198 * @arg DAC_CHANNEL_2: DAC Channel2 selected (Whenever present) 01199 * @retval HAL status 01200 */ 01201 HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef *hdac, DAC_ChannelConfTypeDef *sConfig, uint32_t Channel) 01202 { 01203 uint32_t tmpreg1; 01204 uint32_t tmpreg2; 01205 uint32_t tickstart = 0U; 01206 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx) 01207 uint32_t hclkfreq; 01208 #endif /* STM32L4P5xx STM32L4Q5xx STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */ 01209 01210 /* Check the DAC parameters */ 01211 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx) 01212 assert_param(IS_DAC_HIGH_FREQUENCY_MODE(sConfig->DAC_HighFrequency)); 01213 #endif /* STM32L4P5xx STM32L4Q5xx STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */ 01214 assert_param(IS_DAC_TRIGGER(sConfig->DAC_Trigger)); 01215 assert_param(IS_DAC_OUTPUT_BUFFER_STATE(sConfig->DAC_OutputBuffer)); 01216 assert_param(IS_DAC_CHIP_CONNECTION(sConfig->DAC_ConnectOnChipPeripheral)); 01217 assert_param(IS_DAC_TRIMMING(sConfig->DAC_UserTrimming)); 01218 if ((sConfig->DAC_UserTrimming) == DAC_TRIMMING_USER) 01219 { 01220 assert_param(IS_DAC_TRIMMINGVALUE(sConfig->DAC_TrimmingValue)); 01221 } 01222 assert_param(IS_DAC_SAMPLEANDHOLD(sConfig->DAC_SampleAndHold)); 01223 if ((sConfig->DAC_SampleAndHold) == DAC_SAMPLEANDHOLD_ENABLE) 01224 { 01225 assert_param(IS_DAC_SAMPLETIME(sConfig->DAC_SampleAndHoldConfig.DAC_SampleTime)); 01226 assert_param(IS_DAC_HOLDTIME(sConfig->DAC_SampleAndHoldConfig.DAC_HoldTime)); 01227 assert_param(IS_DAC_REFRESHTIME(sConfig->DAC_SampleAndHoldConfig.DAC_RefreshTime)); 01228 } 01229 assert_param(IS_DAC_CHANNEL(Channel)); 01230 01231 /* Process locked */ 01232 __HAL_LOCK(hdac); 01233 01234 /* Change DAC state */ 01235 hdac->State = HAL_DAC_STATE_BUSY; 01236 01237 if (sConfig->DAC_SampleAndHold == DAC_SAMPLEANDHOLD_ENABLE) 01238 /* Sample on old configuration */ 01239 { 01240 /* Get timeout */ 01241 tickstart = HAL_GetTick(); 01242 01243 if (Channel == DAC_CHANNEL_1) 01244 { 01245 01246 /* SHSR1 can be written when BWST1 is cleared */ 01247 while (((hdac->Instance->SR) & DAC_SR_BWST1) != 0UL) 01248 { 01249 /* Check for the Timeout */ 01250 if ((HAL_GetTick() - tickstart) > TIMEOUT_DAC_CALIBCONFIG) 01251 { 01252 /* Update error code */ 01253 SET_BIT(hdac->ErrorCode, HAL_DAC_ERROR_TIMEOUT); 01254 01255 /* Change the DMA state */ 01256 hdac->State = HAL_DAC_STATE_TIMEOUT; 01257 01258 return HAL_TIMEOUT; 01259 } 01260 } 01261 HAL_Delay(1); 01262 hdac->Instance->SHSR1 = sConfig->DAC_SampleAndHoldConfig.DAC_SampleTime; 01263 } 01264 #if !defined (STM32L451xx) & !defined (STM32L452xx) & !defined (STM32L462xx) 01265 else /* Channel 2 */ 01266 { 01267 /* SHSR2 can be written when BWST2 is cleared */ 01268 01269 while (((hdac->Instance->SR) & DAC_SR_BWST2) != 0UL) 01270 { 01271 /* Check for the Timeout */ 01272 if ((HAL_GetTick() - tickstart) > TIMEOUT_DAC_CALIBCONFIG) 01273 { 01274 /* Update error code */ 01275 SET_BIT(hdac->ErrorCode, HAL_DAC_ERROR_TIMEOUT); 01276 01277 /* Change the DMA state */ 01278 hdac->State = HAL_DAC_STATE_TIMEOUT; 01279 01280 return HAL_TIMEOUT; 01281 } 01282 } 01283 HAL_Delay(1U); 01284 hdac->Instance->SHSR2 = sConfig->DAC_SampleAndHoldConfig.DAC_SampleTime; 01285 } 01286 #endif /* STM32L451xx STM32L452xx STM32L462xx */ 01287 01288 /* HoldTime */ 01289 MODIFY_REG(hdac->Instance->SHHR, DAC_SHHR_THOLD1 << (Channel & 0x10UL), (sConfig->DAC_SampleAndHoldConfig.DAC_HoldTime) << (Channel & 0x10UL)); 01290 /* RefreshTime */ 01291 MODIFY_REG(hdac->Instance->SHRR, DAC_SHRR_TREFRESH1 << (Channel & 0x10UL), (sConfig->DAC_SampleAndHoldConfig.DAC_RefreshTime) << (Channel & 0x10UL)); 01292 } 01293 01294 if (sConfig->DAC_UserTrimming == DAC_TRIMMING_USER) 01295 /* USER TRIMMING */ 01296 { 01297 /* Get the DAC CCR value */ 01298 tmpreg1 = hdac->Instance->CCR; 01299 /* Clear trimming value */ 01300 tmpreg1 &= ~(((uint32_t)(DAC_CCR_OTRIM1)) << (Channel & 0x10UL)); 01301 /* Configure for the selected trimming offset */ 01302 tmpreg2 = sConfig->DAC_TrimmingValue; 01303 /* Calculate CCR register value depending on DAC_Channel */ 01304 tmpreg1 |= tmpreg2 << (Channel & 0x10UL); 01305 /* Write to DAC CCR */ 01306 hdac->Instance->CCR = tmpreg1; 01307 } 01308 /* else factory trimming is used (factory setting are available at reset)*/ 01309 /* SW Nothing has nothing to do */ 01310 01311 /* Get the DAC MCR value */ 01312 tmpreg1 = hdac->Instance->MCR; 01313 /* Clear DAC_MCR_MODEx bits */ 01314 tmpreg1 &= ~(((uint32_t)(DAC_MCR_MODE1)) << (Channel & 0x10UL)); 01315 /* Configure for the selected DAC channel: mode, buffer output & on chip peripheral connect */ 01316 tmpreg2 = (sConfig->DAC_SampleAndHold | sConfig->DAC_OutputBuffer | sConfig->DAC_ConnectOnChipPeripheral); 01317 /* Calculate MCR register value depending on DAC_Channel */ 01318 tmpreg1 |= tmpreg2 << (Channel & 0x10UL); 01319 /* Write to DAC MCR */ 01320 hdac->Instance->MCR = tmpreg1; 01321 01322 /* DAC in normal operating mode hence clear DAC_CR_CENx bit */ 01323 CLEAR_BIT(hdac->Instance->CR, DAC_CR_CEN1 << (Channel & 0x10UL)); 01324 01325 /* Get the DAC CR value */ 01326 tmpreg1 = hdac->Instance->CR; 01327 /* Clear TENx, TSELx, WAVEx and MAMPx bits */ 01328 tmpreg1 &= ~(((uint32_t)(DAC_CR_MAMP1 | DAC_CR_WAVE1 | DAC_CR_TSEL1 | DAC_CR_TEN1)) << (Channel & 0x10UL)); 01329 /* Configure for the selected DAC channel: trigger */ 01330 /* Set TSELx and TENx bits according to DAC_Trigger value */ 01331 tmpreg2 = sConfig->DAC_Trigger; 01332 /* Calculate CR register value depending on DAC_Channel */ 01333 tmpreg1 |= tmpreg2 << (Channel & 0x10UL); 01334 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx) 01335 if (DAC_HIGH_FREQUENCY_INTERFACE_MODE_ABOVE_80MHZ == sConfig->DAC_HighFrequency) 01336 { 01337 tmpreg1 |= DAC_CR_HFSEL; 01338 } 01339 else 01340 { 01341 if (DAC_HIGH_FREQUENCY_INTERFACE_MODE_DISABLE == sConfig->DAC_HighFrequency) 01342 { 01343 tmpreg1 &= ~(DAC_CR_HFSEL); 01344 } 01345 else /* Automatic selection */ 01346 { 01347 hclkfreq = HAL_RCC_GetHCLKFreq(); 01348 if (hclkfreq > HFSEL_ENABLE_THRESHOLD_80MHZ) 01349 { 01350 /* High frequency enable when HCLK frequency higher than 80 */ 01351 tmpreg1 |= DAC_CR_HFSEL; 01352 } 01353 else 01354 { 01355 /* High frequency disable when HCLK frequency higher than 80 */ 01356 tmpreg1 &= ~(DAC_CR_HFSEL); 01357 } 01358 } 01359 } 01360 01361 #endif /* STM32L4P5xx STM32L4Q5xx STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */ 01362 01363 /* Write to DAC CR */ 01364 hdac->Instance->CR = tmpreg1; 01365 /* Disable wave generation */ 01366 hdac->Instance->CR &= ~(DAC_CR_WAVE1 << (Channel & 0x10UL)); 01367 01368 /* Change DAC state */ 01369 hdac->State = HAL_DAC_STATE_READY; 01370 01371 /* Process unlocked */ 01372 __HAL_UNLOCK(hdac); 01373 01374 /* Return function status */ 01375 return HAL_OK; 01376 } 01377 01378 /** 01379 * @} 01380 */ 01381 01382 /** @defgroup DAC_Exported_Functions_Group4 Peripheral State and Errors functions 01383 * @brief Peripheral State and Errors functions 01384 * 01385 @verbatim 01386 ============================================================================== 01387 ##### Peripheral State and Errors functions ##### 01388 ============================================================================== 01389 [..] 01390 This subsection provides functions allowing to 01391 (+) Check the DAC state. 01392 (+) Check the DAC Errors. 01393 01394 @endverbatim 01395 * @{ 01396 */ 01397 01398 /** 01399 * @brief return the DAC handle state 01400 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 01401 * the configuration information for the specified DAC. 01402 * @retval HAL state 01403 */ 01404 HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef *hdac) 01405 { 01406 /* Return DAC handle state */ 01407 return hdac->State; 01408 } 01409 01410 01411 /** 01412 * @brief Return the DAC error code 01413 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 01414 * the configuration information for the specified DAC. 01415 * @retval DAC Error Code 01416 */ 01417 uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac) 01418 { 01419 return hdac->ErrorCode; 01420 } 01421 01422 /** 01423 * @} 01424 */ 01425 01426 /** 01427 * @} 01428 */ 01429 01430 /** @addtogroup DAC_Exported_Functions 01431 * @{ 01432 */ 01433 01434 /** @addtogroup DAC_Exported_Functions_Group1 01435 * @{ 01436 */ 01437 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) 01438 /** 01439 * @brief Register a User DAC Callback 01440 * To be used instead of the weak (surcharged) predefined callback 01441 * @param hdac DAC handle 01442 * @param CallbackID ID of the callback to be registered 01443 * This parameter can be one of the following values: 01444 * @arg @ref HAL_DAC_ERROR_INVALID_CALLBACK DAC Error Callback ID 01445 * @arg @ref HAL_DAC_CH1_COMPLETE_CB_ID DAC CH1 Complete Callback ID 01446 * @arg @ref HAL_DAC_CH1_HALF_COMPLETE_CB_ID DAC CH1 Half Complete Callback ID 01447 * @arg @ref HAL_DAC_CH1_ERROR_ID DAC CH1 Error Callback ID 01448 * @arg @ref HAL_DAC_CH1_UNDERRUN_CB_ID DAC CH1 UnderRun Callback ID 01449 * @arg @ref HAL_DAC_CH2_COMPLETE_CB_ID DAC CH2 Complete Callback ID 01450 * @arg @ref HAL_DAC_CH2_HALF_COMPLETE_CB_ID DAC CH2 Half Complete Callback ID 01451 * @arg @ref HAL_DAC_CH2_ERROR_ID DAC CH2 Error Callback ID 01452 * @arg @ref HAL_DAC_CH2_UNDERRUN_CB_ID DAC CH2 UnderRun Callback ID 01453 * @arg @ref HAL_DAC_MSPINIT_CB_ID DAC MSP Init Callback ID 01454 * @arg @ref HAL_DAC_MSPDEINIT_CB_ID DAC MSP DeInit Callback ID 01455 * 01456 * @param pCallback pointer to the Callback function 01457 * @retval status 01458 */ 01459 HAL_StatusTypeDef HAL_DAC_RegisterCallback(DAC_HandleTypeDef *hdac, HAL_DAC_CallbackIDTypeDef CallbackID, 01460 pDAC_CallbackTypeDef pCallback) 01461 { 01462 HAL_StatusTypeDef status = HAL_OK; 01463 01464 if (pCallback == NULL) 01465 { 01466 /* Update the error code */ 01467 hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK; 01468 return HAL_ERROR; 01469 } 01470 01471 /* Process locked */ 01472 __HAL_LOCK(hdac); 01473 01474 if (hdac->State == HAL_DAC_STATE_READY) 01475 { 01476 switch (CallbackID) 01477 { 01478 case HAL_DAC_CH1_COMPLETE_CB_ID : 01479 hdac->ConvCpltCallbackCh1 = pCallback; 01480 break; 01481 case HAL_DAC_CH1_HALF_COMPLETE_CB_ID : 01482 hdac->ConvHalfCpltCallbackCh1 = pCallback; 01483 break; 01484 case HAL_DAC_CH1_ERROR_ID : 01485 hdac->ErrorCallbackCh1 = pCallback; 01486 break; 01487 case HAL_DAC_CH1_UNDERRUN_CB_ID : 01488 hdac->DMAUnderrunCallbackCh1 = pCallback; 01489 break; 01490 case HAL_DAC_CH2_COMPLETE_CB_ID : 01491 hdac->ConvCpltCallbackCh2 = pCallback; 01492 break; 01493 case HAL_DAC_CH2_HALF_COMPLETE_CB_ID : 01494 hdac->ConvHalfCpltCallbackCh2 = pCallback; 01495 break; 01496 case HAL_DAC_CH2_ERROR_ID : 01497 hdac->ErrorCallbackCh2 = pCallback; 01498 break; 01499 case HAL_DAC_CH2_UNDERRUN_CB_ID : 01500 hdac->DMAUnderrunCallbackCh2 = pCallback; 01501 break; 01502 case HAL_DAC_MSPINIT_CB_ID : 01503 hdac->MspInitCallback = pCallback; 01504 break; 01505 case HAL_DAC_MSPDEINIT_CB_ID : 01506 hdac->MspDeInitCallback = pCallback; 01507 break; 01508 default : 01509 /* Update the error code */ 01510 hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK; 01511 /* update return status */ 01512 status = HAL_ERROR; 01513 break; 01514 } 01515 } 01516 else if (hdac->State == HAL_DAC_STATE_RESET) 01517 { 01518 switch (CallbackID) 01519 { 01520 case HAL_DAC_MSPINIT_CB_ID : 01521 hdac->MspInitCallback = pCallback; 01522 break; 01523 case HAL_DAC_MSPDEINIT_CB_ID : 01524 hdac->MspDeInitCallback = pCallback; 01525 break; 01526 default : 01527 /* Update the error code */ 01528 hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK; 01529 /* update return status */ 01530 status = HAL_ERROR; 01531 break; 01532 } 01533 } 01534 else 01535 { 01536 /* Update the error code */ 01537 hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK; 01538 /* update return status */ 01539 status = HAL_ERROR; 01540 } 01541 01542 /* Release Lock */ 01543 __HAL_UNLOCK(hdac); 01544 return status; 01545 } 01546 01547 /** 01548 * @brief Unregister a User DAC Callback 01549 * DAC Callback is redirected to the weak (surcharged) predefined callback 01550 * @param hdac DAC handle 01551 * @param CallbackID ID of the callback to be unregistered 01552 * This parameter can be one of the following values: 01553 * @arg @ref HAL_DAC_CH1_COMPLETE_CB_ID DAC CH1 tranfer Complete Callback ID 01554 * @arg @ref HAL_DAC_CH1_HALF_COMPLETE_CB_ID DAC CH1 Half Complete Callback ID 01555 * @arg @ref HAL_DAC_CH1_ERROR_ID DAC CH1 Error Callback ID 01556 * @arg @ref HAL_DAC_CH1_UNDERRUN_CB_ID DAC CH1 UnderRun Callback ID 01557 * @arg @ref HAL_DAC_CH2_COMPLETE_CB_ID DAC CH2 Complete Callback ID 01558 * @arg @ref HAL_DAC_CH2_HALF_COMPLETE_CB_ID DAC CH2 Half Complete Callback ID 01559 * @arg @ref HAL_DAC_CH2_ERROR_ID DAC CH2 Error Callback ID 01560 * @arg @ref HAL_DAC_CH2_UNDERRUN_CB_ID DAC CH2 UnderRun Callback ID 01561 * @arg @ref HAL_DAC_MSPINIT_CB_ID DAC MSP Init Callback ID 01562 * @arg @ref HAL_DAC_MSPDEINIT_CB_ID DAC MSP DeInit Callback ID 01563 * @arg @ref HAL_DAC_ALL_CB_ID DAC All callbacks 01564 * @retval status 01565 */ 01566 HAL_StatusTypeDef HAL_DAC_UnRegisterCallback(DAC_HandleTypeDef *hdac, HAL_DAC_CallbackIDTypeDef CallbackID) 01567 { 01568 HAL_StatusTypeDef status = HAL_OK; 01569 01570 /* Process locked */ 01571 __HAL_LOCK(hdac); 01572 01573 if (hdac->State == HAL_DAC_STATE_READY) 01574 { 01575 switch (CallbackID) 01576 { 01577 case HAL_DAC_CH1_COMPLETE_CB_ID : 01578 hdac->ConvCpltCallbackCh1 = HAL_DAC_ConvCpltCallbackCh1; 01579 break; 01580 case HAL_DAC_CH1_HALF_COMPLETE_CB_ID : 01581 hdac->ConvHalfCpltCallbackCh1 = HAL_DAC_ConvHalfCpltCallbackCh1; 01582 break; 01583 case HAL_DAC_CH1_ERROR_ID : 01584 hdac->ErrorCallbackCh1 = HAL_DAC_ErrorCallbackCh1; 01585 break; 01586 case HAL_DAC_CH1_UNDERRUN_CB_ID : 01587 hdac->DMAUnderrunCallbackCh1 = HAL_DAC_DMAUnderrunCallbackCh1; 01588 break; 01589 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \ 01590 defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx) || \ 01591 defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \ 01592 defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx) 01593 case HAL_DAC_CH2_COMPLETE_CB_ID : 01594 hdac->ConvCpltCallbackCh2 = HAL_DACEx_ConvCpltCallbackCh2; 01595 break; 01596 case HAL_DAC_CH2_HALF_COMPLETE_CB_ID : 01597 hdac->ConvHalfCpltCallbackCh2 = HAL_DACEx_ConvHalfCpltCallbackCh2; 01598 break; 01599 case HAL_DAC_CH2_ERROR_ID : 01600 hdac->ErrorCallbackCh2 = HAL_DACEx_ErrorCallbackCh2; 01601 break; 01602 case HAL_DAC_CH2_UNDERRUN_CB_ID : 01603 hdac->DMAUnderrunCallbackCh2 = HAL_DACEx_DMAUnderrunCallbackCh2; 01604 break; 01605 #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */ 01606 /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */ 01607 /* STM32L4P5xx STM32L4Q5xx */ 01608 /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */ 01609 case HAL_DAC_MSPINIT_CB_ID : 01610 hdac->MspInitCallback = HAL_DAC_MspInit; 01611 break; 01612 case HAL_DAC_MSPDEINIT_CB_ID : 01613 hdac->MspDeInitCallback = HAL_DAC_MspDeInit; 01614 break; 01615 case HAL_DAC_ALL_CB_ID : 01616 hdac->ConvCpltCallbackCh1 = HAL_DAC_ConvCpltCallbackCh1; 01617 hdac->ConvHalfCpltCallbackCh1 = HAL_DAC_ConvHalfCpltCallbackCh1; 01618 hdac->ErrorCallbackCh1 = HAL_DAC_ErrorCallbackCh1; 01619 hdac->DMAUnderrunCallbackCh1 = HAL_DAC_DMAUnderrunCallbackCh1; 01620 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \ 01621 defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx) || \ 01622 defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \ 01623 defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx) 01624 hdac->ConvCpltCallbackCh2 = HAL_DACEx_ConvCpltCallbackCh2; 01625 hdac->ConvHalfCpltCallbackCh2 = HAL_DACEx_ConvHalfCpltCallbackCh2; 01626 hdac->ErrorCallbackCh2 = HAL_DACEx_ErrorCallbackCh2; 01627 hdac->DMAUnderrunCallbackCh2 = HAL_DACEx_DMAUnderrunCallbackCh2; 01628 #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */ 01629 /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */ 01630 /* STM32L4P5xx STM32L4Q5xx */ 01631 /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */ 01632 hdac->MspInitCallback = HAL_DAC_MspInit; 01633 hdac->MspDeInitCallback = HAL_DAC_MspDeInit; 01634 break; 01635 default : 01636 /* Update the error code */ 01637 hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK; 01638 /* update return status */ 01639 status = HAL_ERROR; 01640 break; 01641 } 01642 } 01643 else if (hdac->State == HAL_DAC_STATE_RESET) 01644 { 01645 switch (CallbackID) 01646 { 01647 case HAL_DAC_MSPINIT_CB_ID : 01648 hdac->MspInitCallback = HAL_DAC_MspInit; 01649 break; 01650 case HAL_DAC_MSPDEINIT_CB_ID : 01651 hdac->MspDeInitCallback = HAL_DAC_MspDeInit; 01652 break; 01653 default : 01654 /* Update the error code */ 01655 hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK; 01656 /* update return status */ 01657 status = HAL_ERROR; 01658 break; 01659 } 01660 } 01661 else 01662 { 01663 /* Update the error code */ 01664 hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK; 01665 /* update return status */ 01666 status = HAL_ERROR; 01667 } 01668 01669 /* Release Lock */ 01670 __HAL_UNLOCK(hdac); 01671 return status; 01672 } 01673 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ 01674 01675 /** 01676 * @} 01677 */ 01678 01679 /** 01680 * @} 01681 */ 01682 01683 /** @addtogroup DAC_Private_Functions 01684 * @{ 01685 */ 01686 01687 /** 01688 * @brief DMA conversion complete callback. 01689 * @param hdma pointer to a DMA_HandleTypeDef structure that contains 01690 * the configuration information for the specified DMA module. 01691 * @retval None 01692 */ 01693 void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma) 01694 { 01695 DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; 01696 01697 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) 01698 hdac->ConvCpltCallbackCh1(hdac); 01699 #else 01700 HAL_DAC_ConvCpltCallbackCh1(hdac); 01701 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ 01702 01703 hdac->State = HAL_DAC_STATE_READY; 01704 } 01705 01706 /** 01707 * @brief DMA half transfer complete callback. 01708 * @param hdma pointer to a DMA_HandleTypeDef structure that contains 01709 * the configuration information for the specified DMA module. 01710 * @retval None 01711 */ 01712 void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma) 01713 { 01714 DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; 01715 /* Conversion complete callback */ 01716 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) 01717 hdac->ConvHalfCpltCallbackCh1(hdac); 01718 #else 01719 HAL_DAC_ConvHalfCpltCallbackCh1(hdac); 01720 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ 01721 } 01722 01723 /** 01724 * @brief DMA error callback 01725 * @param hdma pointer to a DMA_HandleTypeDef structure that contains 01726 * the configuration information for the specified DMA module. 01727 * @retval None 01728 */ 01729 void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma) 01730 { 01731 DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; 01732 01733 /* Set DAC error code to DMA error */ 01734 hdac->ErrorCode |= HAL_DAC_ERROR_DMA; 01735 01736 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) 01737 hdac->ErrorCallbackCh1(hdac); 01738 #else 01739 HAL_DAC_ErrorCallbackCh1(hdac); 01740 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ 01741 01742 hdac->State = HAL_DAC_STATE_READY; 01743 } 01744 01745 /** 01746 * @} 01747 */ 01748 01749 /** 01750 * @} 01751 */ 01752 01753 #endif /* DAC1 */ 01754 01755 #endif /* HAL_DAC_MODULE_ENABLED */ 01756 01757 /** 01758 * @} 01759 */ 01760