mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Wed Jul 01 09:45:11 2015 +0100
Revision:
579:53297373a894
Parent:
489:119543c9f674
Synchronized with git revision d5b4d2ab9c47edb4dc5776e7177b0c2263459081

Full URL: https://github.com/mbedmicro/mbed/commit/d5b4d2ab9c47edb4dc5776e7177b0c2263459081/

Initial version of drivers for SAMR21

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 376:cb4d9db17537 1 /**
mbed_official 376:cb4d9db17537 2 ******************************************************************************
mbed_official 376:cb4d9db17537 3 * @file stm32l0xx_hal_dac_ex.c
mbed_official 376:cb4d9db17537 4 * @author MCD Application Team
mbed_official 489:119543c9f674 5 * @version V1.2.0
mbed_official 489:119543c9f674 6 * @date 06-February-2015
mbed_official 489:119543c9f674 7 * @brief Extended DAC HAL module driver.
mbed_official 489:119543c9f674 8 * This file provides firmware functions to manage the following
mbed_official 489:119543c9f674 9 * functionalities of DAC extension peripheral:
mbed_official 489:119543c9f674 10 * + Extended features functions
mbed_official 489:119543c9f674 11 *
mbed_official 376:cb4d9db17537 12 *
mbed_official 376:cb4d9db17537 13 @verbatim
mbed_official 489:119543c9f674 14 ==============================================================================
mbed_official 489:119543c9f674 15 ##### How to use this driver #####
mbed_official 489:119543c9f674 16 ==============================================================================
mbed_official 489:119543c9f674 17 [..]
mbed_official 489:119543c9f674 18 (+) When Dual mode is enabled (i.e DAC Channel1 and Channel2 are used simultaneously) :
mbed_official 489:119543c9f674 19 Use HAL_DACEx_DualGetValue() to get digital data to be converted and use
mbed_official 489:119543c9f674 20 HAL_DACEx_DualSetValue() to set digital value to converted simultaneously in Channel 1 and Channel 2.
mbed_official 489:119543c9f674 21 (+) Use HAL_DACEx_TriangleWaveGenerate() to generate Triangle signal.
mbed_official 489:119543c9f674 22 (+) Use HAL_DACEx_NoiseWaveGenerate() to generate Noise signal.
mbed_official 376:cb4d9db17537 23
mbed_official 376:cb4d9db17537 24 @endverbatim
mbed_official 376:cb4d9db17537 25 ******************************************************************************
mbed_official 376:cb4d9db17537 26 * @attention
mbed_official 376:cb4d9db17537 27 *
mbed_official 489:119543c9f674 28 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
mbed_official 376:cb4d9db17537 29 *
mbed_official 376:cb4d9db17537 30 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 376:cb4d9db17537 31 * are permitted provided that the following conditions are met:
mbed_official 376:cb4d9db17537 32 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 376:cb4d9db17537 33 * this list of conditions and the following disclaimer.
mbed_official 376:cb4d9db17537 34 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 376:cb4d9db17537 35 * this list of conditions and the following disclaimer in the documentation
mbed_official 376:cb4d9db17537 36 * and/or other materials provided with the distribution.
mbed_official 376:cb4d9db17537 37 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 376:cb4d9db17537 38 * may be used to endorse or promote products derived from this software
mbed_official 376:cb4d9db17537 39 * without specific prior written permission.
mbed_official 376:cb4d9db17537 40 *
mbed_official 376:cb4d9db17537 41 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 376:cb4d9db17537 42 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 376:cb4d9db17537 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 376:cb4d9db17537 44 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 376:cb4d9db17537 45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 376:cb4d9db17537 46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 376:cb4d9db17537 47 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 376:cb4d9db17537 48 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 376:cb4d9db17537 49 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 376:cb4d9db17537 50 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 376:cb4d9db17537 51 *
mbed_official 376:cb4d9db17537 52 ******************************************************************************
mbed_official 376:cb4d9db17537 53 */
mbed_official 376:cb4d9db17537 54
mbed_official 489:119543c9f674 55
mbed_official 489:119543c9f674 56 #if !defined (STM32L031xx) && !defined (STM32L041xx) && !defined (STM32L051xx) && !defined (STM32L061xx) && !defined (STM32L071xx) && !defined (STM32L081xx)
mbed_official 376:cb4d9db17537 57 /* Includes ------------------------------------------------------------------*/
mbed_official 376:cb4d9db17537 58 #include "stm32l0xx_hal.h"
mbed_official 376:cb4d9db17537 59
mbed_official 489:119543c9f674 60 #ifdef HAL_DAC_MODULE_ENABLED
mbed_official 376:cb4d9db17537 61 /** @addtogroup STM32L0xx_HAL_Driver
mbed_official 376:cb4d9db17537 62 * @{
mbed_official 376:cb4d9db17537 63 */
mbed_official 376:cb4d9db17537 64
mbed_official 489:119543c9f674 65 /** @defgroup DACEx DACEx
mbed_official 376:cb4d9db17537 66 * @brief DAC driver modules
mbed_official 376:cb4d9db17537 67 * @{
mbed_official 376:cb4d9db17537 68 */
mbed_official 376:cb4d9db17537 69
mbed_official 376:cb4d9db17537 70
mbed_official 376:cb4d9db17537 71 /* Private typedef -----------------------------------------------------------*/
mbed_official 376:cb4d9db17537 72 /* Private define ------------------------------------------------------------*/
mbed_official 376:cb4d9db17537 73 /* Private macro -------------------------------------------------------------*/
mbed_official 376:cb4d9db17537 74 /* Private variables ---------------------------------------------------------*/
mbed_official 376:cb4d9db17537 75 /* Private function prototypes -----------------------------------------------*/
mbed_official 376:cb4d9db17537 76 /* Private functions ---------------------------------------------------------*/
mbed_official 489:119543c9f674 77 /** @addtogroup DACEx_Private_Functions
mbed_official 489:119543c9f674 78 * @{
mbed_official 489:119543c9f674 79 */
mbed_official 489:119543c9f674 80 #if defined (STM32L072xx) || defined (STM32L073xx) || defined (STM32L082xx) || defined (STM32L083xx)
mbed_official 489:119543c9f674 81 static void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma);
mbed_official 489:119543c9f674 82 static void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma);
mbed_official 489:119543c9f674 83 static void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma);
mbed_official 489:119543c9f674 84 #endif
mbed_official 489:119543c9f674 85 static void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma);
mbed_official 489:119543c9f674 86 static void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma);
mbed_official 489:119543c9f674 87 static void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma);
mbed_official 376:cb4d9db17537 88
mbed_official 489:119543c9f674 89 /**
mbed_official 489:119543c9f674 90 * @}
mbed_official 489:119543c9f674 91 */
mbed_official 489:119543c9f674 92
mbed_official 489:119543c9f674 93 /** @defgroup DACEx_Exported_Functions DACEx Exported Functions
mbed_official 489:119543c9f674 94 * @{
mbed_official 489:119543c9f674 95 */
mbed_official 489:119543c9f674 96
mbed_official 489:119543c9f674 97 /** @defgroup DACEx_Exported_Functions_Group1 Extended features functions
mbed_official 489:119543c9f674 98 * @brief Extended features functions
mbed_official 489:119543c9f674 99 *
mbed_official 489:119543c9f674 100
mbed_official 376:cb4d9db17537 101 * @{
mbed_official 376:cb4d9db17537 102 */
mbed_official 376:cb4d9db17537 103
mbed_official 489:119543c9f674 104 #if defined (STM32L072xx) || defined (STM32L073xx) || defined (STM32L082xx) || defined (STM32L083xx)
mbed_official 489:119543c9f674 105 /**
mbed_official 489:119543c9f674 106 * @brief Returns the last data output value of the selected DAC channel.
mbed_official 489:119543c9f674 107 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 108 * the configuration information for the specified DAC.
mbed_official 489:119543c9f674 109 * @retval The selected DAC channel data output value.
mbed_official 489:119543c9f674 110 */
mbed_official 489:119543c9f674 111 uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef* hdac)
mbed_official 489:119543c9f674 112 {
mbed_official 489:119543c9f674 113 uint32_t tmp = 0;
mbed_official 376:cb4d9db17537 114
mbed_official 489:119543c9f674 115 tmp |= hdac->Instance->DOR1;
mbed_official 489:119543c9f674 116
mbed_official 489:119543c9f674 117 tmp |= hdac->Instance->DOR2 << 16;
mbed_official 489:119543c9f674 118
mbed_official 489:119543c9f674 119 /* Returns the DAC channel data output register value */
mbed_official 489:119543c9f674 120 return tmp;
mbed_official 489:119543c9f674 121 }
mbed_official 489:119543c9f674 122 #endif
mbed_official 376:cb4d9db17537 123
mbed_official 376:cb4d9db17537 124 /**
mbed_official 489:119543c9f674 125 * @brief Enables or disables the selected DAC channel wave generation.
mbed_official 376:cb4d9db17537 126 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
mbed_official 376:cb4d9db17537 127 * the configuration information for the specified DAC.
mbed_official 489:119543c9f674 128 * @param Channel: The selected DAC channel.
mbed_official 376:cb4d9db17537 129 * This parameter can be one of the following values:
mbed_official 376:cb4d9db17537 130 * @arg DAC_CHANNEL_1: DAC Channel1 selected
mbed_official 489:119543c9f674 131 * @arg DAC_CHANNEL_2: DAC Channel2 selected (STM32L07x/STM32L08x only)
mbed_official 376:cb4d9db17537 132 * @param Amplitude: Select max triangle amplitude.
mbed_official 376:cb4d9db17537 133 * This parameter can be one of the following values:
mbed_official 376:cb4d9db17537 134 * @arg DAC_TRIANGLEAMPLITUDE_1: Select max triangle amplitude of 1
mbed_official 376:cb4d9db17537 135 * @arg DAC_TRIANGLEAMPLITUDE_3: Select max triangle amplitude of 3
mbed_official 376:cb4d9db17537 136 * @arg DAC_TRIANGLEAMPLITUDE_7: Select max triangle amplitude of 7
mbed_official 376:cb4d9db17537 137 * @arg DAC_TRIANGLEAMPLITUDE_15: Select max triangle amplitude of 15
mbed_official 376:cb4d9db17537 138 * @arg DAC_TRIANGLEAMPLITUDE_31: Select max triangle amplitude of 31
mbed_official 376:cb4d9db17537 139 * @arg DAC_TRIANGLEAMPLITUDE_63: Select max triangle amplitude of 63
mbed_official 376:cb4d9db17537 140 * @arg DAC_TRIANGLEAMPLITUDE_127: Select max triangle amplitude of 127
mbed_official 376:cb4d9db17537 141 * @arg DAC_TRIANGLEAMPLITUDE_255: Select max triangle amplitude of 255
mbed_official 376:cb4d9db17537 142 * @arg DAC_TRIANGLEAMPLITUDE_511: Select max triangle amplitude of 511
mbed_official 376:cb4d9db17537 143 * @arg DAC_TRIANGLEAMPLITUDE_1023: Select max triangle amplitude of 1023
mbed_official 376:cb4d9db17537 144 * @arg DAC_TRIANGLEAMPLITUDE_2047: Select max triangle amplitude of 2047
mbed_official 376:cb4d9db17537 145 * @arg DAC_TRIANGLEAMPLITUDE_4095: Select max triangle amplitude of 4095
mbed_official 376:cb4d9db17537 146 * @retval HAL status
mbed_official 376:cb4d9db17537 147 */
mbed_official 489:119543c9f674 148 HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude)
mbed_official 376:cb4d9db17537 149 {
mbed_official 376:cb4d9db17537 150 /* Check the parameters */
mbed_official 489:119543c9f674 151 assert_param(IS_DAC_CHANNEL(Channel));
mbed_official 376:cb4d9db17537 152 assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
mbed_official 376:cb4d9db17537 153
mbed_official 376:cb4d9db17537 154 /* Process locked */
mbed_official 376:cb4d9db17537 155 __HAL_LOCK(hdac);
mbed_official 376:cb4d9db17537 156
mbed_official 376:cb4d9db17537 157 /* Change DAC state */
mbed_official 376:cb4d9db17537 158 hdac->State = HAL_DAC_STATE_BUSY;
mbed_official 376:cb4d9db17537 159
mbed_official 489:119543c9f674 160 /* Enable the triangle wave generation for the selected DAC channel */
mbed_official 489:119543c9f674 161 MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1)|(DAC_CR_MAMP1))<<Channel, (DAC_CR_WAVE1_1 | Amplitude) << Channel);
mbed_official 489:119543c9f674 162
mbed_official 376:cb4d9db17537 163
mbed_official 376:cb4d9db17537 164 /* Change DAC state */
mbed_official 376:cb4d9db17537 165 hdac->State = HAL_DAC_STATE_READY;
mbed_official 376:cb4d9db17537 166
mbed_official 376:cb4d9db17537 167 /* Process unlocked */
mbed_official 376:cb4d9db17537 168 __HAL_UNLOCK(hdac);
mbed_official 376:cb4d9db17537 169
mbed_official 376:cb4d9db17537 170 /* Return function status */
mbed_official 376:cb4d9db17537 171 return HAL_OK;
mbed_official 376:cb4d9db17537 172 }
mbed_official 376:cb4d9db17537 173
mbed_official 376:cb4d9db17537 174 /**
mbed_official 489:119543c9f674 175 * @brief Enables or disables the selected DAC channel wave generation.
mbed_official 489:119543c9f674 176 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 177 * the configuration information for the specified DAC.
mbed_official 489:119543c9f674 178 * @param Channel: The selected DAC channel.
mbed_official 376:cb4d9db17537 179 * This parameter can be one of the following values:
mbed_official 376:cb4d9db17537 180 * @arg DAC_CHANNEL_1: DAC Channel1 selected
mbed_official 489:119543c9f674 181 * @arg DAC_CHANNEL_2: DAC Channel2 selected (STM32L07x/STM32L08x only)
mbed_official 376:cb4d9db17537 182 * @param Amplitude: Unmask DAC channel LFSR for noise wave generation.
mbed_official 376:cb4d9db17537 183 * This parameter can be one of the following values:
mbed_official 376:cb4d9db17537 184 * @arg DAC_LFSRUNMASK_BIT0: Unmask DAC channel LFSR bit0 for noise wave generation
mbed_official 376:cb4d9db17537 185 * @arg DAC_LFSRUNMASK_BITS1_0: Unmask DAC channel LFSR bit[1:0] for noise wave generation
mbed_official 376:cb4d9db17537 186 * @arg DAC_LFSRUNMASK_BITS2_0: Unmask DAC channel LFSR bit[2:0] for noise wave generation
mbed_official 376:cb4d9db17537 187 * @arg DAC_LFSRUNMASK_BITS3_0: Unmask DAC channel LFSR bit[3:0] for noise wave generation
mbed_official 376:cb4d9db17537 188 * @arg DAC_LFSRUNMASK_BITS4_0: Unmask DAC channel LFSR bit[4:0] for noise wave generation
mbed_official 376:cb4d9db17537 189 * @arg DAC_LFSRUNMASK_BITS5_0: Unmask DAC channel LFSR bit[5:0] for noise wave generation
mbed_official 376:cb4d9db17537 190 * @arg DAC_LFSRUNMASK_BITS6_0: Unmask DAC channel LFSR bit[6:0] for noise wave generation
mbed_official 376:cb4d9db17537 191 * @arg DAC_LFSRUNMASK_BITS7_0: Unmask DAC channel LFSR bit[7:0] for noise wave generation
mbed_official 376:cb4d9db17537 192 * @arg DAC_LFSRUNMASK_BITS8_0: Unmask DAC channel LFSR bit[8:0] for noise wave generation
mbed_official 376:cb4d9db17537 193 * @arg DAC_LFSRUNMASK_BITS9_0: Unmask DAC channel LFSR bit[9:0] for noise wave generation
mbed_official 376:cb4d9db17537 194 * @arg DAC_LFSRUNMASK_BITS10_0: Unmask DAC channel LFSR bit[10:0] for noise wave generation
mbed_official 376:cb4d9db17537 195 * @arg DAC_LFSRUNMASK_BITS11_0: Unmask DAC channel LFSR bit[11:0] for noise wave generation
mbed_official 376:cb4d9db17537 196 * @retval HAL status
mbed_official 376:cb4d9db17537 197 */
mbed_official 489:119543c9f674 198 HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude)
mbed_official 376:cb4d9db17537 199 {
mbed_official 376:cb4d9db17537 200 /* Check the parameters */
mbed_official 489:119543c9f674 201 assert_param(IS_DAC_CHANNEL(Channel));
mbed_official 376:cb4d9db17537 202 assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
mbed_official 376:cb4d9db17537 203
mbed_official 376:cb4d9db17537 204 /* Process locked */
mbed_official 376:cb4d9db17537 205 __HAL_LOCK(hdac);
mbed_official 376:cb4d9db17537 206
mbed_official 376:cb4d9db17537 207 /* Change DAC state */
mbed_official 376:cb4d9db17537 208 hdac->State = HAL_DAC_STATE_BUSY;
mbed_official 376:cb4d9db17537 209
mbed_official 489:119543c9f674 210 /* Enable the noise wave generation for the selected DAC channel */
mbed_official 489:119543c9f674 211 MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1)|(DAC_CR_MAMP1))<<Channel, (DAC_CR_WAVE1_0 | Amplitude) << Channel);
mbed_official 489:119543c9f674 212
mbed_official 489:119543c9f674 213 /* Change DAC state */
mbed_official 489:119543c9f674 214 hdac->State = HAL_DAC_STATE_READY;
mbed_official 489:119543c9f674 215
mbed_official 489:119543c9f674 216 /* Process unlocked */
mbed_official 489:119543c9f674 217 __HAL_UNLOCK(hdac);
mbed_official 489:119543c9f674 218
mbed_official 489:119543c9f674 219 /* Return function status */
mbed_official 489:119543c9f674 220 return HAL_OK;
mbed_official 489:119543c9f674 221 }
mbed_official 489:119543c9f674 222
mbed_official 489:119543c9f674 223 #if defined (STM32L072xx) || defined (STM32L073xx) || defined (STM32L082xx) || defined (STM32L083xx)
mbed_official 489:119543c9f674 224 /**
mbed_official 489:119543c9f674 225 * @brief Set the specified data holding register value for dual DAC channel.
mbed_official 489:119543c9f674 226 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 227 * the configuration information for the specified DAC.
mbed_official 489:119543c9f674 228 * @param Alignment: Specifies the data alignment for dual channel DAC.
mbed_official 489:119543c9f674 229 * This parameter can be one of the following values:
mbed_official 489:119543c9f674 230 * DAC_ALIGN_8B_R: 8bit right data alignment selected
mbed_official 489:119543c9f674 231 * DAC_ALIGN_12B_L: 12bit left data alignment selected
mbed_official 489:119543c9f674 232 * DAC_ALIGN_12B_R: 12bit right data alignment selected
mbed_official 489:119543c9f674 233 * @param Data1: Data for DAC Channel2 to be loaded in the selected data holding register.
mbed_official 489:119543c9f674 234 * @param Data2: Data for DAC Channel1 to be loaded in the selected data holding register.
mbed_official 489:119543c9f674 235 * @note In dual mode, a unique register access is required to write in both
mbed_official 489:119543c9f674 236 * DAC channels at the same time.
mbed_official 489:119543c9f674 237 * @retval HAL status
mbed_official 489:119543c9f674 238 */
mbed_official 489:119543c9f674 239 HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef* hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2)
mbed_official 489:119543c9f674 240 {
mbed_official 489:119543c9f674 241 uint32_t data = 0, tmp = 0;
mbed_official 489:119543c9f674 242
mbed_official 489:119543c9f674 243 /* Check the parameters */
mbed_official 489:119543c9f674 244 assert_param(IS_DAC_ALIGN(Alignment));
mbed_official 489:119543c9f674 245 assert_param(IS_DAC_DATA(Data1));
mbed_official 489:119543c9f674 246 assert_param(IS_DAC_DATA(Data2));
mbed_official 489:119543c9f674 247
mbed_official 489:119543c9f674 248 /* Calculate and set dual DAC data holding register value */
mbed_official 489:119543c9f674 249 if (Alignment == DAC_ALIGN_8B_R)
mbed_official 489:119543c9f674 250 {
mbed_official 489:119543c9f674 251 data = ((uint32_t)Data2 << 8) | Data1;
mbed_official 489:119543c9f674 252 }
mbed_official 489:119543c9f674 253 else
mbed_official 489:119543c9f674 254 {
mbed_official 489:119543c9f674 255 data = ((uint32_t)Data2 << 16) | Data1;
mbed_official 489:119543c9f674 256 }
mbed_official 489:119543c9f674 257
mbed_official 489:119543c9f674 258 tmp = (uint32_t)hdac->Instance;
mbed_official 489:119543c9f674 259 tmp += __DAC_DHR12RD_ALIGNEMENT(Alignment);
mbed_official 489:119543c9f674 260
mbed_official 489:119543c9f674 261 /* Set the dual DAC selected data holding register */
mbed_official 489:119543c9f674 262 *(__IO uint32_t *)tmp = data;
mbed_official 489:119543c9f674 263
mbed_official 489:119543c9f674 264 /* Return function status */
mbed_official 489:119543c9f674 265 return HAL_OK;
mbed_official 489:119543c9f674 266 }
mbed_official 489:119543c9f674 267
mbed_official 489:119543c9f674 268
mbed_official 489:119543c9f674 269 /**
mbed_official 489:119543c9f674 270 * @brief Conversion complete callback in non blocking mode for Channel2
mbed_official 489:119543c9f674 271 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 272 * the configuration information for the specified DAC.
mbed_official 489:119543c9f674 273 * @retval None
mbed_official 489:119543c9f674 274 */
mbed_official 489:119543c9f674 275 __weak void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef* hdac)
mbed_official 489:119543c9f674 276 {
mbed_official 489:119543c9f674 277 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 489:119543c9f674 278 the HAL_DACEx_ConvCpltCallbackCh2 could be implemented in the user file
mbed_official 489:119543c9f674 279 */
mbed_official 489:119543c9f674 280 }
mbed_official 489:119543c9f674 281
mbed_official 489:119543c9f674 282 /**
mbed_official 489:119543c9f674 283 * @brief Conversion half DMA transfer callback in non blocking mode for Channel2
mbed_official 489:119543c9f674 284 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 285 * the configuration information for the specified DAC.
mbed_official 489:119543c9f674 286 * @retval None
mbed_official 489:119543c9f674 287 */
mbed_official 489:119543c9f674 288 __weak void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef* hdac)
mbed_official 489:119543c9f674 289 {
mbed_official 489:119543c9f674 290 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 489:119543c9f674 291 the HAL_DACEx_ConvHalfCpltCallbackCh2 could be implemented in the user file
mbed_official 489:119543c9f674 292 */
mbed_official 489:119543c9f674 293 }
mbed_official 489:119543c9f674 294
mbed_official 489:119543c9f674 295 /**
mbed_official 489:119543c9f674 296 * @brief Error DAC callback for Channel2.
mbed_official 489:119543c9f674 297 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 298 * the configuration information for the specified DAC.
mbed_official 489:119543c9f674 299 * @retval None
mbed_official 489:119543c9f674 300 */
mbed_official 489:119543c9f674 301 __weak void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef *hdac)
mbed_official 489:119543c9f674 302 {
mbed_official 489:119543c9f674 303 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 489:119543c9f674 304 the HAL_DACEx_ErrorCallbackCh2 could be implemented in the user file
mbed_official 489:119543c9f674 305 */
mbed_official 489:119543c9f674 306 }
mbed_official 489:119543c9f674 307
mbed_official 489:119543c9f674 308 /**
mbed_official 489:119543c9f674 309 * @brief DMA underrun DAC callback for channel2.
mbed_official 489:119543c9f674 310 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 311 * the configuration information for the specified DAC.
mbed_official 489:119543c9f674 312 * @retval None
mbed_official 489:119543c9f674 313 */
mbed_official 489:119543c9f674 314 __weak void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef *hdac)
mbed_official 489:119543c9f674 315 {
mbed_official 489:119543c9f674 316 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 489:119543c9f674 317 the HAL_DAC_DMAUnderrunCallbackCh2 could be implemented in the user file
mbed_official 489:119543c9f674 318 */
mbed_official 489:119543c9f674 319 }
mbed_official 489:119543c9f674 320
mbed_official 489:119543c9f674 321 /**
mbed_official 489:119543c9f674 322 * @brief Enables DAC and starts conversion of channel.
mbed_official 489:119543c9f674 323 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 324 * the configuration information for the specified DAC.
mbed_official 489:119543c9f674 325 * @param Channel: The selected DAC channel.
mbed_official 489:119543c9f674 326 * This parameter can be one of the following values:
mbed_official 489:119543c9f674 327 * @arg DAC_CHANNEL_1: DAC Channel1 selected
mbed_official 489:119543c9f674 328 * @arg DAC_CHANNEL_2: DAC Channel2 selected
mbed_official 489:119543c9f674 329 * @retval HAL status
mbed_official 489:119543c9f674 330 */
mbed_official 489:119543c9f674 331 HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel)
mbed_official 489:119543c9f674 332 {
mbed_official 489:119543c9f674 333 uint32_t tmp1 = 0, tmp2 = 0;
mbed_official 489:119543c9f674 334
mbed_official 489:119543c9f674 335 /* Check the parameters */
mbed_official 489:119543c9f674 336 assert_param(IS_DAC_CHANNEL(Channel));
mbed_official 489:119543c9f674 337
mbed_official 489:119543c9f674 338 /* Process locked */
mbed_official 489:119543c9f674 339 __HAL_LOCK(hdac);
mbed_official 489:119543c9f674 340
mbed_official 489:119543c9f674 341 /* Change DAC state */
mbed_official 489:119543c9f674 342 hdac->State = HAL_DAC_STATE_BUSY;
mbed_official 489:119543c9f674 343
mbed_official 489:119543c9f674 344 /* Enable the Peripharal */
mbed_official 489:119543c9f674 345 __HAL_DAC_ENABLE(hdac, Channel);
mbed_official 489:119543c9f674 346
mbed_official 489:119543c9f674 347 if(Channel == DAC_CHANNEL_1)
mbed_official 489:119543c9f674 348 {
mbed_official 489:119543c9f674 349 tmp1 = hdac->Instance->CR & DAC_CR_TEN1;
mbed_official 489:119543c9f674 350 tmp2 = hdac->Instance->CR & DAC_CR_TSEL1;
mbed_official 489:119543c9f674 351 /* Check if software trigger enabled */
mbed_official 489:119543c9f674 352 if((tmp1 == DAC_CR_TEN1) && (tmp2 == DAC_CR_TSEL1))
mbed_official 489:119543c9f674 353 {
mbed_official 489:119543c9f674 354 /* Enable the selected DAC software conversion */
mbed_official 489:119543c9f674 355 SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG1);
mbed_official 489:119543c9f674 356 }
mbed_official 489:119543c9f674 357 }
mbed_official 489:119543c9f674 358 else
mbed_official 489:119543c9f674 359 {
mbed_official 489:119543c9f674 360 tmp1 = hdac->Instance->CR & DAC_CR_TEN2;
mbed_official 489:119543c9f674 361 tmp2 = hdac->Instance->CR & DAC_CR_TSEL2;
mbed_official 489:119543c9f674 362 /* Check if software trigger enabled */
mbed_official 489:119543c9f674 363 if((tmp1 == DAC_CR_TEN2) && (tmp2 == DAC_CR_TSEL2))
mbed_official 489:119543c9f674 364 {
mbed_official 489:119543c9f674 365 /* Enable the selected DAC software conversion*/
mbed_official 489:119543c9f674 366 SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG2);
mbed_official 489:119543c9f674 367 }
mbed_official 489:119543c9f674 368 }
mbed_official 376:cb4d9db17537 369
mbed_official 376:cb4d9db17537 370 /* Change DAC state */
mbed_official 376:cb4d9db17537 371 hdac->State = HAL_DAC_STATE_READY;
mbed_official 376:cb4d9db17537 372
mbed_official 376:cb4d9db17537 373 /* Process unlocked */
mbed_official 376:cb4d9db17537 374 __HAL_UNLOCK(hdac);
mbed_official 376:cb4d9db17537 375
mbed_official 376:cb4d9db17537 376 /* Return function status */
mbed_official 376:cb4d9db17537 377 return HAL_OK;
mbed_official 376:cb4d9db17537 378 }
mbed_official 376:cb4d9db17537 379
mbed_official 489:119543c9f674 380 /**
mbed_official 489:119543c9f674 381 * @brief Enables DAC and starts conversion of channel using DMA.
mbed_official 489:119543c9f674 382 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 383 * the configuration information for the specified DAC.
mbed_official 489:119543c9f674 384 * @param Channel: The selected DAC channel.
mbed_official 489:119543c9f674 385 * This parameter can be one of the following values:
mbed_official 489:119543c9f674 386 * @arg DAC_CHANNEL_1: DAC Channel1 selected
mbed_official 489:119543c9f674 387 * @arg DAC_CHANNEL_2: DAC Channel2 selected
mbed_official 489:119543c9f674 388 * @param pData: The destination peripheral Buffer address.
mbed_official 489:119543c9f674 389 * @param Length: The length of data to be transferred from memory to DAC peripheral
mbed_official 489:119543c9f674 390 * @param Alignment: Specifies the data alignment for DAC channel.
mbed_official 489:119543c9f674 391 * This parameter can be one of the following values:
mbed_official 489:119543c9f674 392 * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
mbed_official 489:119543c9f674 393 * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
mbed_official 489:119543c9f674 394 * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
mbed_official 489:119543c9f674 395 * @retval HAL status
mbed_official 489:119543c9f674 396 */
mbed_official 489:119543c9f674 397 HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment)
mbed_official 489:119543c9f674 398 {
mbed_official 489:119543c9f674 399 uint32_t tmpreg = 0;
mbed_official 489:119543c9f674 400
mbed_official 489:119543c9f674 401 /* Check the parameters */
mbed_official 489:119543c9f674 402 assert_param(IS_DAC_CHANNEL(Channel));
mbed_official 489:119543c9f674 403 assert_param(IS_DAC_ALIGN(Alignment));
mbed_official 489:119543c9f674 404
mbed_official 489:119543c9f674 405 /* Process locked */
mbed_official 489:119543c9f674 406 __HAL_LOCK(hdac);
mbed_official 489:119543c9f674 407
mbed_official 489:119543c9f674 408 /* Change DAC state */
mbed_official 489:119543c9f674 409 hdac->State = HAL_DAC_STATE_BUSY;
mbed_official 489:119543c9f674 410
mbed_official 489:119543c9f674 411 if(Channel == DAC_CHANNEL_1)
mbed_official 489:119543c9f674 412 {
mbed_official 489:119543c9f674 413 /* Set the DMA transfer complete callback for channel1 */
mbed_official 489:119543c9f674 414 hdac->DMA_Handle1->XferCpltCallback = DAC_DMAConvCpltCh1;
mbed_official 489:119543c9f674 415
mbed_official 489:119543c9f674 416 /* Set the DMA half transfer complete callback for channel1 */
mbed_official 489:119543c9f674 417 hdac->DMA_Handle1->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh1;
mbed_official 489:119543c9f674 418
mbed_official 489:119543c9f674 419 /* Set the DMA error callback for channel1 */
mbed_official 489:119543c9f674 420 hdac->DMA_Handle1->XferErrorCallback = DAC_DMAErrorCh1;
mbed_official 489:119543c9f674 421
mbed_official 489:119543c9f674 422 /* Enable the selected DAC channel1 DMA request */
mbed_official 489:119543c9f674 423 SET_BIT(hdac->Instance->CR, DAC_CR_DMAEN1);
mbed_official 489:119543c9f674 424
mbed_official 489:119543c9f674 425 /* Case of use of channel 1 */
mbed_official 489:119543c9f674 426 switch(Alignment)
mbed_official 489:119543c9f674 427 {
mbed_official 489:119543c9f674 428 case DAC_ALIGN_12B_R:
mbed_official 489:119543c9f674 429 /* Get DHR12R1 address */
mbed_official 489:119543c9f674 430 tmpreg = (uint32_t)&hdac->Instance->DHR12R1;
mbed_official 489:119543c9f674 431 break;
mbed_official 489:119543c9f674 432 case DAC_ALIGN_12B_L:
mbed_official 489:119543c9f674 433 /* Get DHR12L1 address */
mbed_official 489:119543c9f674 434 tmpreg = (uint32_t)&hdac->Instance->DHR12L1;
mbed_official 489:119543c9f674 435 break;
mbed_official 489:119543c9f674 436 case DAC_ALIGN_8B_R:
mbed_official 489:119543c9f674 437 /* Get DHR8R1 address */
mbed_official 489:119543c9f674 438 tmpreg = (uint32_t)&hdac->Instance->DHR8R1;
mbed_official 489:119543c9f674 439 break;
mbed_official 489:119543c9f674 440 default:
mbed_official 489:119543c9f674 441 break;
mbed_official 489:119543c9f674 442 }
mbed_official 489:119543c9f674 443 UNUSED(tmpreg); /* avoid warning on tmpreg affectation with stupid compiler */
mbed_official 489:119543c9f674 444 }
mbed_official 489:119543c9f674 445 else
mbed_official 489:119543c9f674 446 {
mbed_official 489:119543c9f674 447 /* Set the DMA transfer complete callback for channel2 */
mbed_official 489:119543c9f674 448 hdac->DMA_Handle2->XferCpltCallback = DAC_DMAConvCpltCh2;
mbed_official 489:119543c9f674 449
mbed_official 489:119543c9f674 450 /* Set the DMA half transfer complete callback for channel2 */
mbed_official 489:119543c9f674 451 hdac->DMA_Handle2->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh2;
mbed_official 489:119543c9f674 452
mbed_official 489:119543c9f674 453 /* Set the DMA error callback for channel2 */
mbed_official 489:119543c9f674 454 hdac->DMA_Handle2->XferErrorCallback = DAC_DMAErrorCh2;
mbed_official 489:119543c9f674 455
mbed_official 489:119543c9f674 456 /* Enable the selected DAC channel2 DMA request */
mbed_official 489:119543c9f674 457 SET_BIT(hdac->Instance->CR, DAC_CR_DMAEN2);
mbed_official 489:119543c9f674 458
mbed_official 489:119543c9f674 459 /* Case of use of channel 2 */
mbed_official 489:119543c9f674 460 switch(Alignment)
mbed_official 489:119543c9f674 461 {
mbed_official 489:119543c9f674 462 case DAC_ALIGN_12B_R:
mbed_official 489:119543c9f674 463 /* Get DHR12R2 address */
mbed_official 489:119543c9f674 464 tmpreg = (uint32_t)&hdac->Instance->DHR12R2;
mbed_official 489:119543c9f674 465 break;
mbed_official 489:119543c9f674 466 case DAC_ALIGN_12B_L:
mbed_official 489:119543c9f674 467 /* Get DHR12L2 address */
mbed_official 489:119543c9f674 468 tmpreg = (uint32_t)&hdac->Instance->DHR12L2;
mbed_official 489:119543c9f674 469 break;
mbed_official 489:119543c9f674 470 case DAC_ALIGN_8B_R:
mbed_official 489:119543c9f674 471 /* Get DHR8R2 address */
mbed_official 489:119543c9f674 472 tmpreg = (uint32_t)&hdac->Instance->DHR8R2;
mbed_official 489:119543c9f674 473 break;
mbed_official 489:119543c9f674 474 default:
mbed_official 489:119543c9f674 475 break;
mbed_official 489:119543c9f674 476 }
mbed_official 489:119543c9f674 477 }
mbed_official 489:119543c9f674 478
mbed_official 489:119543c9f674 479 /* Enable the DMA Stream */
mbed_official 489:119543c9f674 480 if(Channel == DAC_CHANNEL_1)
mbed_official 489:119543c9f674 481 {
mbed_official 489:119543c9f674 482 /* Enable the DAC DMA underrun interrupt */
mbed_official 489:119543c9f674 483 __HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR1);
mbed_official 489:119543c9f674 484
mbed_official 489:119543c9f674 485 /* Enable the DMA Stream */
mbed_official 489:119543c9f674 486 HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length);
mbed_official 489:119543c9f674 487 }
mbed_official 489:119543c9f674 488 else
mbed_official 489:119543c9f674 489 {
mbed_official 489:119543c9f674 490 /* Enable the DAC DMA underrun interrupt */
mbed_official 489:119543c9f674 491 __HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR2);
mbed_official 489:119543c9f674 492
mbed_official 489:119543c9f674 493 /* Enable the DMA Stream */
mbed_official 489:119543c9f674 494 HAL_DMA_Start_IT(hdac->DMA_Handle2, (uint32_t)pData, tmpreg, Length);
mbed_official 489:119543c9f674 495 }
mbed_official 489:119543c9f674 496
mbed_official 489:119543c9f674 497 /* Enable the Peripharal */
mbed_official 489:119543c9f674 498 __HAL_DAC_ENABLE(hdac, Channel);
mbed_official 489:119543c9f674 499
mbed_official 489:119543c9f674 500 /* Process Unlocked */
mbed_official 489:119543c9f674 501 __HAL_UNLOCK(hdac);
mbed_official 489:119543c9f674 502
mbed_official 489:119543c9f674 503 /* Return function status */
mbed_official 489:119543c9f674 504 return HAL_OK;
mbed_official 489:119543c9f674 505 }
mbed_official 489:119543c9f674 506
mbed_official 489:119543c9f674 507 /**
mbed_official 489:119543c9f674 508 * @brief Disables DAC and stop conversion of channel.
mbed_official 489:119543c9f674 509 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 510 * the configuration information for the specified DAC.
mbed_official 489:119543c9f674 511 * @param Channel: The selected DAC channel.
mbed_official 489:119543c9f674 512 * This parameter can be one of the following values:
mbed_official 489:119543c9f674 513 * @arg DAC_CHANNEL_1: DAC Channel1 selected
mbed_official 489:119543c9f674 514 * @arg DAC_CHANNEL_2: DAC Channel2 selected
mbed_official 489:119543c9f674 515 * @retval HAL status
mbed_official 489:119543c9f674 516 */
mbed_official 489:119543c9f674 517 HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel)
mbed_official 489:119543c9f674 518 {
mbed_official 489:119543c9f674 519 HAL_StatusTypeDef status = HAL_OK;
mbed_official 489:119543c9f674 520
mbed_official 489:119543c9f674 521 /* Check the parameters */
mbed_official 489:119543c9f674 522 assert_param(IS_DAC_CHANNEL(Channel));
mbed_official 489:119543c9f674 523
mbed_official 489:119543c9f674 524 /* Disable the selected DAC channel DMA request */
mbed_official 489:119543c9f674 525 CLEAR_BIT(hdac->Instance->CR, (DAC_CR_DMAEN1 << Channel));
mbed_official 489:119543c9f674 526
mbed_official 489:119543c9f674 527 /* Disable the Peripharal */
mbed_official 489:119543c9f674 528 __HAL_DAC_DISABLE(hdac, Channel);
mbed_official 489:119543c9f674 529
mbed_official 489:119543c9f674 530 /* Disable the DMA Channel */
mbed_official 489:119543c9f674 531 /* Channel1 is used */
mbed_official 489:119543c9f674 532 if(Channel == DAC_CHANNEL_1)
mbed_official 489:119543c9f674 533 {
mbed_official 489:119543c9f674 534 status = HAL_DMA_Abort(hdac->DMA_Handle1);
mbed_official 489:119543c9f674 535 }
mbed_official 489:119543c9f674 536 else /* Channel2 is used for */
mbed_official 489:119543c9f674 537 {
mbed_official 489:119543c9f674 538 status = HAL_DMA_Abort(hdac->DMA_Handle2);
mbed_official 489:119543c9f674 539 }
mbed_official 489:119543c9f674 540
mbed_official 489:119543c9f674 541 /* Check if DMA Channel effectively disabled */
mbed_official 489:119543c9f674 542 if(status != HAL_OK)
mbed_official 489:119543c9f674 543 {
mbed_official 489:119543c9f674 544 /* Update DAC state machine to error */
mbed_official 489:119543c9f674 545 hdac->State = HAL_DAC_STATE_ERROR;
mbed_official 489:119543c9f674 546 }
mbed_official 489:119543c9f674 547 else
mbed_official 489:119543c9f674 548 {
mbed_official 489:119543c9f674 549 /* Change DAC state */
mbed_official 489:119543c9f674 550 hdac->State = HAL_DAC_STATE_READY;
mbed_official 489:119543c9f674 551 }
mbed_official 489:119543c9f674 552
mbed_official 489:119543c9f674 553 /* Return function status */
mbed_official 489:119543c9f674 554 return status;
mbed_official 489:119543c9f674 555 }
mbed_official 489:119543c9f674 556
mbed_official 489:119543c9f674 557 /**
mbed_official 489:119543c9f674 558 * @brief Returns the last data output value of the selected DAC channel.
mbed_official 489:119543c9f674 559 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 560 * the configuration information for the specified DAC.
mbed_official 489:119543c9f674 561 * @param Channel: The selected DAC channel.
mbed_official 489:119543c9f674 562 * This parameter can be one of the following values:
mbed_official 489:119543c9f674 563 * @arg DAC_CHANNEL_1: DAC Channel1 selected
mbed_official 489:119543c9f674 564 * @arg DAC_CHANNEL_2: DAC Channel2 selected
mbed_official 489:119543c9f674 565 * @retval The selected DAC channel data output value.
mbed_official 489:119543c9f674 566 */
mbed_official 489:119543c9f674 567 uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel)
mbed_official 489:119543c9f674 568 {
mbed_official 489:119543c9f674 569 /* Check the parameters */
mbed_official 489:119543c9f674 570 assert_param(IS_DAC_CHANNEL(Channel));
mbed_official 489:119543c9f674 571
mbed_official 489:119543c9f674 572 /* Returns the DAC channel data output register value */
mbed_official 489:119543c9f674 573 if(Channel == DAC_CHANNEL_1)
mbed_official 489:119543c9f674 574 {
mbed_official 489:119543c9f674 575 return hdac->Instance->DOR1;
mbed_official 489:119543c9f674 576 }
mbed_official 489:119543c9f674 577 else
mbed_official 489:119543c9f674 578 {
mbed_official 489:119543c9f674 579 return hdac->Instance->DOR2;
mbed_official 489:119543c9f674 580 }
mbed_official 489:119543c9f674 581 }
mbed_official 489:119543c9f674 582
mbed_official 489:119543c9f674 583 /**
mbed_official 489:119543c9f674 584 * @brief Handles DAC interrupt request
mbed_official 489:119543c9f674 585 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 586 * the configuration information for the specified DAC.
mbed_official 489:119543c9f674 587 * @retval None
mbed_official 489:119543c9f674 588 */
mbed_official 489:119543c9f674 589 void HAL_DAC_IRQHandler(DAC_HandleTypeDef* hdac)
mbed_official 489:119543c9f674 590 {
mbed_official 489:119543c9f674 591 /* Check underrun flag of DAC channel 1 */
mbed_official 489:119543c9f674 592 if(__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR1))
mbed_official 489:119543c9f674 593 {
mbed_official 489:119543c9f674 594 /* Change DAC state to error state */
mbed_official 489:119543c9f674 595 hdac->State = HAL_DAC_STATE_ERROR;
mbed_official 489:119543c9f674 596
mbed_official 489:119543c9f674 597 /* Set DAC error code to chanel1 DMA underrun error */
mbed_official 489:119543c9f674 598 hdac->ErrorCode |= HAL_DAC_ERROR_DMAUNDERRUNCH1;
mbed_official 489:119543c9f674 599
mbed_official 489:119543c9f674 600 /* Clear the underrun flag */
mbed_official 489:119543c9f674 601 __HAL_DAC_CLEAR_FLAG(hdac,DAC_FLAG_DMAUDR1);
mbed_official 489:119543c9f674 602
mbed_official 489:119543c9f674 603 /* Disable the selected DAC channel1 DMA request */
mbed_official 489:119543c9f674 604 CLEAR_BIT(hdac->Instance->CR, DAC_CR_DMAEN1);
mbed_official 489:119543c9f674 605
mbed_official 489:119543c9f674 606 /* Error callback */
mbed_official 489:119543c9f674 607 HAL_DAC_DMAUnderrunCallbackCh1(hdac);
mbed_official 489:119543c9f674 608 }
mbed_official 489:119543c9f674 609
mbed_official 489:119543c9f674 610 /* Check underrun flag of DAC channel 2 */
mbed_official 489:119543c9f674 611 if(__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR2))
mbed_official 489:119543c9f674 612 {
mbed_official 489:119543c9f674 613 /* Change DAC state to error state */
mbed_official 489:119543c9f674 614 hdac->State = HAL_DAC_STATE_ERROR;
mbed_official 489:119543c9f674 615
mbed_official 489:119543c9f674 616 /* Set DAC error code to channel2 DMA underrun error */
mbed_official 489:119543c9f674 617 hdac->ErrorCode |= HAL_DAC_ERROR_DMAUNDERRUNCH2;
mbed_official 489:119543c9f674 618
mbed_official 489:119543c9f674 619 /* Clear the underrun flag */
mbed_official 489:119543c9f674 620 __HAL_DAC_CLEAR_FLAG(hdac,DAC_FLAG_DMAUDR2);
mbed_official 489:119543c9f674 621
mbed_official 489:119543c9f674 622 /* Disable the selected DAC channel1 DMA request */
mbed_official 489:119543c9f674 623 CLEAR_BIT(hdac->Instance->CR, DAC_CR_DMAEN2);
mbed_official 489:119543c9f674 624
mbed_official 489:119543c9f674 625 /* Error callback */
mbed_official 489:119543c9f674 626 HAL_DACEx_DMAUnderrunCallbackCh2(hdac);
mbed_official 489:119543c9f674 627 }
mbed_official 489:119543c9f674 628 }
mbed_official 489:119543c9f674 629
mbed_official 489:119543c9f674 630
mbed_official 489:119543c9f674 631 /**
mbed_official 489:119543c9f674 632 * @brief Set the specified data holding register value for DAC channel.
mbed_official 489:119543c9f674 633 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 634 * the configuration information for the specified DAC.
mbed_official 489:119543c9f674 635 * @param Channel: The selected DAC channel.
mbed_official 489:119543c9f674 636 * This parameter can be one of the following values:
mbed_official 489:119543c9f674 637 * @arg DAC_CHANNEL_1: DAC Channel1 selected
mbed_official 489:119543c9f674 638 * @arg DAC_CHANNEL_2: DAC Channel2 selected
mbed_official 489:119543c9f674 639 * @param Alignment: Specifies the data alignment.
mbed_official 489:119543c9f674 640 * This parameter can be one of the following values:
mbed_official 489:119543c9f674 641 * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
mbed_official 489:119543c9f674 642 * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
mbed_official 489:119543c9f674 643 * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
mbed_official 489:119543c9f674 644 * @param Data: Data to be loaded in the selected data holding register.
mbed_official 489:119543c9f674 645 * @retval HAL status
mbed_official 489:119543c9f674 646 */
mbed_official 489:119543c9f674 647 HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data)
mbed_official 489:119543c9f674 648 {
mbed_official 489:119543c9f674 649 __IO uint32_t tmp = 0;
mbed_official 489:119543c9f674 650
mbed_official 489:119543c9f674 651 /* Check the parameters */
mbed_official 489:119543c9f674 652 assert_param(IS_DAC_CHANNEL(Channel));
mbed_official 489:119543c9f674 653 assert_param(IS_DAC_ALIGN(Alignment));
mbed_official 489:119543c9f674 654 assert_param(IS_DAC_DATA(Data));
mbed_official 489:119543c9f674 655
mbed_official 489:119543c9f674 656 tmp = (uint32_t)hdac->Instance;
mbed_official 489:119543c9f674 657 if(Channel == DAC_CHANNEL_1)
mbed_official 489:119543c9f674 658 {
mbed_official 489:119543c9f674 659 tmp += __DAC_DHR12R1_ALIGNEMENT(Alignment);
mbed_official 489:119543c9f674 660 }
mbed_official 489:119543c9f674 661 else
mbed_official 489:119543c9f674 662 {
mbed_official 489:119543c9f674 663 tmp += __DAC_DHR12R2_ALIGNEMENT(Alignment);
mbed_official 489:119543c9f674 664 }
mbed_official 489:119543c9f674 665
mbed_official 489:119543c9f674 666 /* Set the DAC channel selected data holding register */
mbed_official 489:119543c9f674 667 *(__IO uint32_t *) tmp = Data;
mbed_official 489:119543c9f674 668
mbed_official 489:119543c9f674 669 /* Return function status */
mbed_official 489:119543c9f674 670 return HAL_OK;
mbed_official 489:119543c9f674 671 }
mbed_official 489:119543c9f674 672 #else /* All products with only one channel */
mbed_official 489:119543c9f674 673
mbed_official 489:119543c9f674 674 /**
mbed_official 489:119543c9f674 675 * @brief Enables DAC and starts conversion of channel.
mbed_official 489:119543c9f674 676 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 677 * the configuration information for the specified DAC.
mbed_official 489:119543c9f674 678 * @param Channel: The selected DAC channel.
mbed_official 489:119543c9f674 679 * This parameter can be one of the following values:
mbed_official 489:119543c9f674 680 * @arg DAC_CHANNEL_1: DAC Channel1 selected
mbed_official 489:119543c9f674 681 * @retval HAL status
mbed_official 489:119543c9f674 682 */
mbed_official 489:119543c9f674 683 HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel)
mbed_official 489:119543c9f674 684 {
mbed_official 489:119543c9f674 685 uint32_t tmp1 = 0, tmp2 = 0;
mbed_official 489:119543c9f674 686
mbed_official 489:119543c9f674 687 /* Check the parameters */
mbed_official 489:119543c9f674 688 assert_param(IS_DAC_CHANNEL(Channel));
mbed_official 489:119543c9f674 689
mbed_official 489:119543c9f674 690 /* Process locked */
mbed_official 489:119543c9f674 691 __HAL_LOCK(hdac);
mbed_official 489:119543c9f674 692
mbed_official 489:119543c9f674 693 /* Change DAC state */
mbed_official 489:119543c9f674 694 hdac->State = HAL_DAC_STATE_BUSY;
mbed_official 489:119543c9f674 695
mbed_official 489:119543c9f674 696 /* Enable the Peripharal */
mbed_official 489:119543c9f674 697 __HAL_DAC_ENABLE(hdac, Channel);
mbed_official 489:119543c9f674 698
mbed_official 489:119543c9f674 699 tmp1 = hdac->Instance->CR & DAC_CR_TEN1;
mbed_official 489:119543c9f674 700 tmp2 = hdac->Instance->CR & DAC_CR_TSEL1;
mbed_official 489:119543c9f674 701 /* Check if software trigger enabled */
mbed_official 489:119543c9f674 702 if((tmp1 == DAC_CR_TEN1) && (tmp2 == DAC_CR_TSEL1))
mbed_official 489:119543c9f674 703 {
mbed_official 489:119543c9f674 704 /* Enable the selected DAC software conversion */
mbed_official 489:119543c9f674 705 SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG1);
mbed_official 489:119543c9f674 706 }
mbed_official 489:119543c9f674 707
mbed_official 489:119543c9f674 708 /* Change DAC state */
mbed_official 489:119543c9f674 709 hdac->State = HAL_DAC_STATE_READY;
mbed_official 489:119543c9f674 710
mbed_official 489:119543c9f674 711 /* Process unlocked */
mbed_official 489:119543c9f674 712 __HAL_UNLOCK(hdac);
mbed_official 489:119543c9f674 713
mbed_official 489:119543c9f674 714 /* Return function status */
mbed_official 489:119543c9f674 715 return HAL_OK;
mbed_official 489:119543c9f674 716 }
mbed_official 489:119543c9f674 717
mbed_official 489:119543c9f674 718 /**
mbed_official 489:119543c9f674 719 * @brief Enables DAC and starts conversion of channel using DMA.
mbed_official 489:119543c9f674 720 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 721 * the configuration information for the specified DAC.
mbed_official 489:119543c9f674 722 * @param Channel: The selected DAC channel.
mbed_official 489:119543c9f674 723 * This parameter can be one of the following values:
mbed_official 489:119543c9f674 724 * @arg DAC_CHANNEL_1: DAC Channel1 selected
mbed_official 489:119543c9f674 725 * @param pData: The destination peripheral Buffer address.
mbed_official 489:119543c9f674 726 * @param Length: The length of data to be transferred from memory to DAC peripheral
mbed_official 489:119543c9f674 727 * @param Alignment: Specifies the data alignment for DAC channel.
mbed_official 489:119543c9f674 728 * This parameter can be one of the following values:
mbed_official 489:119543c9f674 729 * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
mbed_official 489:119543c9f674 730 * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
mbed_official 489:119543c9f674 731 * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
mbed_official 489:119543c9f674 732 * @retval HAL status
mbed_official 489:119543c9f674 733 */
mbed_official 489:119543c9f674 734 HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment)
mbed_official 489:119543c9f674 735 {
mbed_official 489:119543c9f674 736 uint32_t tmpreg = 0;
mbed_official 489:119543c9f674 737
mbed_official 489:119543c9f674 738 /* Check the parameters */
mbed_official 489:119543c9f674 739 assert_param(IS_DAC_CHANNEL(Channel));
mbed_official 489:119543c9f674 740 assert_param(IS_DAC_ALIGN(Alignment));
mbed_official 489:119543c9f674 741
mbed_official 489:119543c9f674 742 /* Process locked */
mbed_official 489:119543c9f674 743 __HAL_LOCK(hdac);
mbed_official 489:119543c9f674 744
mbed_official 489:119543c9f674 745 /* Change DAC state */
mbed_official 489:119543c9f674 746 hdac->State = HAL_DAC_STATE_BUSY;
mbed_official 489:119543c9f674 747
mbed_official 489:119543c9f674 748 /* Set the DMA transfer complete callback for channel1 */
mbed_official 489:119543c9f674 749 hdac->DMA_Handle1->XferCpltCallback = DAC_DMAConvCpltCh1;
mbed_official 489:119543c9f674 750
mbed_official 489:119543c9f674 751 /* Set the DMA half transfer complete callback for channel1 */
mbed_official 489:119543c9f674 752 hdac->DMA_Handle1->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh1;
mbed_official 489:119543c9f674 753
mbed_official 489:119543c9f674 754 /* Set the DMA error callback for channel1 */
mbed_official 489:119543c9f674 755 hdac->DMA_Handle1->XferErrorCallback = DAC_DMAErrorCh1;
mbed_official 489:119543c9f674 756
mbed_official 489:119543c9f674 757 /* Enable the selected DAC channel1 DMA request */
mbed_official 489:119543c9f674 758 SET_BIT(hdac->Instance->CR, DAC_CR_DMAEN1);
mbed_official 489:119543c9f674 759
mbed_official 489:119543c9f674 760 /* Case of use of channel 1 */
mbed_official 489:119543c9f674 761 switch(Alignment)
mbed_official 489:119543c9f674 762 {
mbed_official 489:119543c9f674 763 case DAC_ALIGN_12B_R:
mbed_official 489:119543c9f674 764 /* Get DHR12R1 address */
mbed_official 489:119543c9f674 765 tmpreg = (uint32_t)&hdac->Instance->DHR12R1;
mbed_official 489:119543c9f674 766 break;
mbed_official 489:119543c9f674 767 case DAC_ALIGN_12B_L:
mbed_official 489:119543c9f674 768 /* Get DHR12L1 address */
mbed_official 489:119543c9f674 769 tmpreg = (uint32_t)&hdac->Instance->DHR12L1;
mbed_official 489:119543c9f674 770 break;
mbed_official 489:119543c9f674 771 case DAC_ALIGN_8B_R:
mbed_official 489:119543c9f674 772 /* Get DHR8R1 address */
mbed_official 489:119543c9f674 773 tmpreg = (uint32_t)&hdac->Instance->DHR8R1;
mbed_official 489:119543c9f674 774 break;
mbed_official 489:119543c9f674 775 default:
mbed_official 489:119543c9f674 776 break;
mbed_official 489:119543c9f674 777 }
mbed_official 489:119543c9f674 778 UNUSED(tmpreg); /* avoid warning on tmpreg affectation with stupid compiler */
mbed_official 489:119543c9f674 779
mbed_official 489:119543c9f674 780 /* Enable the DMA Stream */
mbed_official 489:119543c9f674 781 /* Enable the DAC DMA underrun interrupt */
mbed_official 489:119543c9f674 782 __HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR1);
mbed_official 489:119543c9f674 783
mbed_official 489:119543c9f674 784 /* Enable the DMA Stream */
mbed_official 489:119543c9f674 785 HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length);
mbed_official 489:119543c9f674 786
mbed_official 489:119543c9f674 787 /* Enable the Peripharal */
mbed_official 489:119543c9f674 788 __HAL_DAC_ENABLE(hdac, Channel);
mbed_official 489:119543c9f674 789
mbed_official 489:119543c9f674 790 /* Process Unlocked */
mbed_official 489:119543c9f674 791 __HAL_UNLOCK(hdac);
mbed_official 489:119543c9f674 792
mbed_official 489:119543c9f674 793 /* Return function status */
mbed_official 489:119543c9f674 794 return HAL_OK;
mbed_official 489:119543c9f674 795 }
mbed_official 489:119543c9f674 796
mbed_official 489:119543c9f674 797 /**
mbed_official 489:119543c9f674 798 * @brief Disables DAC and stop conversion of channel.
mbed_official 489:119543c9f674 799 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 800 * the configuration information for the specified DAC.
mbed_official 489:119543c9f674 801 * @param Channel: The selected DAC channel.
mbed_official 489:119543c9f674 802 * This parameter can be one of the following values:
mbed_official 489:119543c9f674 803 * @arg DAC_CHANNEL_1: DAC Channel1 selected
mbed_official 489:119543c9f674 804 * @retval HAL status
mbed_official 489:119543c9f674 805 */
mbed_official 489:119543c9f674 806 HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel)
mbed_official 489:119543c9f674 807 {
mbed_official 489:119543c9f674 808 HAL_StatusTypeDef status = HAL_OK;
mbed_official 489:119543c9f674 809
mbed_official 489:119543c9f674 810 /* Check the parameters */
mbed_official 489:119543c9f674 811 assert_param(IS_DAC_CHANNEL(Channel));
mbed_official 489:119543c9f674 812
mbed_official 489:119543c9f674 813 /* Disable the selected DAC channel DMA request */
mbed_official 489:119543c9f674 814 CLEAR_BIT(hdac->Instance->CR, (DAC_CR_DMAEN1 << Channel));
mbed_official 489:119543c9f674 815
mbed_official 489:119543c9f674 816 /* Disable the Peripharal */
mbed_official 489:119543c9f674 817 __HAL_DAC_DISABLE(hdac, Channel);
mbed_official 489:119543c9f674 818
mbed_official 489:119543c9f674 819 /* Disable the DMA Channel */
mbed_official 489:119543c9f674 820 status = HAL_DMA_Abort(hdac->DMA_Handle1);
mbed_official 489:119543c9f674 821
mbed_official 489:119543c9f674 822 /* Check if DMA Channel effectively disabled */
mbed_official 489:119543c9f674 823 if(status != HAL_OK)
mbed_official 489:119543c9f674 824 {
mbed_official 489:119543c9f674 825 /* Update DAC state machine to error */
mbed_official 489:119543c9f674 826 hdac->State = HAL_DAC_STATE_ERROR;
mbed_official 489:119543c9f674 827 }
mbed_official 489:119543c9f674 828 else
mbed_official 489:119543c9f674 829 {
mbed_official 489:119543c9f674 830 /* Change DAC state */
mbed_official 489:119543c9f674 831 hdac->State = HAL_DAC_STATE_READY;
mbed_official 489:119543c9f674 832 }
mbed_official 489:119543c9f674 833
mbed_official 489:119543c9f674 834 /* Return function status */
mbed_official 489:119543c9f674 835 return status;
mbed_official 489:119543c9f674 836 }
mbed_official 489:119543c9f674 837
mbed_official 489:119543c9f674 838 /**
mbed_official 489:119543c9f674 839 * @brief Returns the last data output value of the selected DAC channel.
mbed_official 489:119543c9f674 840 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 841 * the configuration information for the specified DAC.
mbed_official 489:119543c9f674 842 * @param Channel: The selected DAC channel.
mbed_official 489:119543c9f674 843 * This parameter can be one of the following values:
mbed_official 489:119543c9f674 844 * @arg DAC_CHANNEL_1: DAC Channel1 selected
mbed_official 489:119543c9f674 845 * @retval The selected DAC channel data output value.
mbed_official 489:119543c9f674 846 */
mbed_official 489:119543c9f674 847 uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel)
mbed_official 489:119543c9f674 848 {
mbed_official 489:119543c9f674 849 /* Check the parameters */
mbed_official 489:119543c9f674 850 assert_param(IS_DAC_CHANNEL(Channel));
mbed_official 489:119543c9f674 851
mbed_official 489:119543c9f674 852 /* Returns the DAC channel data output register value */
mbed_official 489:119543c9f674 853 return hdac->Instance->DOR1;
mbed_official 489:119543c9f674 854 }
mbed_official 489:119543c9f674 855
mbed_official 489:119543c9f674 856 /**
mbed_official 489:119543c9f674 857 * @brief Handles DAC interrupt request
mbed_official 489:119543c9f674 858 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 859 * the configuration information for the specified DAC.
mbed_official 489:119543c9f674 860 * @retval None
mbed_official 489:119543c9f674 861 */
mbed_official 489:119543c9f674 862 void HAL_DAC_IRQHandler(DAC_HandleTypeDef* hdac)
mbed_official 489:119543c9f674 863 {
mbed_official 489:119543c9f674 864 /* Check underrun flag of DAC channel 1 */
mbed_official 489:119543c9f674 865 if(__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR1))
mbed_official 489:119543c9f674 866 {
mbed_official 489:119543c9f674 867 /* Change DAC state to error state */
mbed_official 489:119543c9f674 868 hdac->State = HAL_DAC_STATE_ERROR;
mbed_official 489:119543c9f674 869
mbed_official 489:119543c9f674 870 /* Set DAC error code to chanel1 DMA underrun error */
mbed_official 489:119543c9f674 871 hdac->ErrorCode |= HAL_DAC_ERROR_DMAUNDERRUNCH1;
mbed_official 489:119543c9f674 872
mbed_official 489:119543c9f674 873 /* Clear the underrun flag */
mbed_official 489:119543c9f674 874 __HAL_DAC_CLEAR_FLAG(hdac,DAC_FLAG_DMAUDR1);
mbed_official 489:119543c9f674 875
mbed_official 489:119543c9f674 876 /* Disable the selected DAC channel1 DMA request */
mbed_official 489:119543c9f674 877 CLEAR_BIT(hdac->Instance->CR, DAC_CR_DMAEN1);
mbed_official 489:119543c9f674 878
mbed_official 489:119543c9f674 879 /* Error callback */
mbed_official 489:119543c9f674 880 HAL_DAC_DMAUnderrunCallbackCh1(hdac);
mbed_official 489:119543c9f674 881 }
mbed_official 489:119543c9f674 882 }
mbed_official 489:119543c9f674 883
mbed_official 489:119543c9f674 884 /**
mbed_official 489:119543c9f674 885 * @brief Set the specified data holding register value for DAC channel.
mbed_official 489:119543c9f674 886 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 887 * the configuration information for the specified DAC.
mbed_official 489:119543c9f674 888 * @param Channel: The selected DAC channel.
mbed_official 489:119543c9f674 889 * This parameter can be one of the following values:
mbed_official 489:119543c9f674 890 * @arg DAC_CHANNEL_1: DAC Channel1 selected
mbed_official 489:119543c9f674 891 * @param Alignment: Specifies the data alignment.
mbed_official 489:119543c9f674 892 * This parameter can be one of the following values:
mbed_official 489:119543c9f674 893 * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
mbed_official 489:119543c9f674 894 * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
mbed_official 489:119543c9f674 895 * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
mbed_official 489:119543c9f674 896 * @param Data: Data to be loaded in the selected data holding register.
mbed_official 489:119543c9f674 897 * @retval HAL status
mbed_official 489:119543c9f674 898 */
mbed_official 489:119543c9f674 899 HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data)
mbed_official 489:119543c9f674 900 {
mbed_official 489:119543c9f674 901 __IO uint32_t tmp = 0;
mbed_official 489:119543c9f674 902
mbed_official 489:119543c9f674 903 /* Check the parameters */
mbed_official 489:119543c9f674 904 assert_param(IS_DAC_CHANNEL(Channel));
mbed_official 489:119543c9f674 905 assert_param(IS_DAC_ALIGN(Alignment));
mbed_official 489:119543c9f674 906 assert_param(IS_DAC_DATA(Data));
mbed_official 489:119543c9f674 907
mbed_official 489:119543c9f674 908 tmp = (uint32_t)hdac->Instance;
mbed_official 489:119543c9f674 909 tmp += __DAC_DHR12R1_ALIGNEMENT(Alignment);
mbed_official 489:119543c9f674 910
mbed_official 489:119543c9f674 911 /* Set the DAC channel selected data holding register */
mbed_official 489:119543c9f674 912 *(__IO uint32_t *) tmp = Data;
mbed_official 489:119543c9f674 913
mbed_official 489:119543c9f674 914 /* Return function status */
mbed_official 489:119543c9f674 915 return HAL_OK;
mbed_official 489:119543c9f674 916 }
mbed_official 489:119543c9f674 917
mbed_official 489:119543c9f674 918 #endif /* #if defined (STM32L072xx) || defined (STM32L073xx) || defined (STM32L082xx) || defined (STM32L083xx) */
mbed_official 376:cb4d9db17537 919
mbed_official 376:cb4d9db17537 920 /**
mbed_official 376:cb4d9db17537 921 * @}
mbed_official 376:cb4d9db17537 922 */
mbed_official 376:cb4d9db17537 923
mbed_official 376:cb4d9db17537 924 /**
mbed_official 376:cb4d9db17537 925 * @}
mbed_official 376:cb4d9db17537 926 */
mbed_official 376:cb4d9db17537 927
mbed_official 489:119543c9f674 928 /** @defgroup DACEx_Private_Functions DACEx Private Functions
mbed_official 489:119543c9f674 929 * @{
mbed_official 489:119543c9f674 930 */
mbed_official 489:119543c9f674 931 #if defined (STM32L072xx) || defined (STM32L073xx) || defined (STM32L082xx) || defined (STM32L083xx)
mbed_official 489:119543c9f674 932 /**
mbed_official 489:119543c9f674 933 * @brief DMA conversion complete callback.
mbed_official 489:119543c9f674 934 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 935 * the configuration information for the specified DMA module.
mbed_official 489:119543c9f674 936 * @retval None
mbed_official 489:119543c9f674 937 */
mbed_official 489:119543c9f674 938 static void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma)
mbed_official 489:119543c9f674 939 {
mbed_official 489:119543c9f674 940 DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
mbed_official 489:119543c9f674 941
mbed_official 489:119543c9f674 942 HAL_DACEx_ConvCpltCallbackCh2(hdac);
mbed_official 489:119543c9f674 943
mbed_official 489:119543c9f674 944 hdac->State= HAL_DAC_STATE_READY;
mbed_official 489:119543c9f674 945 }
mbed_official 489:119543c9f674 946
mbed_official 489:119543c9f674 947 /**
mbed_official 489:119543c9f674 948 * @brief DMA half transfer complete callback.
mbed_official 489:119543c9f674 949 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 950 * the configuration information for the specified DMA module.
mbed_official 489:119543c9f674 951 * @retval None
mbed_official 489:119543c9f674 952 */
mbed_official 489:119543c9f674 953 static void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma)
mbed_official 489:119543c9f674 954 {
mbed_official 489:119543c9f674 955 DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
mbed_official 489:119543c9f674 956 /* Conversion complete callback */
mbed_official 489:119543c9f674 957 HAL_DACEx_ConvHalfCpltCallbackCh2(hdac);
mbed_official 489:119543c9f674 958 }
mbed_official 489:119543c9f674 959
mbed_official 489:119543c9f674 960 /**
mbed_official 489:119543c9f674 961 * @brief DMA error callback
mbed_official 489:119543c9f674 962 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 963 * the configuration information for the specified DMA module.
mbed_official 489:119543c9f674 964 * @retval None
mbed_official 489:119543c9f674 965 */
mbed_official 489:119543c9f674 966 static void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma)
mbed_official 489:119543c9f674 967 {
mbed_official 489:119543c9f674 968 DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
mbed_official 489:119543c9f674 969
mbed_official 489:119543c9f674 970 /* Set DAC error code to DMA error */
mbed_official 489:119543c9f674 971 hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
mbed_official 489:119543c9f674 972
mbed_official 489:119543c9f674 973 HAL_DACEx_ErrorCallbackCh2(hdac);
mbed_official 489:119543c9f674 974
mbed_official 489:119543c9f674 975 hdac->State= HAL_DAC_STATE_READY;
mbed_official 489:119543c9f674 976 }
mbed_official 489:119543c9f674 977 #endif /* STM32L072xx || STM32L073xx || STM32L082xx || STM32L083xx */
mbed_official 489:119543c9f674 978
mbed_official 489:119543c9f674 979 /**
mbed_official 489:119543c9f674 980 * @brief DMA conversion complete callback.
mbed_official 489:119543c9f674 981 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 982 * the configuration information for the specified DMA module.
mbed_official 489:119543c9f674 983 * @retval None
mbed_official 489:119543c9f674 984 */
mbed_official 489:119543c9f674 985 static void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma)
mbed_official 489:119543c9f674 986 {
mbed_official 489:119543c9f674 987 DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
mbed_official 489:119543c9f674 988
mbed_official 489:119543c9f674 989 HAL_DAC_ConvCpltCallbackCh1(hdac);
mbed_official 489:119543c9f674 990
mbed_official 489:119543c9f674 991 hdac->State= HAL_DAC_STATE_READY;
mbed_official 489:119543c9f674 992 }
mbed_official 489:119543c9f674 993
mbed_official 489:119543c9f674 994 /**
mbed_official 489:119543c9f674 995 * @brief DMA half transfer complete callback.
mbed_official 489:119543c9f674 996 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 997 * the configuration information for the specified DMA module.
mbed_official 489:119543c9f674 998 * @retval None
mbed_official 489:119543c9f674 999 */
mbed_official 489:119543c9f674 1000 static void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma)
mbed_official 489:119543c9f674 1001 {
mbed_official 489:119543c9f674 1002 DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
mbed_official 489:119543c9f674 1003 /* Conversion complete callback */
mbed_official 489:119543c9f674 1004 HAL_DAC_ConvHalfCpltCallbackCh1(hdac);
mbed_official 489:119543c9f674 1005 }
mbed_official 489:119543c9f674 1006
mbed_official 489:119543c9f674 1007 /**
mbed_official 489:119543c9f674 1008 * @brief DMA error callback
mbed_official 489:119543c9f674 1009 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
mbed_official 489:119543c9f674 1010 * the configuration information for the specified DMA module.
mbed_official 489:119543c9f674 1011 * @retval None
mbed_official 489:119543c9f674 1012 */
mbed_official 489:119543c9f674 1013 static void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma)
mbed_official 489:119543c9f674 1014 {
mbed_official 489:119543c9f674 1015 DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
mbed_official 489:119543c9f674 1016
mbed_official 489:119543c9f674 1017 /* Set DAC error code to DMA error */
mbed_official 489:119543c9f674 1018 hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
mbed_official 489:119543c9f674 1019
mbed_official 489:119543c9f674 1020 HAL_DAC_ErrorCallbackCh1(hdac);
mbed_official 489:119543c9f674 1021
mbed_official 489:119543c9f674 1022 hdac->State= HAL_DAC_STATE_READY;
mbed_official 489:119543c9f674 1023 }
mbed_official 489:119543c9f674 1024
mbed_official 489:119543c9f674 1025 /**
mbed_official 489:119543c9f674 1026 * @}
mbed_official 489:119543c9f674 1027 */
mbed_official 489:119543c9f674 1028
mbed_official 489:119543c9f674 1029
mbed_official 376:cb4d9db17537 1030
mbed_official 376:cb4d9db17537 1031 /**
mbed_official 376:cb4d9db17537 1032 * @}
mbed_official 376:cb4d9db17537 1033 */
mbed_official 376:cb4d9db17537 1034
mbed_official 376:cb4d9db17537 1035 /**
mbed_official 376:cb4d9db17537 1036 * @}
mbed_official 376:cb4d9db17537 1037 */
mbed_official 489:119543c9f674 1038 #endif /* HAL_DAC_MODULE_ENABLED */
mbed_official 489:119543c9f674 1039 #endif /* #if !defined (STM32L031xx) && !defined (STM32L041xx) && !defined (STM32L051xx) && !defined (STM32L061xx) && !defined (STM32L071xx) && !defined (STM32L081xx) */
mbed_official 489:119543c9f674 1040 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
mbed_official 376:cb4d9db17537 1041