STM32L443xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_hal_dac_ex.c 00004 * @author MCD Application Team 00005 * @brief DAC HAL module driver. 00006 * This file provides firmware functions to manage the extended 00007 * functionalities of the DAC peripheral. 00008 * 00009 * 00010 ****************************************************************************** 00011 * @attention 00012 * 00013 * Copyright (c) 2017 STMicroelectronics. 00014 * All rights reserved. 00015 * 00016 * This software is licensed under terms that can be found in the LICENSE file 00017 * in the root directory of this software component. 00018 * If no LICENSE file comes with this software, it is provided AS-IS. 00019 * 00020 ****************************************************************************** 00021 @verbatim 00022 ============================================================================== 00023 ##### How to use this driver ##### 00024 ============================================================================== 00025 [..] 00026 *** Dual mode IO operation *** 00027 ============================== 00028 (+) When Dual mode is enabled (i.e. DAC Channel1 and Channel2 are used simultaneously) : 00029 Use HAL_DACEx_DualGetValue() to get digital data to be converted and use 00030 HAL_DACEx_DualSetValue() to set digital value to converted simultaneously in 00031 Channel 1 and Channel 2. 00032 00033 *** Signal generation operation *** 00034 =================================== 00035 (+) Use HAL_DACEx_TriangleWaveGenerate() to generate Triangle signal. 00036 (+) Use HAL_DACEx_NoiseWaveGenerate() to generate Noise signal. 00037 00038 (+) HAL_DACEx_SelfCalibrate to calibrate one DAC channel. 00039 (+) HAL_DACEx_SetUserTrimming to set user trimming value. 00040 (+) HAL_DACEx_GetTrimOffset to retrieve trimming value (factory setting 00041 after reset, user setting if HAL_DACEx_SetUserTrimming have been used 00042 at least one time after reset). 00043 00044 @endverbatim 00045 ****************************************************************************** 00046 */ 00047 00048 00049 /* Includes ------------------------------------------------------------------*/ 00050 #include "stm32l4xx_hal.h" 00051 00052 /** @addtogroup STM32L4xx_HAL_Driver 00053 * @{ 00054 */ 00055 00056 #ifdef HAL_DAC_MODULE_ENABLED 00057 00058 #if defined(DAC1) 00059 00060 /** @defgroup DACEx DACEx 00061 * @brief DAC Extended HAL module driver 00062 * @{ 00063 */ 00064 00065 /* Private typedef -----------------------------------------------------------*/ 00066 /* Private define ------------------------------------------------------------*/ 00067 /* Private macro -------------------------------------------------------------*/ 00068 /* Private variables ---------------------------------------------------------*/ 00069 /* Private function prototypes -----------------------------------------------*/ 00070 /* Exported functions --------------------------------------------------------*/ 00071 00072 /** @defgroup DACEx_Exported_Functions DACEx Exported Functions 00073 * @{ 00074 */ 00075 00076 /** @defgroup DACEx_Exported_Functions_Group2 IO operation functions 00077 * @brief Extended IO operation functions 00078 * 00079 @verbatim 00080 ============================================================================== 00081 ##### Extended features functions ##### 00082 ============================================================================== 00083 [..] This section provides functions allowing to: 00084 (+) Start conversion. 00085 (+) Stop conversion. 00086 (+) Start conversion and enable DMA transfer. 00087 (+) Stop conversion and disable DMA transfer. 00088 (+) Get result of conversion. 00089 (+) Get result of dual mode conversion. 00090 00091 @endverbatim 00092 * @{ 00093 */ 00094 00095 /** 00096 * @brief Enable or disable the selected DAC channel wave generation. 00097 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00098 * the configuration information for the specified DAC. 00099 * @param Channel The selected DAC channel. 00100 * This parameter can be one of the following values: 00101 * @arg DAC_CHANNEL_1: DAC Channel1 selected 00102 * @arg DAC_CHANNEL_2: DAC Channel2 selected 00103 * @param Amplitude Select max triangle amplitude. 00104 * This parameter can be one of the following values: 00105 * @arg DAC_TRIANGLEAMPLITUDE_1: Select max triangle amplitude of 1 00106 * @arg DAC_TRIANGLEAMPLITUDE_3: Select max triangle amplitude of 3 00107 * @arg DAC_TRIANGLEAMPLITUDE_7: Select max triangle amplitude of 7 00108 * @arg DAC_TRIANGLEAMPLITUDE_15: Select max triangle amplitude of 15 00109 * @arg DAC_TRIANGLEAMPLITUDE_31: Select max triangle amplitude of 31 00110 * @arg DAC_TRIANGLEAMPLITUDE_63: Select max triangle amplitude of 63 00111 * @arg DAC_TRIANGLEAMPLITUDE_127: Select max triangle amplitude of 127 00112 * @arg DAC_TRIANGLEAMPLITUDE_255: Select max triangle amplitude of 255 00113 * @arg DAC_TRIANGLEAMPLITUDE_511: Select max triangle amplitude of 511 00114 * @arg DAC_TRIANGLEAMPLITUDE_1023: Select max triangle amplitude of 1023 00115 * @arg DAC_TRIANGLEAMPLITUDE_2047: Select max triangle amplitude of 2047 00116 * @arg DAC_TRIANGLEAMPLITUDE_4095: Select max triangle amplitude of 4095 00117 * @retval HAL status 00118 */ 00119 HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude) 00120 { 00121 /* Check the parameters */ 00122 assert_param(IS_DAC_CHANNEL(Channel)); 00123 assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude)); 00124 00125 /* Process locked */ 00126 __HAL_LOCK(hdac); 00127 00128 /* Change DAC state */ 00129 hdac->State = HAL_DAC_STATE_BUSY; 00130 00131 /* Enable the triangle wave generation for the selected DAC channel */ 00132 MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1) | (DAC_CR_MAMP1)) << (Channel & 0x10UL), (DAC_CR_WAVE1_1 | Amplitude) << (Channel & 0x10UL)); 00133 00134 /* Change DAC state */ 00135 hdac->State = HAL_DAC_STATE_READY; 00136 00137 /* Process unlocked */ 00138 __HAL_UNLOCK(hdac); 00139 00140 /* Return function status */ 00141 return HAL_OK; 00142 } 00143 00144 /** 00145 * @brief Enable or disable the selected DAC channel wave generation. 00146 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00147 * the configuration information for the specified DAC. 00148 * @param Channel The selected DAC channel. 00149 * This parameter can be one of the following values: 00150 * @arg DAC_CHANNEL_1: DAC Channel1 selected 00151 * @arg DAC_CHANNEL_2: DAC Channel2 selected 00152 * @param Amplitude Unmask DAC channel LFSR for noise wave generation. 00153 * This parameter can be one of the following values: 00154 * @arg DAC_LFSRUNMASK_BIT0: Unmask DAC channel LFSR bit0 for noise wave generation 00155 * @arg DAC_LFSRUNMASK_BITS1_0: Unmask DAC channel LFSR bit[1:0] for noise wave generation 00156 * @arg DAC_LFSRUNMASK_BITS2_0: Unmask DAC channel LFSR bit[2:0] for noise wave generation 00157 * @arg DAC_LFSRUNMASK_BITS3_0: Unmask DAC channel LFSR bit[3:0] for noise wave generation 00158 * @arg DAC_LFSRUNMASK_BITS4_0: Unmask DAC channel LFSR bit[4:0] for noise wave generation 00159 * @arg DAC_LFSRUNMASK_BITS5_0: Unmask DAC channel LFSR bit[5:0] for noise wave generation 00160 * @arg DAC_LFSRUNMASK_BITS6_0: Unmask DAC channel LFSR bit[6:0] for noise wave generation 00161 * @arg DAC_LFSRUNMASK_BITS7_0: Unmask DAC channel LFSR bit[7:0] for noise wave generation 00162 * @arg DAC_LFSRUNMASK_BITS8_0: Unmask DAC channel LFSR bit[8:0] for noise wave generation 00163 * @arg DAC_LFSRUNMASK_BITS9_0: Unmask DAC channel LFSR bit[9:0] for noise wave generation 00164 * @arg DAC_LFSRUNMASK_BITS10_0: Unmask DAC channel LFSR bit[10:0] for noise wave generation 00165 * @arg DAC_LFSRUNMASK_BITS11_0: Unmask DAC channel LFSR bit[11:0] for noise wave generation 00166 * @retval HAL status 00167 */ 00168 HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude) 00169 { 00170 /* Check the parameters */ 00171 assert_param(IS_DAC_CHANNEL(Channel)); 00172 assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude)); 00173 00174 /* Process locked */ 00175 __HAL_LOCK(hdac); 00176 00177 /* Change DAC state */ 00178 hdac->State = HAL_DAC_STATE_BUSY; 00179 00180 /* Enable the noise wave generation for the selected DAC channel */ 00181 MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1) | (DAC_CR_MAMP1)) << (Channel & 0x10UL), (DAC_CR_WAVE1_0 | Amplitude) << (Channel & 0x10UL)); 00182 00183 /* Change DAC state */ 00184 hdac->State = HAL_DAC_STATE_READY; 00185 00186 /* Process unlocked */ 00187 __HAL_UNLOCK(hdac); 00188 00189 /* Return function status */ 00190 return HAL_OK; 00191 } 00192 00193 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \ 00194 defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx) || \ 00195 defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \ 00196 defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx) 00197 00198 /** 00199 * @brief Set the specified data holding register value for dual DAC channel. 00200 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00201 * the configuration information for the specified DAC. 00202 * @param Alignment Specifies the data alignment for dual channel DAC. 00203 * This parameter can be one of the following values: 00204 * DAC_ALIGN_8B_R: 8bit right data alignment selected 00205 * DAC_ALIGN_12B_L: 12bit left data alignment selected 00206 * DAC_ALIGN_12B_R: 12bit right data alignment selected 00207 * @param Data1 Data for DAC Channel1 to be loaded in the selected data holding register. 00208 * @param Data2 Data for DAC Channel2 to be loaded in the selected data holding register. 00209 * @note In dual mode, a unique register access is required to write in both 00210 * DAC channels at the same time. 00211 * @retval HAL status 00212 */ 00213 HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef *hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2) 00214 { 00215 uint32_t data; 00216 uint32_t tmp; 00217 00218 /* Check the parameters */ 00219 assert_param(IS_DAC_ALIGN(Alignment)); 00220 assert_param(IS_DAC_DATA(Data1)); 00221 assert_param(IS_DAC_DATA(Data2)); 00222 00223 /* Calculate and set dual DAC data holding register value */ 00224 if (Alignment == DAC_ALIGN_8B_R) 00225 { 00226 data = ((uint32_t)Data2 << 8U) | Data1; 00227 } 00228 else 00229 { 00230 data = ((uint32_t)Data2 << 16U) | Data1; 00231 } 00232 00233 tmp = (uint32_t)hdac->Instance; 00234 tmp += DAC_DHR12RD_ALIGNMENT(Alignment); 00235 00236 /* Set the dual DAC selected data holding register */ 00237 *(__IO uint32_t *)tmp = data; 00238 00239 /* Return function status */ 00240 return HAL_OK; 00241 } 00242 00243 /** 00244 * @brief Conversion complete callback in non-blocking mode for Channel2. 00245 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00246 * the configuration information for the specified DAC. 00247 * @retval None 00248 */ 00249 __weak void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef *hdac) 00250 { 00251 /* Prevent unused argument(s) compilation warning */ 00252 UNUSED(hdac); 00253 00254 /* NOTE : This function should not be modified, when the callback is needed, 00255 the HAL_DACEx_ConvCpltCallbackCh2 could be implemented in the user file 00256 */ 00257 } 00258 00259 /** 00260 * @brief Conversion half DMA transfer callback in non-blocking mode for Channel2. 00261 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00262 * the configuration information for the specified DAC. 00263 * @retval None 00264 */ 00265 __weak void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef *hdac) 00266 { 00267 /* Prevent unused argument(s) compilation warning */ 00268 UNUSED(hdac); 00269 00270 /* NOTE : This function should not be modified, when the callback is needed, 00271 the HAL_DACEx_ConvHalfCpltCallbackCh2 could be implemented in the user file 00272 */ 00273 } 00274 00275 /** 00276 * @brief Error DAC callback for Channel2. 00277 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00278 * the configuration information for the specified DAC. 00279 * @retval None 00280 */ 00281 __weak void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef *hdac) 00282 { 00283 /* Prevent unused argument(s) compilation warning */ 00284 UNUSED(hdac); 00285 00286 /* NOTE : This function should not be modified, when the callback is needed, 00287 the HAL_DACEx_ErrorCallbackCh2 could be implemented in the user file 00288 */ 00289 } 00290 00291 /** 00292 * @brief DMA underrun DAC callback for Channel2. 00293 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00294 * the configuration information for the specified DAC. 00295 * @retval None 00296 */ 00297 __weak void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef *hdac) 00298 { 00299 /* Prevent unused argument(s) compilation warning */ 00300 UNUSED(hdac); 00301 00302 /* NOTE : This function should not be modified, when the callback is needed, 00303 the HAL_DACEx_DMAUnderrunCallbackCh2 could be implemented in the user file 00304 */ 00305 } 00306 #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */ 00307 /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */ 00308 /* STM32L4P5xx STM32L4Q5xx */ 00309 /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */ 00310 00311 /** 00312 * @brief Run the self calibration of one DAC channel. 00313 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00314 * the configuration information for the specified DAC. 00315 * @param sConfig DAC channel configuration structure. 00316 * @param Channel The selected DAC channel. 00317 * This parameter can be one of the following values: 00318 * @arg DAC_CHANNEL_1: DAC Channel1 selected 00319 * @arg DAC_CHANNEL_2: DAC Channel2 selected 00320 * @retval Updates DAC_TrimmingValue. , DAC_UserTrimming set to DAC_UserTrimming 00321 * @retval HAL status 00322 * @note Calibration runs about 7 ms. 00323 */ 00324 00325 HAL_StatusTypeDef HAL_DACEx_SelfCalibrate(DAC_HandleTypeDef *hdac, DAC_ChannelConfTypeDef *sConfig, uint32_t Channel) 00326 { 00327 HAL_StatusTypeDef status = HAL_OK; 00328 00329 __IO uint32_t tmp; 00330 uint32_t trimmingvalue; 00331 uint32_t delta; 00332 00333 /* store/restore channel configuration structure purpose */ 00334 uint32_t oldmodeconfiguration; 00335 00336 /* Check the parameters */ 00337 assert_param(IS_DAC_CHANNEL(Channel)); 00338 00339 /* Check the DAC handle allocation */ 00340 /* Check if DAC running */ 00341 if (hdac == NULL) 00342 { 00343 status = HAL_ERROR; 00344 } 00345 else if (hdac->State == HAL_DAC_STATE_BUSY) 00346 { 00347 status = HAL_ERROR; 00348 } 00349 else 00350 { 00351 /* Process locked */ 00352 __HAL_LOCK(hdac); 00353 00354 /* Store configuration */ 00355 oldmodeconfiguration = (hdac->Instance->MCR & (DAC_MCR_MODE1 << (Channel & 0x10UL))); 00356 00357 /* Disable the selected DAC channel */ 00358 CLEAR_BIT((hdac->Instance->CR), (DAC_CR_EN1 << (Channel & 0x10UL))); 00359 00360 /* Set mode in MCR for calibration */ 00361 MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << (Channel & 0x10UL)), 0U); 00362 00363 /* Set DAC Channel1 DHR register to the middle value */ 00364 tmp = (uint32_t)hdac->Instance; 00365 00366 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \ 00367 defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx) || \ 00368 defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \ 00369 defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx) 00370 if(Channel == DAC_CHANNEL_1) 00371 { 00372 tmp += DAC_DHR12R1_ALIGNMENT(DAC_ALIGN_12B_R); 00373 } 00374 else 00375 { 00376 tmp += DAC_DHR12R2_ALIGNMENT(DAC_ALIGN_12B_R); 00377 } 00378 #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */ 00379 /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */ 00380 /* STM32L4P5xx STM32L4Q5xx */ 00381 /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */ 00382 #if defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) 00383 tmp += DAC_DHR12R1_ALIGNMENT(DAC_ALIGN_12B_R); 00384 #endif /* STM32L451xx STM32L452xx STM32L462xx */ 00385 *(__IO uint32_t *) tmp = 0x0800U; 00386 00387 /* Enable the selected DAC channel calibration */ 00388 /* i.e. set DAC_CR_CENx bit */ 00389 SET_BIT((hdac->Instance->CR), (DAC_CR_CEN1 << (Channel & 0x10UL))); 00390 00391 /* Init trimming counter */ 00392 /* Medium value */ 00393 trimmingvalue = 16U; 00394 delta = 8U; 00395 while (delta != 0U) 00396 { 00397 /* Set candidate trimming */ 00398 MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1 << (Channel & 0x10UL)), (trimmingvalue << (Channel & 0x10UL))); 00399 00400 /* tOFFTRIMmax delay x ms as per datasheet (electrical characteristics */ 00401 /* i.e. minimum time needed between two calibration steps */ 00402 HAL_Delay(1); 00403 00404 if ((hdac->Instance->SR & (DAC_SR_CAL_FLAG1 << (Channel & 0x10UL))) == (DAC_SR_CAL_FLAG1 << (Channel & 0x10UL))) 00405 { 00406 /* DAC_SR_CAL_FLAGx is HIGH try higher trimming */ 00407 trimmingvalue -= delta; 00408 } 00409 else 00410 { 00411 /* DAC_SR_CAL_FLAGx is LOW try lower trimming */ 00412 trimmingvalue += delta; 00413 } 00414 delta >>= 1U; 00415 } 00416 00417 /* Still need to check if right calibration is current value or one step below */ 00418 /* Indeed the first value that causes the DAC_SR_CAL_FLAGx bit to change from 0 to 1 */ 00419 /* Set candidate trimming */ 00420 MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1 << (Channel & 0x10UL)), (trimmingvalue << (Channel & 0x10UL))); 00421 00422 /* tOFFTRIMmax delay x ms as per datasheet (electrical characteristics */ 00423 /* i.e. minimum time needed between two calibration steps */ 00424 HAL_Delay(1U); 00425 00426 if ((hdac->Instance->SR & (DAC_SR_CAL_FLAG1 << (Channel & 0x10UL))) == 0UL) 00427 { 00428 /* OPAMP_CSR_OUTCAL is actually one value more */ 00429 trimmingvalue++; 00430 /* Set right trimming */ 00431 MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1 << (Channel & 0x10UL)), (trimmingvalue << (Channel & 0x10UL))); 00432 } 00433 00434 /* Disable the selected DAC channel calibration */ 00435 /* i.e. clear DAC_CR_CENx bit */ 00436 CLEAR_BIT((hdac->Instance->CR), (DAC_CR_CEN1 << (Channel & 0x10UL))); 00437 00438 sConfig->DAC_TrimmingValue = trimmingvalue; 00439 sConfig->DAC_UserTrimming = DAC_TRIMMING_USER; 00440 00441 /* Restore configuration */ 00442 MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << (Channel & 0x10UL)), oldmodeconfiguration); 00443 00444 /* Process unlocked */ 00445 __HAL_UNLOCK(hdac); 00446 } 00447 00448 return status; 00449 } 00450 00451 /** 00452 * @brief Set the trimming mode and trimming value (user trimming mode applied). 00453 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00454 * the configuration information for the specified DAC. 00455 * @param sConfig DAC configuration structure updated with new DAC trimming value. 00456 * @param Channel The selected DAC channel. 00457 * This parameter can be one of the following values: 00458 * @arg DAC_CHANNEL_1: DAC Channel1 selected 00459 * @arg DAC_CHANNEL_2: DAC Channel2 selected 00460 * @param NewTrimmingValue DAC new trimming value 00461 * @retval HAL status 00462 */ 00463 00464 HAL_StatusTypeDef HAL_DACEx_SetUserTrimming(DAC_HandleTypeDef *hdac, DAC_ChannelConfTypeDef *sConfig, uint32_t Channel, 00465 uint32_t NewTrimmingValue) 00466 { 00467 HAL_StatusTypeDef status = HAL_OK; 00468 00469 /* Check the parameters */ 00470 assert_param(IS_DAC_CHANNEL(Channel)); 00471 assert_param(IS_DAC_NEWTRIMMINGVALUE(NewTrimmingValue)); 00472 00473 /* Check the DAC handle allocation */ 00474 if (hdac == NULL) 00475 { 00476 status = HAL_ERROR; 00477 } 00478 else 00479 { 00480 /* Process locked */ 00481 __HAL_LOCK(hdac); 00482 00483 /* Set new trimming */ 00484 MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1 << (Channel & 0x10UL)), (NewTrimmingValue << (Channel & 0x10UL))); 00485 00486 /* Update trimming mode */ 00487 sConfig->DAC_UserTrimming = DAC_TRIMMING_USER; 00488 sConfig->DAC_TrimmingValue = NewTrimmingValue; 00489 00490 /* Process unlocked */ 00491 __HAL_UNLOCK(hdac); 00492 } 00493 return status; 00494 } 00495 00496 /** 00497 * @brief Return the DAC trimming value. 00498 * @param hdac DAC handle 00499 * @param Channel The selected DAC channel. 00500 * This parameter can be one of the following values: 00501 * @arg DAC_CHANNEL_1: DAC Channel1 selected 00502 * @arg DAC_CHANNEL_2: DAC Channel2 selected 00503 * @retval Trimming value : range: 0->31 00504 * 00505 */ 00506 00507 uint32_t HAL_DACEx_GetTrimOffset(DAC_HandleTypeDef *hdac, uint32_t Channel) 00508 { 00509 /* Check the parameter */ 00510 assert_param(IS_DAC_CHANNEL(Channel)); 00511 00512 /* Retrieve trimming */ 00513 return ((hdac->Instance->CCR & (DAC_CCR_OTRIM1 << (Channel & 0x10UL))) >> (Channel & 0x10UL)); 00514 } 00515 00516 /** 00517 * @} 00518 */ 00519 00520 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \ 00521 defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx) || \ 00522 defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \ 00523 defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx) 00524 00525 /** @defgroup DACEx_Exported_Functions_Group3 Peripheral Control functions 00526 * @brief Extended Peripheral Control functions 00527 * 00528 @verbatim 00529 ============================================================================== 00530 ##### Peripheral Control functions ##### 00531 ============================================================================== 00532 [..] This section provides functions allowing to: 00533 (+) Set the specified data holding register value for DAC channel. 00534 00535 @endverbatim 00536 * @{ 00537 */ 00538 00539 /** 00540 * @brief Return the last data output value of the selected DAC channel. 00541 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00542 * the configuration information for the specified DAC. 00543 * @retval The selected DAC channel data output value. 00544 */ 00545 uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef *hdac) 00546 { 00547 uint32_t tmp = 0U; 00548 00549 tmp |= hdac->Instance->DOR1; 00550 00551 tmp |= hdac->Instance->DOR2 << 16U; 00552 00553 /* Returns the DAC channel data output register value */ 00554 return tmp; 00555 } 00556 00557 /** 00558 * @} 00559 */ 00560 00561 #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */ 00562 /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */ 00563 /* STM32L4P5xx STM32L4Q5xx */ 00564 /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */ 00565 00566 /** 00567 * @} 00568 */ 00569 00570 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \ 00571 defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx) || \ 00572 defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \ 00573 defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx) 00574 00575 /* Private functions ---------------------------------------------------------*/ 00576 /** @defgroup DACEx_Private_Functions DACEx private functions 00577 * @brief Extended private functions 00578 * @{ 00579 */ 00580 00581 /** 00582 * @brief DMA conversion complete callback. 00583 * @param hdma pointer to a DMA_HandleTypeDef structure that contains 00584 * the configuration information for the specified DMA module. 00585 * @retval None 00586 */ 00587 void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma) 00588 { 00589 DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; 00590 00591 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) 00592 hdac->ConvCpltCallbackCh2(hdac); 00593 #else 00594 HAL_DACEx_ConvCpltCallbackCh2(hdac); 00595 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ 00596 00597 hdac->State = HAL_DAC_STATE_READY; 00598 } 00599 00600 /** 00601 * @brief DMA half transfer complete callback. 00602 * @param hdma pointer to a DMA_HandleTypeDef structure that contains 00603 * the configuration information for the specified DMA module. 00604 * @retval None 00605 */ 00606 void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma) 00607 { 00608 DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; 00609 /* Conversion complete callback */ 00610 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) 00611 hdac->ConvHalfCpltCallbackCh2(hdac); 00612 #else 00613 HAL_DACEx_ConvHalfCpltCallbackCh2(hdac); 00614 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ 00615 } 00616 00617 /** 00618 * @brief DMA error callback. 00619 * @param hdma pointer to a DMA_HandleTypeDef structure that contains 00620 * the configuration information for the specified DMA module. 00621 * @retval None 00622 */ 00623 void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma) 00624 { 00625 DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; 00626 00627 /* Set DAC error code to DMA error */ 00628 hdac->ErrorCode |= HAL_DAC_ERROR_DMA; 00629 00630 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) 00631 hdac->ErrorCallbackCh2(hdac); 00632 #else 00633 HAL_DACEx_ErrorCallbackCh2(hdac); 00634 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ 00635 00636 hdac->State = HAL_DAC_STATE_READY; 00637 } 00638 00639 /** 00640 * @} 00641 */ 00642 #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */ 00643 /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */ 00644 /* STM32L4P5xx STM32L4Q5xx */ 00645 /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */ 00646 00647 /** 00648 * @} 00649 */ 00650 00651 #endif /* DAC1 */ 00652 00653 #endif /* HAL_DAC_MODULE_ENABLED */ 00654 00655 /** 00656 * @} 00657 */ 00658