mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_DISCO_F407VG/stm32f4xx_hal_dac.c@133:d4dda5c437f0, 2014-03-24 (annotated)
- Committer:
- mbed_official
- Date:
- Mon Mar 24 17:45:07 2014 +0000
- Revision:
- 133:d4dda5c437f0
- Child:
- 242:7074e42da0b2
Synchronized with git revision 47b961246bed973fe4cb8932781ffc8025b78a61
Full URL: https://github.com/mbedmicro/mbed/commit/47b961246bed973fe4cb8932781ffc8025b78a61/
[STM32F4-Discovery (STM32F407VG)] initial port
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 133:d4dda5c437f0 | 1 | /** |
mbed_official | 133:d4dda5c437f0 | 2 | ****************************************************************************** |
mbed_official | 133:d4dda5c437f0 | 3 | * @file stm32f4xx_hal_dac.c |
mbed_official | 133:d4dda5c437f0 | 4 | * @author MCD Application Team |
mbed_official | 133:d4dda5c437f0 | 5 | * @version V1.0.0 |
mbed_official | 133:d4dda5c437f0 | 6 | * @date 18-February-2014 |
mbed_official | 133:d4dda5c437f0 | 7 | * @brief DAC HAL module driver. |
mbed_official | 133:d4dda5c437f0 | 8 | * This file provides firmware functions to manage the following |
mbed_official | 133:d4dda5c437f0 | 9 | * functionalities of the Digital to Analog Converter (DAC) peripheral: |
mbed_official | 133:d4dda5c437f0 | 10 | * + Initialization and de-initialization functions |
mbed_official | 133:d4dda5c437f0 | 11 | * + IO operation functions |
mbed_official | 133:d4dda5c437f0 | 12 | * + Peripheral Control functions |
mbed_official | 133:d4dda5c437f0 | 13 | * + Peripheral State and Errors functions |
mbed_official | 133:d4dda5c437f0 | 14 | * |
mbed_official | 133:d4dda5c437f0 | 15 | * |
mbed_official | 133:d4dda5c437f0 | 16 | @verbatim |
mbed_official | 133:d4dda5c437f0 | 17 | ============================================================================== |
mbed_official | 133:d4dda5c437f0 | 18 | ##### DAC Peripheral features ##### |
mbed_official | 133:d4dda5c437f0 | 19 | ============================================================================== |
mbed_official | 133:d4dda5c437f0 | 20 | [..] |
mbed_official | 133:d4dda5c437f0 | 21 | *** DAC Channels *** |
mbed_official | 133:d4dda5c437f0 | 22 | ==================== |
mbed_official | 133:d4dda5c437f0 | 23 | [..] |
mbed_official | 133:d4dda5c437f0 | 24 | The device integrates two 12-bit Digital Analog Converters that can |
mbed_official | 133:d4dda5c437f0 | 25 | be used independently or simultaneously (dual mode): |
mbed_official | 133:d4dda5c437f0 | 26 | (#) DAC channel1 with DAC_OUT1 (PA4) as output |
mbed_official | 133:d4dda5c437f0 | 27 | (#) DAC channel2 with DAC_OUT2 (PA5) as output |
mbed_official | 133:d4dda5c437f0 | 28 | |
mbed_official | 133:d4dda5c437f0 | 29 | *** DAC Triggers *** |
mbed_official | 133:d4dda5c437f0 | 30 | ==================== |
mbed_official | 133:d4dda5c437f0 | 31 | [..] |
mbed_official | 133:d4dda5c437f0 | 32 | Digital to Analog conversion can be non-triggered using DAC_Trigger_None |
mbed_official | 133:d4dda5c437f0 | 33 | and DAC_OUT1/DAC_OUT2 is available once writing to DHRx register. |
mbed_official | 133:d4dda5c437f0 | 34 | [..] |
mbed_official | 133:d4dda5c437f0 | 35 | Digital to Analog conversion can be triggered by: |
mbed_official | 133:d4dda5c437f0 | 36 | (#) External event: EXTI Line 9 (any GPIOx_Pin9) using DAC_Trigger_Ext_IT9. |
mbed_official | 133:d4dda5c437f0 | 37 | The used pin (GPIOx_Pin9) must be configured in input mode. |
mbed_official | 133:d4dda5c437f0 | 38 | |
mbed_official | 133:d4dda5c437f0 | 39 | (#) Timers TRGO: TIM2, TIM4, TIM5, TIM6, TIM7 and TIM8 |
mbed_official | 133:d4dda5c437f0 | 40 | (DAC_Trigger_T2_TRGO, DAC_Trigger_T4_TRGO...) |
mbed_official | 133:d4dda5c437f0 | 41 | |
mbed_official | 133:d4dda5c437f0 | 42 | (#) Software using DAC_Trigger_Software |
mbed_official | 133:d4dda5c437f0 | 43 | |
mbed_official | 133:d4dda5c437f0 | 44 | *** DAC Buffer mode feature *** |
mbed_official | 133:d4dda5c437f0 | 45 | =============================== |
mbed_official | 133:d4dda5c437f0 | 46 | [..] |
mbed_official | 133:d4dda5c437f0 | 47 | Each DAC channel integrates an output buffer that can be used to |
mbed_official | 133:d4dda5c437f0 | 48 | reduce the output impedance, and to drive external loads directly |
mbed_official | 133:d4dda5c437f0 | 49 | without having to add an external operational amplifier. |
mbed_official | 133:d4dda5c437f0 | 50 | To enable, the output buffer use |
mbed_official | 133:d4dda5c437f0 | 51 | sConfig.DAC_OutputBuffer = DAC_OutputBuffer_Enable; |
mbed_official | 133:d4dda5c437f0 | 52 | [..] |
mbed_official | 133:d4dda5c437f0 | 53 | (@) Refer to the device datasheet for more details about output |
mbed_official | 133:d4dda5c437f0 | 54 | impedance value with and without output buffer. |
mbed_official | 133:d4dda5c437f0 | 55 | |
mbed_official | 133:d4dda5c437f0 | 56 | *** DAC wave generation feature *** |
mbed_official | 133:d4dda5c437f0 | 57 | =================================== |
mbed_official | 133:d4dda5c437f0 | 58 | [..] |
mbed_official | 133:d4dda5c437f0 | 59 | Both DAC channels can be used to generate |
mbed_official | 133:d4dda5c437f0 | 60 | (#) Noise wave |
mbed_official | 133:d4dda5c437f0 | 61 | (#) Triangle wave |
mbed_official | 133:d4dda5c437f0 | 62 | |
mbed_official | 133:d4dda5c437f0 | 63 | *** DAC data format *** |
mbed_official | 133:d4dda5c437f0 | 64 | ======================= |
mbed_official | 133:d4dda5c437f0 | 65 | [..] |
mbed_official | 133:d4dda5c437f0 | 66 | The DAC data format can be: |
mbed_official | 133:d4dda5c437f0 | 67 | (#) 8-bit right alignment using DAC_ALIGN_8B_R |
mbed_official | 133:d4dda5c437f0 | 68 | (#) 12-bit left alignment using DAC_ALIGN_12B_L |
mbed_official | 133:d4dda5c437f0 | 69 | (#) 12-bit right alignment using DAC_ALIGN_12B_R |
mbed_official | 133:d4dda5c437f0 | 70 | |
mbed_official | 133:d4dda5c437f0 | 71 | *** DAC data value to voltage correspondence *** |
mbed_official | 133:d4dda5c437f0 | 72 | ================================================ |
mbed_official | 133:d4dda5c437f0 | 73 | [..] |
mbed_official | 133:d4dda5c437f0 | 74 | The analog output voltage on each DAC channel pin is determined |
mbed_official | 133:d4dda5c437f0 | 75 | by the following equation: |
mbed_official | 133:d4dda5c437f0 | 76 | DAC_OUTx = VREF+ * DOR / 4095 |
mbed_official | 133:d4dda5c437f0 | 77 | with DOR is the Data Output Register |
mbed_official | 133:d4dda5c437f0 | 78 | VEF+ is the input voltage reference (refer to the device datasheet) |
mbed_official | 133:d4dda5c437f0 | 79 | e.g. To set DAC_OUT1 to 0.7V, use |
mbed_official | 133:d4dda5c437f0 | 80 | Assuming that VREF+ = 3.3V, DAC_OUT1 = (3.3 * 868) / 4095 = 0.7V |
mbed_official | 133:d4dda5c437f0 | 81 | |
mbed_official | 133:d4dda5c437f0 | 82 | *** DMA requests *** |
mbed_official | 133:d4dda5c437f0 | 83 | ===================== |
mbed_official | 133:d4dda5c437f0 | 84 | [..] |
mbed_official | 133:d4dda5c437f0 | 85 | A DMA1 request can be generated when an external trigger (but not |
mbed_official | 133:d4dda5c437f0 | 86 | a software trigger) occurs if DMA1 requests are enabled using |
mbed_official | 133:d4dda5c437f0 | 87 | HAL_DAC_Start_DMA() |
mbed_official | 133:d4dda5c437f0 | 88 | [..] |
mbed_official | 133:d4dda5c437f0 | 89 | DMA1 requests are mapped as following: |
mbed_official | 133:d4dda5c437f0 | 90 | (#) DAC channel1 : mapped on DMA1 Stream5 channel7 which must be |
mbed_official | 133:d4dda5c437f0 | 91 | already configured |
mbed_official | 133:d4dda5c437f0 | 92 | (#) DAC channel2 : mapped on DMA1 Stream6 channel7 which must be |
mbed_official | 133:d4dda5c437f0 | 93 | already configured |
mbed_official | 133:d4dda5c437f0 | 94 | |
mbed_official | 133:d4dda5c437f0 | 95 | -@- For Dual mode and specific signal (Triangle and noise) generation please |
mbed_official | 133:d4dda5c437f0 | 96 | refer to Extension Features Driver description |
mbed_official | 133:d4dda5c437f0 | 97 | |
mbed_official | 133:d4dda5c437f0 | 98 | |
mbed_official | 133:d4dda5c437f0 | 99 | ##### How to use this driver ##### |
mbed_official | 133:d4dda5c437f0 | 100 | ============================================================================== |
mbed_official | 133:d4dda5c437f0 | 101 | [..] |
mbed_official | 133:d4dda5c437f0 | 102 | (+) DAC APB clock must be enabled to get write access to DAC |
mbed_official | 133:d4dda5c437f0 | 103 | registers using HAL_DAC_Init() |
mbed_official | 133:d4dda5c437f0 | 104 | (+) Configure DAC_OUTx (DAC_OUT1: PA4, DAC_OUT2: PA5) in analog mode. |
mbed_official | 133:d4dda5c437f0 | 105 | (+) Configure the DAC channel using HAL_DAC_ConfigChannel() function. |
mbed_official | 133:d4dda5c437f0 | 106 | (+) Enable the DAC channel using HAL_DAC_Start() or HAL_DAC_Start_DMA functions |
mbed_official | 133:d4dda5c437f0 | 107 | |
mbed_official | 133:d4dda5c437f0 | 108 | *** Polling mode IO operation *** |
mbed_official | 133:d4dda5c437f0 | 109 | ================================= |
mbed_official | 133:d4dda5c437f0 | 110 | [..] |
mbed_official | 133:d4dda5c437f0 | 111 | (+) Start the DAC peripheral using HAL_DAC_Start() |
mbed_official | 133:d4dda5c437f0 | 112 | (+) To read the DAC last data output value value, use the HAL_DAC_GetValue() function. |
mbed_official | 133:d4dda5c437f0 | 113 | (+) Stop the DAC peripheral using HAL_DAC_Stop() |
mbed_official | 133:d4dda5c437f0 | 114 | |
mbed_official | 133:d4dda5c437f0 | 115 | *** DMA mode IO operation *** |
mbed_official | 133:d4dda5c437f0 | 116 | ============================== |
mbed_official | 133:d4dda5c437f0 | 117 | [..] |
mbed_official | 133:d4dda5c437f0 | 118 | (+) Start the DAC peripheral using HAL_DAC_Start_DMA(), at this stage the user specify the length |
mbed_official | 133:d4dda5c437f0 | 119 | of data to be transfered at each end of conversion |
mbed_official | 133:d4dda5c437f0 | 120 | (+) At The end of data transfer HAL_DAC_ConvCpltCallbackCh1()or HAL_DAC_ConvCpltCallbackCh2() |
mbed_official | 133:d4dda5c437f0 | 121 | function is executed and user can add his own code by customization of function pointer |
mbed_official | 133:d4dda5c437f0 | 122 | HAL_DAC_ConvCpltCallbackCh1 or HAL_DAC_ConvCpltCallbackCh2 |
mbed_official | 133:d4dda5c437f0 | 123 | (+) In case of transfer Error, HAL_DAC_ErrorCallbackCh1() function is executed and user can |
mbed_official | 133:d4dda5c437f0 | 124 | add his own code by customization of function pointer HAL_DAC_ErrorCallbackCh1 |
mbed_official | 133:d4dda5c437f0 | 125 | (+) Stop the DAC peripheral using HAL_DAC_Stop_DMA() |
mbed_official | 133:d4dda5c437f0 | 126 | |
mbed_official | 133:d4dda5c437f0 | 127 | *** DAC HAL driver macros list *** |
mbed_official | 133:d4dda5c437f0 | 128 | ============================================= |
mbed_official | 133:d4dda5c437f0 | 129 | [..] |
mbed_official | 133:d4dda5c437f0 | 130 | Below the list of most used macros in DAC HAL driver. |
mbed_official | 133:d4dda5c437f0 | 131 | |
mbed_official | 133:d4dda5c437f0 | 132 | (+) __HAL_DAC_ENABLE : Enable the DAC peripheral |
mbed_official | 133:d4dda5c437f0 | 133 | (+) __HAL_DAC_DISABLE : Disable the DAC peripheral |
mbed_official | 133:d4dda5c437f0 | 134 | (+) __HAL_DAC_CLEAR_FLAG: Clear the DAC's pending flags |
mbed_official | 133:d4dda5c437f0 | 135 | (+) __HAL_DAC_GET_FLAG: Get the selected DAC's flag status |
mbed_official | 133:d4dda5c437f0 | 136 | |
mbed_official | 133:d4dda5c437f0 | 137 | [..] |
mbed_official | 133:d4dda5c437f0 | 138 | (@) You can refer to the DAC HAL driver header file for more useful macros |
mbed_official | 133:d4dda5c437f0 | 139 | |
mbed_official | 133:d4dda5c437f0 | 140 | @endverbatim |
mbed_official | 133:d4dda5c437f0 | 141 | ****************************************************************************** |
mbed_official | 133:d4dda5c437f0 | 142 | * @attention |
mbed_official | 133:d4dda5c437f0 | 143 | * |
mbed_official | 133:d4dda5c437f0 | 144 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 133:d4dda5c437f0 | 145 | * |
mbed_official | 133:d4dda5c437f0 | 146 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 133:d4dda5c437f0 | 147 | * are permitted provided that the following conditions are met: |
mbed_official | 133:d4dda5c437f0 | 148 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 133:d4dda5c437f0 | 149 | * this list of conditions and the following disclaimer. |
mbed_official | 133:d4dda5c437f0 | 150 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 133:d4dda5c437f0 | 151 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 133:d4dda5c437f0 | 152 | * and/or other materials provided with the distribution. |
mbed_official | 133:d4dda5c437f0 | 153 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 133:d4dda5c437f0 | 154 | * may be used to endorse or promote products derived from this software |
mbed_official | 133:d4dda5c437f0 | 155 | * without specific prior written permission. |
mbed_official | 133:d4dda5c437f0 | 156 | * |
mbed_official | 133:d4dda5c437f0 | 157 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 133:d4dda5c437f0 | 158 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 133:d4dda5c437f0 | 159 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 133:d4dda5c437f0 | 160 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 133:d4dda5c437f0 | 161 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 133:d4dda5c437f0 | 162 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 133:d4dda5c437f0 | 163 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 133:d4dda5c437f0 | 164 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 133:d4dda5c437f0 | 165 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 133:d4dda5c437f0 | 166 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 133:d4dda5c437f0 | 167 | * |
mbed_official | 133:d4dda5c437f0 | 168 | ****************************************************************************** |
mbed_official | 133:d4dda5c437f0 | 169 | */ |
mbed_official | 133:d4dda5c437f0 | 170 | |
mbed_official | 133:d4dda5c437f0 | 171 | |
mbed_official | 133:d4dda5c437f0 | 172 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 133:d4dda5c437f0 | 173 | #include "stm32f4xx_hal.h" |
mbed_official | 133:d4dda5c437f0 | 174 | |
mbed_official | 133:d4dda5c437f0 | 175 | /** @addtogroup STM32F4xx_HAL_Driver |
mbed_official | 133:d4dda5c437f0 | 176 | * @{ |
mbed_official | 133:d4dda5c437f0 | 177 | */ |
mbed_official | 133:d4dda5c437f0 | 178 | |
mbed_official | 133:d4dda5c437f0 | 179 | /** @defgroup DAC |
mbed_official | 133:d4dda5c437f0 | 180 | * @brief DAC driver modules |
mbed_official | 133:d4dda5c437f0 | 181 | * @{ |
mbed_official | 133:d4dda5c437f0 | 182 | */ |
mbed_official | 133:d4dda5c437f0 | 183 | |
mbed_official | 133:d4dda5c437f0 | 184 | #ifdef HAL_DAC_MODULE_ENABLED |
mbed_official | 133:d4dda5c437f0 | 185 | |
mbed_official | 133:d4dda5c437f0 | 186 | #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) |
mbed_official | 133:d4dda5c437f0 | 187 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 133:d4dda5c437f0 | 188 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 133:d4dda5c437f0 | 189 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 133:d4dda5c437f0 | 190 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 133:d4dda5c437f0 | 191 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 133:d4dda5c437f0 | 192 | static void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma); |
mbed_official | 133:d4dda5c437f0 | 193 | static void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma); |
mbed_official | 133:d4dda5c437f0 | 194 | static void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma); |
mbed_official | 133:d4dda5c437f0 | 195 | |
mbed_official | 133:d4dda5c437f0 | 196 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 133:d4dda5c437f0 | 197 | |
mbed_official | 133:d4dda5c437f0 | 198 | /** @defgroup DAC_Private_Functions |
mbed_official | 133:d4dda5c437f0 | 199 | * @{ |
mbed_official | 133:d4dda5c437f0 | 200 | */ |
mbed_official | 133:d4dda5c437f0 | 201 | |
mbed_official | 133:d4dda5c437f0 | 202 | /** @defgroup DAC_Group1 Initialization and de-initialization functions |
mbed_official | 133:d4dda5c437f0 | 203 | * @brief Initialization and Configuration functions |
mbed_official | 133:d4dda5c437f0 | 204 | * |
mbed_official | 133:d4dda5c437f0 | 205 | @verbatim |
mbed_official | 133:d4dda5c437f0 | 206 | ============================================================================== |
mbed_official | 133:d4dda5c437f0 | 207 | ##### Initialization and de-initialization functions ##### |
mbed_official | 133:d4dda5c437f0 | 208 | ============================================================================== |
mbed_official | 133:d4dda5c437f0 | 209 | [..] This section provides functions allowing to: |
mbed_official | 133:d4dda5c437f0 | 210 | (+) Initialize and configure the DAC. |
mbed_official | 133:d4dda5c437f0 | 211 | (+) De-initialize the DAC. |
mbed_official | 133:d4dda5c437f0 | 212 | |
mbed_official | 133:d4dda5c437f0 | 213 | @endverbatim |
mbed_official | 133:d4dda5c437f0 | 214 | * @{ |
mbed_official | 133:d4dda5c437f0 | 215 | */ |
mbed_official | 133:d4dda5c437f0 | 216 | |
mbed_official | 133:d4dda5c437f0 | 217 | /** |
mbed_official | 133:d4dda5c437f0 | 218 | * @brief Initializes the DAC peripheral according to the specified parameters |
mbed_official | 133:d4dda5c437f0 | 219 | * in the DAC_InitStruct. |
mbed_official | 133:d4dda5c437f0 | 220 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 221 | * the configuration information for the specified DAC. |
mbed_official | 133:d4dda5c437f0 | 222 | * @retval HAL status |
mbed_official | 133:d4dda5c437f0 | 223 | */ |
mbed_official | 133:d4dda5c437f0 | 224 | HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef* hdac) |
mbed_official | 133:d4dda5c437f0 | 225 | { |
mbed_official | 133:d4dda5c437f0 | 226 | /* Check DAC handle */ |
mbed_official | 133:d4dda5c437f0 | 227 | if(hdac == NULL) |
mbed_official | 133:d4dda5c437f0 | 228 | { |
mbed_official | 133:d4dda5c437f0 | 229 | return HAL_ERROR; |
mbed_official | 133:d4dda5c437f0 | 230 | } |
mbed_official | 133:d4dda5c437f0 | 231 | /* Check the parameters */ |
mbed_official | 133:d4dda5c437f0 | 232 | assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance)); |
mbed_official | 133:d4dda5c437f0 | 233 | |
mbed_official | 133:d4dda5c437f0 | 234 | if(hdac->State == HAL_DAC_STATE_RESET) |
mbed_official | 133:d4dda5c437f0 | 235 | { |
mbed_official | 133:d4dda5c437f0 | 236 | /* Init the low level hardware */ |
mbed_official | 133:d4dda5c437f0 | 237 | HAL_DAC_MspInit(hdac); |
mbed_official | 133:d4dda5c437f0 | 238 | } |
mbed_official | 133:d4dda5c437f0 | 239 | |
mbed_official | 133:d4dda5c437f0 | 240 | /* Initialize the DAC state*/ |
mbed_official | 133:d4dda5c437f0 | 241 | hdac->State = HAL_DAC_STATE_BUSY; |
mbed_official | 133:d4dda5c437f0 | 242 | |
mbed_official | 133:d4dda5c437f0 | 243 | /* Set DAC error code to none */ |
mbed_official | 133:d4dda5c437f0 | 244 | hdac->ErrorCode = HAL_DAC_ERROR_NONE; |
mbed_official | 133:d4dda5c437f0 | 245 | |
mbed_official | 133:d4dda5c437f0 | 246 | /* Initialize the DAC state*/ |
mbed_official | 133:d4dda5c437f0 | 247 | hdac->State = HAL_DAC_STATE_READY; |
mbed_official | 133:d4dda5c437f0 | 248 | |
mbed_official | 133:d4dda5c437f0 | 249 | /* Return function status */ |
mbed_official | 133:d4dda5c437f0 | 250 | return HAL_OK; |
mbed_official | 133:d4dda5c437f0 | 251 | } |
mbed_official | 133:d4dda5c437f0 | 252 | |
mbed_official | 133:d4dda5c437f0 | 253 | /** |
mbed_official | 133:d4dda5c437f0 | 254 | * @brief Deinitializes the DAC peripheral registers to their default reset values. |
mbed_official | 133:d4dda5c437f0 | 255 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 256 | * the configuration information for the specified DAC. |
mbed_official | 133:d4dda5c437f0 | 257 | * @retval HAL status |
mbed_official | 133:d4dda5c437f0 | 258 | */ |
mbed_official | 133:d4dda5c437f0 | 259 | HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef* hdac) |
mbed_official | 133:d4dda5c437f0 | 260 | { |
mbed_official | 133:d4dda5c437f0 | 261 | /* Check DAC handle */ |
mbed_official | 133:d4dda5c437f0 | 262 | if(hdac == NULL) |
mbed_official | 133:d4dda5c437f0 | 263 | { |
mbed_official | 133:d4dda5c437f0 | 264 | return HAL_ERROR; |
mbed_official | 133:d4dda5c437f0 | 265 | } |
mbed_official | 133:d4dda5c437f0 | 266 | |
mbed_official | 133:d4dda5c437f0 | 267 | /* Check the parameters */ |
mbed_official | 133:d4dda5c437f0 | 268 | assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance)); |
mbed_official | 133:d4dda5c437f0 | 269 | |
mbed_official | 133:d4dda5c437f0 | 270 | /* Change DAC state */ |
mbed_official | 133:d4dda5c437f0 | 271 | hdac->State = HAL_DAC_STATE_BUSY; |
mbed_official | 133:d4dda5c437f0 | 272 | |
mbed_official | 133:d4dda5c437f0 | 273 | /* DeInit the low level hardware */ |
mbed_official | 133:d4dda5c437f0 | 274 | HAL_DAC_MspDeInit(hdac); |
mbed_official | 133:d4dda5c437f0 | 275 | |
mbed_official | 133:d4dda5c437f0 | 276 | /* Set DAC error code to none */ |
mbed_official | 133:d4dda5c437f0 | 277 | hdac->ErrorCode = HAL_DAC_ERROR_NONE; |
mbed_official | 133:d4dda5c437f0 | 278 | |
mbed_official | 133:d4dda5c437f0 | 279 | /* Change DAC state */ |
mbed_official | 133:d4dda5c437f0 | 280 | hdac->State = HAL_DAC_STATE_RESET; |
mbed_official | 133:d4dda5c437f0 | 281 | |
mbed_official | 133:d4dda5c437f0 | 282 | /* Release Lock */ |
mbed_official | 133:d4dda5c437f0 | 283 | __HAL_UNLOCK(hdac); |
mbed_official | 133:d4dda5c437f0 | 284 | |
mbed_official | 133:d4dda5c437f0 | 285 | /* Return function status */ |
mbed_official | 133:d4dda5c437f0 | 286 | return HAL_OK; |
mbed_official | 133:d4dda5c437f0 | 287 | } |
mbed_official | 133:d4dda5c437f0 | 288 | |
mbed_official | 133:d4dda5c437f0 | 289 | /** |
mbed_official | 133:d4dda5c437f0 | 290 | * @brief Initializes the DAC MSP. |
mbed_official | 133:d4dda5c437f0 | 291 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 292 | * the configuration information for the specified DAC. |
mbed_official | 133:d4dda5c437f0 | 293 | * @retval None |
mbed_official | 133:d4dda5c437f0 | 294 | */ |
mbed_official | 133:d4dda5c437f0 | 295 | __weak void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac) |
mbed_official | 133:d4dda5c437f0 | 296 | { |
mbed_official | 133:d4dda5c437f0 | 297 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 133:d4dda5c437f0 | 298 | the HAL_DAC_MspInit could be implemented in the user file |
mbed_official | 133:d4dda5c437f0 | 299 | */ |
mbed_official | 133:d4dda5c437f0 | 300 | } |
mbed_official | 133:d4dda5c437f0 | 301 | |
mbed_official | 133:d4dda5c437f0 | 302 | /** |
mbed_official | 133:d4dda5c437f0 | 303 | * @brief DeInitializes the DAC MSP. |
mbed_official | 133:d4dda5c437f0 | 304 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 305 | * the configuration information for the specified DAC. |
mbed_official | 133:d4dda5c437f0 | 306 | * @retval None |
mbed_official | 133:d4dda5c437f0 | 307 | */ |
mbed_official | 133:d4dda5c437f0 | 308 | __weak void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac) |
mbed_official | 133:d4dda5c437f0 | 309 | { |
mbed_official | 133:d4dda5c437f0 | 310 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 133:d4dda5c437f0 | 311 | the HAL_DAC_MspDeInit could be implemented in the user file |
mbed_official | 133:d4dda5c437f0 | 312 | */ |
mbed_official | 133:d4dda5c437f0 | 313 | } |
mbed_official | 133:d4dda5c437f0 | 314 | |
mbed_official | 133:d4dda5c437f0 | 315 | /** |
mbed_official | 133:d4dda5c437f0 | 316 | * @} |
mbed_official | 133:d4dda5c437f0 | 317 | */ |
mbed_official | 133:d4dda5c437f0 | 318 | |
mbed_official | 133:d4dda5c437f0 | 319 | /** @defgroup DAC_Group2 IO operation functions |
mbed_official | 133:d4dda5c437f0 | 320 | * @brief IO operation functions |
mbed_official | 133:d4dda5c437f0 | 321 | * |
mbed_official | 133:d4dda5c437f0 | 322 | @verbatim |
mbed_official | 133:d4dda5c437f0 | 323 | ============================================================================== |
mbed_official | 133:d4dda5c437f0 | 324 | ##### IO operation functions ##### |
mbed_official | 133:d4dda5c437f0 | 325 | ============================================================================== |
mbed_official | 133:d4dda5c437f0 | 326 | [..] This section provides functions allowing to: |
mbed_official | 133:d4dda5c437f0 | 327 | (+) Start conversion. |
mbed_official | 133:d4dda5c437f0 | 328 | (+) Stop conversion. |
mbed_official | 133:d4dda5c437f0 | 329 | (+) Start conversion and enable DMA transfer. |
mbed_official | 133:d4dda5c437f0 | 330 | (+) Stop conversion and disable DMA transfer. |
mbed_official | 133:d4dda5c437f0 | 331 | (+) Get result of conversion. |
mbed_official | 133:d4dda5c437f0 | 332 | |
mbed_official | 133:d4dda5c437f0 | 333 | @endverbatim |
mbed_official | 133:d4dda5c437f0 | 334 | * @{ |
mbed_official | 133:d4dda5c437f0 | 335 | */ |
mbed_official | 133:d4dda5c437f0 | 336 | |
mbed_official | 133:d4dda5c437f0 | 337 | /** |
mbed_official | 133:d4dda5c437f0 | 338 | * @brief Enables DAC and starts conversion of channel. |
mbed_official | 133:d4dda5c437f0 | 339 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 340 | * the configuration information for the specified DAC. |
mbed_official | 133:d4dda5c437f0 | 341 | * @param Channel: The selected DAC channel. |
mbed_official | 133:d4dda5c437f0 | 342 | * This parameter can be one of the following values: |
mbed_official | 133:d4dda5c437f0 | 343 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
mbed_official | 133:d4dda5c437f0 | 344 | * @arg DAC_CHANNEL_2: DAC Channel2 selected |
mbed_official | 133:d4dda5c437f0 | 345 | * @retval HAL status |
mbed_official | 133:d4dda5c437f0 | 346 | */ |
mbed_official | 133:d4dda5c437f0 | 347 | HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel) |
mbed_official | 133:d4dda5c437f0 | 348 | { |
mbed_official | 133:d4dda5c437f0 | 349 | uint32_t tmp1 = 0, tmp2 = 0; |
mbed_official | 133:d4dda5c437f0 | 350 | |
mbed_official | 133:d4dda5c437f0 | 351 | /* Check the parameters */ |
mbed_official | 133:d4dda5c437f0 | 352 | assert_param(IS_DAC_CHANNEL(Channel)); |
mbed_official | 133:d4dda5c437f0 | 353 | |
mbed_official | 133:d4dda5c437f0 | 354 | /* Process locked */ |
mbed_official | 133:d4dda5c437f0 | 355 | __HAL_LOCK(hdac); |
mbed_official | 133:d4dda5c437f0 | 356 | |
mbed_official | 133:d4dda5c437f0 | 357 | /* Change DAC state */ |
mbed_official | 133:d4dda5c437f0 | 358 | hdac->State = HAL_DAC_STATE_BUSY; |
mbed_official | 133:d4dda5c437f0 | 359 | |
mbed_official | 133:d4dda5c437f0 | 360 | /* Enable the Peripharal */ |
mbed_official | 133:d4dda5c437f0 | 361 | __HAL_DAC_ENABLE(hdac, Channel); |
mbed_official | 133:d4dda5c437f0 | 362 | |
mbed_official | 133:d4dda5c437f0 | 363 | if(Channel == DAC_CHANNEL_1) |
mbed_official | 133:d4dda5c437f0 | 364 | { |
mbed_official | 133:d4dda5c437f0 | 365 | tmp1 = hdac->Instance->CR & DAC_CR_TEN1; |
mbed_official | 133:d4dda5c437f0 | 366 | tmp2 = hdac->Instance->CR & DAC_CR_TSEL1; |
mbed_official | 133:d4dda5c437f0 | 367 | /* Check if software trigger enabled */ |
mbed_official | 133:d4dda5c437f0 | 368 | if((tmp1 == DAC_CR_TEN1) && (tmp2 == DAC_CR_TSEL1)) |
mbed_official | 133:d4dda5c437f0 | 369 | { |
mbed_official | 133:d4dda5c437f0 | 370 | /* Enable the selected DAC software conversion */ |
mbed_official | 133:d4dda5c437f0 | 371 | hdac->Instance->SWTRIGR |= (uint32_t)DAC_SWTRIGR_SWTRIG1; |
mbed_official | 133:d4dda5c437f0 | 372 | } |
mbed_official | 133:d4dda5c437f0 | 373 | } |
mbed_official | 133:d4dda5c437f0 | 374 | else |
mbed_official | 133:d4dda5c437f0 | 375 | { |
mbed_official | 133:d4dda5c437f0 | 376 | tmp1 = hdac->Instance->CR & DAC_CR_TEN2; |
mbed_official | 133:d4dda5c437f0 | 377 | tmp2 = hdac->Instance->CR & DAC_CR_TSEL2; |
mbed_official | 133:d4dda5c437f0 | 378 | /* Check if software trigger enabled */ |
mbed_official | 133:d4dda5c437f0 | 379 | if((tmp1 == DAC_CR_TEN2) && (tmp2 == DAC_CR_TSEL2)) |
mbed_official | 133:d4dda5c437f0 | 380 | { |
mbed_official | 133:d4dda5c437f0 | 381 | /* Enable the selected DAC software conversion*/ |
mbed_official | 133:d4dda5c437f0 | 382 | hdac->Instance->SWTRIGR |= (uint32_t)DAC_SWTRIGR_SWTRIG2; |
mbed_official | 133:d4dda5c437f0 | 383 | } |
mbed_official | 133:d4dda5c437f0 | 384 | } |
mbed_official | 133:d4dda5c437f0 | 385 | |
mbed_official | 133:d4dda5c437f0 | 386 | /* Change DAC state */ |
mbed_official | 133:d4dda5c437f0 | 387 | hdac->State = HAL_DAC_STATE_READY; |
mbed_official | 133:d4dda5c437f0 | 388 | |
mbed_official | 133:d4dda5c437f0 | 389 | /* Process unlocked */ |
mbed_official | 133:d4dda5c437f0 | 390 | __HAL_UNLOCK(hdac); |
mbed_official | 133:d4dda5c437f0 | 391 | |
mbed_official | 133:d4dda5c437f0 | 392 | /* Return function status */ |
mbed_official | 133:d4dda5c437f0 | 393 | return HAL_OK; |
mbed_official | 133:d4dda5c437f0 | 394 | } |
mbed_official | 133:d4dda5c437f0 | 395 | |
mbed_official | 133:d4dda5c437f0 | 396 | /** |
mbed_official | 133:d4dda5c437f0 | 397 | * @brief Disables DAC and stop conversion of channel. |
mbed_official | 133:d4dda5c437f0 | 398 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 399 | * the configuration information for the specified DAC. |
mbed_official | 133:d4dda5c437f0 | 400 | * @param Channel: The selected DAC channel. |
mbed_official | 133:d4dda5c437f0 | 401 | * This parameter can be one of the following values: |
mbed_official | 133:d4dda5c437f0 | 402 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
mbed_official | 133:d4dda5c437f0 | 403 | * @arg DAC_CHANNEL_2: DAC Channel2 selected |
mbed_official | 133:d4dda5c437f0 | 404 | * @retval HAL status |
mbed_official | 133:d4dda5c437f0 | 405 | */ |
mbed_official | 133:d4dda5c437f0 | 406 | HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef* hdac, uint32_t Channel) |
mbed_official | 133:d4dda5c437f0 | 407 | { |
mbed_official | 133:d4dda5c437f0 | 408 | /* Check the parameters */ |
mbed_official | 133:d4dda5c437f0 | 409 | assert_param(IS_DAC_CHANNEL(Channel)); |
mbed_official | 133:d4dda5c437f0 | 410 | |
mbed_official | 133:d4dda5c437f0 | 411 | /* Disable the Peripheral */ |
mbed_official | 133:d4dda5c437f0 | 412 | __HAL_DAC_DISABLE(hdac, Channel); |
mbed_official | 133:d4dda5c437f0 | 413 | |
mbed_official | 133:d4dda5c437f0 | 414 | /* Change DAC state */ |
mbed_official | 133:d4dda5c437f0 | 415 | hdac->State = HAL_DAC_STATE_READY; |
mbed_official | 133:d4dda5c437f0 | 416 | |
mbed_official | 133:d4dda5c437f0 | 417 | /* Return function status */ |
mbed_official | 133:d4dda5c437f0 | 418 | return HAL_OK; |
mbed_official | 133:d4dda5c437f0 | 419 | } |
mbed_official | 133:d4dda5c437f0 | 420 | |
mbed_official | 133:d4dda5c437f0 | 421 | /** |
mbed_official | 133:d4dda5c437f0 | 422 | * @brief Enables DAC and starts conversion of channel. |
mbed_official | 133:d4dda5c437f0 | 423 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 424 | * the configuration information for the specified DAC. |
mbed_official | 133:d4dda5c437f0 | 425 | * @param Channel: The selected DAC channel. |
mbed_official | 133:d4dda5c437f0 | 426 | * This parameter can be one of the following values: |
mbed_official | 133:d4dda5c437f0 | 427 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
mbed_official | 133:d4dda5c437f0 | 428 | * @arg DAC_CHANNEL_2: DAC Channel2 selected |
mbed_official | 133:d4dda5c437f0 | 429 | * @param pData: The destination peripheral Buffer address. |
mbed_official | 133:d4dda5c437f0 | 430 | * @param Length: The length of data to be transferred from memory to DAC peripheral |
mbed_official | 133:d4dda5c437f0 | 431 | * @param Alignment: Specifies the data alignment for DAC channel. |
mbed_official | 133:d4dda5c437f0 | 432 | * This parameter can be one of the following values: |
mbed_official | 133:d4dda5c437f0 | 433 | * @arg DAC_Align_8b_R: 8bit right data alignment selected |
mbed_official | 133:d4dda5c437f0 | 434 | * @arg DAC_Align_12b_L: 12bit left data alignment selected |
mbed_official | 133:d4dda5c437f0 | 435 | * @arg DAC_Align_12b_R: 12bit right data alignment selected |
mbed_official | 133:d4dda5c437f0 | 436 | * @retval HAL status |
mbed_official | 133:d4dda5c437f0 | 437 | */ |
mbed_official | 133:d4dda5c437f0 | 438 | HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment) |
mbed_official | 133:d4dda5c437f0 | 439 | { |
mbed_official | 133:d4dda5c437f0 | 440 | uint32_t tmpreg = 0; |
mbed_official | 133:d4dda5c437f0 | 441 | |
mbed_official | 133:d4dda5c437f0 | 442 | /* Check the parameters */ |
mbed_official | 133:d4dda5c437f0 | 443 | assert_param(IS_DAC_CHANNEL(Channel)); |
mbed_official | 133:d4dda5c437f0 | 444 | assert_param(IS_DAC_ALIGN(Alignment)); |
mbed_official | 133:d4dda5c437f0 | 445 | |
mbed_official | 133:d4dda5c437f0 | 446 | /* Process locked */ |
mbed_official | 133:d4dda5c437f0 | 447 | __HAL_LOCK(hdac); |
mbed_official | 133:d4dda5c437f0 | 448 | |
mbed_official | 133:d4dda5c437f0 | 449 | /* Change DAC state */ |
mbed_official | 133:d4dda5c437f0 | 450 | hdac->State = HAL_DAC_STATE_BUSY; |
mbed_official | 133:d4dda5c437f0 | 451 | |
mbed_official | 133:d4dda5c437f0 | 452 | /* Set the DMA transfer complete callback for channel1 */ |
mbed_official | 133:d4dda5c437f0 | 453 | hdac->DMA_Handle1->XferCpltCallback = DAC_DMAConvCpltCh1; |
mbed_official | 133:d4dda5c437f0 | 454 | |
mbed_official | 133:d4dda5c437f0 | 455 | /* Set the DMA half transfer complete callback for channel1 */ |
mbed_official | 133:d4dda5c437f0 | 456 | hdac->DMA_Handle1->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh1; |
mbed_official | 133:d4dda5c437f0 | 457 | |
mbed_official | 133:d4dda5c437f0 | 458 | /* Set the DMA error callback for channel1 */ |
mbed_official | 133:d4dda5c437f0 | 459 | hdac->DMA_Handle1->XferErrorCallback = DAC_DMAErrorCh1; |
mbed_official | 133:d4dda5c437f0 | 460 | |
mbed_official | 133:d4dda5c437f0 | 461 | /* Set the DMA transfer complete callback for channel2 */ |
mbed_official | 133:d4dda5c437f0 | 462 | hdac->DMA_Handle2->XferCpltCallback = DAC_DMAConvCpltCh2; |
mbed_official | 133:d4dda5c437f0 | 463 | |
mbed_official | 133:d4dda5c437f0 | 464 | /* Set the DMA half transfer complete callback for channel2 */ |
mbed_official | 133:d4dda5c437f0 | 465 | hdac->DMA_Handle2->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh2; |
mbed_official | 133:d4dda5c437f0 | 466 | |
mbed_official | 133:d4dda5c437f0 | 467 | /* Set the DMA error callback for channel2 */ |
mbed_official | 133:d4dda5c437f0 | 468 | hdac->DMA_Handle2->XferErrorCallback = DAC_DMAErrorCh2; |
mbed_official | 133:d4dda5c437f0 | 469 | |
mbed_official | 133:d4dda5c437f0 | 470 | if(Channel == DAC_CHANNEL_1) |
mbed_official | 133:d4dda5c437f0 | 471 | { |
mbed_official | 133:d4dda5c437f0 | 472 | /* Enable the selected DAC channel1 DMA request */ |
mbed_official | 133:d4dda5c437f0 | 473 | hdac->Instance->CR |= DAC_CR_DMAEN1; |
mbed_official | 133:d4dda5c437f0 | 474 | |
mbed_official | 133:d4dda5c437f0 | 475 | /* Case of use of channel 1 */ |
mbed_official | 133:d4dda5c437f0 | 476 | switch(Alignment) |
mbed_official | 133:d4dda5c437f0 | 477 | { |
mbed_official | 133:d4dda5c437f0 | 478 | case DAC_ALIGN_12B_R: |
mbed_official | 133:d4dda5c437f0 | 479 | /* Get DHR12R1 address */ |
mbed_official | 133:d4dda5c437f0 | 480 | tmpreg = (uint32_t)&hdac->Instance->DHR12R1; |
mbed_official | 133:d4dda5c437f0 | 481 | break; |
mbed_official | 133:d4dda5c437f0 | 482 | case DAC_ALIGN_12B_L: |
mbed_official | 133:d4dda5c437f0 | 483 | /* Get DHR12L1 address */ |
mbed_official | 133:d4dda5c437f0 | 484 | tmpreg = (uint32_t)&hdac->Instance->DHR12L1; |
mbed_official | 133:d4dda5c437f0 | 485 | break; |
mbed_official | 133:d4dda5c437f0 | 486 | case DAC_ALIGN_8B_R: |
mbed_official | 133:d4dda5c437f0 | 487 | /* Get DHR8R1 address */ |
mbed_official | 133:d4dda5c437f0 | 488 | tmpreg = (uint32_t)&hdac->Instance->DHR8R1; |
mbed_official | 133:d4dda5c437f0 | 489 | break; |
mbed_official | 133:d4dda5c437f0 | 490 | default: |
mbed_official | 133:d4dda5c437f0 | 491 | break; |
mbed_official | 133:d4dda5c437f0 | 492 | } |
mbed_official | 133:d4dda5c437f0 | 493 | } |
mbed_official | 133:d4dda5c437f0 | 494 | else |
mbed_official | 133:d4dda5c437f0 | 495 | { |
mbed_official | 133:d4dda5c437f0 | 496 | /* Enable the selected DAC channel2 DMA request */ |
mbed_official | 133:d4dda5c437f0 | 497 | hdac->Instance->CR |= DAC_CR_DMAEN2; |
mbed_official | 133:d4dda5c437f0 | 498 | |
mbed_official | 133:d4dda5c437f0 | 499 | /* Case of use of channel 2 */ |
mbed_official | 133:d4dda5c437f0 | 500 | switch(Alignment) |
mbed_official | 133:d4dda5c437f0 | 501 | { |
mbed_official | 133:d4dda5c437f0 | 502 | case DAC_ALIGN_12B_R: |
mbed_official | 133:d4dda5c437f0 | 503 | /* Get DHR12R2 address */ |
mbed_official | 133:d4dda5c437f0 | 504 | tmpreg = (uint32_t)&hdac->Instance->DHR12R2; |
mbed_official | 133:d4dda5c437f0 | 505 | break; |
mbed_official | 133:d4dda5c437f0 | 506 | case DAC_ALIGN_12B_L: |
mbed_official | 133:d4dda5c437f0 | 507 | /* Get DHR12L2 address */ |
mbed_official | 133:d4dda5c437f0 | 508 | tmpreg = (uint32_t)&hdac->Instance->DHR12L2; |
mbed_official | 133:d4dda5c437f0 | 509 | break; |
mbed_official | 133:d4dda5c437f0 | 510 | case DAC_ALIGN_8B_R: |
mbed_official | 133:d4dda5c437f0 | 511 | /* Get DHR8R2 address */ |
mbed_official | 133:d4dda5c437f0 | 512 | tmpreg = (uint32_t)&hdac->Instance->DHR8R2; |
mbed_official | 133:d4dda5c437f0 | 513 | break; |
mbed_official | 133:d4dda5c437f0 | 514 | default: |
mbed_official | 133:d4dda5c437f0 | 515 | break; |
mbed_official | 133:d4dda5c437f0 | 516 | } |
mbed_official | 133:d4dda5c437f0 | 517 | } |
mbed_official | 133:d4dda5c437f0 | 518 | |
mbed_official | 133:d4dda5c437f0 | 519 | /* Enable the DMA Stream */ |
mbed_official | 133:d4dda5c437f0 | 520 | if(Channel == DAC_CHANNEL_1) |
mbed_official | 133:d4dda5c437f0 | 521 | { |
mbed_official | 133:d4dda5c437f0 | 522 | /* Enable the DAC DMA underrun interrupt */ |
mbed_official | 133:d4dda5c437f0 | 523 | __HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR1); |
mbed_official | 133:d4dda5c437f0 | 524 | |
mbed_official | 133:d4dda5c437f0 | 525 | /* Enable the DMA Stream */ |
mbed_official | 133:d4dda5c437f0 | 526 | HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length); |
mbed_official | 133:d4dda5c437f0 | 527 | } |
mbed_official | 133:d4dda5c437f0 | 528 | else |
mbed_official | 133:d4dda5c437f0 | 529 | { |
mbed_official | 133:d4dda5c437f0 | 530 | /* Enable the DAC DMA underrun interrupt */ |
mbed_official | 133:d4dda5c437f0 | 531 | __HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR2); |
mbed_official | 133:d4dda5c437f0 | 532 | |
mbed_official | 133:d4dda5c437f0 | 533 | /* Enable the DMA Stream */ |
mbed_official | 133:d4dda5c437f0 | 534 | HAL_DMA_Start_IT(hdac->DMA_Handle2, (uint32_t)pData, tmpreg, Length); |
mbed_official | 133:d4dda5c437f0 | 535 | } |
mbed_official | 133:d4dda5c437f0 | 536 | |
mbed_official | 133:d4dda5c437f0 | 537 | /* Enable the Peripharal */ |
mbed_official | 133:d4dda5c437f0 | 538 | __HAL_DAC_ENABLE(hdac, Channel); |
mbed_official | 133:d4dda5c437f0 | 539 | |
mbed_official | 133:d4dda5c437f0 | 540 | /* Process Unlocked */ |
mbed_official | 133:d4dda5c437f0 | 541 | __HAL_UNLOCK(hdac); |
mbed_official | 133:d4dda5c437f0 | 542 | |
mbed_official | 133:d4dda5c437f0 | 543 | /* Return function status */ |
mbed_official | 133:d4dda5c437f0 | 544 | return HAL_OK; |
mbed_official | 133:d4dda5c437f0 | 545 | } |
mbed_official | 133:d4dda5c437f0 | 546 | |
mbed_official | 133:d4dda5c437f0 | 547 | /** |
mbed_official | 133:d4dda5c437f0 | 548 | * @brief Disables DAC and stop conversion of channel. |
mbed_official | 133:d4dda5c437f0 | 549 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 550 | * the configuration information for the specified DAC. |
mbed_official | 133:d4dda5c437f0 | 551 | * @param Channel: The selected DAC channel. |
mbed_official | 133:d4dda5c437f0 | 552 | * This parameter can be one of the following values: |
mbed_official | 133:d4dda5c437f0 | 553 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
mbed_official | 133:d4dda5c437f0 | 554 | * @arg DAC_CHANNEL_2: DAC Channel2 selected |
mbed_official | 133:d4dda5c437f0 | 555 | * @retval HAL status |
mbed_official | 133:d4dda5c437f0 | 556 | */ |
mbed_official | 133:d4dda5c437f0 | 557 | HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel) |
mbed_official | 133:d4dda5c437f0 | 558 | { |
mbed_official | 133:d4dda5c437f0 | 559 | /* Check the parameters */ |
mbed_official | 133:d4dda5c437f0 | 560 | assert_param(IS_DAC_CHANNEL(Channel)); |
mbed_official | 133:d4dda5c437f0 | 561 | |
mbed_official | 133:d4dda5c437f0 | 562 | /* Disable the selected DAC channel DMA request */ |
mbed_official | 133:d4dda5c437f0 | 563 | hdac->Instance->CR &= ~(DAC_CR_DMAEN1 << Channel); |
mbed_official | 133:d4dda5c437f0 | 564 | |
mbed_official | 133:d4dda5c437f0 | 565 | /* Disable the Peripharal */ |
mbed_official | 133:d4dda5c437f0 | 566 | __HAL_DAC_DISABLE(hdac, Channel); |
mbed_official | 133:d4dda5c437f0 | 567 | |
mbed_official | 133:d4dda5c437f0 | 568 | /* Change DAC state */ |
mbed_official | 133:d4dda5c437f0 | 569 | hdac->State = HAL_DAC_STATE_READY; |
mbed_official | 133:d4dda5c437f0 | 570 | |
mbed_official | 133:d4dda5c437f0 | 571 | /* Return function status */ |
mbed_official | 133:d4dda5c437f0 | 572 | return HAL_OK; |
mbed_official | 133:d4dda5c437f0 | 573 | } |
mbed_official | 133:d4dda5c437f0 | 574 | |
mbed_official | 133:d4dda5c437f0 | 575 | /** |
mbed_official | 133:d4dda5c437f0 | 576 | * @brief Returns the last data output value of the selected DAC channel. |
mbed_official | 133:d4dda5c437f0 | 577 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 578 | * the configuration information for the specified DAC. |
mbed_official | 133:d4dda5c437f0 | 579 | * @param Channel: The selected DAC channel. |
mbed_official | 133:d4dda5c437f0 | 580 | * This parameter can be one of the following values: |
mbed_official | 133:d4dda5c437f0 | 581 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
mbed_official | 133:d4dda5c437f0 | 582 | * @arg DAC_CHANNEL_2: DAC Channel2 selected |
mbed_official | 133:d4dda5c437f0 | 583 | * @retval The selected DAC channel data output value. |
mbed_official | 133:d4dda5c437f0 | 584 | */ |
mbed_official | 133:d4dda5c437f0 | 585 | uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel) |
mbed_official | 133:d4dda5c437f0 | 586 | { |
mbed_official | 133:d4dda5c437f0 | 587 | /* Check the parameters */ |
mbed_official | 133:d4dda5c437f0 | 588 | assert_param(IS_DAC_CHANNEL(Channel)); |
mbed_official | 133:d4dda5c437f0 | 589 | |
mbed_official | 133:d4dda5c437f0 | 590 | /* Returns the DAC channel data output register value */ |
mbed_official | 133:d4dda5c437f0 | 591 | if(Channel == DAC_CHANNEL_1) |
mbed_official | 133:d4dda5c437f0 | 592 | { |
mbed_official | 133:d4dda5c437f0 | 593 | return hdac->Instance->DOR1; |
mbed_official | 133:d4dda5c437f0 | 594 | } |
mbed_official | 133:d4dda5c437f0 | 595 | else |
mbed_official | 133:d4dda5c437f0 | 596 | { |
mbed_official | 133:d4dda5c437f0 | 597 | return hdac->Instance->DOR2; |
mbed_official | 133:d4dda5c437f0 | 598 | } |
mbed_official | 133:d4dda5c437f0 | 599 | } |
mbed_official | 133:d4dda5c437f0 | 600 | |
mbed_official | 133:d4dda5c437f0 | 601 | /** |
mbed_official | 133:d4dda5c437f0 | 602 | * @brief Handles DAC interrupt request |
mbed_official | 133:d4dda5c437f0 | 603 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 604 | * the configuration information for the specified DAC. |
mbed_official | 133:d4dda5c437f0 | 605 | * @retval None |
mbed_official | 133:d4dda5c437f0 | 606 | */ |
mbed_official | 133:d4dda5c437f0 | 607 | void HAL_DAC_IRQHandler(DAC_HandleTypeDef* hdac) |
mbed_official | 133:d4dda5c437f0 | 608 | { |
mbed_official | 133:d4dda5c437f0 | 609 | /* Check Overrun flag */ |
mbed_official | 133:d4dda5c437f0 | 610 | if(__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR1)) |
mbed_official | 133:d4dda5c437f0 | 611 | { |
mbed_official | 133:d4dda5c437f0 | 612 | /* Change DAC state to error state */ |
mbed_official | 133:d4dda5c437f0 | 613 | hdac->State = HAL_DAC_STATE_ERROR; |
mbed_official | 133:d4dda5c437f0 | 614 | |
mbed_official | 133:d4dda5c437f0 | 615 | /* Set DAC error code to chanel1 DMA underrun error */ |
mbed_official | 133:d4dda5c437f0 | 616 | hdac->ErrorCode |= HAL_DAC_ERROR_DMAUNDERRUNCH1; |
mbed_official | 133:d4dda5c437f0 | 617 | |
mbed_official | 133:d4dda5c437f0 | 618 | /* Clear the underrun flag */ |
mbed_official | 133:d4dda5c437f0 | 619 | __HAL_DAC_CLEAR_FLAG(hdac,DAC_FLAG_DMAUDR1); |
mbed_official | 133:d4dda5c437f0 | 620 | |
mbed_official | 133:d4dda5c437f0 | 621 | /* Disable the selected DAC channel1 DMA request */ |
mbed_official | 133:d4dda5c437f0 | 622 | hdac->Instance->CR &= ~DAC_CR_DMAEN1; |
mbed_official | 133:d4dda5c437f0 | 623 | |
mbed_official | 133:d4dda5c437f0 | 624 | /* Error callback */ |
mbed_official | 133:d4dda5c437f0 | 625 | HAL_DAC_DMAUnderrunCallbackCh1(hdac); |
mbed_official | 133:d4dda5c437f0 | 626 | } |
mbed_official | 133:d4dda5c437f0 | 627 | else |
mbed_official | 133:d4dda5c437f0 | 628 | { |
mbed_official | 133:d4dda5c437f0 | 629 | /* Change DAC state to error state */ |
mbed_official | 133:d4dda5c437f0 | 630 | hdac->State = HAL_DAC_STATE_ERROR; |
mbed_official | 133:d4dda5c437f0 | 631 | |
mbed_official | 133:d4dda5c437f0 | 632 | /* Set DAC error code to channel2 DMA underrun error */ |
mbed_official | 133:d4dda5c437f0 | 633 | hdac->ErrorCode |= HAL_DAC_ERROR_DMAUNDERRUNCH2; |
mbed_official | 133:d4dda5c437f0 | 634 | |
mbed_official | 133:d4dda5c437f0 | 635 | /* Clear the underrun flag */ |
mbed_official | 133:d4dda5c437f0 | 636 | __HAL_DAC_CLEAR_FLAG(hdac,DAC_FLAG_DMAUDR2); |
mbed_official | 133:d4dda5c437f0 | 637 | |
mbed_official | 133:d4dda5c437f0 | 638 | /* Disable the selected DAC channel1 DMA request */ |
mbed_official | 133:d4dda5c437f0 | 639 | hdac->Instance->CR &= ~DAC_CR_DMAEN2; |
mbed_official | 133:d4dda5c437f0 | 640 | |
mbed_official | 133:d4dda5c437f0 | 641 | /* Error callback */ |
mbed_official | 133:d4dda5c437f0 | 642 | HAL_DACEx_DMAUnderrunCallbackCh2(hdac); |
mbed_official | 133:d4dda5c437f0 | 643 | } |
mbed_official | 133:d4dda5c437f0 | 644 | } |
mbed_official | 133:d4dda5c437f0 | 645 | |
mbed_official | 133:d4dda5c437f0 | 646 | /** |
mbed_official | 133:d4dda5c437f0 | 647 | * @brief Conversion complete callback in non blocking mode for Channel1 |
mbed_official | 133:d4dda5c437f0 | 648 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 649 | * the configuration information for the specified DAC. |
mbed_official | 133:d4dda5c437f0 | 650 | * @retval None |
mbed_official | 133:d4dda5c437f0 | 651 | */ |
mbed_official | 133:d4dda5c437f0 | 652 | __weak void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef* hdac) |
mbed_official | 133:d4dda5c437f0 | 653 | { |
mbed_official | 133:d4dda5c437f0 | 654 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 133:d4dda5c437f0 | 655 | the HAL_DAC_ConvCpltCallback could be implemented in the user file |
mbed_official | 133:d4dda5c437f0 | 656 | */ |
mbed_official | 133:d4dda5c437f0 | 657 | } |
mbed_official | 133:d4dda5c437f0 | 658 | |
mbed_official | 133:d4dda5c437f0 | 659 | /** |
mbed_official | 133:d4dda5c437f0 | 660 | * @brief Conversion half DMA transfer callback in non blocking mode for Channel1 |
mbed_official | 133:d4dda5c437f0 | 661 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 662 | * the configuration information for the specified DAC. |
mbed_official | 133:d4dda5c437f0 | 663 | * @retval None |
mbed_official | 133:d4dda5c437f0 | 664 | */ |
mbed_official | 133:d4dda5c437f0 | 665 | __weak void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef* hdac) |
mbed_official | 133:d4dda5c437f0 | 666 | { |
mbed_official | 133:d4dda5c437f0 | 667 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 133:d4dda5c437f0 | 668 | the HAL_DAC_ConvHalfCpltCallbackCh1 could be implemented in the user file |
mbed_official | 133:d4dda5c437f0 | 669 | */ |
mbed_official | 133:d4dda5c437f0 | 670 | } |
mbed_official | 133:d4dda5c437f0 | 671 | |
mbed_official | 133:d4dda5c437f0 | 672 | /** |
mbed_official | 133:d4dda5c437f0 | 673 | * @brief Error DAC callback for Channel1. |
mbed_official | 133:d4dda5c437f0 | 674 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 675 | * the configuration information for the specified DAC. |
mbed_official | 133:d4dda5c437f0 | 676 | * @retval None |
mbed_official | 133:d4dda5c437f0 | 677 | */ |
mbed_official | 133:d4dda5c437f0 | 678 | __weak void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac) |
mbed_official | 133:d4dda5c437f0 | 679 | { |
mbed_official | 133:d4dda5c437f0 | 680 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 133:d4dda5c437f0 | 681 | the HAL_DAC_ErrorCallback could be implemented in the user file |
mbed_official | 133:d4dda5c437f0 | 682 | */ |
mbed_official | 133:d4dda5c437f0 | 683 | } |
mbed_official | 133:d4dda5c437f0 | 684 | |
mbed_official | 133:d4dda5c437f0 | 685 | /** |
mbed_official | 133:d4dda5c437f0 | 686 | * @brief DMA underrun DAC callback for channel1. |
mbed_official | 133:d4dda5c437f0 | 687 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 688 | * the configuration information for the specified DAC. |
mbed_official | 133:d4dda5c437f0 | 689 | * @retval None |
mbed_official | 133:d4dda5c437f0 | 690 | */ |
mbed_official | 133:d4dda5c437f0 | 691 | __weak void HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef *hdac) |
mbed_official | 133:d4dda5c437f0 | 692 | { |
mbed_official | 133:d4dda5c437f0 | 693 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 133:d4dda5c437f0 | 694 | the HAL_DAC_DMAUnderrunCallbackCh1 could be implemented in the user file |
mbed_official | 133:d4dda5c437f0 | 695 | */ |
mbed_official | 133:d4dda5c437f0 | 696 | } |
mbed_official | 133:d4dda5c437f0 | 697 | |
mbed_official | 133:d4dda5c437f0 | 698 | /** |
mbed_official | 133:d4dda5c437f0 | 699 | * @} |
mbed_official | 133:d4dda5c437f0 | 700 | */ |
mbed_official | 133:d4dda5c437f0 | 701 | |
mbed_official | 133:d4dda5c437f0 | 702 | /** @defgroup DAC_Group3 Peripheral Control functions |
mbed_official | 133:d4dda5c437f0 | 703 | * @brief Peripheral Control functions |
mbed_official | 133:d4dda5c437f0 | 704 | * |
mbed_official | 133:d4dda5c437f0 | 705 | @verbatim |
mbed_official | 133:d4dda5c437f0 | 706 | ============================================================================== |
mbed_official | 133:d4dda5c437f0 | 707 | ##### Peripheral Control functions ##### |
mbed_official | 133:d4dda5c437f0 | 708 | ============================================================================== |
mbed_official | 133:d4dda5c437f0 | 709 | [..] This section provides functions allowing to: |
mbed_official | 133:d4dda5c437f0 | 710 | (+) Configure channels. |
mbed_official | 133:d4dda5c437f0 | 711 | (+) Set the specified data holding register value for DAC channel. |
mbed_official | 133:d4dda5c437f0 | 712 | |
mbed_official | 133:d4dda5c437f0 | 713 | @endverbatim |
mbed_official | 133:d4dda5c437f0 | 714 | * @{ |
mbed_official | 133:d4dda5c437f0 | 715 | */ |
mbed_official | 133:d4dda5c437f0 | 716 | |
mbed_official | 133:d4dda5c437f0 | 717 | /** |
mbed_official | 133:d4dda5c437f0 | 718 | * @brief Configures the selected DAC channel. |
mbed_official | 133:d4dda5c437f0 | 719 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 720 | * the configuration information for the specified DAC. |
mbed_official | 133:d4dda5c437f0 | 721 | * @param sConfig: DAC configuration structure. |
mbed_official | 133:d4dda5c437f0 | 722 | * @param Channel: The selected DAC channel. |
mbed_official | 133:d4dda5c437f0 | 723 | * This parameter can be one of the following values: |
mbed_official | 133:d4dda5c437f0 | 724 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
mbed_official | 133:d4dda5c437f0 | 725 | * @arg DAC_CHANNEL_2: DAC Channel2 selected |
mbed_official | 133:d4dda5c437f0 | 726 | * @retval HAL status |
mbed_official | 133:d4dda5c437f0 | 727 | */ |
mbed_official | 133:d4dda5c437f0 | 728 | HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel) |
mbed_official | 133:d4dda5c437f0 | 729 | { |
mbed_official | 133:d4dda5c437f0 | 730 | uint32_t tmpreg1 = 0, tmpreg2 = 0; |
mbed_official | 133:d4dda5c437f0 | 731 | |
mbed_official | 133:d4dda5c437f0 | 732 | /* Check the DAC parameters */ |
mbed_official | 133:d4dda5c437f0 | 733 | assert_param(IS_DAC_TRIGGER(sConfig->DAC_Trigger)); |
mbed_official | 133:d4dda5c437f0 | 734 | assert_param(IS_DAC_OUTPUT_BUFFER_STATE(sConfig->DAC_OutputBuffer)); |
mbed_official | 133:d4dda5c437f0 | 735 | assert_param(IS_DAC_TRIGGER(sConfig->DAC_Trigger)); |
mbed_official | 133:d4dda5c437f0 | 736 | assert_param(IS_DAC_CHANNEL(Channel)); |
mbed_official | 133:d4dda5c437f0 | 737 | |
mbed_official | 133:d4dda5c437f0 | 738 | /* Process locked */ |
mbed_official | 133:d4dda5c437f0 | 739 | __HAL_LOCK(hdac); |
mbed_official | 133:d4dda5c437f0 | 740 | |
mbed_official | 133:d4dda5c437f0 | 741 | /* Change DAC state */ |
mbed_official | 133:d4dda5c437f0 | 742 | hdac->State = HAL_DAC_STATE_BUSY; |
mbed_official | 133:d4dda5c437f0 | 743 | |
mbed_official | 133:d4dda5c437f0 | 744 | /* Get the DAC CR value */ |
mbed_official | 133:d4dda5c437f0 | 745 | tmpreg1 = DAC->CR; |
mbed_official | 133:d4dda5c437f0 | 746 | /* Clear BOFFx, TENx, TSELx, WAVEx and MAMPx bits */ |
mbed_official | 133:d4dda5c437f0 | 747 | tmpreg1 &= ~(((uint32_t)(DAC_CR_MAMP1 | DAC_CR_WAVE1 | DAC_CR_TSEL1 | DAC_CR_TEN1 | DAC_CR_BOFF1)) << Channel); |
mbed_official | 133:d4dda5c437f0 | 748 | /* Configure for the selected DAC channel: buffer output, trigger */ |
mbed_official | 133:d4dda5c437f0 | 749 | /* Set TSELx and TENx bits according to DAC_Trigger value */ |
mbed_official | 133:d4dda5c437f0 | 750 | /* Set BOFFx bit according to DAC_OutputBuffer value */ |
mbed_official | 133:d4dda5c437f0 | 751 | tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputBuffer); |
mbed_official | 133:d4dda5c437f0 | 752 | /* Calculate CR register value depending on DAC_Channel */ |
mbed_official | 133:d4dda5c437f0 | 753 | tmpreg1 |= tmpreg2 << Channel; |
mbed_official | 133:d4dda5c437f0 | 754 | /* Write to DAC CR */ |
mbed_official | 133:d4dda5c437f0 | 755 | DAC->CR = tmpreg1; |
mbed_official | 133:d4dda5c437f0 | 756 | /* Disable wave generation */ |
mbed_official | 133:d4dda5c437f0 | 757 | DAC->CR &= ~(DAC_CR_WAVE1 << Channel); |
mbed_official | 133:d4dda5c437f0 | 758 | |
mbed_official | 133:d4dda5c437f0 | 759 | /* Change DAC state */ |
mbed_official | 133:d4dda5c437f0 | 760 | hdac->State = HAL_DAC_STATE_READY; |
mbed_official | 133:d4dda5c437f0 | 761 | |
mbed_official | 133:d4dda5c437f0 | 762 | /* Process unlocked */ |
mbed_official | 133:d4dda5c437f0 | 763 | __HAL_UNLOCK(hdac); |
mbed_official | 133:d4dda5c437f0 | 764 | |
mbed_official | 133:d4dda5c437f0 | 765 | /* Return function status */ |
mbed_official | 133:d4dda5c437f0 | 766 | return HAL_OK; |
mbed_official | 133:d4dda5c437f0 | 767 | } |
mbed_official | 133:d4dda5c437f0 | 768 | |
mbed_official | 133:d4dda5c437f0 | 769 | /** |
mbed_official | 133:d4dda5c437f0 | 770 | * @brief Set the specified data holding register value for DAC channel. |
mbed_official | 133:d4dda5c437f0 | 771 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 772 | * the configuration information for the specified DAC. |
mbed_official | 133:d4dda5c437f0 | 773 | * @param Channel: The selected DAC channel. |
mbed_official | 133:d4dda5c437f0 | 774 | * This parameter can be one of the following values: |
mbed_official | 133:d4dda5c437f0 | 775 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
mbed_official | 133:d4dda5c437f0 | 776 | * @arg DAC_CHANNEL_2: DAC Channel2 selected |
mbed_official | 133:d4dda5c437f0 | 777 | * @param Alignment: Specifies the data alignment. |
mbed_official | 133:d4dda5c437f0 | 778 | * This parameter can be one of the following values: |
mbed_official | 133:d4dda5c437f0 | 779 | * @arg DAC_Align_8b_R: 8bit right data alignment selected |
mbed_official | 133:d4dda5c437f0 | 780 | * @arg DAC_Align_12b_L: 12bit left data alignment selected |
mbed_official | 133:d4dda5c437f0 | 781 | * @arg DAC_Align_12b_R: 12bit right data alignment selected |
mbed_official | 133:d4dda5c437f0 | 782 | * @param Data: Data to be loaded in the selected data holding register. |
mbed_official | 133:d4dda5c437f0 | 783 | * @retval HAL status |
mbed_official | 133:d4dda5c437f0 | 784 | */ |
mbed_official | 133:d4dda5c437f0 | 785 | HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data) |
mbed_official | 133:d4dda5c437f0 | 786 | { |
mbed_official | 133:d4dda5c437f0 | 787 | __IO uint32_t tmp = 0; |
mbed_official | 133:d4dda5c437f0 | 788 | |
mbed_official | 133:d4dda5c437f0 | 789 | /* Check the parameters */ |
mbed_official | 133:d4dda5c437f0 | 790 | assert_param(IS_DAC_CHANNEL(Channel)); |
mbed_official | 133:d4dda5c437f0 | 791 | assert_param(IS_DAC_ALIGN(Alignment)); |
mbed_official | 133:d4dda5c437f0 | 792 | assert_param(IS_DAC_DATA(Data)); |
mbed_official | 133:d4dda5c437f0 | 793 | |
mbed_official | 133:d4dda5c437f0 | 794 | tmp = (uint32_t)hdac->Instance; |
mbed_official | 133:d4dda5c437f0 | 795 | if(Channel == DAC_CHANNEL_1) |
mbed_official | 133:d4dda5c437f0 | 796 | { |
mbed_official | 133:d4dda5c437f0 | 797 | tmp += __HAL_DHR12R1_ALIGNEMENT(Alignment); |
mbed_official | 133:d4dda5c437f0 | 798 | } |
mbed_official | 133:d4dda5c437f0 | 799 | else |
mbed_official | 133:d4dda5c437f0 | 800 | { |
mbed_official | 133:d4dda5c437f0 | 801 | tmp += __HAL_DHR12R2_ALIGNEMENT(Alignment); |
mbed_official | 133:d4dda5c437f0 | 802 | } |
mbed_official | 133:d4dda5c437f0 | 803 | |
mbed_official | 133:d4dda5c437f0 | 804 | /* Set the DAC channel1 selected data holding register */ |
mbed_official | 133:d4dda5c437f0 | 805 | *(__IO uint32_t *) tmp = Data; |
mbed_official | 133:d4dda5c437f0 | 806 | |
mbed_official | 133:d4dda5c437f0 | 807 | /* Return function status */ |
mbed_official | 133:d4dda5c437f0 | 808 | return HAL_OK; |
mbed_official | 133:d4dda5c437f0 | 809 | } |
mbed_official | 133:d4dda5c437f0 | 810 | |
mbed_official | 133:d4dda5c437f0 | 811 | /** |
mbed_official | 133:d4dda5c437f0 | 812 | * @} |
mbed_official | 133:d4dda5c437f0 | 813 | */ |
mbed_official | 133:d4dda5c437f0 | 814 | |
mbed_official | 133:d4dda5c437f0 | 815 | /** @defgroup DAC_Group4 Peripheral State and Errors functions |
mbed_official | 133:d4dda5c437f0 | 816 | * @brief Peripheral State and Errors functions |
mbed_official | 133:d4dda5c437f0 | 817 | * |
mbed_official | 133:d4dda5c437f0 | 818 | @verbatim |
mbed_official | 133:d4dda5c437f0 | 819 | ============================================================================== |
mbed_official | 133:d4dda5c437f0 | 820 | ##### Peripheral State and Errors functions ##### |
mbed_official | 133:d4dda5c437f0 | 821 | ============================================================================== |
mbed_official | 133:d4dda5c437f0 | 822 | [..] |
mbed_official | 133:d4dda5c437f0 | 823 | This subsection provides functions allowing to |
mbed_official | 133:d4dda5c437f0 | 824 | (+) Check the DAC state. |
mbed_official | 133:d4dda5c437f0 | 825 | (+) Check the DAC Errors. |
mbed_official | 133:d4dda5c437f0 | 826 | |
mbed_official | 133:d4dda5c437f0 | 827 | @endverbatim |
mbed_official | 133:d4dda5c437f0 | 828 | * @{ |
mbed_official | 133:d4dda5c437f0 | 829 | */ |
mbed_official | 133:d4dda5c437f0 | 830 | |
mbed_official | 133:d4dda5c437f0 | 831 | /** |
mbed_official | 133:d4dda5c437f0 | 832 | * @brief return the DAC state |
mbed_official | 133:d4dda5c437f0 | 833 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 834 | * the configuration information for the specified DAC. |
mbed_official | 133:d4dda5c437f0 | 835 | * @retval HAL state |
mbed_official | 133:d4dda5c437f0 | 836 | */ |
mbed_official | 133:d4dda5c437f0 | 837 | HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef* hdac) |
mbed_official | 133:d4dda5c437f0 | 838 | { |
mbed_official | 133:d4dda5c437f0 | 839 | /* Return DAC state */ |
mbed_official | 133:d4dda5c437f0 | 840 | return hdac->State; |
mbed_official | 133:d4dda5c437f0 | 841 | } |
mbed_official | 133:d4dda5c437f0 | 842 | |
mbed_official | 133:d4dda5c437f0 | 843 | |
mbed_official | 133:d4dda5c437f0 | 844 | /** |
mbed_official | 133:d4dda5c437f0 | 845 | * @brief Return the DAC error code |
mbed_official | 133:d4dda5c437f0 | 846 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 847 | * the configuration information for the specified DAC. |
mbed_official | 133:d4dda5c437f0 | 848 | * @retval DAC Error Code |
mbed_official | 133:d4dda5c437f0 | 849 | */ |
mbed_official | 133:d4dda5c437f0 | 850 | uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac) |
mbed_official | 133:d4dda5c437f0 | 851 | { |
mbed_official | 133:d4dda5c437f0 | 852 | return hdac->ErrorCode; |
mbed_official | 133:d4dda5c437f0 | 853 | } |
mbed_official | 133:d4dda5c437f0 | 854 | |
mbed_official | 133:d4dda5c437f0 | 855 | /** |
mbed_official | 133:d4dda5c437f0 | 856 | * @} |
mbed_official | 133:d4dda5c437f0 | 857 | */ |
mbed_official | 133:d4dda5c437f0 | 858 | |
mbed_official | 133:d4dda5c437f0 | 859 | /** |
mbed_official | 133:d4dda5c437f0 | 860 | * @brief DMA conversion complete callback. |
mbed_official | 133:d4dda5c437f0 | 861 | * @param hdma: pointer to DMA handle. |
mbed_official | 133:d4dda5c437f0 | 862 | * @retval None |
mbed_official | 133:d4dda5c437f0 | 863 | */ |
mbed_official | 133:d4dda5c437f0 | 864 | static void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma) |
mbed_official | 133:d4dda5c437f0 | 865 | { |
mbed_official | 133:d4dda5c437f0 | 866 | DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 133:d4dda5c437f0 | 867 | |
mbed_official | 133:d4dda5c437f0 | 868 | HAL_DAC_ConvCpltCallbackCh1(hdac); |
mbed_official | 133:d4dda5c437f0 | 869 | |
mbed_official | 133:d4dda5c437f0 | 870 | hdac->State= HAL_DAC_STATE_READY; |
mbed_official | 133:d4dda5c437f0 | 871 | } |
mbed_official | 133:d4dda5c437f0 | 872 | |
mbed_official | 133:d4dda5c437f0 | 873 | /** |
mbed_official | 133:d4dda5c437f0 | 874 | * @brief DMA half transfer complete callback. |
mbed_official | 133:d4dda5c437f0 | 875 | * @param hdma: pointer to DMA handle. |
mbed_official | 133:d4dda5c437f0 | 876 | * @retval None |
mbed_official | 133:d4dda5c437f0 | 877 | */ |
mbed_official | 133:d4dda5c437f0 | 878 | static void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma) |
mbed_official | 133:d4dda5c437f0 | 879 | { |
mbed_official | 133:d4dda5c437f0 | 880 | DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 133:d4dda5c437f0 | 881 | /* Conversion complete callback */ |
mbed_official | 133:d4dda5c437f0 | 882 | HAL_DAC_ConvHalfCpltCallbackCh1(hdac); |
mbed_official | 133:d4dda5c437f0 | 883 | } |
mbed_official | 133:d4dda5c437f0 | 884 | |
mbed_official | 133:d4dda5c437f0 | 885 | /** |
mbed_official | 133:d4dda5c437f0 | 886 | * @brief DMA error callback |
mbed_official | 133:d4dda5c437f0 | 887 | * @param hdma: pointer to DMA handle. |
mbed_official | 133:d4dda5c437f0 | 888 | * @retval None |
mbed_official | 133:d4dda5c437f0 | 889 | */ |
mbed_official | 133:d4dda5c437f0 | 890 | static void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma) |
mbed_official | 133:d4dda5c437f0 | 891 | { |
mbed_official | 133:d4dda5c437f0 | 892 | DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 133:d4dda5c437f0 | 893 | |
mbed_official | 133:d4dda5c437f0 | 894 | /* Set DAC error code to DMA error */ |
mbed_official | 133:d4dda5c437f0 | 895 | hdac->ErrorCode |= HAL_DAC_ERROR_DMA; |
mbed_official | 133:d4dda5c437f0 | 896 | |
mbed_official | 133:d4dda5c437f0 | 897 | HAL_DAC_ErrorCallbackCh1(hdac); |
mbed_official | 133:d4dda5c437f0 | 898 | |
mbed_official | 133:d4dda5c437f0 | 899 | hdac->State= HAL_DAC_STATE_READY; |
mbed_official | 133:d4dda5c437f0 | 900 | } |
mbed_official | 133:d4dda5c437f0 | 901 | |
mbed_official | 133:d4dda5c437f0 | 902 | /** |
mbed_official | 133:d4dda5c437f0 | 903 | * @} |
mbed_official | 133:d4dda5c437f0 | 904 | */ |
mbed_official | 133:d4dda5c437f0 | 905 | #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */ |
mbed_official | 133:d4dda5c437f0 | 906 | #endif /* HAL_DAC_MODULE_ENABLED */ |
mbed_official | 133:d4dda5c437f0 | 907 | |
mbed_official | 133:d4dda5c437f0 | 908 | /** |
mbed_official | 133:d4dda5c437f0 | 909 | * @} |
mbed_official | 133:d4dda5c437f0 | 910 | */ |
mbed_official | 133:d4dda5c437f0 | 911 | |
mbed_official | 133:d4dda5c437f0 | 912 | /** |
mbed_official | 133:d4dda5c437f0 | 913 | * @} |
mbed_official | 133:d4dda5c437f0 | 914 | */ |
mbed_official | 133:d4dda5c437f0 | 915 | |
mbed_official | 133:d4dda5c437f0 | 916 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |