mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_DISCO_F407VG/stm32f4xx_hal_adc_ex.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_adc_ex.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 This file provides firmware functions to manage the following |
mbed_official | 133:d4dda5c437f0 | 8 | * functionalities of the ADC extension peripheral: |
mbed_official | 133:d4dda5c437f0 | 9 | * + Extended features functions |
mbed_official | 133:d4dda5c437f0 | 10 | * |
mbed_official | 133:d4dda5c437f0 | 11 | @verbatim |
mbed_official | 133:d4dda5c437f0 | 12 | ============================================================================== |
mbed_official | 133:d4dda5c437f0 | 13 | ##### How to use this driver ##### |
mbed_official | 133:d4dda5c437f0 | 14 | ============================================================================== |
mbed_official | 133:d4dda5c437f0 | 15 | [..] |
mbed_official | 133:d4dda5c437f0 | 16 | (#)Initialize the ADC low level resources by implementing the HAL_ADC_MspInit(): |
mbed_official | 133:d4dda5c437f0 | 17 | (##) Enable the ADC interface clock using __ADC_CLK_ENABLE() |
mbed_official | 133:d4dda5c437f0 | 18 | (##) ADC pins configuration |
mbed_official | 133:d4dda5c437f0 | 19 | (+++) Enable the clock for the ADC GPIOs using the following function: |
mbed_official | 133:d4dda5c437f0 | 20 | __GPIOx_CLK_ENABLE() |
mbed_official | 133:d4dda5c437f0 | 21 | (+++) Configure these ADC pins in analog mode using HAL_GPIO_Init() |
mbed_official | 133:d4dda5c437f0 | 22 | (##) In case of using interrupts (e.g. HAL_ADC_Start_IT()) |
mbed_official | 133:d4dda5c437f0 | 23 | (+++) Configure the ADC interrupt priority using HAL_NVIC_SetPriority() |
mbed_official | 133:d4dda5c437f0 | 24 | (+++) Enable the ADC IRQ handler using HAL_NVIC_EnableIRQ() |
mbed_official | 133:d4dda5c437f0 | 25 | (+++) In ADC IRQ handler, call HAL_ADC_IRQHandler() |
mbed_official | 133:d4dda5c437f0 | 26 | (##) In case of using DMA to control data transfer (e.g. HAL_ADC_Start_DMA()) |
mbed_official | 133:d4dda5c437f0 | 27 | (++) Enable the DMAx interface clock using __DMAx_CLK_ENABLE() |
mbed_official | 133:d4dda5c437f0 | 28 | (++) Configure and enable two DMA streams stream for managing data |
mbed_official | 133:d4dda5c437f0 | 29 | transfer from peripheral to memory (output stream) |
mbed_official | 133:d4dda5c437f0 | 30 | (++) Associate the initilalized DMA handle to the CRYP DMA handle |
mbed_official | 133:d4dda5c437f0 | 31 | using __HAL_LINKDMA() |
mbed_official | 133:d4dda5c437f0 | 32 | (++) Configure the priority and enable the NVIC for the transfer complete |
mbed_official | 133:d4dda5c437f0 | 33 | interrupt on the two DMA Streams. The output stream should have higher |
mbed_official | 133:d4dda5c437f0 | 34 | priority than the input stream. |
mbed_official | 133:d4dda5c437f0 | 35 | |
mbed_official | 133:d4dda5c437f0 | 36 | (#) Configure the ADC Prescaler, conversion resolution and data alignment |
mbed_official | 133:d4dda5c437f0 | 37 | using the HAL_ADC_Init() function. |
mbed_official | 133:d4dda5c437f0 | 38 | |
mbed_official | 133:d4dda5c437f0 | 39 | (#) Configure the ADC Injected channels group features, use HAL_ADC_Init() |
mbed_official | 133:d4dda5c437f0 | 40 | and HAL_ADC_ConfigChannel() functions. |
mbed_official | 133:d4dda5c437f0 | 41 | |
mbed_official | 133:d4dda5c437f0 | 42 | (#) Three mode of operations are available within this driver : |
mbed_official | 133:d4dda5c437f0 | 43 | |
mbed_official | 133:d4dda5c437f0 | 44 | *** Polling mode IO operation *** |
mbed_official | 133:d4dda5c437f0 | 45 | ================================= |
mbed_official | 133:d4dda5c437f0 | 46 | [..] |
mbed_official | 133:d4dda5c437f0 | 47 | (+) Start the ADC peripheral using HAL_ADCEx_InjectedStart() |
mbed_official | 133:d4dda5c437f0 | 48 | (+) Wait for end of conversion using HAL_ADC_PollForConversion(), at this stage |
mbed_official | 133:d4dda5c437f0 | 49 | user can specify the value of timeout according to his end application |
mbed_official | 133:d4dda5c437f0 | 50 | (+) To read the ADC converted values, use the HAL_ADCEx_InjectedGetValue() function. |
mbed_official | 133:d4dda5c437f0 | 51 | (+) Stop the ADC peripheral using HAL_ADCEx_InjectedStop() |
mbed_official | 133:d4dda5c437f0 | 52 | |
mbed_official | 133:d4dda5c437f0 | 53 | *** Interrupt mode IO operation *** |
mbed_official | 133:d4dda5c437f0 | 54 | =================================== |
mbed_official | 133:d4dda5c437f0 | 55 | [..] |
mbed_official | 133:d4dda5c437f0 | 56 | (+) Start the ADC peripheral using HAL_ADCEx_InjectedStart_IT() |
mbed_official | 133:d4dda5c437f0 | 57 | (+) Use HAL_ADC_IRQHandler() called under ADC_IRQHandler() Interrupt subroutine |
mbed_official | 133:d4dda5c437f0 | 58 | (+) At ADC end of conversion HAL_ADCEx_InjectedConvCpltCallback() function is executed and user can |
mbed_official | 133:d4dda5c437f0 | 59 | add his own code by customization of function pointer HAL_ADCEx_InjectedConvCpltCallback |
mbed_official | 133:d4dda5c437f0 | 60 | (+) In case of ADC Error, HAL_ADCEx_InjectedErrorCallback() function is executed and user can |
mbed_official | 133:d4dda5c437f0 | 61 | add his own code by customization of function pointer HAL_ADCEx_InjectedErrorCallback |
mbed_official | 133:d4dda5c437f0 | 62 | (+) Stop the ADC peripheral using HAL_ADCEx_InjectedStop_IT() |
mbed_official | 133:d4dda5c437f0 | 63 | |
mbed_official | 133:d4dda5c437f0 | 64 | |
mbed_official | 133:d4dda5c437f0 | 65 | *** DMA mode IO operation *** |
mbed_official | 133:d4dda5c437f0 | 66 | ============================== |
mbed_official | 133:d4dda5c437f0 | 67 | [..] |
mbed_official | 133:d4dda5c437f0 | 68 | (+) Start the ADC peripheral using HAL_ADCEx_InjectedStart_DMA(), at this stage the user specify the length |
mbed_official | 133:d4dda5c437f0 | 69 | of data to be transfered at each end of conversion |
mbed_official | 133:d4dda5c437f0 | 70 | (+) At The end of data transfer ba HAL_ADCEx_InjectedConvCpltCallback() function is executed and user can |
mbed_official | 133:d4dda5c437f0 | 71 | add his own code by customization of function pointer HAL_ADCEx_InjectedConvCpltCallback |
mbed_official | 133:d4dda5c437f0 | 72 | (+) In case of transfer Error, HAL_ADCEx_InjectedErrorCallback() function is executed and user can |
mbed_official | 133:d4dda5c437f0 | 73 | add his own code by customization of function pointer HAL_ADCEx_InjectedErrorCallback |
mbed_official | 133:d4dda5c437f0 | 74 | (+) Stop the ADC peripheral using HAL_ADCEx_InjectedStop_DMA() |
mbed_official | 133:d4dda5c437f0 | 75 | |
mbed_official | 133:d4dda5c437f0 | 76 | *** Multi mode ADCs Regular channels configuration *** |
mbed_official | 133:d4dda5c437f0 | 77 | ====================================================== |
mbed_official | 133:d4dda5c437f0 | 78 | [..] |
mbed_official | 133:d4dda5c437f0 | 79 | (+) Select the Multi mode ADC regular channels features (dual or triple mode) |
mbed_official | 133:d4dda5c437f0 | 80 | and configure the DMA mode using HAL_ADCEx_MultiModeConfigChannel() functions. |
mbed_official | 133:d4dda5c437f0 | 81 | (+) Start the ADC peripheral using HAL_ADCEx_MultiModeStart_DMA(), at this stage the user specify the length |
mbed_official | 133:d4dda5c437f0 | 82 | of data to be transfered at each end of conversion |
mbed_official | 133:d4dda5c437f0 | 83 | (+) Read the ADCs converted values using the HAL_ADCEx_MultiModeGetValue() function. |
mbed_official | 133:d4dda5c437f0 | 84 | |
mbed_official | 133:d4dda5c437f0 | 85 | |
mbed_official | 133:d4dda5c437f0 | 86 | @endverbatim |
mbed_official | 133:d4dda5c437f0 | 87 | ****************************************************************************** |
mbed_official | 133:d4dda5c437f0 | 88 | * @attention |
mbed_official | 133:d4dda5c437f0 | 89 | * |
mbed_official | 133:d4dda5c437f0 | 90 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 133:d4dda5c437f0 | 91 | * |
mbed_official | 133:d4dda5c437f0 | 92 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 133:d4dda5c437f0 | 93 | * are permitted provided that the following conditions are met: |
mbed_official | 133:d4dda5c437f0 | 94 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 133:d4dda5c437f0 | 95 | * this list of conditions and the following disclaimer. |
mbed_official | 133:d4dda5c437f0 | 96 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 133:d4dda5c437f0 | 97 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 133:d4dda5c437f0 | 98 | * and/or other materials provided with the distribution. |
mbed_official | 133:d4dda5c437f0 | 99 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 133:d4dda5c437f0 | 100 | * may be used to endorse or promote products derived from this software |
mbed_official | 133:d4dda5c437f0 | 101 | * without specific prior written permission. |
mbed_official | 133:d4dda5c437f0 | 102 | * |
mbed_official | 133:d4dda5c437f0 | 103 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 133:d4dda5c437f0 | 104 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 133:d4dda5c437f0 | 105 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 133:d4dda5c437f0 | 106 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 133:d4dda5c437f0 | 107 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 133:d4dda5c437f0 | 108 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 133:d4dda5c437f0 | 109 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 133:d4dda5c437f0 | 110 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 133:d4dda5c437f0 | 111 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 133:d4dda5c437f0 | 112 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 133:d4dda5c437f0 | 113 | * |
mbed_official | 133:d4dda5c437f0 | 114 | ****************************************************************************** |
mbed_official | 133:d4dda5c437f0 | 115 | */ |
mbed_official | 133:d4dda5c437f0 | 116 | |
mbed_official | 133:d4dda5c437f0 | 117 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 133:d4dda5c437f0 | 118 | #include "stm32f4xx_hal.h" |
mbed_official | 133:d4dda5c437f0 | 119 | |
mbed_official | 133:d4dda5c437f0 | 120 | /** @addtogroup STM32F4xx_HAL_Driver |
mbed_official | 133:d4dda5c437f0 | 121 | * @{ |
mbed_official | 133:d4dda5c437f0 | 122 | */ |
mbed_official | 133:d4dda5c437f0 | 123 | |
mbed_official | 133:d4dda5c437f0 | 124 | /** @defgroup ADCEx |
mbed_official | 133:d4dda5c437f0 | 125 | * @brief ADC Extended driver modules |
mbed_official | 133:d4dda5c437f0 | 126 | * @{ |
mbed_official | 133:d4dda5c437f0 | 127 | */ |
mbed_official | 133:d4dda5c437f0 | 128 | |
mbed_official | 133:d4dda5c437f0 | 129 | #ifdef HAL_ADC_MODULE_ENABLED |
mbed_official | 133:d4dda5c437f0 | 130 | |
mbed_official | 133:d4dda5c437f0 | 131 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 133:d4dda5c437f0 | 132 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 133:d4dda5c437f0 | 133 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 133:d4dda5c437f0 | 134 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 133:d4dda5c437f0 | 135 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 133:d4dda5c437f0 | 136 | static void ADC_MultiModeDMAConvCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 133:d4dda5c437f0 | 137 | static void ADC_MultiModeDMAError(DMA_HandleTypeDef *hdma); |
mbed_official | 133:d4dda5c437f0 | 138 | static void ADC_MultiModeDMAHalfConvCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 133:d4dda5c437f0 | 139 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 133:d4dda5c437f0 | 140 | |
mbed_official | 133:d4dda5c437f0 | 141 | /** @defgroup ADCEx_Private_Functions |
mbed_official | 133:d4dda5c437f0 | 142 | * @{ |
mbed_official | 133:d4dda5c437f0 | 143 | */ |
mbed_official | 133:d4dda5c437f0 | 144 | |
mbed_official | 133:d4dda5c437f0 | 145 | /** @defgroup ADCEx_Group1 Extended features functions |
mbed_official | 133:d4dda5c437f0 | 146 | * @brief Extended features functions |
mbed_official | 133:d4dda5c437f0 | 147 | * |
mbed_official | 133:d4dda5c437f0 | 148 | @verbatim |
mbed_official | 133:d4dda5c437f0 | 149 | =============================================================================== |
mbed_official | 133:d4dda5c437f0 | 150 | ##### Extended features functions ##### |
mbed_official | 133:d4dda5c437f0 | 151 | =============================================================================== |
mbed_official | 133:d4dda5c437f0 | 152 | [..] This section provides functions allowing to: |
mbed_official | 133:d4dda5c437f0 | 153 | (+) Start conversion of injected channel. |
mbed_official | 133:d4dda5c437f0 | 154 | (+) Stop conversion of injected channel. |
mbed_official | 133:d4dda5c437f0 | 155 | (+) Start multimode and enable DMA transfer. |
mbed_official | 133:d4dda5c437f0 | 156 | (+) Stop multimode and disable DMA transfer. |
mbed_official | 133:d4dda5c437f0 | 157 | (+) Get result of injected channel conversion. |
mbed_official | 133:d4dda5c437f0 | 158 | (+) Get result of multimode conversion. |
mbed_official | 133:d4dda5c437f0 | 159 | (+) Configure injected channels. |
mbed_official | 133:d4dda5c437f0 | 160 | (+) Configure multimode. |
mbed_official | 133:d4dda5c437f0 | 161 | |
mbed_official | 133:d4dda5c437f0 | 162 | @endverbatim |
mbed_official | 133:d4dda5c437f0 | 163 | * @{ |
mbed_official | 133:d4dda5c437f0 | 164 | */ |
mbed_official | 133:d4dda5c437f0 | 165 | |
mbed_official | 133:d4dda5c437f0 | 166 | /** |
mbed_official | 133:d4dda5c437f0 | 167 | * @brief Enables the selected ADC software start conversion of the injected channels. |
mbed_official | 133:d4dda5c437f0 | 168 | * @param hadc: pointer to a ADC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 169 | * the configuration information for the specified ADC. |
mbed_official | 133:d4dda5c437f0 | 170 | * @retval HAL status |
mbed_official | 133:d4dda5c437f0 | 171 | */ |
mbed_official | 133:d4dda5c437f0 | 172 | HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc) |
mbed_official | 133:d4dda5c437f0 | 173 | { |
mbed_official | 133:d4dda5c437f0 | 174 | uint32_t i = 0, tmp1 = 0, tmp2 = 0; |
mbed_official | 133:d4dda5c437f0 | 175 | |
mbed_official | 133:d4dda5c437f0 | 176 | /* Process locked */ |
mbed_official | 133:d4dda5c437f0 | 177 | __HAL_LOCK(hadc); |
mbed_official | 133:d4dda5c437f0 | 178 | |
mbed_official | 133:d4dda5c437f0 | 179 | /* Check if a regular conversion is ongoing */ |
mbed_official | 133:d4dda5c437f0 | 180 | if(hadc->State == HAL_ADC_STATE_BUSY_REG) |
mbed_official | 133:d4dda5c437f0 | 181 | { |
mbed_official | 133:d4dda5c437f0 | 182 | /* Change ADC state */ |
mbed_official | 133:d4dda5c437f0 | 183 | hadc->State = HAL_ADC_STATE_BUSY_INJ_REG; |
mbed_official | 133:d4dda5c437f0 | 184 | } |
mbed_official | 133:d4dda5c437f0 | 185 | else |
mbed_official | 133:d4dda5c437f0 | 186 | { |
mbed_official | 133:d4dda5c437f0 | 187 | /* Change ADC state */ |
mbed_official | 133:d4dda5c437f0 | 188 | hadc->State = HAL_ADC_STATE_BUSY_INJ; |
mbed_official | 133:d4dda5c437f0 | 189 | } |
mbed_official | 133:d4dda5c437f0 | 190 | |
mbed_official | 133:d4dda5c437f0 | 191 | /* Check if ADC peripheral is disabled in order to enable it and wait during |
mbed_official | 133:d4dda5c437f0 | 192 | Tstab time the ADC's stabilization */ |
mbed_official | 133:d4dda5c437f0 | 193 | if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON) |
mbed_official | 133:d4dda5c437f0 | 194 | { |
mbed_official | 133:d4dda5c437f0 | 195 | /* Enable the Peripheral */ |
mbed_official | 133:d4dda5c437f0 | 196 | __HAL_ADC_ENABLE(hadc); |
mbed_official | 133:d4dda5c437f0 | 197 | |
mbed_official | 133:d4dda5c437f0 | 198 | /* Delay inserted to wait during Tstab time the ADC's stabilazation */ |
mbed_official | 133:d4dda5c437f0 | 199 | for(; i <= 540; i++) |
mbed_official | 133:d4dda5c437f0 | 200 | { |
mbed_official | 133:d4dda5c437f0 | 201 | __NOP(); |
mbed_official | 133:d4dda5c437f0 | 202 | } |
mbed_official | 133:d4dda5c437f0 | 203 | } |
mbed_official | 133:d4dda5c437f0 | 204 | |
mbed_official | 133:d4dda5c437f0 | 205 | /* Check if Multimode enabled */ |
mbed_official | 133:d4dda5c437f0 | 206 | if(HAL_IS_BIT_CLR(ADC->CCR, ADC_CCR_MULTI)) |
mbed_official | 133:d4dda5c437f0 | 207 | { |
mbed_official | 133:d4dda5c437f0 | 208 | tmp1 = HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_JEXTEN); |
mbed_official | 133:d4dda5c437f0 | 209 | tmp2 = HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO); |
mbed_official | 133:d4dda5c437f0 | 210 | if(tmp1 && tmp2) |
mbed_official | 133:d4dda5c437f0 | 211 | { |
mbed_official | 133:d4dda5c437f0 | 212 | /* Enable the selected ADC software conversion for injected group */ |
mbed_official | 133:d4dda5c437f0 | 213 | hadc->Instance->CR2 |= ADC_CR2_JSWSTART; |
mbed_official | 133:d4dda5c437f0 | 214 | } |
mbed_official | 133:d4dda5c437f0 | 215 | } |
mbed_official | 133:d4dda5c437f0 | 216 | else |
mbed_official | 133:d4dda5c437f0 | 217 | { |
mbed_official | 133:d4dda5c437f0 | 218 | tmp1 = HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_JEXTEN); |
mbed_official | 133:d4dda5c437f0 | 219 | tmp2 = HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO); |
mbed_official | 133:d4dda5c437f0 | 220 | if((hadc->Instance == ADC1) && tmp1 && tmp2) |
mbed_official | 133:d4dda5c437f0 | 221 | { |
mbed_official | 133:d4dda5c437f0 | 222 | /* Enable the selected ADC software conversion for injected group */ |
mbed_official | 133:d4dda5c437f0 | 223 | hadc->Instance->CR2 |= ADC_CR2_JSWSTART; |
mbed_official | 133:d4dda5c437f0 | 224 | } |
mbed_official | 133:d4dda5c437f0 | 225 | } |
mbed_official | 133:d4dda5c437f0 | 226 | |
mbed_official | 133:d4dda5c437f0 | 227 | /* Process unlocked */ |
mbed_official | 133:d4dda5c437f0 | 228 | __HAL_UNLOCK(hadc); |
mbed_official | 133:d4dda5c437f0 | 229 | |
mbed_official | 133:d4dda5c437f0 | 230 | /* Return function status */ |
mbed_official | 133:d4dda5c437f0 | 231 | return HAL_OK; |
mbed_official | 133:d4dda5c437f0 | 232 | } |
mbed_official | 133:d4dda5c437f0 | 233 | |
mbed_official | 133:d4dda5c437f0 | 234 | /** |
mbed_official | 133:d4dda5c437f0 | 235 | * @brief Enables the interrupt and starts ADC conversion of injected channels. |
mbed_official | 133:d4dda5c437f0 | 236 | * @param hadc: pointer to a ADC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 237 | * the configuration information for the specified ADC. |
mbed_official | 133:d4dda5c437f0 | 238 | * |
mbed_official | 133:d4dda5c437f0 | 239 | * @retval HAL status. |
mbed_official | 133:d4dda5c437f0 | 240 | */ |
mbed_official | 133:d4dda5c437f0 | 241 | HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc) |
mbed_official | 133:d4dda5c437f0 | 242 | { |
mbed_official | 133:d4dda5c437f0 | 243 | uint32_t i = 0, tmp1 = 0, tmp2 =0; |
mbed_official | 133:d4dda5c437f0 | 244 | |
mbed_official | 133:d4dda5c437f0 | 245 | /* Process locked */ |
mbed_official | 133:d4dda5c437f0 | 246 | __HAL_LOCK(hadc); |
mbed_official | 133:d4dda5c437f0 | 247 | |
mbed_official | 133:d4dda5c437f0 | 248 | /* Check if a regular conversion is ongoing */ |
mbed_official | 133:d4dda5c437f0 | 249 | if(hadc->State == HAL_ADC_STATE_BUSY_REG) |
mbed_official | 133:d4dda5c437f0 | 250 | { |
mbed_official | 133:d4dda5c437f0 | 251 | /* Change ADC state */ |
mbed_official | 133:d4dda5c437f0 | 252 | hadc->State = HAL_ADC_STATE_BUSY_INJ_REG; |
mbed_official | 133:d4dda5c437f0 | 253 | } |
mbed_official | 133:d4dda5c437f0 | 254 | else |
mbed_official | 133:d4dda5c437f0 | 255 | { |
mbed_official | 133:d4dda5c437f0 | 256 | /* Change ADC state */ |
mbed_official | 133:d4dda5c437f0 | 257 | hadc->State = HAL_ADC_STATE_BUSY_INJ; |
mbed_official | 133:d4dda5c437f0 | 258 | } |
mbed_official | 133:d4dda5c437f0 | 259 | |
mbed_official | 133:d4dda5c437f0 | 260 | /* Set ADC error code to none */ |
mbed_official | 133:d4dda5c437f0 | 261 | hadc->ErrorCode = HAL_ADC_ERROR_NONE; |
mbed_official | 133:d4dda5c437f0 | 262 | |
mbed_official | 133:d4dda5c437f0 | 263 | /* Check if ADC peripheral is disabled in order to enable it and wait during |
mbed_official | 133:d4dda5c437f0 | 264 | Tstab time the ADC's stabilization */ |
mbed_official | 133:d4dda5c437f0 | 265 | if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON) |
mbed_official | 133:d4dda5c437f0 | 266 | { |
mbed_official | 133:d4dda5c437f0 | 267 | /* Enable the Peripheral */ |
mbed_official | 133:d4dda5c437f0 | 268 | __HAL_ADC_ENABLE(hadc); |
mbed_official | 133:d4dda5c437f0 | 269 | |
mbed_official | 133:d4dda5c437f0 | 270 | /* Delay inserted to wait during Tstab time the ADC's stabilazation */ |
mbed_official | 133:d4dda5c437f0 | 271 | for(; i <= 540; i++) |
mbed_official | 133:d4dda5c437f0 | 272 | { |
mbed_official | 133:d4dda5c437f0 | 273 | __NOP(); |
mbed_official | 133:d4dda5c437f0 | 274 | } |
mbed_official | 133:d4dda5c437f0 | 275 | } |
mbed_official | 133:d4dda5c437f0 | 276 | |
mbed_official | 133:d4dda5c437f0 | 277 | /* Enable the ADC end of conversion interrupt for injected group */ |
mbed_official | 133:d4dda5c437f0 | 278 | __HAL_ADC_ENABLE_IT(hadc, ADC_IT_JEOC); |
mbed_official | 133:d4dda5c437f0 | 279 | |
mbed_official | 133:d4dda5c437f0 | 280 | /* Enable the ADC overrun interrupt */ |
mbed_official | 133:d4dda5c437f0 | 281 | __HAL_ADC_ENABLE_IT(hadc, ADC_IT_OVR); |
mbed_official | 133:d4dda5c437f0 | 282 | |
mbed_official | 133:d4dda5c437f0 | 283 | /* Check if Multimode enabled */ |
mbed_official | 133:d4dda5c437f0 | 284 | if(HAL_IS_BIT_CLR(ADC->CCR, ADC_CCR_MULTI)) |
mbed_official | 133:d4dda5c437f0 | 285 | { |
mbed_official | 133:d4dda5c437f0 | 286 | tmp1 = HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_JEXTEN); |
mbed_official | 133:d4dda5c437f0 | 287 | tmp2 = HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO); |
mbed_official | 133:d4dda5c437f0 | 288 | if(tmp1 && tmp2) |
mbed_official | 133:d4dda5c437f0 | 289 | { |
mbed_official | 133:d4dda5c437f0 | 290 | /* Enable the selected ADC software conversion for injected group */ |
mbed_official | 133:d4dda5c437f0 | 291 | hadc->Instance->CR2 |= ADC_CR2_JSWSTART; |
mbed_official | 133:d4dda5c437f0 | 292 | } |
mbed_official | 133:d4dda5c437f0 | 293 | } |
mbed_official | 133:d4dda5c437f0 | 294 | else |
mbed_official | 133:d4dda5c437f0 | 295 | { |
mbed_official | 133:d4dda5c437f0 | 296 | tmp1 = HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_JEXTEN); |
mbed_official | 133:d4dda5c437f0 | 297 | tmp2 = HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO); |
mbed_official | 133:d4dda5c437f0 | 298 | if((hadc->Instance == ADC1) && tmp1 && tmp2) |
mbed_official | 133:d4dda5c437f0 | 299 | { |
mbed_official | 133:d4dda5c437f0 | 300 | /* Enable the selected ADC software conversion for injected group */ |
mbed_official | 133:d4dda5c437f0 | 301 | hadc->Instance->CR2 |= ADC_CR2_JSWSTART; |
mbed_official | 133:d4dda5c437f0 | 302 | } |
mbed_official | 133:d4dda5c437f0 | 303 | } |
mbed_official | 133:d4dda5c437f0 | 304 | |
mbed_official | 133:d4dda5c437f0 | 305 | /* Process unlocked */ |
mbed_official | 133:d4dda5c437f0 | 306 | __HAL_UNLOCK(hadc); |
mbed_official | 133:d4dda5c437f0 | 307 | |
mbed_official | 133:d4dda5c437f0 | 308 | /* Return function status */ |
mbed_official | 133:d4dda5c437f0 | 309 | return HAL_OK; |
mbed_official | 133:d4dda5c437f0 | 310 | } |
mbed_official | 133:d4dda5c437f0 | 311 | |
mbed_official | 133:d4dda5c437f0 | 312 | /** |
mbed_official | 133:d4dda5c437f0 | 313 | * @brief Disables ADC and stop conversion of injected channels. |
mbed_official | 133:d4dda5c437f0 | 314 | * |
mbed_official | 133:d4dda5c437f0 | 315 | * @note Caution: This function will stop also regular channels. |
mbed_official | 133:d4dda5c437f0 | 316 | * |
mbed_official | 133:d4dda5c437f0 | 317 | * @param hadc: pointer to a ADC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 318 | * the configuration information for the specified ADC. |
mbed_official | 133:d4dda5c437f0 | 319 | * @retval HAL status. |
mbed_official | 133:d4dda5c437f0 | 320 | */ |
mbed_official | 133:d4dda5c437f0 | 321 | HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc) |
mbed_official | 133:d4dda5c437f0 | 322 | { |
mbed_official | 133:d4dda5c437f0 | 323 | /* Disable the Peripheral */ |
mbed_official | 133:d4dda5c437f0 | 324 | __HAL_ADC_DISABLE(hadc); |
mbed_official | 133:d4dda5c437f0 | 325 | |
mbed_official | 133:d4dda5c437f0 | 326 | /* Change ADC state */ |
mbed_official | 133:d4dda5c437f0 | 327 | hadc->State = HAL_ADC_STATE_READY; |
mbed_official | 133:d4dda5c437f0 | 328 | |
mbed_official | 133:d4dda5c437f0 | 329 | /* Return function status */ |
mbed_official | 133:d4dda5c437f0 | 330 | return HAL_OK; |
mbed_official | 133:d4dda5c437f0 | 331 | } |
mbed_official | 133:d4dda5c437f0 | 332 | |
mbed_official | 133:d4dda5c437f0 | 333 | /** |
mbed_official | 133:d4dda5c437f0 | 334 | * @brief Poll for injected conversion complete |
mbed_official | 133:d4dda5c437f0 | 335 | * @param hadc: pointer to a ADC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 336 | * the configuration information for the specified ADC. |
mbed_official | 133:d4dda5c437f0 | 337 | * @param Timeout: Timeout value in millisecond. |
mbed_official | 133:d4dda5c437f0 | 338 | * @retval HAL status |
mbed_official | 133:d4dda5c437f0 | 339 | */ |
mbed_official | 133:d4dda5c437f0 | 340 | HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout) |
mbed_official | 133:d4dda5c437f0 | 341 | { |
mbed_official | 133:d4dda5c437f0 | 342 | uint32_t timeout; |
mbed_official | 133:d4dda5c437f0 | 343 | |
mbed_official | 133:d4dda5c437f0 | 344 | /* Get timeout */ |
mbed_official | 133:d4dda5c437f0 | 345 | timeout = HAL_GetTick() + Timeout; |
mbed_official | 133:d4dda5c437f0 | 346 | |
mbed_official | 133:d4dda5c437f0 | 347 | /* Check End of conversion flag */ |
mbed_official | 133:d4dda5c437f0 | 348 | while(!(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_JEOC))) |
mbed_official | 133:d4dda5c437f0 | 349 | { |
mbed_official | 133:d4dda5c437f0 | 350 | /* Check for the Timeout */ |
mbed_official | 133:d4dda5c437f0 | 351 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 133:d4dda5c437f0 | 352 | { |
mbed_official | 133:d4dda5c437f0 | 353 | if(HAL_GetTick() >= timeout) |
mbed_official | 133:d4dda5c437f0 | 354 | { |
mbed_official | 133:d4dda5c437f0 | 355 | hadc->State= HAL_ADC_STATE_TIMEOUT; |
mbed_official | 133:d4dda5c437f0 | 356 | /* Process unlocked */ |
mbed_official | 133:d4dda5c437f0 | 357 | __HAL_UNLOCK(hadc); |
mbed_official | 133:d4dda5c437f0 | 358 | return HAL_TIMEOUT; |
mbed_official | 133:d4dda5c437f0 | 359 | } |
mbed_official | 133:d4dda5c437f0 | 360 | } |
mbed_official | 133:d4dda5c437f0 | 361 | } |
mbed_official | 133:d4dda5c437f0 | 362 | |
mbed_official | 133:d4dda5c437f0 | 363 | /* Check if a regular conversion is ready */ |
mbed_official | 133:d4dda5c437f0 | 364 | if(hadc->State == HAL_ADC_STATE_EOC_REG) |
mbed_official | 133:d4dda5c437f0 | 365 | { |
mbed_official | 133:d4dda5c437f0 | 366 | /* Change ADC state */ |
mbed_official | 133:d4dda5c437f0 | 367 | hadc->State = HAL_ADC_STATE_EOC_INJ_REG; |
mbed_official | 133:d4dda5c437f0 | 368 | } |
mbed_official | 133:d4dda5c437f0 | 369 | else |
mbed_official | 133:d4dda5c437f0 | 370 | { |
mbed_official | 133:d4dda5c437f0 | 371 | /* Change ADC state */ |
mbed_official | 133:d4dda5c437f0 | 372 | hadc->State = HAL_ADC_STATE_EOC_INJ; |
mbed_official | 133:d4dda5c437f0 | 373 | } |
mbed_official | 133:d4dda5c437f0 | 374 | |
mbed_official | 133:d4dda5c437f0 | 375 | /* Return ADC state */ |
mbed_official | 133:d4dda5c437f0 | 376 | return HAL_OK; |
mbed_official | 133:d4dda5c437f0 | 377 | } |
mbed_official | 133:d4dda5c437f0 | 378 | |
mbed_official | 133:d4dda5c437f0 | 379 | /** |
mbed_official | 133:d4dda5c437f0 | 380 | * @brief Disables the interrupt and stop ADC conversion of injected channels. |
mbed_official | 133:d4dda5c437f0 | 381 | * |
mbed_official | 133:d4dda5c437f0 | 382 | * @note Caution: This function will stop also regular channels. |
mbed_official | 133:d4dda5c437f0 | 383 | * |
mbed_official | 133:d4dda5c437f0 | 384 | * @param hadc: pointer to a ADC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 385 | * the configuration information for the specified ADC. |
mbed_official | 133:d4dda5c437f0 | 386 | * @retval HAL status. |
mbed_official | 133:d4dda5c437f0 | 387 | */ |
mbed_official | 133:d4dda5c437f0 | 388 | HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc) |
mbed_official | 133:d4dda5c437f0 | 389 | { |
mbed_official | 133:d4dda5c437f0 | 390 | /* Disable the ADC end of conversion interrupt for regular group */ |
mbed_official | 133:d4dda5c437f0 | 391 | __HAL_ADC_DISABLE_IT(hadc, ADC_IT_EOC); |
mbed_official | 133:d4dda5c437f0 | 392 | |
mbed_official | 133:d4dda5c437f0 | 393 | /* Disable the ADC end of conversion interrupt for injected group */ |
mbed_official | 133:d4dda5c437f0 | 394 | __HAL_ADC_DISABLE_IT(hadc, ADC_CR1_JEOCIE); |
mbed_official | 133:d4dda5c437f0 | 395 | |
mbed_official | 133:d4dda5c437f0 | 396 | /* Enable the Periphral */ |
mbed_official | 133:d4dda5c437f0 | 397 | __HAL_ADC_DISABLE(hadc); |
mbed_official | 133:d4dda5c437f0 | 398 | |
mbed_official | 133:d4dda5c437f0 | 399 | /* Change ADC state */ |
mbed_official | 133:d4dda5c437f0 | 400 | hadc->State = HAL_ADC_STATE_READY; |
mbed_official | 133:d4dda5c437f0 | 401 | |
mbed_official | 133:d4dda5c437f0 | 402 | /* Return function status */ |
mbed_official | 133:d4dda5c437f0 | 403 | return HAL_OK; |
mbed_official | 133:d4dda5c437f0 | 404 | } |
mbed_official | 133:d4dda5c437f0 | 405 | |
mbed_official | 133:d4dda5c437f0 | 406 | /** |
mbed_official | 133:d4dda5c437f0 | 407 | * @brief Gets the converted value from data register of injected channel. |
mbed_official | 133:d4dda5c437f0 | 408 | * @param hadc: pointer to a ADC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 409 | * the configuration information for the specified ADC. |
mbed_official | 133:d4dda5c437f0 | 410 | * @param InjectedRank: the ADC injected rank. |
mbed_official | 133:d4dda5c437f0 | 411 | * This parameter can be one of the following values: |
mbed_official | 133:d4dda5c437f0 | 412 | * @arg ADC_InjectedChannel_1: Injected Channel1 selected |
mbed_official | 133:d4dda5c437f0 | 413 | * @arg ADC_InjectedChannel_2: Injected Channel2 selected |
mbed_official | 133:d4dda5c437f0 | 414 | * @arg ADC_InjectedChannel_3: Injected Channel3 selected |
mbed_official | 133:d4dda5c437f0 | 415 | * @arg ADC_InjectedChannel_4: Injected Channel4 selected |
mbed_official | 133:d4dda5c437f0 | 416 | * @retval None |
mbed_official | 133:d4dda5c437f0 | 417 | */ |
mbed_official | 133:d4dda5c437f0 | 418 | uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef* hadc, uint32_t InjectedRank) |
mbed_official | 133:d4dda5c437f0 | 419 | { |
mbed_official | 133:d4dda5c437f0 | 420 | __IO uint32_t tmp = 0; |
mbed_official | 133:d4dda5c437f0 | 421 | |
mbed_official | 133:d4dda5c437f0 | 422 | /* Check the parameters */ |
mbed_official | 133:d4dda5c437f0 | 423 | assert_param(IS_ADC_INJECTED_RANK(InjectedRank)); |
mbed_official | 133:d4dda5c437f0 | 424 | |
mbed_official | 133:d4dda5c437f0 | 425 | /* Clear the ADCx's flag for injected end of conversion */ |
mbed_official | 133:d4dda5c437f0 | 426 | __HAL_ADC_CLEAR_FLAG(hadc,ADC_FLAG_JEOC); |
mbed_official | 133:d4dda5c437f0 | 427 | |
mbed_official | 133:d4dda5c437f0 | 428 | /* Return the selected ADC converted value */ |
mbed_official | 133:d4dda5c437f0 | 429 | switch(InjectedRank) |
mbed_official | 133:d4dda5c437f0 | 430 | { |
mbed_official | 133:d4dda5c437f0 | 431 | case ADC_INJECTED_RANK_4: |
mbed_official | 133:d4dda5c437f0 | 432 | { |
mbed_official | 133:d4dda5c437f0 | 433 | tmp = hadc->Instance->JDR4; |
mbed_official | 133:d4dda5c437f0 | 434 | } |
mbed_official | 133:d4dda5c437f0 | 435 | break; |
mbed_official | 133:d4dda5c437f0 | 436 | case ADC_INJECTED_RANK_3: |
mbed_official | 133:d4dda5c437f0 | 437 | { |
mbed_official | 133:d4dda5c437f0 | 438 | tmp = hadc->Instance->JDR3; |
mbed_official | 133:d4dda5c437f0 | 439 | } |
mbed_official | 133:d4dda5c437f0 | 440 | break; |
mbed_official | 133:d4dda5c437f0 | 441 | case ADC_INJECTED_RANK_2: |
mbed_official | 133:d4dda5c437f0 | 442 | { |
mbed_official | 133:d4dda5c437f0 | 443 | tmp = hadc->Instance->JDR2; |
mbed_official | 133:d4dda5c437f0 | 444 | } |
mbed_official | 133:d4dda5c437f0 | 445 | break; |
mbed_official | 133:d4dda5c437f0 | 446 | case ADC_INJECTED_RANK_1: |
mbed_official | 133:d4dda5c437f0 | 447 | { |
mbed_official | 133:d4dda5c437f0 | 448 | tmp = hadc->Instance->JDR1; |
mbed_official | 133:d4dda5c437f0 | 449 | } |
mbed_official | 133:d4dda5c437f0 | 450 | break; |
mbed_official | 133:d4dda5c437f0 | 451 | default: |
mbed_official | 133:d4dda5c437f0 | 452 | break; |
mbed_official | 133:d4dda5c437f0 | 453 | } |
mbed_official | 133:d4dda5c437f0 | 454 | return tmp; |
mbed_official | 133:d4dda5c437f0 | 455 | } |
mbed_official | 133:d4dda5c437f0 | 456 | |
mbed_official | 133:d4dda5c437f0 | 457 | /** |
mbed_official | 133:d4dda5c437f0 | 458 | * @brief Enables ADC DMA request after last transfer (Multi-ADC mode) and enables ADC peripheral |
mbed_official | 133:d4dda5c437f0 | 459 | * |
mbed_official | 133:d4dda5c437f0 | 460 | * @note Caution: This function must be used only with the ADC master. |
mbed_official | 133:d4dda5c437f0 | 461 | * |
mbed_official | 133:d4dda5c437f0 | 462 | * @param hadc: pointer to a ADC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 463 | * the configuration information for the specified ADC. |
mbed_official | 133:d4dda5c437f0 | 464 | * @param pData: Pointer to buffer in which transferred from ADC peripheral to memory will be stored. |
mbed_official | 133:d4dda5c437f0 | 465 | * @param Length: The length of data to be transferred from ADC peripheral to memory. |
mbed_official | 133:d4dda5c437f0 | 466 | * @retval None |
mbed_official | 133:d4dda5c437f0 | 467 | */ |
mbed_official | 133:d4dda5c437f0 | 468 | HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length) |
mbed_official | 133:d4dda5c437f0 | 469 | { |
mbed_official | 133:d4dda5c437f0 | 470 | uint16_t counter = 0; |
mbed_official | 133:d4dda5c437f0 | 471 | |
mbed_official | 133:d4dda5c437f0 | 472 | /* Check the parameters */ |
mbed_official | 133:d4dda5c437f0 | 473 | assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ContinuousConvMode)); |
mbed_official | 133:d4dda5c437f0 | 474 | assert_param(IS_ADC_EXT_TRIG_EDGE(hadc->Init.ExternalTrigConvEdge)); |
mbed_official | 133:d4dda5c437f0 | 475 | assert_param(IS_FUNCTIONAL_STATE(hadc->Init.DMAContinuousRequests)); |
mbed_official | 133:d4dda5c437f0 | 476 | |
mbed_official | 133:d4dda5c437f0 | 477 | /* Process locked */ |
mbed_official | 133:d4dda5c437f0 | 478 | __HAL_LOCK(hadc); |
mbed_official | 133:d4dda5c437f0 | 479 | |
mbed_official | 133:d4dda5c437f0 | 480 | /* Enable ADC overrun interrupt */ |
mbed_official | 133:d4dda5c437f0 | 481 | __HAL_ADC_ENABLE_IT(hadc, ADC_IT_OVR); |
mbed_official | 133:d4dda5c437f0 | 482 | |
mbed_official | 133:d4dda5c437f0 | 483 | if (hadc->Init.DMAContinuousRequests != DISABLE) |
mbed_official | 133:d4dda5c437f0 | 484 | { |
mbed_official | 133:d4dda5c437f0 | 485 | /* Enable the selected ADC DMA request after last transfer */ |
mbed_official | 133:d4dda5c437f0 | 486 | ADC->CCR |= ADC_CCR_DDS; |
mbed_official | 133:d4dda5c437f0 | 487 | } |
mbed_official | 133:d4dda5c437f0 | 488 | else |
mbed_official | 133:d4dda5c437f0 | 489 | { |
mbed_official | 133:d4dda5c437f0 | 490 | /* Disable the selected ADC EOC rising on each regular channel conversion */ |
mbed_official | 133:d4dda5c437f0 | 491 | ADC->CCR &= ~ADC_CCR_DDS; |
mbed_official | 133:d4dda5c437f0 | 492 | } |
mbed_official | 133:d4dda5c437f0 | 493 | |
mbed_official | 133:d4dda5c437f0 | 494 | /* Set the DMA transfer complete callback */ |
mbed_official | 133:d4dda5c437f0 | 495 | hadc->DMA_Handle->XferCpltCallback = ADC_MultiModeDMAConvCplt; |
mbed_official | 133:d4dda5c437f0 | 496 | |
mbed_official | 133:d4dda5c437f0 | 497 | /* Set the DMA half transfer complete callback */ |
mbed_official | 133:d4dda5c437f0 | 498 | hadc->DMA_Handle->XferHalfCpltCallback = ADC_MultiModeDMAHalfConvCplt; |
mbed_official | 133:d4dda5c437f0 | 499 | |
mbed_official | 133:d4dda5c437f0 | 500 | /* Set the DMA error callback */ |
mbed_official | 133:d4dda5c437f0 | 501 | hadc->DMA_Handle->XferErrorCallback = ADC_MultiModeDMAError ; |
mbed_official | 133:d4dda5c437f0 | 502 | |
mbed_official | 133:d4dda5c437f0 | 503 | /* Enable the DMA Stream */ |
mbed_official | 133:d4dda5c437f0 | 504 | HAL_DMA_Start_IT(hadc->DMA_Handle, (uint32_t)&ADC->CDR, (uint32_t)pData, Length); |
mbed_official | 133:d4dda5c437f0 | 505 | |
mbed_official | 133:d4dda5c437f0 | 506 | /* Change ADC state */ |
mbed_official | 133:d4dda5c437f0 | 507 | hadc->State = HAL_ADC_STATE_BUSY_REG; |
mbed_official | 133:d4dda5c437f0 | 508 | |
mbed_official | 133:d4dda5c437f0 | 509 | /* Check if ADC peripheral is disabled in order to enable it and wait during |
mbed_official | 133:d4dda5c437f0 | 510 | Tstab time the ADC's stabilization */ |
mbed_official | 133:d4dda5c437f0 | 511 | if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON) |
mbed_official | 133:d4dda5c437f0 | 512 | { |
mbed_official | 133:d4dda5c437f0 | 513 | /* Enable the Peripheral */ |
mbed_official | 133:d4dda5c437f0 | 514 | __HAL_ADC_ENABLE(hadc); |
mbed_official | 133:d4dda5c437f0 | 515 | |
mbed_official | 133:d4dda5c437f0 | 516 | /* Delay inserted to wait during Tstab time the ADC's stabilazation */ |
mbed_official | 133:d4dda5c437f0 | 517 | for(; counter <= 540; counter++) |
mbed_official | 133:d4dda5c437f0 | 518 | { |
mbed_official | 133:d4dda5c437f0 | 519 | __NOP(); |
mbed_official | 133:d4dda5c437f0 | 520 | } |
mbed_official | 133:d4dda5c437f0 | 521 | } |
mbed_official | 133:d4dda5c437f0 | 522 | |
mbed_official | 133:d4dda5c437f0 | 523 | /* if no external trigger present enable software conversion of regular channels */ |
mbed_official | 133:d4dda5c437f0 | 524 | if (hadc->Init.ExternalTrigConvEdge == ADC_EXTERNALTRIGCONVEDGE_NONE) |
mbed_official | 133:d4dda5c437f0 | 525 | { |
mbed_official | 133:d4dda5c437f0 | 526 | /* Enable the selected ADC software conversion for regular group */ |
mbed_official | 133:d4dda5c437f0 | 527 | hadc->Instance->CR2 |= (uint32_t)ADC_CR2_SWSTART; |
mbed_official | 133:d4dda5c437f0 | 528 | } |
mbed_official | 133:d4dda5c437f0 | 529 | |
mbed_official | 133:d4dda5c437f0 | 530 | /* Process unlocked */ |
mbed_official | 133:d4dda5c437f0 | 531 | __HAL_UNLOCK(hadc); |
mbed_official | 133:d4dda5c437f0 | 532 | |
mbed_official | 133:d4dda5c437f0 | 533 | /* Return function status */ |
mbed_official | 133:d4dda5c437f0 | 534 | return HAL_OK; |
mbed_official | 133:d4dda5c437f0 | 535 | } |
mbed_official | 133:d4dda5c437f0 | 536 | |
mbed_official | 133:d4dda5c437f0 | 537 | /** |
mbed_official | 133:d4dda5c437f0 | 538 | * @brief Disables ADC DMA (multi-ADC mode) and disables ADC peripheral |
mbed_official | 133:d4dda5c437f0 | 539 | * @param hadc: pointer to a ADC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 540 | * the configuration information for the specified ADC. |
mbed_official | 133:d4dda5c437f0 | 541 | * @retval None |
mbed_official | 133:d4dda5c437f0 | 542 | */ |
mbed_official | 133:d4dda5c437f0 | 543 | HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc) |
mbed_official | 133:d4dda5c437f0 | 544 | { |
mbed_official | 133:d4dda5c437f0 | 545 | /* Process locked */ |
mbed_official | 133:d4dda5c437f0 | 546 | __HAL_LOCK(hadc); |
mbed_official | 133:d4dda5c437f0 | 547 | |
mbed_official | 133:d4dda5c437f0 | 548 | /* Enable the Peripheral */ |
mbed_official | 133:d4dda5c437f0 | 549 | __HAL_ADC_DISABLE(hadc); |
mbed_official | 133:d4dda5c437f0 | 550 | |
mbed_official | 133:d4dda5c437f0 | 551 | /* Disable ADC overrun interrupt */ |
mbed_official | 133:d4dda5c437f0 | 552 | __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR); |
mbed_official | 133:d4dda5c437f0 | 553 | |
mbed_official | 133:d4dda5c437f0 | 554 | /* Disable the selected ADC DMA request after last transfer */ |
mbed_official | 133:d4dda5c437f0 | 555 | ADC->CCR &= ~ADC_CCR_DDS; |
mbed_official | 133:d4dda5c437f0 | 556 | |
mbed_official | 133:d4dda5c437f0 | 557 | /* Disable the ADC DMA Stream */ |
mbed_official | 133:d4dda5c437f0 | 558 | HAL_DMA_Abort(hadc->DMA_Handle); |
mbed_official | 133:d4dda5c437f0 | 559 | |
mbed_official | 133:d4dda5c437f0 | 560 | /* Change ADC state */ |
mbed_official | 133:d4dda5c437f0 | 561 | hadc->State = HAL_ADC_STATE_READY; |
mbed_official | 133:d4dda5c437f0 | 562 | |
mbed_official | 133:d4dda5c437f0 | 563 | /* Process unlocked */ |
mbed_official | 133:d4dda5c437f0 | 564 | __HAL_UNLOCK(hadc); |
mbed_official | 133:d4dda5c437f0 | 565 | |
mbed_official | 133:d4dda5c437f0 | 566 | /* Return function status */ |
mbed_official | 133:d4dda5c437f0 | 567 | return HAL_OK; |
mbed_official | 133:d4dda5c437f0 | 568 | } |
mbed_official | 133:d4dda5c437f0 | 569 | |
mbed_official | 133:d4dda5c437f0 | 570 | /** |
mbed_official | 133:d4dda5c437f0 | 571 | * @brief Returns the last ADC1, ADC2 and ADC3 regular conversions results |
mbed_official | 133:d4dda5c437f0 | 572 | * data in the selected multi mode. |
mbed_official | 133:d4dda5c437f0 | 573 | * @param hadc: pointer to a ADC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 574 | * the configuration information for the specified ADC. |
mbed_official | 133:d4dda5c437f0 | 575 | * @retval The converted data value. |
mbed_official | 133:d4dda5c437f0 | 576 | */ |
mbed_official | 133:d4dda5c437f0 | 577 | uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef* hadc) |
mbed_official | 133:d4dda5c437f0 | 578 | { |
mbed_official | 133:d4dda5c437f0 | 579 | /* Return the multi mode conversion value */ |
mbed_official | 133:d4dda5c437f0 | 580 | return ADC->CDR; |
mbed_official | 133:d4dda5c437f0 | 581 | } |
mbed_official | 133:d4dda5c437f0 | 582 | |
mbed_official | 133:d4dda5c437f0 | 583 | /** |
mbed_official | 133:d4dda5c437f0 | 584 | * @brief Injected conversion complete callback in non blocking mode |
mbed_official | 133:d4dda5c437f0 | 585 | * @param hadc: pointer to a ADC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 586 | * the configuration information for the specified ADC. |
mbed_official | 133:d4dda5c437f0 | 587 | * @retval None |
mbed_official | 133:d4dda5c437f0 | 588 | */ |
mbed_official | 133:d4dda5c437f0 | 589 | __weak void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc) |
mbed_official | 133:d4dda5c437f0 | 590 | { |
mbed_official | 133:d4dda5c437f0 | 591 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 133:d4dda5c437f0 | 592 | the HAL_ADC_InjectedConvCpltCallback could be implemented in the user file |
mbed_official | 133:d4dda5c437f0 | 593 | */ |
mbed_official | 133:d4dda5c437f0 | 594 | } |
mbed_official | 133:d4dda5c437f0 | 595 | |
mbed_official | 133:d4dda5c437f0 | 596 | /** |
mbed_official | 133:d4dda5c437f0 | 597 | * @brief Configures for the selected ADC injected channel its corresponding |
mbed_official | 133:d4dda5c437f0 | 598 | * rank in the sequencer and its sample time. |
mbed_official | 133:d4dda5c437f0 | 599 | * @param hadc: pointer to a ADC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 600 | * the configuration information for the specified ADC. |
mbed_official | 133:d4dda5c437f0 | 601 | * @param sConfigInjected: ADC configuration structure for injected channel. |
mbed_official | 133:d4dda5c437f0 | 602 | * @retval None |
mbed_official | 133:d4dda5c437f0 | 603 | */ |
mbed_official | 133:d4dda5c437f0 | 604 | HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_InjectionConfTypeDef* sConfigInjected) |
mbed_official | 133:d4dda5c437f0 | 605 | { |
mbed_official | 133:d4dda5c437f0 | 606 | |
mbed_official | 133:d4dda5c437f0 | 607 | #ifdef USE_FULL_ASSERT |
mbed_official | 133:d4dda5c437f0 | 608 | uint32_t tmp = 0; |
mbed_official | 133:d4dda5c437f0 | 609 | #endif /* USE_FULL_ASSERT */ |
mbed_official | 133:d4dda5c437f0 | 610 | |
mbed_official | 133:d4dda5c437f0 | 611 | /* Check the parameters */ |
mbed_official | 133:d4dda5c437f0 | 612 | assert_param(IS_ADC_CHANNEL(sConfigInjected->InjectedChannel)); |
mbed_official | 133:d4dda5c437f0 | 613 | assert_param(IS_ADC_INJECTED_RANK(sConfigInjected->InjectedRank)); |
mbed_official | 133:d4dda5c437f0 | 614 | assert_param(IS_ADC_SAMPLE_TIME(sConfigInjected->InjectedSamplingTime)); |
mbed_official | 133:d4dda5c437f0 | 615 | assert_param(IS_ADC_EXT_INJEC_TRIG(sConfigInjected->ExternalTrigInjecConv)); |
mbed_official | 133:d4dda5c437f0 | 616 | assert_param(IS_ADC_EXT_INJEC_TRIG_EDGE(sConfigInjected->ExternalTrigInjecConvEdge)); |
mbed_official | 133:d4dda5c437f0 | 617 | assert_param(IS_ADC_INJECTED_LENGTH(sConfigInjected->InjectedNbrOfConversion)); |
mbed_official | 133:d4dda5c437f0 | 618 | assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->AutoInjectedConv)); |
mbed_official | 133:d4dda5c437f0 | 619 | assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->InjectedDiscontinuousConvMode)); |
mbed_official | 133:d4dda5c437f0 | 620 | |
mbed_official | 133:d4dda5c437f0 | 621 | #ifdef USE_FULL_ASSERT |
mbed_official | 133:d4dda5c437f0 | 622 | tmp = __HAL_ADC_GET_RESOLUTION(hadc); |
mbed_official | 133:d4dda5c437f0 | 623 | assert_param(IS_ADC_RANGE(tmp, sConfigInjected->InjectedOffset)); |
mbed_official | 133:d4dda5c437f0 | 624 | #endif /* USE_FULL_ASSERT */ |
mbed_official | 133:d4dda5c437f0 | 625 | |
mbed_official | 133:d4dda5c437f0 | 626 | /* Process locked */ |
mbed_official | 133:d4dda5c437f0 | 627 | __HAL_LOCK(hadc); |
mbed_official | 133:d4dda5c437f0 | 628 | |
mbed_official | 133:d4dda5c437f0 | 629 | /* if ADC_Channel_10 ... ADC_Channel_18 is selected */ |
mbed_official | 133:d4dda5c437f0 | 630 | if (sConfigInjected->InjectedChannel > ADC_CHANNEL_9) |
mbed_official | 133:d4dda5c437f0 | 631 | { |
mbed_official | 133:d4dda5c437f0 | 632 | /* Clear the old sample time */ |
mbed_official | 133:d4dda5c437f0 | 633 | hadc->Instance->SMPR1 &= ~__HAL_ADC_SMPR1(ADC_SMPR1_SMP10, sConfigInjected->InjectedChannel); |
mbed_official | 133:d4dda5c437f0 | 634 | |
mbed_official | 133:d4dda5c437f0 | 635 | /* Set the new sample time */ |
mbed_official | 133:d4dda5c437f0 | 636 | hadc->Instance->SMPR1 |= __HAL_ADC_SMPR1(sConfigInjected->InjectedSamplingTime, sConfigInjected->InjectedChannel); |
mbed_official | 133:d4dda5c437f0 | 637 | } |
mbed_official | 133:d4dda5c437f0 | 638 | else /* ADC_Channel include in ADC_Channel_[0..9] */ |
mbed_official | 133:d4dda5c437f0 | 639 | { |
mbed_official | 133:d4dda5c437f0 | 640 | /* Clear the old sample time */ |
mbed_official | 133:d4dda5c437f0 | 641 | hadc->Instance->SMPR2 &= ~__HAL_ADC_SMPR2(ADC_SMPR2_SMP0, sConfigInjected->InjectedChannel); |
mbed_official | 133:d4dda5c437f0 | 642 | |
mbed_official | 133:d4dda5c437f0 | 643 | /* Set the new sample time */ |
mbed_official | 133:d4dda5c437f0 | 644 | hadc->Instance->SMPR2 |= __HAL_ADC_SMPR2(sConfigInjected->InjectedSamplingTime, sConfigInjected->InjectedChannel); |
mbed_official | 133:d4dda5c437f0 | 645 | } |
mbed_official | 133:d4dda5c437f0 | 646 | |
mbed_official | 133:d4dda5c437f0 | 647 | /*---------------------------- ADCx JSQR Configuration -----------------*/ |
mbed_official | 133:d4dda5c437f0 | 648 | hadc->Instance->JSQR &= ~(ADC_JSQR_JL); |
mbed_official | 133:d4dda5c437f0 | 649 | hadc->Instance->JSQR |= __HAL_ADC_SQR1(sConfigInjected->InjectedNbrOfConversion); |
mbed_official | 133:d4dda5c437f0 | 650 | |
mbed_official | 133:d4dda5c437f0 | 651 | /* Rank configuration */ |
mbed_official | 133:d4dda5c437f0 | 652 | |
mbed_official | 133:d4dda5c437f0 | 653 | /* Clear the old SQx bits for the selected rank */ |
mbed_official | 133:d4dda5c437f0 | 654 | hadc->Instance->JSQR &= ~__HAL_ADC_JSQR(ADC_JSQR_JSQ1, sConfigInjected->InjectedRank,sConfigInjected->InjectedNbrOfConversion); |
mbed_official | 133:d4dda5c437f0 | 655 | |
mbed_official | 133:d4dda5c437f0 | 656 | /* Set the SQx bits for the selected rank */ |
mbed_official | 133:d4dda5c437f0 | 657 | hadc->Instance->JSQR |= __HAL_ADC_JSQR(sConfigInjected->InjectedChannel, sConfigInjected->InjectedRank,sConfigInjected->InjectedNbrOfConversion); |
mbed_official | 133:d4dda5c437f0 | 658 | |
mbed_official | 133:d4dda5c437f0 | 659 | /* Select external trigger to start conversion */ |
mbed_official | 133:d4dda5c437f0 | 660 | hadc->Instance->CR2 &= ~(ADC_CR2_JEXTSEL); |
mbed_official | 133:d4dda5c437f0 | 661 | hadc->Instance->CR2 |= sConfigInjected->ExternalTrigInjecConv; |
mbed_official | 133:d4dda5c437f0 | 662 | |
mbed_official | 133:d4dda5c437f0 | 663 | /* Select external trigger polarity */ |
mbed_official | 133:d4dda5c437f0 | 664 | hadc->Instance->CR2 &= ~(ADC_CR2_JEXTEN); |
mbed_official | 133:d4dda5c437f0 | 665 | hadc->Instance->CR2 |= sConfigInjected->ExternalTrigInjecConvEdge; |
mbed_official | 133:d4dda5c437f0 | 666 | |
mbed_official | 133:d4dda5c437f0 | 667 | if (sConfigInjected->AutoInjectedConv != DISABLE) |
mbed_official | 133:d4dda5c437f0 | 668 | { |
mbed_official | 133:d4dda5c437f0 | 669 | /* Enable the selected ADC automatic injected group conversion */ |
mbed_official | 133:d4dda5c437f0 | 670 | hadc->Instance->CR1 |= ADC_CR1_JAUTO; |
mbed_official | 133:d4dda5c437f0 | 671 | } |
mbed_official | 133:d4dda5c437f0 | 672 | else |
mbed_official | 133:d4dda5c437f0 | 673 | { |
mbed_official | 133:d4dda5c437f0 | 674 | /* Disable the selected ADC automatic injected group conversion */ |
mbed_official | 133:d4dda5c437f0 | 675 | hadc->Instance->CR1 &= ~(ADC_CR1_JAUTO); |
mbed_official | 133:d4dda5c437f0 | 676 | } |
mbed_official | 133:d4dda5c437f0 | 677 | |
mbed_official | 133:d4dda5c437f0 | 678 | if (sConfigInjected->InjectedDiscontinuousConvMode != DISABLE) |
mbed_official | 133:d4dda5c437f0 | 679 | { |
mbed_official | 133:d4dda5c437f0 | 680 | /* Enable the selected ADC injected discontinuous mode */ |
mbed_official | 133:d4dda5c437f0 | 681 | hadc->Instance->CR1 |= ADC_CR1_JDISCEN; |
mbed_official | 133:d4dda5c437f0 | 682 | } |
mbed_official | 133:d4dda5c437f0 | 683 | else |
mbed_official | 133:d4dda5c437f0 | 684 | { |
mbed_official | 133:d4dda5c437f0 | 685 | /* Disable the selected ADC injected discontinuous mode */ |
mbed_official | 133:d4dda5c437f0 | 686 | hadc->Instance->CR1 &= ~(ADC_CR1_JDISCEN); |
mbed_official | 133:d4dda5c437f0 | 687 | } |
mbed_official | 133:d4dda5c437f0 | 688 | |
mbed_official | 133:d4dda5c437f0 | 689 | switch(sConfigInjected->InjectedRank) |
mbed_official | 133:d4dda5c437f0 | 690 | { |
mbed_official | 133:d4dda5c437f0 | 691 | case 1: |
mbed_official | 133:d4dda5c437f0 | 692 | /* Set injected channel 1 offset */ |
mbed_official | 133:d4dda5c437f0 | 693 | hadc->Instance->JOFR1 &= ~(ADC_JOFR1_JOFFSET1); |
mbed_official | 133:d4dda5c437f0 | 694 | hadc->Instance->JOFR1 |= sConfigInjected->InjectedOffset; |
mbed_official | 133:d4dda5c437f0 | 695 | break; |
mbed_official | 133:d4dda5c437f0 | 696 | case 2: |
mbed_official | 133:d4dda5c437f0 | 697 | /* Set injected channel 2 offset */ |
mbed_official | 133:d4dda5c437f0 | 698 | hadc->Instance->JOFR2 &= ~(ADC_JOFR2_JOFFSET2); |
mbed_official | 133:d4dda5c437f0 | 699 | hadc->Instance->JOFR2 |= sConfigInjected->InjectedOffset; |
mbed_official | 133:d4dda5c437f0 | 700 | break; |
mbed_official | 133:d4dda5c437f0 | 701 | case 3: |
mbed_official | 133:d4dda5c437f0 | 702 | /* Set injected channel 3 offset */ |
mbed_official | 133:d4dda5c437f0 | 703 | hadc->Instance->JOFR3 &= ~(ADC_JOFR3_JOFFSET3); |
mbed_official | 133:d4dda5c437f0 | 704 | hadc->Instance->JOFR3 |= sConfigInjected->InjectedOffset; |
mbed_official | 133:d4dda5c437f0 | 705 | break; |
mbed_official | 133:d4dda5c437f0 | 706 | default: |
mbed_official | 133:d4dda5c437f0 | 707 | /* Set injected channel 4 offset */ |
mbed_official | 133:d4dda5c437f0 | 708 | hadc->Instance->JOFR4 &= ~(ADC_JOFR4_JOFFSET4); |
mbed_official | 133:d4dda5c437f0 | 709 | hadc->Instance->JOFR4 |= sConfigInjected->InjectedOffset; |
mbed_official | 133:d4dda5c437f0 | 710 | break; |
mbed_official | 133:d4dda5c437f0 | 711 | } |
mbed_official | 133:d4dda5c437f0 | 712 | |
mbed_official | 133:d4dda5c437f0 | 713 | /* if ADC1 Channel_18 is selected enable VBAT Channel */ |
mbed_official | 133:d4dda5c437f0 | 714 | if ((hadc->Instance == ADC1) && (sConfigInjected->InjectedChannel == ADC_CHANNEL_VBAT)) |
mbed_official | 133:d4dda5c437f0 | 715 | { |
mbed_official | 133:d4dda5c437f0 | 716 | /* Enable the VBAT channel*/ |
mbed_official | 133:d4dda5c437f0 | 717 | ADC->CCR |= ADC_CCR_VBATE; |
mbed_official | 133:d4dda5c437f0 | 718 | } |
mbed_official | 133:d4dda5c437f0 | 719 | |
mbed_official | 133:d4dda5c437f0 | 720 | /* if ADC1 Channel_16 or Channel_17 is selected enable TSVREFE Channel(Temperature sensor and VREFINT) */ |
mbed_official | 133:d4dda5c437f0 | 721 | if ((hadc->Instance == ADC1) && ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR) || (sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT))) |
mbed_official | 133:d4dda5c437f0 | 722 | { |
mbed_official | 133:d4dda5c437f0 | 723 | /* Enable the TSVREFE channel*/ |
mbed_official | 133:d4dda5c437f0 | 724 | ADC->CCR |= ADC_CCR_TSVREFE; |
mbed_official | 133:d4dda5c437f0 | 725 | } |
mbed_official | 133:d4dda5c437f0 | 726 | |
mbed_official | 133:d4dda5c437f0 | 727 | /* Process unlocked */ |
mbed_official | 133:d4dda5c437f0 | 728 | __HAL_UNLOCK(hadc); |
mbed_official | 133:d4dda5c437f0 | 729 | |
mbed_official | 133:d4dda5c437f0 | 730 | /* Return function status */ |
mbed_official | 133:d4dda5c437f0 | 731 | return HAL_OK; |
mbed_official | 133:d4dda5c437f0 | 732 | } |
mbed_official | 133:d4dda5c437f0 | 733 | |
mbed_official | 133:d4dda5c437f0 | 734 | /** |
mbed_official | 133:d4dda5c437f0 | 735 | * @brief Configures the ADC multi-mode |
mbed_official | 133:d4dda5c437f0 | 736 | * @param hadc : pointer to a ADC_HandleTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 737 | * the configuration information for the specified ADC. |
mbed_official | 133:d4dda5c437f0 | 738 | * @param multimode : pointer to an ADC_MultiModeTypeDef structure that contains |
mbed_official | 133:d4dda5c437f0 | 739 | * the configuration information for multimode. |
mbed_official | 133:d4dda5c437f0 | 740 | * @retval HAL status |
mbed_official | 133:d4dda5c437f0 | 741 | */ |
mbed_official | 133:d4dda5c437f0 | 742 | HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef* hadc, ADC_MultiModeTypeDef* multimode) |
mbed_official | 133:d4dda5c437f0 | 743 | { |
mbed_official | 133:d4dda5c437f0 | 744 | /* Check the parameters */ |
mbed_official | 133:d4dda5c437f0 | 745 | assert_param(IS_ADC_MODE(multimode->Mode)); |
mbed_official | 133:d4dda5c437f0 | 746 | assert_param(IS_ADC_DMA_ACCESS_MODE(multimode->DMAAccessMode)); |
mbed_official | 133:d4dda5c437f0 | 747 | assert_param(IS_ADC_SAMPLING_DELAY(multimode->TwoSamplingDelay)); |
mbed_official | 133:d4dda5c437f0 | 748 | |
mbed_official | 133:d4dda5c437f0 | 749 | /* Process locked */ |
mbed_official | 133:d4dda5c437f0 | 750 | __HAL_LOCK(hadc); |
mbed_official | 133:d4dda5c437f0 | 751 | |
mbed_official | 133:d4dda5c437f0 | 752 | /* Set ADC mode */ |
mbed_official | 133:d4dda5c437f0 | 753 | ADC->CCR &= ~(ADC_CCR_MULTI); |
mbed_official | 133:d4dda5c437f0 | 754 | ADC->CCR |= multimode->Mode; |
mbed_official | 133:d4dda5c437f0 | 755 | |
mbed_official | 133:d4dda5c437f0 | 756 | /* Set the ADC DMA access mode */ |
mbed_official | 133:d4dda5c437f0 | 757 | ADC->CCR &= ~(ADC_CCR_DMA); |
mbed_official | 133:d4dda5c437f0 | 758 | ADC->CCR |= multimode->DMAAccessMode; |
mbed_official | 133:d4dda5c437f0 | 759 | |
mbed_official | 133:d4dda5c437f0 | 760 | /* Set delay between two sampling phases */ |
mbed_official | 133:d4dda5c437f0 | 761 | ADC->CCR &= ~(ADC_CCR_DELAY); |
mbed_official | 133:d4dda5c437f0 | 762 | ADC->CCR |= multimode->TwoSamplingDelay; |
mbed_official | 133:d4dda5c437f0 | 763 | |
mbed_official | 133:d4dda5c437f0 | 764 | /* Process unlocked */ |
mbed_official | 133:d4dda5c437f0 | 765 | __HAL_UNLOCK(hadc); |
mbed_official | 133:d4dda5c437f0 | 766 | |
mbed_official | 133:d4dda5c437f0 | 767 | /* Return function status */ |
mbed_official | 133:d4dda5c437f0 | 768 | return HAL_OK; |
mbed_official | 133:d4dda5c437f0 | 769 | } |
mbed_official | 133:d4dda5c437f0 | 770 | |
mbed_official | 133:d4dda5c437f0 | 771 | /** |
mbed_official | 133:d4dda5c437f0 | 772 | * @} |
mbed_official | 133:d4dda5c437f0 | 773 | */ |
mbed_official | 133:d4dda5c437f0 | 774 | |
mbed_official | 133:d4dda5c437f0 | 775 | /** |
mbed_official | 133:d4dda5c437f0 | 776 | * @brief DMA transfer complete callback. |
mbed_official | 133:d4dda5c437f0 | 777 | * @param hdma: pointer to DMA handle. |
mbed_official | 133:d4dda5c437f0 | 778 | * @retval None |
mbed_official | 133:d4dda5c437f0 | 779 | */ |
mbed_official | 133:d4dda5c437f0 | 780 | static void ADC_MultiModeDMAConvCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 133:d4dda5c437f0 | 781 | { |
mbed_official | 133:d4dda5c437f0 | 782 | ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 133:d4dda5c437f0 | 783 | |
mbed_official | 133:d4dda5c437f0 | 784 | /* Check if an injected conversion is ready */ |
mbed_official | 133:d4dda5c437f0 | 785 | if(hadc->State == HAL_ADC_STATE_EOC_INJ) |
mbed_official | 133:d4dda5c437f0 | 786 | { |
mbed_official | 133:d4dda5c437f0 | 787 | /* Change ADC state */ |
mbed_official | 133:d4dda5c437f0 | 788 | hadc->State = HAL_ADC_STATE_EOC_INJ_REG; |
mbed_official | 133:d4dda5c437f0 | 789 | } |
mbed_official | 133:d4dda5c437f0 | 790 | else |
mbed_official | 133:d4dda5c437f0 | 791 | { |
mbed_official | 133:d4dda5c437f0 | 792 | /* Change ADC state */ |
mbed_official | 133:d4dda5c437f0 | 793 | hadc->State = HAL_ADC_STATE_EOC_REG; |
mbed_official | 133:d4dda5c437f0 | 794 | } |
mbed_official | 133:d4dda5c437f0 | 795 | |
mbed_official | 133:d4dda5c437f0 | 796 | HAL_ADC_ConvCpltCallback(hadc); |
mbed_official | 133:d4dda5c437f0 | 797 | } |
mbed_official | 133:d4dda5c437f0 | 798 | |
mbed_official | 133:d4dda5c437f0 | 799 | /** |
mbed_official | 133:d4dda5c437f0 | 800 | * @brief DMA half transfer complete callback. |
mbed_official | 133:d4dda5c437f0 | 801 | * @param hdma: pointer to DMA handle. |
mbed_official | 133:d4dda5c437f0 | 802 | * @retval None |
mbed_official | 133:d4dda5c437f0 | 803 | */ |
mbed_official | 133:d4dda5c437f0 | 804 | static void ADC_MultiModeDMAHalfConvCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 133:d4dda5c437f0 | 805 | { |
mbed_official | 133:d4dda5c437f0 | 806 | ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 133:d4dda5c437f0 | 807 | /* Conversion complete callback */ |
mbed_official | 133:d4dda5c437f0 | 808 | HAL_ADC_ConvHalfCpltCallback(hadc); |
mbed_official | 133:d4dda5c437f0 | 809 | } |
mbed_official | 133:d4dda5c437f0 | 810 | |
mbed_official | 133:d4dda5c437f0 | 811 | /** |
mbed_official | 133:d4dda5c437f0 | 812 | * @brief DMA error callback |
mbed_official | 133:d4dda5c437f0 | 813 | * @param hdma: pointer to DMA handle. |
mbed_official | 133:d4dda5c437f0 | 814 | * @retval None |
mbed_official | 133:d4dda5c437f0 | 815 | */ |
mbed_official | 133:d4dda5c437f0 | 816 | static void ADC_MultiModeDMAError(DMA_HandleTypeDef *hdma) |
mbed_official | 133:d4dda5c437f0 | 817 | { |
mbed_official | 133:d4dda5c437f0 | 818 | ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 133:d4dda5c437f0 | 819 | hadc->State= HAL_ADC_STATE_ERROR; |
mbed_official | 133:d4dda5c437f0 | 820 | /* Set ADC error code to DMA error */ |
mbed_official | 133:d4dda5c437f0 | 821 | hadc->ErrorCode |= HAL_ADC_ERROR_DMA; |
mbed_official | 133:d4dda5c437f0 | 822 | HAL_ADC_ErrorCallback(hadc); |
mbed_official | 133:d4dda5c437f0 | 823 | } |
mbed_official | 133:d4dda5c437f0 | 824 | |
mbed_official | 133:d4dda5c437f0 | 825 | /** |
mbed_official | 133:d4dda5c437f0 | 826 | * @} |
mbed_official | 133:d4dda5c437f0 | 827 | */ |
mbed_official | 133:d4dda5c437f0 | 828 | |
mbed_official | 133:d4dda5c437f0 | 829 | #endif /* HAL_ADC_MODULE_ENABLED */ |
mbed_official | 133:d4dda5c437f0 | 830 | /** |
mbed_official | 133:d4dda5c437f0 | 831 | * @} |
mbed_official | 133:d4dda5c437f0 | 832 | */ |
mbed_official | 133:d4dda5c437f0 | 833 | |
mbed_official | 133:d4dda5c437f0 | 834 | /** |
mbed_official | 133:d4dda5c437f0 | 835 | * @} |
mbed_official | 133:d4dda5c437f0 | 836 | */ |
mbed_official | 133:d4dda5c437f0 | 837 | |
mbed_official | 133:d4dda5c437f0 | 838 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |