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