mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F334R8/stm32f3xx_hal_sdadc.c@237:f3da66175598, 2014-06-24 (annotated)
- Committer:
- mbed_official
- Date:
- Tue Jun 24 14:45:08 2014 +0100
- Revision:
- 237:f3da66175598
Synchronized with git revision 8ef659bca81f12dfc896b5a7af7c2abbd1a1b8b7
Full URL: https://github.com/mbedmicro/mbed/commit/8ef659bca81f12dfc896b5a7af7c2abbd1a1b8b7/
[NUCLEO_F334R8] Add platform files
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 237:f3da66175598 | 1 | /** |
mbed_official | 237:f3da66175598 | 2 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 3 | * @file stm32f3xx_hal_sdadc.c |
mbed_official | 237:f3da66175598 | 4 | * @author MCD Application Team |
mbed_official | 237:f3da66175598 | 5 | * @version V1.0.1 |
mbed_official | 237:f3da66175598 | 6 | * @date 18-June-2014 |
mbed_official | 237:f3da66175598 | 7 | * @brief This file provides firmware functions to manage the following |
mbed_official | 237:f3da66175598 | 8 | * functionalities of the Sigma-Delta Analog to Digital Convertor |
mbed_official | 237:f3da66175598 | 9 | * (SDADC) peripherals: |
mbed_official | 237:f3da66175598 | 10 | * + Initialization and Configuration |
mbed_official | 237:f3da66175598 | 11 | * + Regular Channels Configuration |
mbed_official | 237:f3da66175598 | 12 | * + Injected channels Configuration |
mbed_official | 237:f3da66175598 | 13 | * + Power saving |
mbed_official | 237:f3da66175598 | 14 | * + Regular/Injected Channels DMA Configuration |
mbed_official | 237:f3da66175598 | 15 | * + Interrupts and flags management |
mbed_official | 237:f3da66175598 | 16 | * |
mbed_official | 237:f3da66175598 | 17 | @verbatim |
mbed_official | 237:f3da66175598 | 18 | ============================================================================== |
mbed_official | 237:f3da66175598 | 19 | ##### SDADC specific features ##### |
mbed_official | 237:f3da66175598 | 20 | ============================================================================== |
mbed_official | 237:f3da66175598 | 21 | [..] |
mbed_official | 237:f3da66175598 | 22 | (#) 16-bit sigma delta architecture. |
mbed_official | 237:f3da66175598 | 23 | (#) Self calibration. |
mbed_official | 237:f3da66175598 | 24 | (#) Interrupt generation at the end of calibration, regular/injected conversion |
mbed_official | 237:f3da66175598 | 25 | and in case of overrun events. |
mbed_official | 237:f3da66175598 | 26 | (#) Single and continuous conversion modes. |
mbed_official | 237:f3da66175598 | 27 | (#) External trigger option with configurable polarity for injected conversion. |
mbed_official | 237:f3da66175598 | 28 | (#) Multi mode (synchronized another SDADC with SDADC1). |
mbed_official | 237:f3da66175598 | 29 | (#) DMA request generation during regular or injected channel conversion. |
mbed_official | 237:f3da66175598 | 30 | |
mbed_official | 237:f3da66175598 | 31 | ##### How to use this driver ##### |
mbed_official | 237:f3da66175598 | 32 | ============================================================================== |
mbed_official | 237:f3da66175598 | 33 | [..] |
mbed_official | 237:f3da66175598 | 34 | *** Initialization *** |
mbed_official | 237:f3da66175598 | 35 | ====================== |
mbed_official | 237:f3da66175598 | 36 | [..] |
mbed_official | 237:f3da66175598 | 37 | (#) As prerequisite, fill in the HAL_SDADC_MspInit() : |
mbed_official | 237:f3da66175598 | 38 | (+) Enable SDADCx clock interface with __SDADCx_CLK_ENABLE(). |
mbed_official | 237:f3da66175598 | 39 | (+) Configure SDADCx clock divider with HAL_RCCEx_PeriphCLKConfig. |
mbed_official | 237:f3da66175598 | 40 | (+) Enable power on SDADC with HAL_PWREx_EnableSDADCAnalog(). |
mbed_official | 237:f3da66175598 | 41 | (+) Enable the clocks for the SDADC GPIOS with __GPIOx_CLK_ENABLE(). |
mbed_official | 237:f3da66175598 | 42 | (+) Configure these SDADC pins in analog mode using HAL_GPIO_Init(). |
mbed_official | 237:f3da66175598 | 43 | (+) If interrupt mode is used, enable and configure SDADC global |
mbed_official | 237:f3da66175598 | 44 | interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ(). |
mbed_official | 237:f3da66175598 | 45 | (+) If DMA mode is used, configure DMA with HAL_DMA_Init and link it |
mbed_official | 237:f3da66175598 | 46 | with SDADC handle using __HAL_LINKDMA. |
mbed_official | 237:f3da66175598 | 47 | (#) Configure the SDADC low power mode, fast conversion mode, slow clock |
mbed_official | 237:f3da66175598 | 48 | mode and SDADC1 reference voltage using the HAL_ADC_Init() function. |
mbed_official | 237:f3da66175598 | 49 | If multiple SDADC are used, please configure first SDADC1 with the |
mbed_official | 237:f3da66175598 | 50 | common reference voltage. |
mbed_official | 237:f3da66175598 | 51 | (#) Prepare channel configurations (input mode, common mode, gain and |
mbed_official | 237:f3da66175598 | 52 | offset) using HAL_SDADC_PrepareChannelConfig and associate channel |
mbed_official | 237:f3da66175598 | 53 | with one configuration using HAL_SDADC_AssociateChannelConfig. |
mbed_official | 237:f3da66175598 | 54 | |
mbed_official | 237:f3da66175598 | 55 | *** Calibration *** |
mbed_official | 237:f3da66175598 | 56 | ============================================ |
mbed_official | 237:f3da66175598 | 57 | [..] |
mbed_official | 237:f3da66175598 | 58 | (#) Start calibration using HAL_SDADC_StartCalibration or |
mbed_official | 237:f3da66175598 | 59 | HAL_SDADC_CalibrationStart_IT. |
mbed_official | 237:f3da66175598 | 60 | (#) In polling mode, use HAL_SDADC_PollForCalibEvent to detect the end of |
mbed_official | 237:f3da66175598 | 61 | calibration. |
mbed_official | 237:f3da66175598 | 62 | (#) In interrupt mode, HAL_SDADC_CalibrationCpltCallback will be called at |
mbed_official | 237:f3da66175598 | 63 | the end of calibration. |
mbed_official | 237:f3da66175598 | 64 | |
mbed_official | 237:f3da66175598 | 65 | *** Regular channel conversion *** |
mbed_official | 237:f3da66175598 | 66 | ============================================ |
mbed_official | 237:f3da66175598 | 67 | [..] |
mbed_official | 237:f3da66175598 | 68 | (#) Select trigger for regular conversion using |
mbed_official | 237:f3da66175598 | 69 | HAL_SDADC_SelectRegularTrigger. |
mbed_official | 237:f3da66175598 | 70 | (#) Select regular channel and enable/disable continuous mode using |
mbed_official | 237:f3da66175598 | 71 | HAL_SDADC_ConfigChannel. |
mbed_official | 237:f3da66175598 | 72 | (#) Start regular conversion using HAL_SDADC_Start, HAL_SDADC_Start_IT |
mbed_official | 237:f3da66175598 | 73 | or HAL_SDADC_Start_DMA. |
mbed_official | 237:f3da66175598 | 74 | (#) In polling mode, use HAL_SDADC_PollForConversion to detect the end of |
mbed_official | 237:f3da66175598 | 75 | regular conversion. |
mbed_official | 237:f3da66175598 | 76 | (#) In interrupt mode, HAL_SDADC_ConvCpltCallback will be called at the |
mbed_official | 237:f3da66175598 | 77 | end of regular conversion. |
mbed_official | 237:f3da66175598 | 78 | (#) Get value of regular conversion using HAL_SDADC_GetValue. |
mbed_official | 237:f3da66175598 | 79 | (#) In DMA mode, HAL_SDADC_ConvHalfCpltCallback and |
mbed_official | 237:f3da66175598 | 80 | HAL_SDADC_ConvCpltCallback will be called respectively at the half |
mbed_official | 237:f3da66175598 | 81 | tranfer and at the tranfer complete. |
mbed_official | 237:f3da66175598 | 82 | (#) Stop regular conversion using HAL_SDADC_Stop, HAL_SDADC_Stop_IT |
mbed_official | 237:f3da66175598 | 83 | or HAL_SDADC_Stop_DMA. |
mbed_official | 237:f3da66175598 | 84 | |
mbed_official | 237:f3da66175598 | 85 | *** Injected channels conversion *** |
mbed_official | 237:f3da66175598 | 86 | ============================================ |
mbed_official | 237:f3da66175598 | 87 | [..] |
mbed_official | 237:f3da66175598 | 88 | (#) Enable/disable delay on injected conversion using |
mbed_official | 237:f3da66175598 | 89 | HAL_SDADC_SelectInjectedDelay. |
mbed_official | 237:f3da66175598 | 90 | (#) If external trigger is used for injected conversion, configure this |
mbed_official | 237:f3da66175598 | 91 | trigger using HAL_SDADC_SelectInjectedExtTrigger. |
mbed_official | 237:f3da66175598 | 92 | (#) Select trigger for injected conversion using |
mbed_official | 237:f3da66175598 | 93 | HAL_SDADC_SelectInjectedTrigger. |
mbed_official | 237:f3da66175598 | 94 | (#) Select injected channels and enable/disable continuous mode using |
mbed_official | 237:f3da66175598 | 95 | HAL_SDADC_InjectedConfigChannel. |
mbed_official | 237:f3da66175598 | 96 | (#) Start injected conversion using HAL_SDADC_InjectedStart, |
mbed_official | 237:f3da66175598 | 97 | HAL_SDADC_InjectedStart_IT or HAL_SDADC_InjectedStart_DMA. |
mbed_official | 237:f3da66175598 | 98 | (#) In polling mode, use HAL_SDADC_PollForInjectedConversion to detect the |
mbed_official | 237:f3da66175598 | 99 | end of injected conversion. |
mbed_official | 237:f3da66175598 | 100 | (#) In interrupt mode, HAL_SDADC_InjectedConvCpltCallback will be called |
mbed_official | 237:f3da66175598 | 101 | at the end of injected conversion. |
mbed_official | 237:f3da66175598 | 102 | (#) Get value of injected conversion and corresponding channel using |
mbed_official | 237:f3da66175598 | 103 | HAL_SDADC_InjectedGetValue. |
mbed_official | 237:f3da66175598 | 104 | (#) In DMA mode, HAL_SDADC_InjectedConvHalfCpltCallback and |
mbed_official | 237:f3da66175598 | 105 | HAL_SDADC_InjectedConvCpltCallback will be called respectively at the |
mbed_official | 237:f3da66175598 | 106 | half tranfer and at the tranfer complete. |
mbed_official | 237:f3da66175598 | 107 | (#) Stop injected conversion using HAL_SDADC_InjectedStop, |
mbed_official | 237:f3da66175598 | 108 | HAL_SDADC_InjectedStop_IT or HAL_SDADC_InjectedStop_DMA. |
mbed_official | 237:f3da66175598 | 109 | |
mbed_official | 237:f3da66175598 | 110 | *** Multi mode regular channels conversions *** |
mbed_official | 237:f3da66175598 | 111 | ====================================================== |
mbed_official | 237:f3da66175598 | 112 | [..] |
mbed_official | 237:f3da66175598 | 113 | (#) Select type of multimode (SDADC1/SDADC2 or SDADC1/SDADC3) using |
mbed_official | 237:f3da66175598 | 114 | HAL_SDADC_MultiModeConfigChannel. |
mbed_official | 237:f3da66175598 | 115 | (#) Select software trigger for SDADC1 and synchronized trigger for |
mbed_official | 237:f3da66175598 | 116 | SDADC2 (or SDADC3) using HAL_SDADC_SelectRegularTrigger. |
mbed_official | 237:f3da66175598 | 117 | (#) Select regular channel for SDADC1 and SDADC2 (or SDADC3) using |
mbed_official | 237:f3da66175598 | 118 | HAL_SDADC_ConfigChannel. |
mbed_official | 237:f3da66175598 | 119 | (#) Start regular conversion for SDADC2 (or SDADC3) with HAL_SDADC_Start. |
mbed_official | 237:f3da66175598 | 120 | (#) Start regular conversion for SDADC1 using HAL_SDADC_Start, |
mbed_official | 237:f3da66175598 | 121 | HAL_SDADC_Start_IT or HAL_SDADC_MultiModeStart_DMA. |
mbed_official | 237:f3da66175598 | 122 | (#) In polling mode, use HAL_SDADC_PollForConversion to detect the end of |
mbed_official | 237:f3da66175598 | 123 | regular conversion for SDADC1. |
mbed_official | 237:f3da66175598 | 124 | (#) In interrupt mode, HAL_SDADC_ConvCpltCallback will be called at the |
mbed_official | 237:f3da66175598 | 125 | end of regular conversion for SDADC1. |
mbed_official | 237:f3da66175598 | 126 | (#) Get value of regular conversions using HAL_SDADC_MultiModeGetValue. |
mbed_official | 237:f3da66175598 | 127 | (#) In DMA mode, HAL_SDADC_ConvHalfCpltCallback and |
mbed_official | 237:f3da66175598 | 128 | HAL_SDADC_ConvCpltCallback will be called respectively at the half |
mbed_official | 237:f3da66175598 | 129 | tranfer and at the tranfer complete for SDADC1. |
mbed_official | 237:f3da66175598 | 130 | (#) Stop regular conversion using HAL_SDADC_Stop, HAL_SDADC_Stop_IT |
mbed_official | 237:f3da66175598 | 131 | or HAL_SDADC_MultiModeStop_DMA for SDADC1. |
mbed_official | 237:f3da66175598 | 132 | (#) Stop regular conversion using HAL_SDADC_Stop for SDADC2 (or SDADC3). |
mbed_official | 237:f3da66175598 | 133 | |
mbed_official | 237:f3da66175598 | 134 | *** Multi mode injected channels conversions *** |
mbed_official | 237:f3da66175598 | 135 | ====================================================== |
mbed_official | 237:f3da66175598 | 136 | [..] |
mbed_official | 237:f3da66175598 | 137 | (#) Select type of multimode (SDADC1/SDADC2 or SDADC1/SDADC3) using |
mbed_official | 237:f3da66175598 | 138 | HAL_SDADC_InjectedMultiModeConfigChannel. |
mbed_official | 237:f3da66175598 | 139 | (#) Select software or external trigger for SDADC1 and synchronized |
mbed_official | 237:f3da66175598 | 140 | trigger for SDADC2 (or SDADC3) using HAL_SDADC_SelectInjectedTrigger. |
mbed_official | 237:f3da66175598 | 141 | (#) Select injected channels for SDADC1 and SDADC2 (or SDADC3) using |
mbed_official | 237:f3da66175598 | 142 | HAL_SDADC_InjectedConfigChannel. |
mbed_official | 237:f3da66175598 | 143 | (#) Start injected conversion for SDADC2 (or SDADC3) with |
mbed_official | 237:f3da66175598 | 144 | HAL_SDADC_InjectedStart. |
mbed_official | 237:f3da66175598 | 145 | (#) Start injected conversion for SDADC1 using HAL_SDADC_InjectedStart, |
mbed_official | 237:f3da66175598 | 146 | HAL_SDADC_InjectedStart_IT or HAL_SDADC_InjectedMultiModeStart_DMA. |
mbed_official | 237:f3da66175598 | 147 | (#) In polling mode, use HAL_SDADC_InjectedPollForConversion to detect |
mbed_official | 237:f3da66175598 | 148 | the end of injected conversion for SDADC1. |
mbed_official | 237:f3da66175598 | 149 | (#) In interrupt mode, HAL_SDADC_InjectedConvCpltCallback will be called |
mbed_official | 237:f3da66175598 | 150 | at the end of injected conversion for SDADC1. |
mbed_official | 237:f3da66175598 | 151 | (#) Get value of injected conversions using |
mbed_official | 237:f3da66175598 | 152 | HAL_SDADC_InjectedMultiModeGetValue. |
mbed_official | 237:f3da66175598 | 153 | (#) In DMA mode, HAL_SDADC_InjectedConvHalfCpltCallback and |
mbed_official | 237:f3da66175598 | 154 | HAL_SDADC_InjectedConvCpltCallback will be called respectively at the |
mbed_official | 237:f3da66175598 | 155 | half tranfer and at the tranfer complete for SDADC1. |
mbed_official | 237:f3da66175598 | 156 | (#) Stop injected conversion using HAL_SDADC_InjectedStop, |
mbed_official | 237:f3da66175598 | 157 | HAL_SDADC_InjectedStop_IT or HAL_SDADC_InjecteddMultiModeStop_DMA |
mbed_official | 237:f3da66175598 | 158 | for SDADC1. |
mbed_official | 237:f3da66175598 | 159 | (#) Stop injected conversion using HAL_SDADC_InjectedStop for SDADC2 |
mbed_official | 237:f3da66175598 | 160 | (or SDADC3). |
mbed_official | 237:f3da66175598 | 161 | |
mbed_official | 237:f3da66175598 | 162 | @endverbatim |
mbed_official | 237:f3da66175598 | 163 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 164 | * @attention |
mbed_official | 237:f3da66175598 | 165 | * |
mbed_official | 237:f3da66175598 | 166 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 237:f3da66175598 | 167 | * |
mbed_official | 237:f3da66175598 | 168 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 237:f3da66175598 | 169 | * are permitted provided that the following conditions are met: |
mbed_official | 237:f3da66175598 | 170 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 237:f3da66175598 | 171 | * this list of conditions and the following disclaimer. |
mbed_official | 237:f3da66175598 | 172 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 237:f3da66175598 | 173 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 237:f3da66175598 | 174 | * and/or other materials provided with the distribution. |
mbed_official | 237:f3da66175598 | 175 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 237:f3da66175598 | 176 | * may be used to endorse or promote products derived from this software |
mbed_official | 237:f3da66175598 | 177 | * without specific prior written permission. |
mbed_official | 237:f3da66175598 | 178 | * |
mbed_official | 237:f3da66175598 | 179 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 237:f3da66175598 | 180 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 237:f3da66175598 | 181 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 237:f3da66175598 | 182 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 237:f3da66175598 | 183 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 237:f3da66175598 | 184 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 237:f3da66175598 | 185 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 237:f3da66175598 | 186 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 237:f3da66175598 | 187 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 237:f3da66175598 | 188 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 237:f3da66175598 | 189 | * |
mbed_official | 237:f3da66175598 | 190 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 191 | */ |
mbed_official | 237:f3da66175598 | 192 | |
mbed_official | 237:f3da66175598 | 193 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 194 | #include "stm32f3xx_hal.h" |
mbed_official | 237:f3da66175598 | 195 | |
mbed_official | 237:f3da66175598 | 196 | /** @addtogroup STM32F3xx_HAL_Driver |
mbed_official | 237:f3da66175598 | 197 | * @{ |
mbed_official | 237:f3da66175598 | 198 | */ |
mbed_official | 237:f3da66175598 | 199 | |
mbed_official | 237:f3da66175598 | 200 | /** @defgroup SDADC |
mbed_official | 237:f3da66175598 | 201 | * @brief SDADC driver modules |
mbed_official | 237:f3da66175598 | 202 | * @{ |
mbed_official | 237:f3da66175598 | 203 | */ |
mbed_official | 237:f3da66175598 | 204 | |
mbed_official | 237:f3da66175598 | 205 | #ifdef HAL_SDADC_MODULE_ENABLED |
mbed_official | 237:f3da66175598 | 206 | #if defined(STM32F373xC) || defined(STM32F378xx) |
mbed_official | 237:f3da66175598 | 207 | |
mbed_official | 237:f3da66175598 | 208 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 209 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 210 | #define SDADC_TIMEOUT 200 |
mbed_official | 237:f3da66175598 | 211 | #define SDADC_CONFREG_OFFSET 0x00000020 |
mbed_official | 237:f3da66175598 | 212 | #define SDADC_JDATAR_CH_OFFSET 24 |
mbed_official | 237:f3da66175598 | 213 | #define SDADC_MSB_MASK 0xFFFF0000 |
mbed_official | 237:f3da66175598 | 214 | #define SDADC_LSB_MASK 0x0000FFFF |
mbed_official | 237:f3da66175598 | 215 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 216 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 217 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 218 | static HAL_StatusTypeDef SDADC_EnterInitMode(SDADC_HandleTypeDef* hsdadc); |
mbed_official | 237:f3da66175598 | 219 | static void SDADC_ExitInitMode(SDADC_HandleTypeDef* hsdadc); |
mbed_official | 237:f3da66175598 | 220 | static uint32_t SDADC_GetInjChannelsNbr(uint32_t Channels); |
mbed_official | 237:f3da66175598 | 221 | static HAL_StatusTypeDef SDADC_RegConvStart(SDADC_HandleTypeDef* hsdadc); |
mbed_official | 237:f3da66175598 | 222 | static HAL_StatusTypeDef SDADC_RegConvStop(SDADC_HandleTypeDef* hsdadc); |
mbed_official | 237:f3da66175598 | 223 | static HAL_StatusTypeDef SDADC_InjConvStart(SDADC_HandleTypeDef* hsdadc); |
mbed_official | 237:f3da66175598 | 224 | static HAL_StatusTypeDef SDADC_InjConvStop(SDADC_HandleTypeDef* hsdadc); |
mbed_official | 237:f3da66175598 | 225 | static void SDADC_DMARegularHalfConvCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 237:f3da66175598 | 226 | static void SDADC_DMARegularConvCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 237:f3da66175598 | 227 | static void SDADC_DMAInjectedHalfConvCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 237:f3da66175598 | 228 | static void SDADC_DMAInjectedConvCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 237:f3da66175598 | 229 | static void SDADC_DMAError(DMA_HandleTypeDef *hdma); |
mbed_official | 237:f3da66175598 | 230 | |
mbed_official | 237:f3da66175598 | 231 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 232 | |
mbed_official | 237:f3da66175598 | 233 | /** @defgroup SDADC_Private_Functions |
mbed_official | 237:f3da66175598 | 234 | * @{ |
mbed_official | 237:f3da66175598 | 235 | */ |
mbed_official | 237:f3da66175598 | 236 | |
mbed_official | 237:f3da66175598 | 237 | /** @defgroup SDADC_Group1 Initialization/de-initialization functions |
mbed_official | 237:f3da66175598 | 238 | * @brief Initialization and de-initialization functions |
mbed_official | 237:f3da66175598 | 239 | * |
mbed_official | 237:f3da66175598 | 240 | @verbatim |
mbed_official | 237:f3da66175598 | 241 | =============================================================================== |
mbed_official | 237:f3da66175598 | 242 | ##### Initialization and de-initialization functions ##### |
mbed_official | 237:f3da66175598 | 243 | =============================================================================== |
mbed_official | 237:f3da66175598 | 244 | [..] This section provides functions allowing to: |
mbed_official | 237:f3da66175598 | 245 | (+) Initialize the SDADC. |
mbed_official | 237:f3da66175598 | 246 | (+) De-initialize the SDADC. |
mbed_official | 237:f3da66175598 | 247 | |
mbed_official | 237:f3da66175598 | 248 | @endverbatim |
mbed_official | 237:f3da66175598 | 249 | * @{ |
mbed_official | 237:f3da66175598 | 250 | */ |
mbed_official | 237:f3da66175598 | 251 | |
mbed_official | 237:f3da66175598 | 252 | /** |
mbed_official | 237:f3da66175598 | 253 | * @brief Initializes the SDADC according to the specified |
mbed_official | 237:f3da66175598 | 254 | * parameters in the SDADC_InitTypeDef structure. |
mbed_official | 237:f3da66175598 | 255 | * @note If multiple SDADC are used, please configure first SDADC1 to set |
mbed_official | 237:f3da66175598 | 256 | * the common reference voltage. |
mbed_official | 237:f3da66175598 | 257 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 258 | * @retval HAL status. |
mbed_official | 237:f3da66175598 | 259 | */ |
mbed_official | 237:f3da66175598 | 260 | HAL_StatusTypeDef HAL_SDADC_Init(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 261 | { |
mbed_official | 237:f3da66175598 | 262 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 263 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 264 | assert_param(IS_SDADC_LOWPOWER_MODE(hsdadc->Init.IdleLowPowerMode)); |
mbed_official | 237:f3da66175598 | 265 | assert_param(IS_SDADC_FAST_CONV_MODE(hsdadc->Init.FastConversionMode)); |
mbed_official | 237:f3da66175598 | 266 | assert_param(IS_SDADC_SLOW_CLOCK_MODE(hsdadc->Init.SlowClockMode)); |
mbed_official | 237:f3da66175598 | 267 | assert_param(IS_SDADC_VREF(hsdadc->Init.ReferenceVoltage)); |
mbed_official | 237:f3da66175598 | 268 | |
mbed_official | 237:f3da66175598 | 269 | /* Check SDADC handle */ |
mbed_official | 237:f3da66175598 | 270 | if(hsdadc == NULL) |
mbed_official | 237:f3da66175598 | 271 | { |
mbed_official | 237:f3da66175598 | 272 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 273 | } |
mbed_official | 237:f3da66175598 | 274 | |
mbed_official | 237:f3da66175598 | 275 | /* Initialize SDADC variables with default values */ |
mbed_official | 237:f3da66175598 | 276 | hsdadc->RegularContMode = SDADC_CONTINUOUS_CONV_OFF; |
mbed_official | 237:f3da66175598 | 277 | hsdadc->InjectedContMode = SDADC_CONTINUOUS_CONV_OFF; |
mbed_official | 237:f3da66175598 | 278 | hsdadc->InjectedChannelsNbr = 1; |
mbed_official | 237:f3da66175598 | 279 | hsdadc->InjConvRemaining = 1; |
mbed_official | 237:f3da66175598 | 280 | hsdadc->RegularTrigger = SDADC_SOFTWARE_TRIGGER; |
mbed_official | 237:f3da66175598 | 281 | hsdadc->InjectedTrigger = SDADC_SOFTWARE_TRIGGER; |
mbed_official | 237:f3da66175598 | 282 | hsdadc->ExtTriggerEdge = SDADC_EXT_TRIG_RISING_EDGE; |
mbed_official | 237:f3da66175598 | 283 | hsdadc->RegularMultimode = SDADC_MULTIMODE_SDADC1_SDADC2; |
mbed_official | 237:f3da66175598 | 284 | hsdadc->InjectedMultimode = SDADC_MULTIMODE_SDADC1_SDADC2; |
mbed_official | 237:f3da66175598 | 285 | hsdadc->ErrorCode = SDADC_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 286 | |
mbed_official | 237:f3da66175598 | 287 | /* Call MSP init function */ |
mbed_official | 237:f3da66175598 | 288 | HAL_SDADC_MspInit(hsdadc); |
mbed_official | 237:f3da66175598 | 289 | |
mbed_official | 237:f3da66175598 | 290 | /* Set idle low power and slow clock modes */ |
mbed_official | 237:f3da66175598 | 291 | hsdadc->Instance->CR1 &= ~(SDADC_CR1_SBI|SDADC_CR1_PDI|SDADC_CR1_SLOWCK); |
mbed_official | 237:f3da66175598 | 292 | hsdadc->Instance->CR1 |= (hsdadc->Init.IdleLowPowerMode | \ |
mbed_official | 237:f3da66175598 | 293 | hsdadc->Init.SlowClockMode); |
mbed_official | 237:f3da66175598 | 294 | |
mbed_official | 237:f3da66175598 | 295 | /* Set fast conversion mode */ |
mbed_official | 237:f3da66175598 | 296 | hsdadc->Instance->CR2 &= ~(SDADC_CR2_FAST); |
mbed_official | 237:f3da66175598 | 297 | hsdadc->Instance->CR2 |= hsdadc->Init.FastConversionMode; |
mbed_official | 237:f3da66175598 | 298 | |
mbed_official | 237:f3da66175598 | 299 | /* Set reference voltage only for SDADC1 */ |
mbed_official | 237:f3da66175598 | 300 | if(hsdadc->Instance == SDADC1) |
mbed_official | 237:f3da66175598 | 301 | { |
mbed_official | 237:f3da66175598 | 302 | hsdadc->Instance->CR1 &= ~(SDADC_CR1_REFV); |
mbed_official | 237:f3da66175598 | 303 | hsdadc->Instance->CR1 |= hsdadc->Init.ReferenceVoltage; |
mbed_official | 237:f3da66175598 | 304 | |
mbed_official | 237:f3da66175598 | 305 | /* Wait at least 2ms before setting ADON */ |
mbed_official | 237:f3da66175598 | 306 | HAL_Delay(2); |
mbed_official | 237:f3da66175598 | 307 | } |
mbed_official | 237:f3da66175598 | 308 | |
mbed_official | 237:f3da66175598 | 309 | /* Enable SDADC */ |
mbed_official | 237:f3da66175598 | 310 | hsdadc->Instance->CR2 |= SDADC_CR2_ADON; |
mbed_official | 237:f3da66175598 | 311 | |
mbed_official | 237:f3da66175598 | 312 | /* Wait end of stabilization */ |
mbed_official | 237:f3da66175598 | 313 | while((hsdadc->Instance->ISR & SDADC_ISR_STABIP) != 0); |
mbed_official | 237:f3da66175598 | 314 | |
mbed_official | 237:f3da66175598 | 315 | /* Set SDADC to ready state */ |
mbed_official | 237:f3da66175598 | 316 | hsdadc->State = HAL_SDADC_STATE_READY; |
mbed_official | 237:f3da66175598 | 317 | |
mbed_official | 237:f3da66175598 | 318 | /* Return HAL status */ |
mbed_official | 237:f3da66175598 | 319 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 320 | } |
mbed_official | 237:f3da66175598 | 321 | |
mbed_official | 237:f3da66175598 | 322 | /** |
mbed_official | 237:f3da66175598 | 323 | * @brief De-initializes the SDADC. |
mbed_official | 237:f3da66175598 | 324 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 325 | * @retval HAL status. |
mbed_official | 237:f3da66175598 | 326 | */ |
mbed_official | 237:f3da66175598 | 327 | HAL_StatusTypeDef HAL_SDADC_DeInit(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 328 | { |
mbed_official | 237:f3da66175598 | 329 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 330 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 331 | |
mbed_official | 237:f3da66175598 | 332 | /* Check SDADC handle */ |
mbed_official | 237:f3da66175598 | 333 | if(hsdadc == NULL) |
mbed_official | 237:f3da66175598 | 334 | { |
mbed_official | 237:f3da66175598 | 335 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 336 | } |
mbed_official | 237:f3da66175598 | 337 | |
mbed_official | 237:f3da66175598 | 338 | /* Disable the SDADC */ |
mbed_official | 237:f3da66175598 | 339 | hsdadc->Instance->CR2 &= ~(SDADC_CR2_ADON); |
mbed_official | 237:f3da66175598 | 340 | |
mbed_official | 237:f3da66175598 | 341 | /* Reset all registers */ |
mbed_official | 237:f3da66175598 | 342 | hsdadc->Instance->CR1 = 0x00000000; |
mbed_official | 237:f3da66175598 | 343 | hsdadc->Instance->CR2 = 0x00000000; |
mbed_official | 237:f3da66175598 | 344 | hsdadc->Instance->JCHGR = 0x00000001; |
mbed_official | 237:f3da66175598 | 345 | hsdadc->Instance->CONF0R = 0x00000000; |
mbed_official | 237:f3da66175598 | 346 | hsdadc->Instance->CONF1R = 0x00000000; |
mbed_official | 237:f3da66175598 | 347 | hsdadc->Instance->CONF2R = 0x00000000; |
mbed_official | 237:f3da66175598 | 348 | hsdadc->Instance->CONFCHR1 = 0x00000000; |
mbed_official | 237:f3da66175598 | 349 | hsdadc->Instance->CONFCHR2 = 0x00000000; |
mbed_official | 237:f3da66175598 | 350 | |
mbed_official | 237:f3da66175598 | 351 | /* Call MSP deinit function */ |
mbed_official | 237:f3da66175598 | 352 | HAL_SDADC_MspDeInit(hsdadc); |
mbed_official | 237:f3da66175598 | 353 | |
mbed_official | 237:f3da66175598 | 354 | /* Set SDADC in reset state */ |
mbed_official | 237:f3da66175598 | 355 | hsdadc->State = HAL_SDADC_STATE_RESET; |
mbed_official | 237:f3da66175598 | 356 | |
mbed_official | 237:f3da66175598 | 357 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 358 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 359 | } |
mbed_official | 237:f3da66175598 | 360 | |
mbed_official | 237:f3da66175598 | 361 | /** |
mbed_official | 237:f3da66175598 | 362 | * @brief Initializes the SDADC MSP. |
mbed_official | 237:f3da66175598 | 363 | * @param hsdadc : SDADC handle |
mbed_official | 237:f3da66175598 | 364 | * @retval None |
mbed_official | 237:f3da66175598 | 365 | */ |
mbed_official | 237:f3da66175598 | 366 | __weak void HAL_SDADC_MspInit(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 367 | { |
mbed_official | 237:f3da66175598 | 368 | /* NOTE : This function should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 369 | the HAL_SDADC_MspInit could be implemented in the user file. |
mbed_official | 237:f3da66175598 | 370 | */ |
mbed_official | 237:f3da66175598 | 371 | } |
mbed_official | 237:f3da66175598 | 372 | |
mbed_official | 237:f3da66175598 | 373 | /** |
mbed_official | 237:f3da66175598 | 374 | * @brief De-initializes the SDADC MSP. |
mbed_official | 237:f3da66175598 | 375 | * @param hsdadc : SDADC handle |
mbed_official | 237:f3da66175598 | 376 | * @retval None |
mbed_official | 237:f3da66175598 | 377 | */ |
mbed_official | 237:f3da66175598 | 378 | __weak void HAL_SDADC_MspDeInit(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 379 | { |
mbed_official | 237:f3da66175598 | 380 | /* NOTE : This function should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 381 | the HAL_SDADC_MspDeInit could be implemented in the user file. |
mbed_official | 237:f3da66175598 | 382 | */ |
mbed_official | 237:f3da66175598 | 383 | } |
mbed_official | 237:f3da66175598 | 384 | |
mbed_official | 237:f3da66175598 | 385 | /** |
mbed_official | 237:f3da66175598 | 386 | * @} |
mbed_official | 237:f3da66175598 | 387 | */ |
mbed_official | 237:f3da66175598 | 388 | |
mbed_official | 237:f3da66175598 | 389 | /** @defgroup SDADC_Group2 peripheral control functions |
mbed_official | 237:f3da66175598 | 390 | * @brief Peripheral control functions |
mbed_official | 237:f3da66175598 | 391 | * |
mbed_official | 237:f3da66175598 | 392 | @verbatim |
mbed_official | 237:f3da66175598 | 393 | =============================================================================== |
mbed_official | 237:f3da66175598 | 394 | ##### Peripheral control functions ##### |
mbed_official | 237:f3da66175598 | 395 | =============================================================================== |
mbed_official | 237:f3da66175598 | 396 | [..] This section provides functions allowing to: |
mbed_official | 237:f3da66175598 | 397 | (+) Program on of the three different configurations for channels. |
mbed_official | 237:f3da66175598 | 398 | (+) Associate channel to one of configurations. |
mbed_official | 237:f3da66175598 | 399 | (+) Select regular and injected channels. |
mbed_official | 237:f3da66175598 | 400 | (+) Enable/disable continuous mode for regular and injected conversions. |
mbed_official | 237:f3da66175598 | 401 | (+) Select regular and injected triggers. |
mbed_official | 237:f3da66175598 | 402 | (+) Select and configure injected external trigger. |
mbed_official | 237:f3da66175598 | 403 | (+) Enable/disable delay addition for injected conversions. |
mbed_official | 237:f3da66175598 | 404 | (+) Configure multimode. |
mbed_official | 237:f3da66175598 | 405 | |
mbed_official | 237:f3da66175598 | 406 | @endverbatim |
mbed_official | 237:f3da66175598 | 407 | * @{ |
mbed_official | 237:f3da66175598 | 408 | */ |
mbed_official | 237:f3da66175598 | 409 | |
mbed_official | 237:f3da66175598 | 410 | /** |
mbed_official | 237:f3da66175598 | 411 | * @brief This function allows the user to set parameters for a configuration. |
mbed_official | 237:f3da66175598 | 412 | * Parameters are input mode, common mode, gain and offset. |
mbed_official | 237:f3da66175598 | 413 | * @note This function should be called only when SDADC instance is in idle state |
mbed_official | 237:f3da66175598 | 414 | * (neither calibration nor regular or injected conversion ongoing) |
mbed_official | 237:f3da66175598 | 415 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 416 | * @param ConfIndex : Index of configuration to modify. |
mbed_official | 237:f3da66175598 | 417 | * This parameter can be a value of @ref SDADC_ConfIndex. |
mbed_official | 237:f3da66175598 | 418 | * @param ConfParamStruct : Parameters to apply for this configuration. |
mbed_official | 237:f3da66175598 | 419 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 420 | */ |
mbed_official | 237:f3da66175598 | 421 | HAL_StatusTypeDef HAL_SDADC_PrepareChannelConfig(SDADC_HandleTypeDef *hsdadc, |
mbed_official | 237:f3da66175598 | 422 | uint32_t ConfIndex, |
mbed_official | 237:f3da66175598 | 423 | SDADC_ConfParamTypeDef* ConfParamStruct) |
mbed_official | 237:f3da66175598 | 424 | { |
mbed_official | 237:f3da66175598 | 425 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 426 | uint32_t tmp = 0; |
mbed_official | 237:f3da66175598 | 427 | |
mbed_official | 237:f3da66175598 | 428 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 429 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 430 | assert_param(IS_SDADC_CONF_INDEX(ConfIndex)); |
mbed_official | 237:f3da66175598 | 431 | assert_param(ConfParamStruct != NULL); |
mbed_official | 237:f3da66175598 | 432 | assert_param(IS_SDADC_INPUT_MODE(ConfParamStruct->InputMode)); |
mbed_official | 237:f3da66175598 | 433 | assert_param(IS_SDADC_GAIN(ConfParamStruct->Gain)); |
mbed_official | 237:f3da66175598 | 434 | assert_param(IS_SDADC_COMMON_MODE(ConfParamStruct->CommonMode)); |
mbed_official | 237:f3da66175598 | 435 | assert_param(IS_SDADC_OFFSET_VALUE(ConfParamStruct->Offset)); |
mbed_official | 237:f3da66175598 | 436 | |
mbed_official | 237:f3da66175598 | 437 | /* Check SDADC state is ready */ |
mbed_official | 237:f3da66175598 | 438 | if(hsdadc->State != HAL_SDADC_STATE_READY) |
mbed_official | 237:f3da66175598 | 439 | { |
mbed_official | 237:f3da66175598 | 440 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 441 | } |
mbed_official | 237:f3da66175598 | 442 | else |
mbed_official | 237:f3da66175598 | 443 | { |
mbed_official | 237:f3da66175598 | 444 | /* Enter init mode */ |
mbed_official | 237:f3da66175598 | 445 | if(SDADC_EnterInitMode(hsdadc) != HAL_OK) |
mbed_official | 237:f3da66175598 | 446 | { |
mbed_official | 237:f3da66175598 | 447 | /* Set SDADC in error state */ |
mbed_official | 237:f3da66175598 | 448 | hsdadc->State = HAL_SDADC_STATE_ERROR; |
mbed_official | 237:f3da66175598 | 449 | status = HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 450 | } |
mbed_official | 237:f3da66175598 | 451 | else |
mbed_official | 237:f3da66175598 | 452 | { |
mbed_official | 237:f3da66175598 | 453 | /* Program configuration register with parameters */ |
mbed_official | 237:f3da66175598 | 454 | tmp = (uint32_t)((uint32_t)(hsdadc->Instance) + \ |
mbed_official | 237:f3da66175598 | 455 | SDADC_CONFREG_OFFSET + \ |
mbed_official | 237:f3da66175598 | 456 | (uint32_t)(ConfIndex << 2)); |
mbed_official | 237:f3da66175598 | 457 | *(__IO uint32_t *) (tmp) = (uint32_t) (ConfParamStruct->InputMode | \ |
mbed_official | 237:f3da66175598 | 458 | ConfParamStruct->Gain | \ |
mbed_official | 237:f3da66175598 | 459 | ConfParamStruct->CommonMode | \ |
mbed_official | 237:f3da66175598 | 460 | ConfParamStruct->Offset); |
mbed_official | 237:f3da66175598 | 461 | /* Exit init mode */ |
mbed_official | 237:f3da66175598 | 462 | SDADC_ExitInitMode(hsdadc); |
mbed_official | 237:f3da66175598 | 463 | } |
mbed_official | 237:f3da66175598 | 464 | } |
mbed_official | 237:f3da66175598 | 465 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 466 | return status; |
mbed_official | 237:f3da66175598 | 467 | } |
mbed_official | 237:f3da66175598 | 468 | |
mbed_official | 237:f3da66175598 | 469 | /** |
mbed_official | 237:f3da66175598 | 470 | * @brief This function allows the user to associate a channel with one of the |
mbed_official | 237:f3da66175598 | 471 | * available configurations. |
mbed_official | 237:f3da66175598 | 472 | * @note This function should be called only when SDADC instance is in idle state |
mbed_official | 237:f3da66175598 | 473 | * (neither calibration nor regular or injected conversion ongoing) |
mbed_official | 237:f3da66175598 | 474 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 475 | * @param Channel : Channel to associate with configuration. |
mbed_official | 237:f3da66175598 | 476 | * This parameter can be a value of @ref SDADC_Channel_Selection. |
mbed_official | 237:f3da66175598 | 477 | * @param ConfIndex : Index of configuration to associate with channel. |
mbed_official | 237:f3da66175598 | 478 | * This parameter can be a value of @ref SDADC_ConfIndex. |
mbed_official | 237:f3da66175598 | 479 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 480 | */ |
mbed_official | 237:f3da66175598 | 481 | HAL_StatusTypeDef HAL_SDADC_AssociateChannelConfig(SDADC_HandleTypeDef *hsdadc, |
mbed_official | 237:f3da66175598 | 482 | uint32_t Channel, |
mbed_official | 237:f3da66175598 | 483 | uint32_t ConfIndex) |
mbed_official | 237:f3da66175598 | 484 | { |
mbed_official | 237:f3da66175598 | 485 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 486 | uint32_t channelnum = 0; |
mbed_official | 237:f3da66175598 | 487 | |
mbed_official | 237:f3da66175598 | 488 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 489 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 490 | assert_param(IS_SDADC_REGULAR_CHANNEL(Channel)); |
mbed_official | 237:f3da66175598 | 491 | assert_param(IS_SDADC_CONF_INDEX(ConfIndex)); |
mbed_official | 237:f3da66175598 | 492 | |
mbed_official | 237:f3da66175598 | 493 | /* Check SDADC state is ready */ |
mbed_official | 237:f3da66175598 | 494 | if(hsdadc->State != HAL_SDADC_STATE_READY) |
mbed_official | 237:f3da66175598 | 495 | { |
mbed_official | 237:f3da66175598 | 496 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 497 | } |
mbed_official | 237:f3da66175598 | 498 | else |
mbed_official | 237:f3da66175598 | 499 | { |
mbed_official | 237:f3da66175598 | 500 | /* Enter init mode */ |
mbed_official | 237:f3da66175598 | 501 | if(SDADC_EnterInitMode(hsdadc) != HAL_OK) |
mbed_official | 237:f3da66175598 | 502 | { |
mbed_official | 237:f3da66175598 | 503 | /* Set SDADC in error state */ |
mbed_official | 237:f3da66175598 | 504 | hsdadc->State = HAL_SDADC_STATE_ERROR; |
mbed_official | 237:f3da66175598 | 505 | status = HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 506 | } |
mbed_official | 237:f3da66175598 | 507 | else |
mbed_official | 237:f3da66175598 | 508 | { |
mbed_official | 237:f3da66175598 | 509 | /* Program channel configuration register according parameters */ |
mbed_official | 237:f3da66175598 | 510 | if(Channel != SDADC_CHANNEL_8) |
mbed_official | 237:f3da66175598 | 511 | { |
mbed_official | 237:f3da66175598 | 512 | /* Get channel number */ |
mbed_official | 237:f3da66175598 | 513 | channelnum = (uint32_t)(Channel>>16); |
mbed_official | 237:f3da66175598 | 514 | |
mbed_official | 237:f3da66175598 | 515 | /* Set the channel configuration */ |
mbed_official | 237:f3da66175598 | 516 | hsdadc->Instance->CONFCHR1 &= (uint32_t) ~(SDADC_CONFCHR1_CONFCH0 << (channelnum << 2)); |
mbed_official | 237:f3da66175598 | 517 | hsdadc->Instance->CONFCHR1 |= (uint32_t) (ConfIndex << (channelnum << 2)); |
mbed_official | 237:f3da66175598 | 518 | } |
mbed_official | 237:f3da66175598 | 519 | else |
mbed_official | 237:f3da66175598 | 520 | { |
mbed_official | 237:f3da66175598 | 521 | hsdadc->Instance->CONFCHR2 = (uint32_t) (ConfIndex); |
mbed_official | 237:f3da66175598 | 522 | } |
mbed_official | 237:f3da66175598 | 523 | /* Exit init mode */ |
mbed_official | 237:f3da66175598 | 524 | SDADC_ExitInitMode(hsdadc); |
mbed_official | 237:f3da66175598 | 525 | } |
mbed_official | 237:f3da66175598 | 526 | } |
mbed_official | 237:f3da66175598 | 527 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 528 | return status; |
mbed_official | 237:f3da66175598 | 529 | } |
mbed_official | 237:f3da66175598 | 530 | |
mbed_official | 237:f3da66175598 | 531 | /** |
mbed_official | 237:f3da66175598 | 532 | * @brief This function allows to select channel for regular conversion and |
mbed_official | 237:f3da66175598 | 533 | * to enable/disable continuous mode for regular conversion. |
mbed_official | 237:f3da66175598 | 534 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 535 | * @param Channel : Channel for regular conversion. |
mbed_official | 237:f3da66175598 | 536 | * This parameter can be a value of @ref SDADC_Channel_Selection. |
mbed_official | 237:f3da66175598 | 537 | * @param ContinuousMode : Enable/disable continuous mode for regular conversion. |
mbed_official | 237:f3da66175598 | 538 | * This parameter can be a value of @ref SDADC_ContinuousMode. |
mbed_official | 237:f3da66175598 | 539 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 540 | */ |
mbed_official | 237:f3da66175598 | 541 | HAL_StatusTypeDef HAL_SDADC_ConfigChannel(SDADC_HandleTypeDef *hsdadc, |
mbed_official | 237:f3da66175598 | 542 | uint32_t Channel, |
mbed_official | 237:f3da66175598 | 543 | uint32_t ContinuousMode) |
mbed_official | 237:f3da66175598 | 544 | { |
mbed_official | 237:f3da66175598 | 545 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 546 | |
mbed_official | 237:f3da66175598 | 547 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 548 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 549 | assert_param(IS_SDADC_REGULAR_CHANNEL(Channel)); |
mbed_official | 237:f3da66175598 | 550 | assert_param(IS_SDADC_CONTINUOUS_MODE(ContinuousMode)); |
mbed_official | 237:f3da66175598 | 551 | |
mbed_official | 237:f3da66175598 | 552 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 553 | if((hsdadc->State != HAL_SDADC_STATE_RESET) && (hsdadc->State != HAL_SDADC_STATE_ERROR)) |
mbed_official | 237:f3da66175598 | 554 | { |
mbed_official | 237:f3da66175598 | 555 | /* Set RCH[3:0] and RCONT bits in SDADC_CR2 */ |
mbed_official | 237:f3da66175598 | 556 | hsdadc->Instance->CR2 &= (uint32_t) ~(SDADC_CR2_RCH | SDADC_CR2_RCONT); |
mbed_official | 237:f3da66175598 | 557 | if(ContinuousMode == SDADC_CONTINUOUS_CONV_ON) |
mbed_official | 237:f3da66175598 | 558 | { |
mbed_official | 237:f3da66175598 | 559 | hsdadc->Instance->CR2 |= (uint32_t) ((Channel & SDADC_MSB_MASK) | SDADC_CR2_RCONT); |
mbed_official | 237:f3da66175598 | 560 | } |
mbed_official | 237:f3da66175598 | 561 | else |
mbed_official | 237:f3da66175598 | 562 | { |
mbed_official | 237:f3da66175598 | 563 | hsdadc->Instance->CR2 |= (uint32_t) ((Channel & SDADC_MSB_MASK)); |
mbed_official | 237:f3da66175598 | 564 | } |
mbed_official | 237:f3da66175598 | 565 | /* Store continuous mode information */ |
mbed_official | 237:f3da66175598 | 566 | hsdadc->RegularContMode = ContinuousMode; |
mbed_official | 237:f3da66175598 | 567 | } |
mbed_official | 237:f3da66175598 | 568 | else |
mbed_official | 237:f3da66175598 | 569 | { |
mbed_official | 237:f3da66175598 | 570 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 571 | } |
mbed_official | 237:f3da66175598 | 572 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 573 | return status; |
mbed_official | 237:f3da66175598 | 574 | } |
mbed_official | 237:f3da66175598 | 575 | |
mbed_official | 237:f3da66175598 | 576 | /** |
mbed_official | 237:f3da66175598 | 577 | * @brief This function allows to select channels for injected conversion and |
mbed_official | 237:f3da66175598 | 578 | * to enable/disable continuous mode for injected conversion. |
mbed_official | 237:f3da66175598 | 579 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 580 | * @param Channel : Channels for injected conversion. |
mbed_official | 237:f3da66175598 | 581 | * This parameter can be a values combination of @ref SDADC_Channel_Selection. |
mbed_official | 237:f3da66175598 | 582 | * @param ContinuousMode : Enable/disable continuous mode for injected conversion. |
mbed_official | 237:f3da66175598 | 583 | * This parameter can be a value of @ref SDADC_ContinuousMode. |
mbed_official | 237:f3da66175598 | 584 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 585 | */ |
mbed_official | 237:f3da66175598 | 586 | HAL_StatusTypeDef HAL_SDADC_InjectedConfigChannel(SDADC_HandleTypeDef *hsdadc, |
mbed_official | 237:f3da66175598 | 587 | uint32_t Channel, |
mbed_official | 237:f3da66175598 | 588 | uint32_t ContinuousMode) |
mbed_official | 237:f3da66175598 | 589 | { |
mbed_official | 237:f3da66175598 | 590 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 591 | |
mbed_official | 237:f3da66175598 | 592 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 593 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 594 | assert_param(IS_SDADC_INJECTED_CHANNEL(Channel)); |
mbed_official | 237:f3da66175598 | 595 | assert_param(IS_SDADC_CONTINUOUS_MODE(ContinuousMode)); |
mbed_official | 237:f3da66175598 | 596 | |
mbed_official | 237:f3da66175598 | 597 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 598 | if((hsdadc->State != HAL_SDADC_STATE_RESET) && (hsdadc->State != HAL_SDADC_STATE_ERROR)) |
mbed_official | 237:f3da66175598 | 599 | { |
mbed_official | 237:f3da66175598 | 600 | /* Set JCHG[8:0] bits in SDADC_JCHG */ |
mbed_official | 237:f3da66175598 | 601 | hsdadc->Instance->JCHGR = (uint32_t) (Channel & SDADC_LSB_MASK); |
mbed_official | 237:f3da66175598 | 602 | /* Set or clear JCONT bit in SDADC_CR2 */ |
mbed_official | 237:f3da66175598 | 603 | if(ContinuousMode == SDADC_CONTINUOUS_CONV_ON) |
mbed_official | 237:f3da66175598 | 604 | { |
mbed_official | 237:f3da66175598 | 605 | hsdadc->Instance->CR2 |= SDADC_CR2_JCONT; |
mbed_official | 237:f3da66175598 | 606 | } |
mbed_official | 237:f3da66175598 | 607 | else |
mbed_official | 237:f3da66175598 | 608 | { |
mbed_official | 237:f3da66175598 | 609 | hsdadc->Instance->CR2 &= ~(SDADC_CR2_JCONT); |
mbed_official | 237:f3da66175598 | 610 | } |
mbed_official | 237:f3da66175598 | 611 | /* Store continuous mode information */ |
mbed_official | 237:f3da66175598 | 612 | hsdadc->InjectedContMode = ContinuousMode; |
mbed_official | 237:f3da66175598 | 613 | /* Store number of injected channels */ |
mbed_official | 237:f3da66175598 | 614 | hsdadc->InjectedChannelsNbr = SDADC_GetInjChannelsNbr(Channel); |
mbed_official | 237:f3da66175598 | 615 | } |
mbed_official | 237:f3da66175598 | 616 | else |
mbed_official | 237:f3da66175598 | 617 | { |
mbed_official | 237:f3da66175598 | 618 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 619 | } |
mbed_official | 237:f3da66175598 | 620 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 621 | return status; |
mbed_official | 237:f3da66175598 | 622 | } |
mbed_official | 237:f3da66175598 | 623 | |
mbed_official | 237:f3da66175598 | 624 | /** |
mbed_official | 237:f3da66175598 | 625 | * @brief This function allows to select trigger for regular conversions. |
mbed_official | 237:f3da66175598 | 626 | * @note This function should not be called if regular conversion is ongoing. |
mbed_official | 237:f3da66175598 | 627 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 628 | * @param Trigger : Trigger for regular conversions. |
mbed_official | 237:f3da66175598 | 629 | * This parameter can be one of the following value : |
mbed_official | 237:f3da66175598 | 630 | * @arg SDADC_SOFTWARE_TRIGGER : Software trigger. |
mbed_official | 237:f3da66175598 | 631 | * @arg SDADC_SYNCHRONOUS_TRIGGER : Synchronous with SDADC1 (only for SDADC2 and SDADC3). |
mbed_official | 237:f3da66175598 | 632 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 633 | */ |
mbed_official | 237:f3da66175598 | 634 | HAL_StatusTypeDef HAL_SDADC_SelectRegularTrigger(SDADC_HandleTypeDef *hsdadc, uint32_t Trigger) |
mbed_official | 237:f3da66175598 | 635 | { |
mbed_official | 237:f3da66175598 | 636 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 637 | |
mbed_official | 237:f3da66175598 | 638 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 639 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 640 | assert_param(IS_SDADC_REGULAR_TRIGGER(Trigger)); |
mbed_official | 237:f3da66175598 | 641 | |
mbed_official | 237:f3da66175598 | 642 | /* Check parameters compatibility */ |
mbed_official | 237:f3da66175598 | 643 | if((hsdadc->Instance == SDADC1) && (Trigger == SDADC_SYNCHRONOUS_TRIGGER)) |
mbed_official | 237:f3da66175598 | 644 | { |
mbed_official | 237:f3da66175598 | 645 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 646 | } |
mbed_official | 237:f3da66175598 | 647 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 648 | else if((hsdadc->State == HAL_SDADC_STATE_READY) || \ |
mbed_official | 237:f3da66175598 | 649 | (hsdadc->State == HAL_SDADC_STATE_CALIB) || \ |
mbed_official | 237:f3da66175598 | 650 | (hsdadc->State == HAL_SDADC_STATE_INJ)) |
mbed_official | 237:f3da66175598 | 651 | { |
mbed_official | 237:f3da66175598 | 652 | /* Store regular trigger information */ |
mbed_official | 237:f3da66175598 | 653 | hsdadc->RegularTrigger = Trigger; |
mbed_official | 237:f3da66175598 | 654 | } |
mbed_official | 237:f3da66175598 | 655 | else |
mbed_official | 237:f3da66175598 | 656 | { |
mbed_official | 237:f3da66175598 | 657 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 658 | } |
mbed_official | 237:f3da66175598 | 659 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 660 | return status; |
mbed_official | 237:f3da66175598 | 661 | } |
mbed_official | 237:f3da66175598 | 662 | |
mbed_official | 237:f3da66175598 | 663 | /** |
mbed_official | 237:f3da66175598 | 664 | * @brief This function allows to select trigger for injected conversions. |
mbed_official | 237:f3da66175598 | 665 | * @note This function should not be called if injected conversion is ongoing. |
mbed_official | 237:f3da66175598 | 666 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 667 | * @param Trigger : Trigger for injected conversions. |
mbed_official | 237:f3da66175598 | 668 | * This parameter can be one of the following value : |
mbed_official | 237:f3da66175598 | 669 | * @arg SDADC_SOFTWARE_TRIGGER : Software trigger. |
mbed_official | 237:f3da66175598 | 670 | * @arg SDADC_SYNCHRONOUS_TRIGGER : Synchronous with SDADC1 (only for SDADC2 and SDADC3). |
mbed_official | 237:f3da66175598 | 671 | * @arg SDADC_EXTERNAL_TRIGGER : External trigger. |
mbed_official | 237:f3da66175598 | 672 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 673 | */ |
mbed_official | 237:f3da66175598 | 674 | HAL_StatusTypeDef HAL_SDADC_SelectInjectedTrigger(SDADC_HandleTypeDef *hsdadc, uint32_t Trigger) |
mbed_official | 237:f3da66175598 | 675 | { |
mbed_official | 237:f3da66175598 | 676 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 677 | |
mbed_official | 237:f3da66175598 | 678 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 679 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 680 | assert_param(IS_SDADC_INJECTED_TRIGGER(Trigger)); |
mbed_official | 237:f3da66175598 | 681 | |
mbed_official | 237:f3da66175598 | 682 | /* Check parameters compatibility */ |
mbed_official | 237:f3da66175598 | 683 | if((hsdadc->Instance == SDADC1) && (Trigger == SDADC_SYNCHRONOUS_TRIGGER)) |
mbed_official | 237:f3da66175598 | 684 | { |
mbed_official | 237:f3da66175598 | 685 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 686 | } |
mbed_official | 237:f3da66175598 | 687 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 688 | else if((hsdadc->State == HAL_SDADC_STATE_READY) || \ |
mbed_official | 237:f3da66175598 | 689 | (hsdadc->State == HAL_SDADC_STATE_CALIB) || \ |
mbed_official | 237:f3da66175598 | 690 | (hsdadc->State == HAL_SDADC_STATE_REG)) |
mbed_official | 237:f3da66175598 | 691 | { |
mbed_official | 237:f3da66175598 | 692 | /* Store regular trigger information */ |
mbed_official | 237:f3da66175598 | 693 | hsdadc->InjectedTrigger = Trigger; |
mbed_official | 237:f3da66175598 | 694 | } |
mbed_official | 237:f3da66175598 | 695 | else |
mbed_official | 237:f3da66175598 | 696 | { |
mbed_official | 237:f3da66175598 | 697 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 698 | } |
mbed_official | 237:f3da66175598 | 699 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 700 | return status; |
mbed_official | 237:f3da66175598 | 701 | } |
mbed_official | 237:f3da66175598 | 702 | |
mbed_official | 237:f3da66175598 | 703 | /** |
mbed_official | 237:f3da66175598 | 704 | * @brief This function allows to select and configure injected external trigger. |
mbed_official | 237:f3da66175598 | 705 | * @note This function should be called only when SDADC instance is in idle state |
mbed_official | 237:f3da66175598 | 706 | * (neither calibration nor regular or injected conversion ongoing) |
mbed_official | 237:f3da66175598 | 707 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 708 | * @param InjectedExtTrigger : External trigger for injected conversions. |
mbed_official | 237:f3da66175598 | 709 | * This parameter can be a value of @ref SDADC_InjectedExtTrigger. |
mbed_official | 237:f3da66175598 | 710 | * @param ExtTriggerEdge : Edge of external injected trigger. |
mbed_official | 237:f3da66175598 | 711 | * This parameter can be a value of @ref SDADC_ExtTriggerEdge. |
mbed_official | 237:f3da66175598 | 712 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 713 | */ |
mbed_official | 237:f3da66175598 | 714 | HAL_StatusTypeDef HAL_SDADC_SelectInjectedExtTrigger(SDADC_HandleTypeDef *hsdadc, |
mbed_official | 237:f3da66175598 | 715 | uint32_t InjectedExtTrigger, |
mbed_official | 237:f3da66175598 | 716 | uint32_t ExtTriggerEdge) |
mbed_official | 237:f3da66175598 | 717 | { |
mbed_official | 237:f3da66175598 | 718 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 719 | |
mbed_official | 237:f3da66175598 | 720 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 721 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 722 | assert_param(IS_SDADC_EXT_INJEC_TRIG(InjectedExtTrigger)); |
mbed_official | 237:f3da66175598 | 723 | assert_param(IS_SDADC_EXT_TRIG_EDGE(ExtTriggerEdge)); |
mbed_official | 237:f3da66175598 | 724 | |
mbed_official | 237:f3da66175598 | 725 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 726 | if(hsdadc->State == HAL_SDADC_STATE_READY) |
mbed_official | 237:f3da66175598 | 727 | { |
mbed_official | 237:f3da66175598 | 728 | /* Enter init mode */ |
mbed_official | 237:f3da66175598 | 729 | if(SDADC_EnterInitMode(hsdadc) != HAL_OK) |
mbed_official | 237:f3da66175598 | 730 | { |
mbed_official | 237:f3da66175598 | 731 | /* Set SDADC in error state */ |
mbed_official | 237:f3da66175598 | 732 | hsdadc->State = HAL_SDADC_STATE_ERROR; |
mbed_official | 237:f3da66175598 | 733 | status = HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 734 | } |
mbed_official | 237:f3da66175598 | 735 | else |
mbed_official | 237:f3da66175598 | 736 | { |
mbed_official | 237:f3da66175598 | 737 | /* Set JEXTSEL[2:0] bits in SDADC_CR2 register */ |
mbed_official | 237:f3da66175598 | 738 | hsdadc->Instance->CR2 &= ~(SDADC_CR2_JEXTSEL); |
mbed_official | 237:f3da66175598 | 739 | hsdadc->Instance->CR2 |= InjectedExtTrigger; |
mbed_official | 237:f3da66175598 | 740 | |
mbed_official | 237:f3da66175598 | 741 | /* Store external trigger edge information */ |
mbed_official | 237:f3da66175598 | 742 | hsdadc->ExtTriggerEdge = ExtTriggerEdge; |
mbed_official | 237:f3da66175598 | 743 | |
mbed_official | 237:f3da66175598 | 744 | /* Exit init mode */ |
mbed_official | 237:f3da66175598 | 745 | SDADC_ExitInitMode(hsdadc); |
mbed_official | 237:f3da66175598 | 746 | } |
mbed_official | 237:f3da66175598 | 747 | } |
mbed_official | 237:f3da66175598 | 748 | else |
mbed_official | 237:f3da66175598 | 749 | { |
mbed_official | 237:f3da66175598 | 750 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 751 | } |
mbed_official | 237:f3da66175598 | 752 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 753 | return status; |
mbed_official | 237:f3da66175598 | 754 | } |
mbed_official | 237:f3da66175598 | 755 | |
mbed_official | 237:f3da66175598 | 756 | /** |
mbed_official | 237:f3da66175598 | 757 | * @brief This function allows to enable/disable delay addition for injected conversions. |
mbed_official | 237:f3da66175598 | 758 | * @note This function should be called only when SDADC instance is in idle state |
mbed_official | 237:f3da66175598 | 759 | * (neither calibration nor regular or injected conversion ongoing) |
mbed_official | 237:f3da66175598 | 760 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 761 | * @param InjectedDelay : Enable/disable delay for injected conversions. |
mbed_official | 237:f3da66175598 | 762 | * This parameter can be a value of @ref SDADC_InjectedDelay. |
mbed_official | 237:f3da66175598 | 763 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 764 | */ |
mbed_official | 237:f3da66175598 | 765 | HAL_StatusTypeDef HAL_SDADC_SelectInjectedDelay(SDADC_HandleTypeDef *hsdadc, |
mbed_official | 237:f3da66175598 | 766 | uint32_t InjectedDelay) |
mbed_official | 237:f3da66175598 | 767 | { |
mbed_official | 237:f3da66175598 | 768 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 769 | |
mbed_official | 237:f3da66175598 | 770 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 771 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 772 | assert_param(IS_SDADC_INJECTED_DELAY(InjectedDelay)); |
mbed_official | 237:f3da66175598 | 773 | |
mbed_official | 237:f3da66175598 | 774 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 775 | if(hsdadc->State == HAL_SDADC_STATE_READY) |
mbed_official | 237:f3da66175598 | 776 | { |
mbed_official | 237:f3da66175598 | 777 | /* Enter init mode */ |
mbed_official | 237:f3da66175598 | 778 | if(SDADC_EnterInitMode(hsdadc) != HAL_OK) |
mbed_official | 237:f3da66175598 | 779 | { |
mbed_official | 237:f3da66175598 | 780 | /* Set SDADC in error state */ |
mbed_official | 237:f3da66175598 | 781 | hsdadc->State = HAL_SDADC_STATE_ERROR; |
mbed_official | 237:f3da66175598 | 782 | status = HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 783 | } |
mbed_official | 237:f3da66175598 | 784 | else |
mbed_official | 237:f3da66175598 | 785 | { |
mbed_official | 237:f3da66175598 | 786 | /* Set JDS bit in SDADC_CR2 register */ |
mbed_official | 237:f3da66175598 | 787 | hsdadc->Instance->CR2 &= ~(SDADC_CR2_JDS); |
mbed_official | 237:f3da66175598 | 788 | hsdadc->Instance->CR2 |= InjectedDelay; |
mbed_official | 237:f3da66175598 | 789 | |
mbed_official | 237:f3da66175598 | 790 | /* Exit init mode */ |
mbed_official | 237:f3da66175598 | 791 | SDADC_ExitInitMode(hsdadc); |
mbed_official | 237:f3da66175598 | 792 | } |
mbed_official | 237:f3da66175598 | 793 | } |
mbed_official | 237:f3da66175598 | 794 | else |
mbed_official | 237:f3da66175598 | 795 | { |
mbed_official | 237:f3da66175598 | 796 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 797 | } |
mbed_official | 237:f3da66175598 | 798 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 799 | return status; |
mbed_official | 237:f3da66175598 | 800 | } |
mbed_official | 237:f3da66175598 | 801 | |
mbed_official | 237:f3da66175598 | 802 | /** |
mbed_official | 237:f3da66175598 | 803 | * @brief This function allows to configure multimode for regular conversions. |
mbed_official | 237:f3da66175598 | 804 | * @note This function should not be called if regular conversion is ongoing |
mbed_official | 237:f3da66175598 | 805 | * and should be could only for SDADC1. |
mbed_official | 237:f3da66175598 | 806 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 807 | * @param MultimodeType : Type of multimode for regular conversions. |
mbed_official | 237:f3da66175598 | 808 | * This parameter can be a value of @ref SDADC_MultimodeType. |
mbed_official | 237:f3da66175598 | 809 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 810 | */ |
mbed_official | 237:f3da66175598 | 811 | HAL_StatusTypeDef HAL_SDADC_MultiModeConfigChannel(SDADC_HandleTypeDef* hsdadc, |
mbed_official | 237:f3da66175598 | 812 | uint32_t MultimodeType) |
mbed_official | 237:f3da66175598 | 813 | { |
mbed_official | 237:f3da66175598 | 814 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 815 | |
mbed_official | 237:f3da66175598 | 816 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 817 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 818 | assert_param(IS_SDADC_MULTIMODE_TYPE(MultimodeType)); |
mbed_official | 237:f3da66175598 | 819 | |
mbed_official | 237:f3da66175598 | 820 | /* Check instance is SDADC1 */ |
mbed_official | 237:f3da66175598 | 821 | if(hsdadc->Instance != SDADC1) |
mbed_official | 237:f3da66175598 | 822 | { |
mbed_official | 237:f3da66175598 | 823 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 824 | } |
mbed_official | 237:f3da66175598 | 825 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 826 | else if((hsdadc->State == HAL_SDADC_STATE_READY) || \ |
mbed_official | 237:f3da66175598 | 827 | (hsdadc->State == HAL_SDADC_STATE_CALIB) || \ |
mbed_official | 237:f3da66175598 | 828 | (hsdadc->State == HAL_SDADC_STATE_INJ)) |
mbed_official | 237:f3da66175598 | 829 | { |
mbed_official | 237:f3da66175598 | 830 | /* Store regular trigger information */ |
mbed_official | 237:f3da66175598 | 831 | hsdadc->RegularMultimode = MultimodeType; |
mbed_official | 237:f3da66175598 | 832 | } |
mbed_official | 237:f3da66175598 | 833 | else |
mbed_official | 237:f3da66175598 | 834 | { |
mbed_official | 237:f3da66175598 | 835 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 836 | } |
mbed_official | 237:f3da66175598 | 837 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 838 | return status; |
mbed_official | 237:f3da66175598 | 839 | } |
mbed_official | 237:f3da66175598 | 840 | |
mbed_official | 237:f3da66175598 | 841 | /** |
mbed_official | 237:f3da66175598 | 842 | * @brief This function allows to configure multimode for injected conversions. |
mbed_official | 237:f3da66175598 | 843 | * @note This function should not be called if injected conversion is ongoing |
mbed_official | 237:f3da66175598 | 844 | * and should be could only for SDADC1. |
mbed_official | 237:f3da66175598 | 845 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 846 | * @param MultimodeType : Type of multimode for injected conversions. |
mbed_official | 237:f3da66175598 | 847 | * This parameter can be a value of @ref SDADC_MultimodeType. |
mbed_official | 237:f3da66175598 | 848 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 849 | */ |
mbed_official | 237:f3da66175598 | 850 | HAL_StatusTypeDef HAL_SDADC_InjectedMultiModeConfigChannel(SDADC_HandleTypeDef* hsdadc, |
mbed_official | 237:f3da66175598 | 851 | uint32_t MultimodeType) |
mbed_official | 237:f3da66175598 | 852 | { |
mbed_official | 237:f3da66175598 | 853 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 854 | |
mbed_official | 237:f3da66175598 | 855 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 856 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 857 | assert_param(IS_SDADC_MULTIMODE_TYPE(MultimodeType)); |
mbed_official | 237:f3da66175598 | 858 | |
mbed_official | 237:f3da66175598 | 859 | /* Check instance is SDADC1 */ |
mbed_official | 237:f3da66175598 | 860 | if(hsdadc->Instance != SDADC1) |
mbed_official | 237:f3da66175598 | 861 | { |
mbed_official | 237:f3da66175598 | 862 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 863 | } |
mbed_official | 237:f3da66175598 | 864 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 865 | else if((hsdadc->State == HAL_SDADC_STATE_READY) || \ |
mbed_official | 237:f3da66175598 | 866 | (hsdadc->State == HAL_SDADC_STATE_CALIB) || \ |
mbed_official | 237:f3da66175598 | 867 | (hsdadc->State == HAL_SDADC_STATE_REG)) |
mbed_official | 237:f3da66175598 | 868 | { |
mbed_official | 237:f3da66175598 | 869 | /* Store regular trigger information */ |
mbed_official | 237:f3da66175598 | 870 | hsdadc->InjectedMultimode = MultimodeType; |
mbed_official | 237:f3da66175598 | 871 | } |
mbed_official | 237:f3da66175598 | 872 | else |
mbed_official | 237:f3da66175598 | 873 | { |
mbed_official | 237:f3da66175598 | 874 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 875 | } |
mbed_official | 237:f3da66175598 | 876 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 877 | return status; |
mbed_official | 237:f3da66175598 | 878 | } |
mbed_official | 237:f3da66175598 | 879 | |
mbed_official | 237:f3da66175598 | 880 | /** |
mbed_official | 237:f3da66175598 | 881 | * @} |
mbed_official | 237:f3da66175598 | 882 | */ |
mbed_official | 237:f3da66175598 | 883 | |
mbed_official | 237:f3da66175598 | 884 | /** @defgroup SDADC_Group3 I/O operation functions |
mbed_official | 237:f3da66175598 | 885 | * @brief I/O operation Control functions |
mbed_official | 237:f3da66175598 | 886 | * |
mbed_official | 237:f3da66175598 | 887 | @verbatim |
mbed_official | 237:f3da66175598 | 888 | =============================================================================== |
mbed_official | 237:f3da66175598 | 889 | ##### I/O operation functions ##### |
mbed_official | 237:f3da66175598 | 890 | =============================================================================== |
mbed_official | 237:f3da66175598 | 891 | [..] This section provides functions allowing to: |
mbed_official | 237:f3da66175598 | 892 | (+) Start calibration. |
mbed_official | 237:f3da66175598 | 893 | (+) Poll for the end of calibration. |
mbed_official | 237:f3da66175598 | 894 | (+) Start calibration and enable interrupt. |
mbed_official | 237:f3da66175598 | 895 | (+) Start conversion of regular/injected channel. |
mbed_official | 237:f3da66175598 | 896 | (+) Poll for the end of regular/injected conversion. |
mbed_official | 237:f3da66175598 | 897 | (+) Stop conversion of regular/injected channel. |
mbed_official | 237:f3da66175598 | 898 | (+) Start conversion of regular/injected channel and enable interrupt. |
mbed_official | 237:f3da66175598 | 899 | (+) Stop conversion of regular/injected channel and disable interrupt. |
mbed_official | 237:f3da66175598 | 900 | (+) Start conversion of regular/injected channel and enable DMA transfer. |
mbed_official | 237:f3da66175598 | 901 | (+) Stop conversion of regular/injected channel and disable DMA transfer. |
mbed_official | 237:f3da66175598 | 902 | (+) Start multimode and enable DMA transfer for regular/injected conversion. |
mbed_official | 237:f3da66175598 | 903 | (+) Stop multimode and disable DMA transfer for regular/injected conversion.. |
mbed_official | 237:f3da66175598 | 904 | (+) Get result of regular channel conversion. |
mbed_official | 237:f3da66175598 | 905 | (+) Get result of injected channel conversion. |
mbed_official | 237:f3da66175598 | 906 | (+) Get result of multimode conversion. |
mbed_official | 237:f3da66175598 | 907 | (+) Handle SDADC interrupt request. |
mbed_official | 237:f3da66175598 | 908 | (+) Callbacks for calibration and regular/injected conversions. |
mbed_official | 237:f3da66175598 | 909 | |
mbed_official | 237:f3da66175598 | 910 | @endverbatim |
mbed_official | 237:f3da66175598 | 911 | * @{ |
mbed_official | 237:f3da66175598 | 912 | */ |
mbed_official | 237:f3da66175598 | 913 | |
mbed_official | 237:f3da66175598 | 914 | /** |
mbed_official | 237:f3da66175598 | 915 | * @brief This function allows to start calibration in polling mode. |
mbed_official | 237:f3da66175598 | 916 | * @note This function should be called only when SDADC instance is in idle state |
mbed_official | 237:f3da66175598 | 917 | * (neither calibration nor regular or injected conversion ongoing). |
mbed_official | 237:f3da66175598 | 918 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 919 | * @param CalibrationSequence : Calibration sequence. |
mbed_official | 237:f3da66175598 | 920 | * This parameter can be a value of @ref SDADC_CalibrationSequence. |
mbed_official | 237:f3da66175598 | 921 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 922 | */ |
mbed_official | 237:f3da66175598 | 923 | HAL_StatusTypeDef HAL_SDADC_CalibrationStart(SDADC_HandleTypeDef *hsdadc, |
mbed_official | 237:f3da66175598 | 924 | uint32_t CalibrationSequence) |
mbed_official | 237:f3da66175598 | 925 | { |
mbed_official | 237:f3da66175598 | 926 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 927 | |
mbed_official | 237:f3da66175598 | 928 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 929 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 930 | assert_param(IS_SDADC_CALIB_SEQUENCE(CalibrationSequence)); |
mbed_official | 237:f3da66175598 | 931 | |
mbed_official | 237:f3da66175598 | 932 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 933 | if(hsdadc->State == HAL_SDADC_STATE_READY) |
mbed_official | 237:f3da66175598 | 934 | { |
mbed_official | 237:f3da66175598 | 935 | /* Enter init mode */ |
mbed_official | 237:f3da66175598 | 936 | if(SDADC_EnterInitMode(hsdadc) != HAL_OK) |
mbed_official | 237:f3da66175598 | 937 | { |
mbed_official | 237:f3da66175598 | 938 | /* Set SDADC in error state */ |
mbed_official | 237:f3da66175598 | 939 | hsdadc->State = HAL_SDADC_STATE_ERROR; |
mbed_official | 237:f3da66175598 | 940 | status = HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 941 | } |
mbed_official | 237:f3da66175598 | 942 | else |
mbed_official | 237:f3da66175598 | 943 | { |
mbed_official | 237:f3da66175598 | 944 | /* Set CALIBCNT[1:0] bits in SDADC_CR2 register */ |
mbed_official | 237:f3da66175598 | 945 | hsdadc->Instance->CR2 &= ~(SDADC_CR2_CALIBCNT); |
mbed_official | 237:f3da66175598 | 946 | hsdadc->Instance->CR2 |= CalibrationSequence; |
mbed_official | 237:f3da66175598 | 947 | |
mbed_official | 237:f3da66175598 | 948 | /* Exit init mode */ |
mbed_official | 237:f3da66175598 | 949 | SDADC_ExitInitMode(hsdadc); |
mbed_official | 237:f3da66175598 | 950 | |
mbed_official | 237:f3da66175598 | 951 | /* Set STARTCALIB in SDADC_CR2 */ |
mbed_official | 237:f3da66175598 | 952 | hsdadc->Instance->CR2 |= SDADC_CR2_STARTCALIB; |
mbed_official | 237:f3da66175598 | 953 | |
mbed_official | 237:f3da66175598 | 954 | /* Set SDADC in calibration state */ |
mbed_official | 237:f3da66175598 | 955 | hsdadc->State = HAL_SDADC_STATE_CALIB; |
mbed_official | 237:f3da66175598 | 956 | } |
mbed_official | 237:f3da66175598 | 957 | } |
mbed_official | 237:f3da66175598 | 958 | else |
mbed_official | 237:f3da66175598 | 959 | { |
mbed_official | 237:f3da66175598 | 960 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 961 | } |
mbed_official | 237:f3da66175598 | 962 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 963 | return status; |
mbed_official | 237:f3da66175598 | 964 | } |
mbed_official | 237:f3da66175598 | 965 | |
mbed_official | 237:f3da66175598 | 966 | /** |
mbed_official | 237:f3da66175598 | 967 | * @brief This function allows to poll for the end of calibration. |
mbed_official | 237:f3da66175598 | 968 | * @note This function should be called only if calibration is ongoing. |
mbed_official | 237:f3da66175598 | 969 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 970 | * @param Timeout : Timeout value in milliseconds. |
mbed_official | 237:f3da66175598 | 971 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 972 | */ |
mbed_official | 237:f3da66175598 | 973 | HAL_StatusTypeDef HAL_SDADC_PollForCalibEvent(SDADC_HandleTypeDef* hsdadc, uint32_t Timeout) |
mbed_official | 237:f3da66175598 | 974 | { |
mbed_official | 237:f3da66175598 | 975 | uint32_t tickstart; |
mbed_official | 237:f3da66175598 | 976 | |
mbed_official | 237:f3da66175598 | 977 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 978 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 979 | |
mbed_official | 237:f3da66175598 | 980 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 981 | if(hsdadc->State != HAL_SDADC_STATE_CALIB) |
mbed_official | 237:f3da66175598 | 982 | { |
mbed_official | 237:f3da66175598 | 983 | /* Return error status */ |
mbed_official | 237:f3da66175598 | 984 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 985 | } |
mbed_official | 237:f3da66175598 | 986 | else |
mbed_official | 237:f3da66175598 | 987 | { |
mbed_official | 237:f3da66175598 | 988 | /* Get timeout */ |
mbed_official | 237:f3da66175598 | 989 | tickstart = HAL_GetTick(); |
mbed_official | 237:f3da66175598 | 990 | |
mbed_official | 237:f3da66175598 | 991 | /* Wait EOCALF bit in SDADC_ISR register */ |
mbed_official | 237:f3da66175598 | 992 | while((hsdadc->Instance->ISR & SDADC_ISR_EOCALF) != SDADC_ISR_EOCALF) |
mbed_official | 237:f3da66175598 | 993 | { |
mbed_official | 237:f3da66175598 | 994 | /* Check the Timeout */ |
mbed_official | 237:f3da66175598 | 995 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 237:f3da66175598 | 996 | { |
mbed_official | 237:f3da66175598 | 997 | if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout)) |
mbed_official | 237:f3da66175598 | 998 | { |
mbed_official | 237:f3da66175598 | 999 | /* Return timeout status */ |
mbed_official | 237:f3da66175598 | 1000 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 1001 | } |
mbed_official | 237:f3da66175598 | 1002 | } |
mbed_official | 237:f3da66175598 | 1003 | } |
mbed_official | 237:f3da66175598 | 1004 | /* Set CLREOCALF bit in SDADC_CLRISR register */ |
mbed_official | 237:f3da66175598 | 1005 | hsdadc->Instance->CLRISR |= SDADC_ISR_CLREOCALF; |
mbed_official | 237:f3da66175598 | 1006 | |
mbed_official | 237:f3da66175598 | 1007 | /* Set SDADC in ready state */ |
mbed_official | 237:f3da66175598 | 1008 | hsdadc->State = HAL_SDADC_STATE_READY; |
mbed_official | 237:f3da66175598 | 1009 | |
mbed_official | 237:f3da66175598 | 1010 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 1011 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 1012 | } |
mbed_official | 237:f3da66175598 | 1013 | } |
mbed_official | 237:f3da66175598 | 1014 | |
mbed_official | 237:f3da66175598 | 1015 | /** |
mbed_official | 237:f3da66175598 | 1016 | * @brief This function allows to start calibration in interrupt mode. |
mbed_official | 237:f3da66175598 | 1017 | * @note This function should be called only when SDADC instance is in idle state |
mbed_official | 237:f3da66175598 | 1018 | * (neither calibration nor regular or injected conversion ongoing). |
mbed_official | 237:f3da66175598 | 1019 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1020 | * @param CalibrationSequence : Calibration sequence. |
mbed_official | 237:f3da66175598 | 1021 | * This parameter can be a value of @ref SDADC_CalibrationSequence. |
mbed_official | 237:f3da66175598 | 1022 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1023 | */ |
mbed_official | 237:f3da66175598 | 1024 | HAL_StatusTypeDef HAL_SDADC_CalibrationStart_IT(SDADC_HandleTypeDef *hsdadc, |
mbed_official | 237:f3da66175598 | 1025 | uint32_t CalibrationSequence) |
mbed_official | 237:f3da66175598 | 1026 | { |
mbed_official | 237:f3da66175598 | 1027 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 1028 | |
mbed_official | 237:f3da66175598 | 1029 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 1030 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1031 | assert_param(IS_SDADC_CALIB_SEQUENCE(CalibrationSequence)); |
mbed_official | 237:f3da66175598 | 1032 | |
mbed_official | 237:f3da66175598 | 1033 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 1034 | if(hsdadc->State == HAL_SDADC_STATE_READY) |
mbed_official | 237:f3da66175598 | 1035 | { |
mbed_official | 237:f3da66175598 | 1036 | /* Enter init mode */ |
mbed_official | 237:f3da66175598 | 1037 | if(SDADC_EnterInitMode(hsdadc) != HAL_OK) |
mbed_official | 237:f3da66175598 | 1038 | { |
mbed_official | 237:f3da66175598 | 1039 | /* Set SDADC in error state */ |
mbed_official | 237:f3da66175598 | 1040 | hsdadc->State = HAL_SDADC_STATE_ERROR; |
mbed_official | 237:f3da66175598 | 1041 | status = HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 1042 | } |
mbed_official | 237:f3da66175598 | 1043 | else |
mbed_official | 237:f3da66175598 | 1044 | { |
mbed_official | 237:f3da66175598 | 1045 | /* Set CALIBCNT[1:0] bits in SDADC_CR2 register */ |
mbed_official | 237:f3da66175598 | 1046 | hsdadc->Instance->CR2 &= ~(SDADC_CR2_CALIBCNT); |
mbed_official | 237:f3da66175598 | 1047 | hsdadc->Instance->CR2 |= CalibrationSequence; |
mbed_official | 237:f3da66175598 | 1048 | |
mbed_official | 237:f3da66175598 | 1049 | /* Exit init mode */ |
mbed_official | 237:f3da66175598 | 1050 | SDADC_ExitInitMode(hsdadc); |
mbed_official | 237:f3da66175598 | 1051 | |
mbed_official | 237:f3da66175598 | 1052 | /* Set EOCALIE bit in SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 1053 | hsdadc->Instance->CR1 |= SDADC_CR1_EOCALIE; |
mbed_official | 237:f3da66175598 | 1054 | |
mbed_official | 237:f3da66175598 | 1055 | /* Set STARTCALIB in SDADC_CR2 */ |
mbed_official | 237:f3da66175598 | 1056 | hsdadc->Instance->CR2 |= SDADC_CR2_STARTCALIB; |
mbed_official | 237:f3da66175598 | 1057 | |
mbed_official | 237:f3da66175598 | 1058 | /* Set SDADC in calibration state */ |
mbed_official | 237:f3da66175598 | 1059 | hsdadc->State = HAL_SDADC_STATE_CALIB; |
mbed_official | 237:f3da66175598 | 1060 | } |
mbed_official | 237:f3da66175598 | 1061 | } |
mbed_official | 237:f3da66175598 | 1062 | else |
mbed_official | 237:f3da66175598 | 1063 | { |
mbed_official | 237:f3da66175598 | 1064 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1065 | } |
mbed_official | 237:f3da66175598 | 1066 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 1067 | return status; |
mbed_official | 237:f3da66175598 | 1068 | } |
mbed_official | 237:f3da66175598 | 1069 | |
mbed_official | 237:f3da66175598 | 1070 | /** |
mbed_official | 237:f3da66175598 | 1071 | * @brief This function allows to start regular conversion in polling mode. |
mbed_official | 237:f3da66175598 | 1072 | * @note This function should be called only when SDADC instance is in idle state |
mbed_official | 237:f3da66175598 | 1073 | * or if injected conversion is ongoing. |
mbed_official | 237:f3da66175598 | 1074 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1075 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1076 | */ |
mbed_official | 237:f3da66175598 | 1077 | HAL_StatusTypeDef HAL_SDADC_Start(SDADC_HandleTypeDef *hsdadc) |
mbed_official | 237:f3da66175598 | 1078 | { |
mbed_official | 237:f3da66175598 | 1079 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 1080 | |
mbed_official | 237:f3da66175598 | 1081 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 1082 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1083 | |
mbed_official | 237:f3da66175598 | 1084 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 1085 | if((hsdadc->State == HAL_SDADC_STATE_READY) || \ |
mbed_official | 237:f3da66175598 | 1086 | (hsdadc->State == HAL_SDADC_STATE_INJ)) |
mbed_official | 237:f3da66175598 | 1087 | { |
mbed_official | 237:f3da66175598 | 1088 | /* Start regular conversion */ |
mbed_official | 237:f3da66175598 | 1089 | status = SDADC_RegConvStart(hsdadc); |
mbed_official | 237:f3da66175598 | 1090 | } |
mbed_official | 237:f3da66175598 | 1091 | else |
mbed_official | 237:f3da66175598 | 1092 | { |
mbed_official | 237:f3da66175598 | 1093 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1094 | } |
mbed_official | 237:f3da66175598 | 1095 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 1096 | return status; |
mbed_official | 237:f3da66175598 | 1097 | } |
mbed_official | 237:f3da66175598 | 1098 | |
mbed_official | 237:f3da66175598 | 1099 | /** |
mbed_official | 237:f3da66175598 | 1100 | * @brief This function allows to poll for the end of regular conversion. |
mbed_official | 237:f3da66175598 | 1101 | * @note This function should be called only if regular conversion is ongoing. |
mbed_official | 237:f3da66175598 | 1102 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1103 | * @param Timeout : Timeout value in milliseconds. |
mbed_official | 237:f3da66175598 | 1104 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1105 | */ |
mbed_official | 237:f3da66175598 | 1106 | HAL_StatusTypeDef HAL_SDADC_PollForConversion(SDADC_HandleTypeDef* hsdadc, uint32_t Timeout) |
mbed_official | 237:f3da66175598 | 1107 | { |
mbed_official | 237:f3da66175598 | 1108 | uint32_t tickstart; |
mbed_official | 237:f3da66175598 | 1109 | |
mbed_official | 237:f3da66175598 | 1110 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 1111 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1112 | |
mbed_official | 237:f3da66175598 | 1113 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 1114 | if((hsdadc->State != HAL_SDADC_STATE_REG) && \ |
mbed_official | 237:f3da66175598 | 1115 | (hsdadc->State != HAL_SDADC_STATE_REG_INJ)) |
mbed_official | 237:f3da66175598 | 1116 | { |
mbed_official | 237:f3da66175598 | 1117 | /* Return error status */ |
mbed_official | 237:f3da66175598 | 1118 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1119 | } |
mbed_official | 237:f3da66175598 | 1120 | else |
mbed_official | 237:f3da66175598 | 1121 | { |
mbed_official | 237:f3da66175598 | 1122 | /* Get timeout */ |
mbed_official | 237:f3da66175598 | 1123 | tickstart = HAL_GetTick(); |
mbed_official | 237:f3da66175598 | 1124 | |
mbed_official | 237:f3da66175598 | 1125 | /* Wait REOCF bit in SDADC_ISR register */ |
mbed_official | 237:f3da66175598 | 1126 | while((hsdadc->Instance->ISR & SDADC_ISR_REOCF) != SDADC_ISR_REOCF) |
mbed_official | 237:f3da66175598 | 1127 | { |
mbed_official | 237:f3da66175598 | 1128 | /* Check the Timeout */ |
mbed_official | 237:f3da66175598 | 1129 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 237:f3da66175598 | 1130 | { |
mbed_official | 237:f3da66175598 | 1131 | if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout)) |
mbed_official | 237:f3da66175598 | 1132 | { |
mbed_official | 237:f3da66175598 | 1133 | /* Return timeout status */ |
mbed_official | 237:f3da66175598 | 1134 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 1135 | } |
mbed_official | 237:f3da66175598 | 1136 | } |
mbed_official | 237:f3da66175598 | 1137 | } |
mbed_official | 237:f3da66175598 | 1138 | /* Check if overrun occurs */ |
mbed_official | 237:f3da66175598 | 1139 | if((hsdadc->Instance->ISR & SDADC_ISR_ROVRF) == SDADC_ISR_ROVRF) |
mbed_official | 237:f3da66175598 | 1140 | { |
mbed_official | 237:f3da66175598 | 1141 | /* Update error code and call error callback */ |
mbed_official | 237:f3da66175598 | 1142 | hsdadc->ErrorCode = SDADC_ERROR_REGULAR_OVERRUN; |
mbed_official | 237:f3da66175598 | 1143 | HAL_SDADC_ErrorCallback(hsdadc); |
mbed_official | 237:f3da66175598 | 1144 | |
mbed_official | 237:f3da66175598 | 1145 | /* Set CLRROVRF bit in SDADC_CLRISR register */ |
mbed_official | 237:f3da66175598 | 1146 | hsdadc->Instance->CLRISR |= SDADC_ISR_CLRROVRF; |
mbed_official | 237:f3da66175598 | 1147 | } |
mbed_official | 237:f3da66175598 | 1148 | /* Update SDADC state only if not continuous conversion and SW trigger */ |
mbed_official | 237:f3da66175598 | 1149 | if((hsdadc->RegularContMode == SDADC_CONTINUOUS_CONV_OFF) && \ |
mbed_official | 237:f3da66175598 | 1150 | (hsdadc->RegularTrigger == SDADC_SOFTWARE_TRIGGER)) |
mbed_official | 237:f3da66175598 | 1151 | { |
mbed_official | 237:f3da66175598 | 1152 | hsdadc->State = (hsdadc->State == HAL_SDADC_STATE_REG) ? \ |
mbed_official | 237:f3da66175598 | 1153 | HAL_SDADC_STATE_READY : HAL_SDADC_STATE_INJ; |
mbed_official | 237:f3da66175598 | 1154 | } |
mbed_official | 237:f3da66175598 | 1155 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 1156 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 1157 | } |
mbed_official | 237:f3da66175598 | 1158 | } |
mbed_official | 237:f3da66175598 | 1159 | |
mbed_official | 237:f3da66175598 | 1160 | /** |
mbed_official | 237:f3da66175598 | 1161 | * @brief This function allows to stop regular conversion in polling mode. |
mbed_official | 237:f3da66175598 | 1162 | * @note This function should be called only if regular conversion is ongoing. |
mbed_official | 237:f3da66175598 | 1163 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1164 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1165 | */ |
mbed_official | 237:f3da66175598 | 1166 | HAL_StatusTypeDef HAL_SDADC_Stop(SDADC_HandleTypeDef *hsdadc) |
mbed_official | 237:f3da66175598 | 1167 | { |
mbed_official | 237:f3da66175598 | 1168 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 1169 | |
mbed_official | 237:f3da66175598 | 1170 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 1171 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1172 | |
mbed_official | 237:f3da66175598 | 1173 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 1174 | if((hsdadc->State != HAL_SDADC_STATE_REG) && \ |
mbed_official | 237:f3da66175598 | 1175 | (hsdadc->State != HAL_SDADC_STATE_REG_INJ)) |
mbed_official | 237:f3da66175598 | 1176 | { |
mbed_official | 237:f3da66175598 | 1177 | /* Return error status */ |
mbed_official | 237:f3da66175598 | 1178 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1179 | } |
mbed_official | 237:f3da66175598 | 1180 | else |
mbed_official | 237:f3da66175598 | 1181 | { |
mbed_official | 237:f3da66175598 | 1182 | /* Stop regular conversion */ |
mbed_official | 237:f3da66175598 | 1183 | status = SDADC_RegConvStop(hsdadc); |
mbed_official | 237:f3da66175598 | 1184 | } |
mbed_official | 237:f3da66175598 | 1185 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 1186 | return status; |
mbed_official | 237:f3da66175598 | 1187 | } |
mbed_official | 237:f3da66175598 | 1188 | |
mbed_official | 237:f3da66175598 | 1189 | /** |
mbed_official | 237:f3da66175598 | 1190 | * @brief This function allows to start regular conversion in interrupt mode. |
mbed_official | 237:f3da66175598 | 1191 | * @note This function should be called only when SDADC instance is in idle state |
mbed_official | 237:f3da66175598 | 1192 | * or if injected conversion is ongoing. |
mbed_official | 237:f3da66175598 | 1193 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1194 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1195 | */ |
mbed_official | 237:f3da66175598 | 1196 | HAL_StatusTypeDef HAL_SDADC_Start_IT(SDADC_HandleTypeDef *hsdadc) |
mbed_official | 237:f3da66175598 | 1197 | { |
mbed_official | 237:f3da66175598 | 1198 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 1199 | |
mbed_official | 237:f3da66175598 | 1200 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 1201 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1202 | |
mbed_official | 237:f3da66175598 | 1203 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 1204 | if((hsdadc->State == HAL_SDADC_STATE_READY) || \ |
mbed_official | 237:f3da66175598 | 1205 | (hsdadc->State == HAL_SDADC_STATE_INJ)) |
mbed_official | 237:f3da66175598 | 1206 | { |
mbed_official | 237:f3da66175598 | 1207 | /* Set REOCIE and ROVRIE bits in SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 1208 | hsdadc->Instance->CR1 |= (uint32_t) (SDADC_CR1_REOCIE | SDADC_CR1_ROVRIE); |
mbed_official | 237:f3da66175598 | 1209 | |
mbed_official | 237:f3da66175598 | 1210 | /* Start regular conversion */ |
mbed_official | 237:f3da66175598 | 1211 | status = SDADC_RegConvStart(hsdadc); |
mbed_official | 237:f3da66175598 | 1212 | } |
mbed_official | 237:f3da66175598 | 1213 | else |
mbed_official | 237:f3da66175598 | 1214 | { |
mbed_official | 237:f3da66175598 | 1215 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1216 | } |
mbed_official | 237:f3da66175598 | 1217 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 1218 | return status; |
mbed_official | 237:f3da66175598 | 1219 | } |
mbed_official | 237:f3da66175598 | 1220 | |
mbed_official | 237:f3da66175598 | 1221 | /** |
mbed_official | 237:f3da66175598 | 1222 | * @brief This function allows to stop regular conversion in interrupt mode. |
mbed_official | 237:f3da66175598 | 1223 | * @note This function should be called only if regular conversion is ongoing. |
mbed_official | 237:f3da66175598 | 1224 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1225 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1226 | */ |
mbed_official | 237:f3da66175598 | 1227 | HAL_StatusTypeDef HAL_SDADC_Stop_IT(SDADC_HandleTypeDef *hsdadc) |
mbed_official | 237:f3da66175598 | 1228 | { |
mbed_official | 237:f3da66175598 | 1229 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 1230 | |
mbed_official | 237:f3da66175598 | 1231 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 1232 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1233 | |
mbed_official | 237:f3da66175598 | 1234 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 1235 | if((hsdadc->State != HAL_SDADC_STATE_REG) && \ |
mbed_official | 237:f3da66175598 | 1236 | (hsdadc->State != HAL_SDADC_STATE_REG_INJ)) |
mbed_official | 237:f3da66175598 | 1237 | { |
mbed_official | 237:f3da66175598 | 1238 | /* Return error status */ |
mbed_official | 237:f3da66175598 | 1239 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1240 | } |
mbed_official | 237:f3da66175598 | 1241 | else |
mbed_official | 237:f3da66175598 | 1242 | { |
mbed_official | 237:f3da66175598 | 1243 | /* Clear REOCIE and ROVRIE bits in SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 1244 | hsdadc->Instance->CR1 &= (uint32_t) ~(SDADC_CR1_REOCIE | SDADC_CR1_ROVRIE); |
mbed_official | 237:f3da66175598 | 1245 | |
mbed_official | 237:f3da66175598 | 1246 | /* Stop regular conversion */ |
mbed_official | 237:f3da66175598 | 1247 | status = SDADC_RegConvStop(hsdadc); |
mbed_official | 237:f3da66175598 | 1248 | } |
mbed_official | 237:f3da66175598 | 1249 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 1250 | return status; |
mbed_official | 237:f3da66175598 | 1251 | } |
mbed_official | 237:f3da66175598 | 1252 | |
mbed_official | 237:f3da66175598 | 1253 | /** |
mbed_official | 237:f3da66175598 | 1254 | * @brief This function allows to start regular conversion in DMA mode. |
mbed_official | 237:f3da66175598 | 1255 | * @note This function should be called only when SDADC instance is in idle state |
mbed_official | 237:f3da66175598 | 1256 | * or if injected conversion is ongoing. |
mbed_official | 237:f3da66175598 | 1257 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1258 | * @param pData : The destination buffer address. |
mbed_official | 237:f3da66175598 | 1259 | * @param Length : The length of data to be transferred from SDADC peripheral to memory. |
mbed_official | 237:f3da66175598 | 1260 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1261 | */ |
mbed_official | 237:f3da66175598 | 1262 | HAL_StatusTypeDef HAL_SDADC_Start_DMA(SDADC_HandleTypeDef *hsdadc, uint32_t *pData, |
mbed_official | 237:f3da66175598 | 1263 | uint32_t Length) |
mbed_official | 237:f3da66175598 | 1264 | { |
mbed_official | 237:f3da66175598 | 1265 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 1266 | |
mbed_official | 237:f3da66175598 | 1267 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 1268 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1269 | assert_param(pData != NULL); |
mbed_official | 237:f3da66175598 | 1270 | assert_param(Length != 0); |
mbed_official | 237:f3da66175598 | 1271 | |
mbed_official | 237:f3da66175598 | 1272 | /* Check that DMA is not enabled for injected conversion */ |
mbed_official | 237:f3da66175598 | 1273 | if((hsdadc->Instance->CR1 & SDADC_CR1_JDMAEN) == SDADC_CR1_JDMAEN) |
mbed_official | 237:f3da66175598 | 1274 | { |
mbed_official | 237:f3da66175598 | 1275 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1276 | } |
mbed_official | 237:f3da66175598 | 1277 | /* Check parameters compatibility */ |
mbed_official | 237:f3da66175598 | 1278 | else if((hsdadc->RegularTrigger == SDADC_SOFTWARE_TRIGGER) && \ |
mbed_official | 237:f3da66175598 | 1279 | (hsdadc->RegularContMode == SDADC_CONTINUOUS_CONV_OFF) && \ |
mbed_official | 237:f3da66175598 | 1280 | (hsdadc->hdma->Init.Mode == DMA_NORMAL) && \ |
mbed_official | 237:f3da66175598 | 1281 | (Length != 1)) |
mbed_official | 237:f3da66175598 | 1282 | { |
mbed_official | 237:f3da66175598 | 1283 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1284 | } |
mbed_official | 237:f3da66175598 | 1285 | else if((hsdadc->RegularTrigger == SDADC_SOFTWARE_TRIGGER) && \ |
mbed_official | 237:f3da66175598 | 1286 | (hsdadc->RegularContMode == SDADC_CONTINUOUS_CONV_OFF) && \ |
mbed_official | 237:f3da66175598 | 1287 | (hsdadc->hdma->Init.Mode == DMA_CIRCULAR)) |
mbed_official | 237:f3da66175598 | 1288 | { |
mbed_official | 237:f3da66175598 | 1289 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1290 | } |
mbed_official | 237:f3da66175598 | 1291 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 1292 | else if((hsdadc->State == HAL_SDADC_STATE_READY) || \ |
mbed_official | 237:f3da66175598 | 1293 | (hsdadc->State == HAL_SDADC_STATE_INJ)) |
mbed_official | 237:f3da66175598 | 1294 | { |
mbed_official | 237:f3da66175598 | 1295 | /* Set callbacks on DMA handler */ |
mbed_official | 237:f3da66175598 | 1296 | hsdadc->hdma->XferCpltCallback = SDADC_DMARegularConvCplt; |
mbed_official | 237:f3da66175598 | 1297 | hsdadc->hdma->XferErrorCallback = SDADC_DMAError; |
mbed_official | 237:f3da66175598 | 1298 | if(hsdadc->hdma->Init.Mode == DMA_CIRCULAR) |
mbed_official | 237:f3da66175598 | 1299 | { |
mbed_official | 237:f3da66175598 | 1300 | hsdadc->hdma->XferHalfCpltCallback = SDADC_DMARegularHalfConvCplt; |
mbed_official | 237:f3da66175598 | 1301 | } |
mbed_official | 237:f3da66175598 | 1302 | |
mbed_official | 237:f3da66175598 | 1303 | /* Set RDMAEN bit in SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 1304 | hsdadc->Instance->CR1 |= SDADC_CR1_RDMAEN; |
mbed_official | 237:f3da66175598 | 1305 | |
mbed_official | 237:f3da66175598 | 1306 | /* Start DMA in interrupt mode */ |
mbed_official | 237:f3da66175598 | 1307 | if(HAL_DMA_Start_IT(hsdadc->hdma, (uint32_t)&hsdadc->Instance->RDATAR, \ |
mbed_official | 237:f3da66175598 | 1308 | (uint32_t) pData, Length) != HAL_OK) |
mbed_official | 237:f3da66175598 | 1309 | { |
mbed_official | 237:f3da66175598 | 1310 | /* Set SDADC in error state */ |
mbed_official | 237:f3da66175598 | 1311 | hsdadc->State = HAL_SDADC_STATE_ERROR; |
mbed_official | 237:f3da66175598 | 1312 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1313 | } |
mbed_official | 237:f3da66175598 | 1314 | else |
mbed_official | 237:f3da66175598 | 1315 | { |
mbed_official | 237:f3da66175598 | 1316 | /* Start regular conversion */ |
mbed_official | 237:f3da66175598 | 1317 | status = SDADC_RegConvStart(hsdadc); |
mbed_official | 237:f3da66175598 | 1318 | } |
mbed_official | 237:f3da66175598 | 1319 | } |
mbed_official | 237:f3da66175598 | 1320 | else |
mbed_official | 237:f3da66175598 | 1321 | { |
mbed_official | 237:f3da66175598 | 1322 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1323 | } |
mbed_official | 237:f3da66175598 | 1324 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 1325 | return status; |
mbed_official | 237:f3da66175598 | 1326 | } |
mbed_official | 237:f3da66175598 | 1327 | |
mbed_official | 237:f3da66175598 | 1328 | /** |
mbed_official | 237:f3da66175598 | 1329 | * @brief This function allows to stop regular conversion in DMA mode. |
mbed_official | 237:f3da66175598 | 1330 | * @note This function should be called only if regular conversion is ongoing. |
mbed_official | 237:f3da66175598 | 1331 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1332 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1333 | */ |
mbed_official | 237:f3da66175598 | 1334 | HAL_StatusTypeDef HAL_SDADC_Stop_DMA(SDADC_HandleTypeDef *hsdadc) |
mbed_official | 237:f3da66175598 | 1335 | { |
mbed_official | 237:f3da66175598 | 1336 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 1337 | |
mbed_official | 237:f3da66175598 | 1338 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 1339 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1340 | |
mbed_official | 237:f3da66175598 | 1341 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 1342 | if((hsdadc->State != HAL_SDADC_STATE_REG) && \ |
mbed_official | 237:f3da66175598 | 1343 | (hsdadc->State != HAL_SDADC_STATE_REG_INJ)) |
mbed_official | 237:f3da66175598 | 1344 | { |
mbed_official | 237:f3da66175598 | 1345 | /* Return error status */ |
mbed_official | 237:f3da66175598 | 1346 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1347 | } |
mbed_official | 237:f3da66175598 | 1348 | else |
mbed_official | 237:f3da66175598 | 1349 | { |
mbed_official | 237:f3da66175598 | 1350 | /* Clear RDMAEN bit in SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 1351 | hsdadc->Instance->CR1 &= ~(SDADC_CR1_RDMAEN); |
mbed_official | 237:f3da66175598 | 1352 | |
mbed_official | 237:f3da66175598 | 1353 | /* Stop current DMA transfer */ |
mbed_official | 237:f3da66175598 | 1354 | if(HAL_DMA_Abort(hsdadc->hdma) != HAL_OK) |
mbed_official | 237:f3da66175598 | 1355 | { |
mbed_official | 237:f3da66175598 | 1356 | /* Set SDADC in error state */ |
mbed_official | 237:f3da66175598 | 1357 | hsdadc->State = HAL_SDADC_STATE_ERROR; |
mbed_official | 237:f3da66175598 | 1358 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1359 | } |
mbed_official | 237:f3da66175598 | 1360 | else |
mbed_official | 237:f3da66175598 | 1361 | { |
mbed_official | 237:f3da66175598 | 1362 | /* Stop regular conversion */ |
mbed_official | 237:f3da66175598 | 1363 | status = SDADC_RegConvStop(hsdadc); |
mbed_official | 237:f3da66175598 | 1364 | } |
mbed_official | 237:f3da66175598 | 1365 | } |
mbed_official | 237:f3da66175598 | 1366 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 1367 | return status; |
mbed_official | 237:f3da66175598 | 1368 | } |
mbed_official | 237:f3da66175598 | 1369 | |
mbed_official | 237:f3da66175598 | 1370 | /** |
mbed_official | 237:f3da66175598 | 1371 | * @brief This function allows to get regular conversion value. |
mbed_official | 237:f3da66175598 | 1372 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1373 | * @retval Regular conversion value |
mbed_official | 237:f3da66175598 | 1374 | */ |
mbed_official | 237:f3da66175598 | 1375 | uint32_t HAL_SDADC_GetValue(SDADC_HandleTypeDef *hsdadc) |
mbed_official | 237:f3da66175598 | 1376 | { |
mbed_official | 237:f3da66175598 | 1377 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 1378 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1379 | |
mbed_official | 237:f3da66175598 | 1380 | /* Return regular conversion value */ |
mbed_official | 237:f3da66175598 | 1381 | return hsdadc->Instance->RDATAR; |
mbed_official | 237:f3da66175598 | 1382 | } |
mbed_official | 237:f3da66175598 | 1383 | |
mbed_official | 237:f3da66175598 | 1384 | /** |
mbed_official | 237:f3da66175598 | 1385 | * @brief This function allows to start injected conversion in polling mode. |
mbed_official | 237:f3da66175598 | 1386 | * @note This function should be called only when SDADC instance is in idle state |
mbed_official | 237:f3da66175598 | 1387 | * or if regular conversion is ongoing. |
mbed_official | 237:f3da66175598 | 1388 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1389 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1390 | */ |
mbed_official | 237:f3da66175598 | 1391 | HAL_StatusTypeDef HAL_SDADC_InjectedStart(SDADC_HandleTypeDef *hsdadc) |
mbed_official | 237:f3da66175598 | 1392 | { |
mbed_official | 237:f3da66175598 | 1393 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 1394 | |
mbed_official | 237:f3da66175598 | 1395 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 1396 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1397 | |
mbed_official | 237:f3da66175598 | 1398 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 1399 | if((hsdadc->State == HAL_SDADC_STATE_READY) || \ |
mbed_official | 237:f3da66175598 | 1400 | (hsdadc->State == HAL_SDADC_STATE_REG)) |
mbed_official | 237:f3da66175598 | 1401 | { |
mbed_official | 237:f3da66175598 | 1402 | /* Start injected conversion */ |
mbed_official | 237:f3da66175598 | 1403 | status = SDADC_InjConvStart(hsdadc); |
mbed_official | 237:f3da66175598 | 1404 | } |
mbed_official | 237:f3da66175598 | 1405 | else |
mbed_official | 237:f3da66175598 | 1406 | { |
mbed_official | 237:f3da66175598 | 1407 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1408 | } |
mbed_official | 237:f3da66175598 | 1409 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 1410 | return status; |
mbed_official | 237:f3da66175598 | 1411 | } |
mbed_official | 237:f3da66175598 | 1412 | |
mbed_official | 237:f3da66175598 | 1413 | /** |
mbed_official | 237:f3da66175598 | 1414 | * @brief This function allows to poll for the end of injected conversion. |
mbed_official | 237:f3da66175598 | 1415 | * @note This function should be called only if injected conversion is ongoing. |
mbed_official | 237:f3da66175598 | 1416 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1417 | * @param Timeout : Timeout value in milliseconds. |
mbed_official | 237:f3da66175598 | 1418 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1419 | */ |
mbed_official | 237:f3da66175598 | 1420 | HAL_StatusTypeDef HAL_SDADC_PollForInjectedConversion(SDADC_HandleTypeDef* hsdadc, |
mbed_official | 237:f3da66175598 | 1421 | uint32_t Timeout) |
mbed_official | 237:f3da66175598 | 1422 | { |
mbed_official | 237:f3da66175598 | 1423 | uint32_t tickstart; |
mbed_official | 237:f3da66175598 | 1424 | |
mbed_official | 237:f3da66175598 | 1425 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 1426 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1427 | |
mbed_official | 237:f3da66175598 | 1428 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 1429 | if((hsdadc->State != HAL_SDADC_STATE_INJ) && \ |
mbed_official | 237:f3da66175598 | 1430 | (hsdadc->State != HAL_SDADC_STATE_REG_INJ)) |
mbed_official | 237:f3da66175598 | 1431 | { |
mbed_official | 237:f3da66175598 | 1432 | /* Return error status */ |
mbed_official | 237:f3da66175598 | 1433 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1434 | } |
mbed_official | 237:f3da66175598 | 1435 | else |
mbed_official | 237:f3da66175598 | 1436 | { |
mbed_official | 237:f3da66175598 | 1437 | /* Get timeout */ |
mbed_official | 237:f3da66175598 | 1438 | tickstart = HAL_GetTick(); |
mbed_official | 237:f3da66175598 | 1439 | |
mbed_official | 237:f3da66175598 | 1440 | /* Wait JEOCF bit in SDADC_ISR register */ |
mbed_official | 237:f3da66175598 | 1441 | while((hsdadc->Instance->ISR & SDADC_ISR_JEOCF) != SDADC_ISR_JEOCF) |
mbed_official | 237:f3da66175598 | 1442 | { |
mbed_official | 237:f3da66175598 | 1443 | /* Check the Timeout */ |
mbed_official | 237:f3da66175598 | 1444 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 237:f3da66175598 | 1445 | { |
mbed_official | 237:f3da66175598 | 1446 | if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout)) |
mbed_official | 237:f3da66175598 | 1447 | { |
mbed_official | 237:f3da66175598 | 1448 | /* Return timeout status */ |
mbed_official | 237:f3da66175598 | 1449 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 1450 | } |
mbed_official | 237:f3da66175598 | 1451 | } |
mbed_official | 237:f3da66175598 | 1452 | } |
mbed_official | 237:f3da66175598 | 1453 | /* Check if overrun occurs */ |
mbed_official | 237:f3da66175598 | 1454 | if((hsdadc->Instance->ISR & SDADC_ISR_JOVRF) == SDADC_ISR_JOVRF) |
mbed_official | 237:f3da66175598 | 1455 | { |
mbed_official | 237:f3da66175598 | 1456 | /* Update error code and call error callback */ |
mbed_official | 237:f3da66175598 | 1457 | hsdadc->ErrorCode = SDADC_ERROR_INJECTED_OVERRUN; |
mbed_official | 237:f3da66175598 | 1458 | HAL_SDADC_ErrorCallback(hsdadc); |
mbed_official | 237:f3da66175598 | 1459 | |
mbed_official | 237:f3da66175598 | 1460 | /* Set CLRJOVRF bit in SDADC_CLRISR register */ |
mbed_official | 237:f3da66175598 | 1461 | hsdadc->Instance->CLRISR |= SDADC_ISR_CLRJOVRF; |
mbed_official | 237:f3da66175598 | 1462 | } |
mbed_official | 237:f3da66175598 | 1463 | /* Update remaining injected conversions */ |
mbed_official | 237:f3da66175598 | 1464 | hsdadc->InjConvRemaining--; |
mbed_official | 237:f3da66175598 | 1465 | if(hsdadc->InjConvRemaining == 0) |
mbed_official | 237:f3da66175598 | 1466 | { |
mbed_official | 237:f3da66175598 | 1467 | /* end of injected sequence, reset the value */ |
mbed_official | 237:f3da66175598 | 1468 | hsdadc->InjConvRemaining = hsdadc->InjectedChannelsNbr; |
mbed_official | 237:f3da66175598 | 1469 | } |
mbed_official | 237:f3da66175598 | 1470 | |
mbed_official | 237:f3da66175598 | 1471 | /* Update SDADC state only if not continuous conversion, SW trigger */ |
mbed_official | 237:f3da66175598 | 1472 | /* and end of injected sequence */ |
mbed_official | 237:f3da66175598 | 1473 | if((hsdadc->InjectedContMode == SDADC_CONTINUOUS_CONV_OFF) && \ |
mbed_official | 237:f3da66175598 | 1474 | (hsdadc->InjectedTrigger == SDADC_SOFTWARE_TRIGGER) && \ |
mbed_official | 237:f3da66175598 | 1475 | (hsdadc->InjConvRemaining == hsdadc->InjectedChannelsNbr)) |
mbed_official | 237:f3da66175598 | 1476 | { |
mbed_official | 237:f3da66175598 | 1477 | hsdadc->State = (hsdadc->State == HAL_SDADC_STATE_INJ) ? \ |
mbed_official | 237:f3da66175598 | 1478 | HAL_SDADC_STATE_READY : HAL_SDADC_STATE_REG; |
mbed_official | 237:f3da66175598 | 1479 | } |
mbed_official | 237:f3da66175598 | 1480 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 1481 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 1482 | } |
mbed_official | 237:f3da66175598 | 1483 | } |
mbed_official | 237:f3da66175598 | 1484 | |
mbed_official | 237:f3da66175598 | 1485 | /** |
mbed_official | 237:f3da66175598 | 1486 | * @brief This function allows to stop injected conversion in polling mode. |
mbed_official | 237:f3da66175598 | 1487 | * @note This function should be called only if injected conversion is ongoing. |
mbed_official | 237:f3da66175598 | 1488 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1489 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1490 | */ |
mbed_official | 237:f3da66175598 | 1491 | HAL_StatusTypeDef HAL_SDADC_InjectedStop(SDADC_HandleTypeDef *hsdadc) |
mbed_official | 237:f3da66175598 | 1492 | { |
mbed_official | 237:f3da66175598 | 1493 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 1494 | |
mbed_official | 237:f3da66175598 | 1495 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 1496 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1497 | |
mbed_official | 237:f3da66175598 | 1498 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 1499 | if((hsdadc->State != HAL_SDADC_STATE_INJ) && \ |
mbed_official | 237:f3da66175598 | 1500 | (hsdadc->State != HAL_SDADC_STATE_REG_INJ)) |
mbed_official | 237:f3da66175598 | 1501 | { |
mbed_official | 237:f3da66175598 | 1502 | /* Return error status */ |
mbed_official | 237:f3da66175598 | 1503 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1504 | } |
mbed_official | 237:f3da66175598 | 1505 | else |
mbed_official | 237:f3da66175598 | 1506 | { |
mbed_official | 237:f3da66175598 | 1507 | /* Stop injected conversion */ |
mbed_official | 237:f3da66175598 | 1508 | status = SDADC_InjConvStop(hsdadc); |
mbed_official | 237:f3da66175598 | 1509 | } |
mbed_official | 237:f3da66175598 | 1510 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 1511 | return status; |
mbed_official | 237:f3da66175598 | 1512 | } |
mbed_official | 237:f3da66175598 | 1513 | |
mbed_official | 237:f3da66175598 | 1514 | /** |
mbed_official | 237:f3da66175598 | 1515 | * @brief This function allows to start injected conversion in interrupt mode. |
mbed_official | 237:f3da66175598 | 1516 | * @note This function should be called only when SDADC instance is in idle state |
mbed_official | 237:f3da66175598 | 1517 | * or if regular conversion is ongoing. |
mbed_official | 237:f3da66175598 | 1518 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1519 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1520 | */ |
mbed_official | 237:f3da66175598 | 1521 | HAL_StatusTypeDef HAL_SDADC_InjectedStart_IT(SDADC_HandleTypeDef *hsdadc) |
mbed_official | 237:f3da66175598 | 1522 | { |
mbed_official | 237:f3da66175598 | 1523 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 1524 | |
mbed_official | 237:f3da66175598 | 1525 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 1526 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1527 | |
mbed_official | 237:f3da66175598 | 1528 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 1529 | if((hsdadc->State == HAL_SDADC_STATE_READY) || \ |
mbed_official | 237:f3da66175598 | 1530 | (hsdadc->State == HAL_SDADC_STATE_REG)) |
mbed_official | 237:f3da66175598 | 1531 | { |
mbed_official | 237:f3da66175598 | 1532 | /* Set JEOCIE and JOVRIE bits in SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 1533 | hsdadc->Instance->CR1 |= (uint32_t) (SDADC_CR1_JEOCIE | SDADC_CR1_JOVRIE); |
mbed_official | 237:f3da66175598 | 1534 | |
mbed_official | 237:f3da66175598 | 1535 | /* Start injected conversion */ |
mbed_official | 237:f3da66175598 | 1536 | status = SDADC_InjConvStart(hsdadc); |
mbed_official | 237:f3da66175598 | 1537 | } |
mbed_official | 237:f3da66175598 | 1538 | else |
mbed_official | 237:f3da66175598 | 1539 | { |
mbed_official | 237:f3da66175598 | 1540 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1541 | } |
mbed_official | 237:f3da66175598 | 1542 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 1543 | return status; |
mbed_official | 237:f3da66175598 | 1544 | } |
mbed_official | 237:f3da66175598 | 1545 | |
mbed_official | 237:f3da66175598 | 1546 | /** |
mbed_official | 237:f3da66175598 | 1547 | * @brief This function allows to stop injected conversion in interrupt mode. |
mbed_official | 237:f3da66175598 | 1548 | * @note This function should be called only if injected conversion is ongoing. |
mbed_official | 237:f3da66175598 | 1549 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1550 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1551 | */ |
mbed_official | 237:f3da66175598 | 1552 | HAL_StatusTypeDef HAL_SDADC_InjectedStop_IT(SDADC_HandleTypeDef *hsdadc) |
mbed_official | 237:f3da66175598 | 1553 | { |
mbed_official | 237:f3da66175598 | 1554 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 1555 | |
mbed_official | 237:f3da66175598 | 1556 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 1557 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1558 | |
mbed_official | 237:f3da66175598 | 1559 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 1560 | if((hsdadc->State != HAL_SDADC_STATE_INJ) && \ |
mbed_official | 237:f3da66175598 | 1561 | (hsdadc->State != HAL_SDADC_STATE_REG_INJ)) |
mbed_official | 237:f3da66175598 | 1562 | { |
mbed_official | 237:f3da66175598 | 1563 | /* Return error status */ |
mbed_official | 237:f3da66175598 | 1564 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1565 | } |
mbed_official | 237:f3da66175598 | 1566 | else |
mbed_official | 237:f3da66175598 | 1567 | { |
mbed_official | 237:f3da66175598 | 1568 | /* Clear JEOCIE and JOVRIE bits in SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 1569 | hsdadc->Instance->CR1 &= (uint32_t) ~(SDADC_CR1_JEOCIE | SDADC_CR1_JOVRIE); |
mbed_official | 237:f3da66175598 | 1570 | |
mbed_official | 237:f3da66175598 | 1571 | /* Stop injected conversion */ |
mbed_official | 237:f3da66175598 | 1572 | status = SDADC_InjConvStop(hsdadc); |
mbed_official | 237:f3da66175598 | 1573 | } |
mbed_official | 237:f3da66175598 | 1574 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 1575 | return status; |
mbed_official | 237:f3da66175598 | 1576 | } |
mbed_official | 237:f3da66175598 | 1577 | |
mbed_official | 237:f3da66175598 | 1578 | /** |
mbed_official | 237:f3da66175598 | 1579 | * @brief This function allows to start injected conversion in DMA mode. |
mbed_official | 237:f3da66175598 | 1580 | * @note This function should be called only when SDADC instance is in idle state |
mbed_official | 237:f3da66175598 | 1581 | * or if regular conversion is ongoing. |
mbed_official | 237:f3da66175598 | 1582 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1583 | * @param pData : The destination buffer address. |
mbed_official | 237:f3da66175598 | 1584 | * @param Length : The length of data to be transferred from SDADC peripheral to memory. |
mbed_official | 237:f3da66175598 | 1585 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1586 | */ |
mbed_official | 237:f3da66175598 | 1587 | HAL_StatusTypeDef HAL_SDADC_InjectedStart_DMA(SDADC_HandleTypeDef *hsdadc, uint32_t *pData, |
mbed_official | 237:f3da66175598 | 1588 | uint32_t Length) |
mbed_official | 237:f3da66175598 | 1589 | { |
mbed_official | 237:f3da66175598 | 1590 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 1591 | |
mbed_official | 237:f3da66175598 | 1592 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 1593 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1594 | assert_param(pData != NULL); |
mbed_official | 237:f3da66175598 | 1595 | assert_param(Length != 0); |
mbed_official | 237:f3da66175598 | 1596 | |
mbed_official | 237:f3da66175598 | 1597 | /* Check that DMA is not enabled for regular conversion */ |
mbed_official | 237:f3da66175598 | 1598 | if((hsdadc->Instance->CR1 & SDADC_CR1_RDMAEN) == SDADC_CR1_RDMAEN) |
mbed_official | 237:f3da66175598 | 1599 | { |
mbed_official | 237:f3da66175598 | 1600 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1601 | } |
mbed_official | 237:f3da66175598 | 1602 | /* Check parameters compatibility */ |
mbed_official | 237:f3da66175598 | 1603 | else if((hsdadc->InjectedTrigger == SDADC_SOFTWARE_TRIGGER) && \ |
mbed_official | 237:f3da66175598 | 1604 | (hsdadc->InjectedContMode == SDADC_CONTINUOUS_CONV_OFF) && \ |
mbed_official | 237:f3da66175598 | 1605 | (hsdadc->hdma->Init.Mode == DMA_NORMAL) && \ |
mbed_official | 237:f3da66175598 | 1606 | (Length > hsdadc->InjectedChannelsNbr)) |
mbed_official | 237:f3da66175598 | 1607 | { |
mbed_official | 237:f3da66175598 | 1608 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1609 | } |
mbed_official | 237:f3da66175598 | 1610 | else if((hsdadc->InjectedTrigger == SDADC_SOFTWARE_TRIGGER) && \ |
mbed_official | 237:f3da66175598 | 1611 | (hsdadc->InjectedContMode == SDADC_CONTINUOUS_CONV_OFF) && \ |
mbed_official | 237:f3da66175598 | 1612 | (hsdadc->hdma->Init.Mode == DMA_CIRCULAR)) |
mbed_official | 237:f3da66175598 | 1613 | { |
mbed_official | 237:f3da66175598 | 1614 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1615 | } |
mbed_official | 237:f3da66175598 | 1616 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 1617 | else if((hsdadc->State == HAL_SDADC_STATE_READY) || \ |
mbed_official | 237:f3da66175598 | 1618 | (hsdadc->State == HAL_SDADC_STATE_REG)) |
mbed_official | 237:f3da66175598 | 1619 | { |
mbed_official | 237:f3da66175598 | 1620 | /* Set callbacks on DMA handler */ |
mbed_official | 237:f3da66175598 | 1621 | hsdadc->hdma->XferCpltCallback = SDADC_DMAInjectedConvCplt; |
mbed_official | 237:f3da66175598 | 1622 | hsdadc->hdma->XferErrorCallback = SDADC_DMAError; |
mbed_official | 237:f3da66175598 | 1623 | if(hsdadc->hdma->Init.Mode == DMA_CIRCULAR) |
mbed_official | 237:f3da66175598 | 1624 | { |
mbed_official | 237:f3da66175598 | 1625 | hsdadc->hdma->XferHalfCpltCallback = SDADC_DMAInjectedHalfConvCplt; |
mbed_official | 237:f3da66175598 | 1626 | } |
mbed_official | 237:f3da66175598 | 1627 | |
mbed_official | 237:f3da66175598 | 1628 | /* Set JDMAEN bit in SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 1629 | hsdadc->Instance->CR1 |= SDADC_CR1_JDMAEN; |
mbed_official | 237:f3da66175598 | 1630 | |
mbed_official | 237:f3da66175598 | 1631 | /* Start DMA in interrupt mode */ |
mbed_official | 237:f3da66175598 | 1632 | if(HAL_DMA_Start_IT(hsdadc->hdma, (uint32_t)&hsdadc->Instance->JDATAR, \ |
mbed_official | 237:f3da66175598 | 1633 | (uint32_t) pData, Length) != HAL_OK) |
mbed_official | 237:f3da66175598 | 1634 | { |
mbed_official | 237:f3da66175598 | 1635 | /* Set SDADC in error state */ |
mbed_official | 237:f3da66175598 | 1636 | hsdadc->State = HAL_SDADC_STATE_ERROR; |
mbed_official | 237:f3da66175598 | 1637 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1638 | } |
mbed_official | 237:f3da66175598 | 1639 | else |
mbed_official | 237:f3da66175598 | 1640 | { |
mbed_official | 237:f3da66175598 | 1641 | /* Start injected conversion */ |
mbed_official | 237:f3da66175598 | 1642 | status = SDADC_InjConvStart(hsdadc); |
mbed_official | 237:f3da66175598 | 1643 | } |
mbed_official | 237:f3da66175598 | 1644 | } |
mbed_official | 237:f3da66175598 | 1645 | else |
mbed_official | 237:f3da66175598 | 1646 | { |
mbed_official | 237:f3da66175598 | 1647 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1648 | } |
mbed_official | 237:f3da66175598 | 1649 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 1650 | return status; |
mbed_official | 237:f3da66175598 | 1651 | } |
mbed_official | 237:f3da66175598 | 1652 | |
mbed_official | 237:f3da66175598 | 1653 | /** |
mbed_official | 237:f3da66175598 | 1654 | * @brief This function allows to stop injected conversion in DMA mode. |
mbed_official | 237:f3da66175598 | 1655 | * @note This function should be called only if injected conversion is ongoing. |
mbed_official | 237:f3da66175598 | 1656 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1657 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1658 | */ |
mbed_official | 237:f3da66175598 | 1659 | HAL_StatusTypeDef HAL_SDADC_InjectedStop_DMA(SDADC_HandleTypeDef *hsdadc) |
mbed_official | 237:f3da66175598 | 1660 | { |
mbed_official | 237:f3da66175598 | 1661 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 1662 | |
mbed_official | 237:f3da66175598 | 1663 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 1664 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1665 | |
mbed_official | 237:f3da66175598 | 1666 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 1667 | if((hsdadc->State != HAL_SDADC_STATE_INJ) && \ |
mbed_official | 237:f3da66175598 | 1668 | (hsdadc->State != HAL_SDADC_STATE_REG_INJ)) |
mbed_official | 237:f3da66175598 | 1669 | { |
mbed_official | 237:f3da66175598 | 1670 | /* Return error status */ |
mbed_official | 237:f3da66175598 | 1671 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1672 | } |
mbed_official | 237:f3da66175598 | 1673 | else |
mbed_official | 237:f3da66175598 | 1674 | { |
mbed_official | 237:f3da66175598 | 1675 | /* Clear JDMAEN bit in SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 1676 | hsdadc->Instance->CR1 &= ~(SDADC_CR1_JDMAEN); |
mbed_official | 237:f3da66175598 | 1677 | |
mbed_official | 237:f3da66175598 | 1678 | /* Stop current DMA transfer */ |
mbed_official | 237:f3da66175598 | 1679 | if(HAL_DMA_Abort(hsdadc->hdma) != HAL_OK) |
mbed_official | 237:f3da66175598 | 1680 | { |
mbed_official | 237:f3da66175598 | 1681 | /* Set SDADC in error state */ |
mbed_official | 237:f3da66175598 | 1682 | hsdadc->State = HAL_SDADC_STATE_ERROR; |
mbed_official | 237:f3da66175598 | 1683 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1684 | } |
mbed_official | 237:f3da66175598 | 1685 | else |
mbed_official | 237:f3da66175598 | 1686 | { |
mbed_official | 237:f3da66175598 | 1687 | /* Stop injected conversion */ |
mbed_official | 237:f3da66175598 | 1688 | status = SDADC_InjConvStop(hsdadc); |
mbed_official | 237:f3da66175598 | 1689 | } |
mbed_official | 237:f3da66175598 | 1690 | } |
mbed_official | 237:f3da66175598 | 1691 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 1692 | return status; |
mbed_official | 237:f3da66175598 | 1693 | } |
mbed_official | 237:f3da66175598 | 1694 | |
mbed_official | 237:f3da66175598 | 1695 | /** |
mbed_official | 237:f3da66175598 | 1696 | * @brief This function allows to get injected conversion value. |
mbed_official | 237:f3da66175598 | 1697 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1698 | * @param Channel : Corresponding channel of injected conversion. |
mbed_official | 237:f3da66175598 | 1699 | * @retval Injected conversion value |
mbed_official | 237:f3da66175598 | 1700 | */ |
mbed_official | 237:f3da66175598 | 1701 | uint32_t HAL_SDADC_InjectedGetValue(SDADC_HandleTypeDef *hsdadc, uint32_t* Channel) |
mbed_official | 237:f3da66175598 | 1702 | { |
mbed_official | 237:f3da66175598 | 1703 | uint32_t value = 0; |
mbed_official | 237:f3da66175598 | 1704 | |
mbed_official | 237:f3da66175598 | 1705 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 1706 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1707 | assert_param(Channel != NULL); |
mbed_official | 237:f3da66175598 | 1708 | |
mbed_official | 237:f3da66175598 | 1709 | /* Read SDADC_JDATAR register and extract channel and conversion value */ |
mbed_official | 237:f3da66175598 | 1710 | value = hsdadc->Instance->JDATAR; |
mbed_official | 237:f3da66175598 | 1711 | *Channel = ((value & SDADC_JDATAR_JDATACH) >> SDADC_JDATAR_CH_OFFSET); |
mbed_official | 237:f3da66175598 | 1712 | value &= SDADC_JDATAR_JDATA; |
mbed_official | 237:f3da66175598 | 1713 | |
mbed_official | 237:f3da66175598 | 1714 | /* Return injected conversion value */ |
mbed_official | 237:f3da66175598 | 1715 | return value; |
mbed_official | 237:f3da66175598 | 1716 | } |
mbed_official | 237:f3da66175598 | 1717 | |
mbed_official | 237:f3da66175598 | 1718 | /** |
mbed_official | 237:f3da66175598 | 1719 | * @brief This function allows to start multimode regular conversions in DMA mode. |
mbed_official | 237:f3da66175598 | 1720 | * @note This function should be called only when SDADC instance is in idle state |
mbed_official | 237:f3da66175598 | 1721 | * or if injected conversion is ongoing. |
mbed_official | 237:f3da66175598 | 1722 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1723 | * @param pData : The destination buffer address. |
mbed_official | 237:f3da66175598 | 1724 | * @param Length : The length of data to be transferred from SDADC peripheral to memory. |
mbed_official | 237:f3da66175598 | 1725 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1726 | */ |
mbed_official | 237:f3da66175598 | 1727 | HAL_StatusTypeDef HAL_SDADC_MultiModeStart_DMA(SDADC_HandleTypeDef* hsdadc, uint32_t* pData, |
mbed_official | 237:f3da66175598 | 1728 | uint32_t Length) |
mbed_official | 237:f3da66175598 | 1729 | { |
mbed_official | 237:f3da66175598 | 1730 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 1731 | |
mbed_official | 237:f3da66175598 | 1732 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 1733 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1734 | assert_param(pData != NULL); |
mbed_official | 237:f3da66175598 | 1735 | assert_param(Length != 0); |
mbed_official | 237:f3da66175598 | 1736 | |
mbed_official | 237:f3da66175598 | 1737 | /* Check instance is SDADC1 */ |
mbed_official | 237:f3da66175598 | 1738 | if(hsdadc->Instance != SDADC1) |
mbed_official | 237:f3da66175598 | 1739 | { |
mbed_official | 237:f3da66175598 | 1740 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1741 | } |
mbed_official | 237:f3da66175598 | 1742 | /* Check that DMA is not enabled for injected conversion */ |
mbed_official | 237:f3da66175598 | 1743 | else if((hsdadc->Instance->CR1 & SDADC_CR1_JDMAEN) == SDADC_CR1_JDMAEN) |
mbed_official | 237:f3da66175598 | 1744 | { |
mbed_official | 237:f3da66175598 | 1745 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1746 | } |
mbed_official | 237:f3da66175598 | 1747 | /* Check parameters compatibility */ |
mbed_official | 237:f3da66175598 | 1748 | else if((hsdadc->RegularTrigger == SDADC_SOFTWARE_TRIGGER) && \ |
mbed_official | 237:f3da66175598 | 1749 | (hsdadc->RegularContMode == SDADC_CONTINUOUS_CONV_OFF) && \ |
mbed_official | 237:f3da66175598 | 1750 | (hsdadc->hdma->Init.Mode == DMA_NORMAL) && \ |
mbed_official | 237:f3da66175598 | 1751 | (Length != 1)) |
mbed_official | 237:f3da66175598 | 1752 | { |
mbed_official | 237:f3da66175598 | 1753 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1754 | } |
mbed_official | 237:f3da66175598 | 1755 | else if((hsdadc->RegularTrigger == SDADC_SOFTWARE_TRIGGER) && \ |
mbed_official | 237:f3da66175598 | 1756 | (hsdadc->RegularContMode == SDADC_CONTINUOUS_CONV_OFF) && \ |
mbed_official | 237:f3da66175598 | 1757 | (hsdadc->hdma->Init.Mode == DMA_CIRCULAR)) |
mbed_official | 237:f3da66175598 | 1758 | { |
mbed_official | 237:f3da66175598 | 1759 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1760 | } |
mbed_official | 237:f3da66175598 | 1761 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 1762 | else if((hsdadc->State == HAL_SDADC_STATE_READY) || \ |
mbed_official | 237:f3da66175598 | 1763 | (hsdadc->State == HAL_SDADC_STATE_INJ)) |
mbed_official | 237:f3da66175598 | 1764 | { |
mbed_official | 237:f3da66175598 | 1765 | /* Set callbacks on DMA handler */ |
mbed_official | 237:f3da66175598 | 1766 | hsdadc->hdma->XferCpltCallback = SDADC_DMARegularConvCplt; |
mbed_official | 237:f3da66175598 | 1767 | hsdadc->hdma->XferErrorCallback = SDADC_DMAError; |
mbed_official | 237:f3da66175598 | 1768 | if(hsdadc->hdma->Init.Mode == DMA_CIRCULAR) |
mbed_official | 237:f3da66175598 | 1769 | { |
mbed_official | 237:f3da66175598 | 1770 | hsdadc->hdma->XferHalfCpltCallback = SDADC_DMARegularHalfConvCplt; |
mbed_official | 237:f3da66175598 | 1771 | } |
mbed_official | 237:f3da66175598 | 1772 | /* Set RDMAEN bit in SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 1773 | hsdadc->Instance->CR1 |= SDADC_CR1_RDMAEN; |
mbed_official | 237:f3da66175598 | 1774 | |
mbed_official | 237:f3da66175598 | 1775 | /* Start DMA in interrupt mode */ |
mbed_official | 237:f3da66175598 | 1776 | if(hsdadc->RegularMultimode == SDADC_MULTIMODE_SDADC1_SDADC2) |
mbed_official | 237:f3da66175598 | 1777 | { |
mbed_official | 237:f3da66175598 | 1778 | status = HAL_DMA_Start_IT(hsdadc->hdma, (uint32_t)&hsdadc->Instance->RDATA12R, \ |
mbed_official | 237:f3da66175598 | 1779 | (uint32_t) pData, Length); |
mbed_official | 237:f3da66175598 | 1780 | } |
mbed_official | 237:f3da66175598 | 1781 | else |
mbed_official | 237:f3da66175598 | 1782 | { |
mbed_official | 237:f3da66175598 | 1783 | status = HAL_DMA_Start_IT(hsdadc->hdma, (uint32_t)&hsdadc->Instance->RDATA13R, \ |
mbed_official | 237:f3da66175598 | 1784 | (uint32_t) pData, Length); |
mbed_official | 237:f3da66175598 | 1785 | } |
mbed_official | 237:f3da66175598 | 1786 | if(status != HAL_OK) |
mbed_official | 237:f3da66175598 | 1787 | { |
mbed_official | 237:f3da66175598 | 1788 | /* Set SDADC in error state */ |
mbed_official | 237:f3da66175598 | 1789 | hsdadc->State = HAL_SDADC_STATE_ERROR; |
mbed_official | 237:f3da66175598 | 1790 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1791 | } |
mbed_official | 237:f3da66175598 | 1792 | else |
mbed_official | 237:f3da66175598 | 1793 | { |
mbed_official | 237:f3da66175598 | 1794 | /* Start regular conversion */ |
mbed_official | 237:f3da66175598 | 1795 | status = SDADC_RegConvStart(hsdadc); |
mbed_official | 237:f3da66175598 | 1796 | } |
mbed_official | 237:f3da66175598 | 1797 | } |
mbed_official | 237:f3da66175598 | 1798 | else |
mbed_official | 237:f3da66175598 | 1799 | { |
mbed_official | 237:f3da66175598 | 1800 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1801 | } |
mbed_official | 237:f3da66175598 | 1802 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 1803 | return status; |
mbed_official | 237:f3da66175598 | 1804 | } |
mbed_official | 237:f3da66175598 | 1805 | |
mbed_official | 237:f3da66175598 | 1806 | /** |
mbed_official | 237:f3da66175598 | 1807 | * @brief This function allows to stop multimode regular conversions in DMA mode. |
mbed_official | 237:f3da66175598 | 1808 | * @note This function should be called only if regular conversion is ongoing. |
mbed_official | 237:f3da66175598 | 1809 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1810 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1811 | */ |
mbed_official | 237:f3da66175598 | 1812 | HAL_StatusTypeDef HAL_SDADC_MultiModeStop_DMA(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 1813 | { |
mbed_official | 237:f3da66175598 | 1814 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 1815 | |
mbed_official | 237:f3da66175598 | 1816 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 1817 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1818 | |
mbed_official | 237:f3da66175598 | 1819 | /* Check instance is SDADC1 */ |
mbed_official | 237:f3da66175598 | 1820 | if(hsdadc->Instance != SDADC1) |
mbed_official | 237:f3da66175598 | 1821 | { |
mbed_official | 237:f3da66175598 | 1822 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1823 | } |
mbed_official | 237:f3da66175598 | 1824 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 1825 | else if((hsdadc->State != HAL_SDADC_STATE_REG) && \ |
mbed_official | 237:f3da66175598 | 1826 | (hsdadc->State != HAL_SDADC_STATE_REG_INJ)) |
mbed_official | 237:f3da66175598 | 1827 | { |
mbed_official | 237:f3da66175598 | 1828 | /* Return error status */ |
mbed_official | 237:f3da66175598 | 1829 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1830 | } |
mbed_official | 237:f3da66175598 | 1831 | else |
mbed_official | 237:f3da66175598 | 1832 | { |
mbed_official | 237:f3da66175598 | 1833 | /* Clear RDMAEN bit in SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 1834 | hsdadc->Instance->CR1 &= ~(SDADC_CR1_RDMAEN); |
mbed_official | 237:f3da66175598 | 1835 | |
mbed_official | 237:f3da66175598 | 1836 | /* Stop current DMA transfer */ |
mbed_official | 237:f3da66175598 | 1837 | if(HAL_DMA_Abort(hsdadc->hdma) != HAL_OK) |
mbed_official | 237:f3da66175598 | 1838 | { |
mbed_official | 237:f3da66175598 | 1839 | /* Set SDADC in error state */ |
mbed_official | 237:f3da66175598 | 1840 | hsdadc->State = HAL_SDADC_STATE_ERROR; |
mbed_official | 237:f3da66175598 | 1841 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1842 | } |
mbed_official | 237:f3da66175598 | 1843 | else |
mbed_official | 237:f3da66175598 | 1844 | { |
mbed_official | 237:f3da66175598 | 1845 | /* Stop regular conversion */ |
mbed_official | 237:f3da66175598 | 1846 | status = SDADC_RegConvStop(hsdadc); |
mbed_official | 237:f3da66175598 | 1847 | } |
mbed_official | 237:f3da66175598 | 1848 | } |
mbed_official | 237:f3da66175598 | 1849 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 1850 | return status; |
mbed_official | 237:f3da66175598 | 1851 | } |
mbed_official | 237:f3da66175598 | 1852 | |
mbed_official | 237:f3da66175598 | 1853 | /** |
mbed_official | 237:f3da66175598 | 1854 | * @brief This function allows to get multimode regular conversion value. |
mbed_official | 237:f3da66175598 | 1855 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1856 | * @retval Multimode regular conversion value |
mbed_official | 237:f3da66175598 | 1857 | */ |
mbed_official | 237:f3da66175598 | 1858 | uint32_t HAL_SDADC_MultiModeGetValue(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 1859 | { |
mbed_official | 237:f3da66175598 | 1860 | uint32_t value = 0; |
mbed_official | 237:f3da66175598 | 1861 | |
mbed_official | 237:f3da66175598 | 1862 | /* Check parameters and check instance is SDADC1 */ |
mbed_official | 237:f3da66175598 | 1863 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1864 | assert_param(hsdadc->Instance == SDADC1); |
mbed_official | 237:f3da66175598 | 1865 | |
mbed_official | 237:f3da66175598 | 1866 | /* read multimode regular value */ |
mbed_official | 237:f3da66175598 | 1867 | value = (hsdadc->RegularMultimode == SDADC_MULTIMODE_SDADC1_SDADC2) ? \ |
mbed_official | 237:f3da66175598 | 1868 | hsdadc->Instance->RDATA12R : hsdadc->Instance->RDATA13R; |
mbed_official | 237:f3da66175598 | 1869 | |
mbed_official | 237:f3da66175598 | 1870 | /* Return multimode regular conversions value */ |
mbed_official | 237:f3da66175598 | 1871 | return value; |
mbed_official | 237:f3da66175598 | 1872 | } |
mbed_official | 237:f3da66175598 | 1873 | |
mbed_official | 237:f3da66175598 | 1874 | /** |
mbed_official | 237:f3da66175598 | 1875 | * @brief This function allows to start multimode injected conversions in DMA mode. |
mbed_official | 237:f3da66175598 | 1876 | * @note This function should be called only when SDADC instance is in idle state |
mbed_official | 237:f3da66175598 | 1877 | * or if regular conversion is ongoing. |
mbed_official | 237:f3da66175598 | 1878 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1879 | * @param pData : The destination buffer address. |
mbed_official | 237:f3da66175598 | 1880 | * @param Length : The length of data to be transferred from SDADC peripheral to memory. |
mbed_official | 237:f3da66175598 | 1881 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1882 | */ |
mbed_official | 237:f3da66175598 | 1883 | HAL_StatusTypeDef HAL_SDADC_InjectedMultiModeStart_DMA(SDADC_HandleTypeDef* hsdadc, |
mbed_official | 237:f3da66175598 | 1884 | uint32_t* pData, uint32_t Length) |
mbed_official | 237:f3da66175598 | 1885 | { |
mbed_official | 237:f3da66175598 | 1886 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 1887 | |
mbed_official | 237:f3da66175598 | 1888 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 1889 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1890 | assert_param(pData != NULL); |
mbed_official | 237:f3da66175598 | 1891 | assert_param(Length != 0); |
mbed_official | 237:f3da66175598 | 1892 | |
mbed_official | 237:f3da66175598 | 1893 | /* Check instance is SDADC1 */ |
mbed_official | 237:f3da66175598 | 1894 | if(hsdadc->Instance != SDADC1) |
mbed_official | 237:f3da66175598 | 1895 | { |
mbed_official | 237:f3da66175598 | 1896 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1897 | } |
mbed_official | 237:f3da66175598 | 1898 | /* Check that DMA is not enabled for regular conversion */ |
mbed_official | 237:f3da66175598 | 1899 | else if((hsdadc->Instance->CR1 & SDADC_CR1_RDMAEN) == SDADC_CR1_RDMAEN) |
mbed_official | 237:f3da66175598 | 1900 | { |
mbed_official | 237:f3da66175598 | 1901 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1902 | } |
mbed_official | 237:f3da66175598 | 1903 | /* Check parameters compatibility */ |
mbed_official | 237:f3da66175598 | 1904 | else if((hsdadc->InjectedTrigger == SDADC_SOFTWARE_TRIGGER) && \ |
mbed_official | 237:f3da66175598 | 1905 | (hsdadc->InjectedContMode == SDADC_CONTINUOUS_CONV_OFF) && \ |
mbed_official | 237:f3da66175598 | 1906 | (hsdadc->hdma->Init.Mode == DMA_NORMAL) && \ |
mbed_official | 237:f3da66175598 | 1907 | (Length > (hsdadc->InjectedChannelsNbr << 1))) |
mbed_official | 237:f3da66175598 | 1908 | { |
mbed_official | 237:f3da66175598 | 1909 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1910 | } |
mbed_official | 237:f3da66175598 | 1911 | else if((hsdadc->InjectedTrigger == SDADC_SOFTWARE_TRIGGER) && \ |
mbed_official | 237:f3da66175598 | 1912 | (hsdadc->InjectedContMode == SDADC_CONTINUOUS_CONV_OFF) && \ |
mbed_official | 237:f3da66175598 | 1913 | (hsdadc->hdma->Init.Mode == DMA_CIRCULAR)) |
mbed_official | 237:f3da66175598 | 1914 | { |
mbed_official | 237:f3da66175598 | 1915 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1916 | } |
mbed_official | 237:f3da66175598 | 1917 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 1918 | else if((hsdadc->State == HAL_SDADC_STATE_READY) || \ |
mbed_official | 237:f3da66175598 | 1919 | (hsdadc->State == HAL_SDADC_STATE_REG)) |
mbed_official | 237:f3da66175598 | 1920 | { |
mbed_official | 237:f3da66175598 | 1921 | /* Set callbacks on DMA handler */ |
mbed_official | 237:f3da66175598 | 1922 | hsdadc->hdma->XferCpltCallback = SDADC_DMAInjectedConvCplt; |
mbed_official | 237:f3da66175598 | 1923 | hsdadc->hdma->XferErrorCallback = SDADC_DMAError; |
mbed_official | 237:f3da66175598 | 1924 | if(hsdadc->hdma->Init.Mode == DMA_CIRCULAR) |
mbed_official | 237:f3da66175598 | 1925 | { |
mbed_official | 237:f3da66175598 | 1926 | hsdadc->hdma->XferHalfCpltCallback = SDADC_DMAInjectedHalfConvCplt; |
mbed_official | 237:f3da66175598 | 1927 | } |
mbed_official | 237:f3da66175598 | 1928 | /* Set JDMAEN bit in SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 1929 | hsdadc->Instance->CR1 |= SDADC_CR1_JDMAEN; |
mbed_official | 237:f3da66175598 | 1930 | |
mbed_official | 237:f3da66175598 | 1931 | /* Start DMA in interrupt mode */ |
mbed_official | 237:f3da66175598 | 1932 | if(hsdadc->InjectedMultimode == SDADC_MULTIMODE_SDADC1_SDADC2) |
mbed_official | 237:f3da66175598 | 1933 | { |
mbed_official | 237:f3da66175598 | 1934 | status = HAL_DMA_Start_IT(hsdadc->hdma, (uint32_t)&hsdadc->Instance->JDATA12R, \ |
mbed_official | 237:f3da66175598 | 1935 | (uint32_t) pData, Length); |
mbed_official | 237:f3da66175598 | 1936 | } |
mbed_official | 237:f3da66175598 | 1937 | else |
mbed_official | 237:f3da66175598 | 1938 | { |
mbed_official | 237:f3da66175598 | 1939 | status = HAL_DMA_Start_IT(hsdadc->hdma, (uint32_t)&hsdadc->Instance->JDATA13R, \ |
mbed_official | 237:f3da66175598 | 1940 | (uint32_t) pData, Length); |
mbed_official | 237:f3da66175598 | 1941 | } |
mbed_official | 237:f3da66175598 | 1942 | if(status != HAL_OK) |
mbed_official | 237:f3da66175598 | 1943 | { |
mbed_official | 237:f3da66175598 | 1944 | /* Set SDADC in error state */ |
mbed_official | 237:f3da66175598 | 1945 | hsdadc->State = HAL_SDADC_STATE_ERROR; |
mbed_official | 237:f3da66175598 | 1946 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1947 | } |
mbed_official | 237:f3da66175598 | 1948 | else |
mbed_official | 237:f3da66175598 | 1949 | { |
mbed_official | 237:f3da66175598 | 1950 | /* Start injected conversion */ |
mbed_official | 237:f3da66175598 | 1951 | status = SDADC_InjConvStart(hsdadc); |
mbed_official | 237:f3da66175598 | 1952 | } |
mbed_official | 237:f3da66175598 | 1953 | } |
mbed_official | 237:f3da66175598 | 1954 | else |
mbed_official | 237:f3da66175598 | 1955 | { |
mbed_official | 237:f3da66175598 | 1956 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1957 | } |
mbed_official | 237:f3da66175598 | 1958 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 1959 | return status; |
mbed_official | 237:f3da66175598 | 1960 | } |
mbed_official | 237:f3da66175598 | 1961 | |
mbed_official | 237:f3da66175598 | 1962 | /** |
mbed_official | 237:f3da66175598 | 1963 | * @brief This function allows to stop multimode injected conversions in DMA mode. |
mbed_official | 237:f3da66175598 | 1964 | * @note This function should be called only if injected conversion is ongoing. |
mbed_official | 237:f3da66175598 | 1965 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 1966 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1967 | */ |
mbed_official | 237:f3da66175598 | 1968 | HAL_StatusTypeDef HAL_SDADC_InjectedMultiModeStop_DMA(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 1969 | { |
mbed_official | 237:f3da66175598 | 1970 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 1971 | |
mbed_official | 237:f3da66175598 | 1972 | /* Check parameters */ |
mbed_official | 237:f3da66175598 | 1973 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 1974 | |
mbed_official | 237:f3da66175598 | 1975 | /* Check instance is SDADC1 */ |
mbed_official | 237:f3da66175598 | 1976 | if(hsdadc->Instance != SDADC1) |
mbed_official | 237:f3da66175598 | 1977 | { |
mbed_official | 237:f3da66175598 | 1978 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1979 | } |
mbed_official | 237:f3da66175598 | 1980 | /* Check SDADC state */ |
mbed_official | 237:f3da66175598 | 1981 | else if((hsdadc->State != HAL_SDADC_STATE_INJ) && \ |
mbed_official | 237:f3da66175598 | 1982 | (hsdadc->State != HAL_SDADC_STATE_REG_INJ)) |
mbed_official | 237:f3da66175598 | 1983 | { |
mbed_official | 237:f3da66175598 | 1984 | /* Return error status */ |
mbed_official | 237:f3da66175598 | 1985 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1986 | } |
mbed_official | 237:f3da66175598 | 1987 | else |
mbed_official | 237:f3da66175598 | 1988 | { |
mbed_official | 237:f3da66175598 | 1989 | /* Clear JDMAEN bit in SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 1990 | hsdadc->Instance->CR1 &= ~(SDADC_CR1_JDMAEN); |
mbed_official | 237:f3da66175598 | 1991 | |
mbed_official | 237:f3da66175598 | 1992 | /* Stop current DMA transfer */ |
mbed_official | 237:f3da66175598 | 1993 | if(HAL_DMA_Abort(hsdadc->hdma) != HAL_OK) |
mbed_official | 237:f3da66175598 | 1994 | { |
mbed_official | 237:f3da66175598 | 1995 | /* Set SDADC in error state */ |
mbed_official | 237:f3da66175598 | 1996 | hsdadc->State = HAL_SDADC_STATE_ERROR; |
mbed_official | 237:f3da66175598 | 1997 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1998 | } |
mbed_official | 237:f3da66175598 | 1999 | else |
mbed_official | 237:f3da66175598 | 2000 | { |
mbed_official | 237:f3da66175598 | 2001 | /* Stop injected conversion */ |
mbed_official | 237:f3da66175598 | 2002 | status = SDADC_InjConvStop(hsdadc); |
mbed_official | 237:f3da66175598 | 2003 | } |
mbed_official | 237:f3da66175598 | 2004 | } |
mbed_official | 237:f3da66175598 | 2005 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 2006 | return status; |
mbed_official | 237:f3da66175598 | 2007 | } |
mbed_official | 237:f3da66175598 | 2008 | |
mbed_official | 237:f3da66175598 | 2009 | /** |
mbed_official | 237:f3da66175598 | 2010 | * @brief This function allows to get multimode injected conversion value. |
mbed_official | 237:f3da66175598 | 2011 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 2012 | * @retval Multimode injected conversion value |
mbed_official | 237:f3da66175598 | 2013 | */ |
mbed_official | 237:f3da66175598 | 2014 | uint32_t HAL_SDADC_InjectedMultiModeGetValue(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 2015 | { |
mbed_official | 237:f3da66175598 | 2016 | uint32_t value = 0; |
mbed_official | 237:f3da66175598 | 2017 | |
mbed_official | 237:f3da66175598 | 2018 | /* Check parameters and check instance is SDADC1 */ |
mbed_official | 237:f3da66175598 | 2019 | assert_param(IS_SDADC_ALL_INSTANCE(hsdadc->Instance)); |
mbed_official | 237:f3da66175598 | 2020 | assert_param(hsdadc->Instance == SDADC1); |
mbed_official | 237:f3da66175598 | 2021 | |
mbed_official | 237:f3da66175598 | 2022 | /* read multimode injected value */ |
mbed_official | 237:f3da66175598 | 2023 | value = (hsdadc->InjectedMultimode == SDADC_MULTIMODE_SDADC1_SDADC2) ? \ |
mbed_official | 237:f3da66175598 | 2024 | hsdadc->Instance->JDATA12R : hsdadc->Instance->JDATA13R; |
mbed_official | 237:f3da66175598 | 2025 | |
mbed_official | 237:f3da66175598 | 2026 | /* Return multimode injected conversions value */ |
mbed_official | 237:f3da66175598 | 2027 | return value; |
mbed_official | 237:f3da66175598 | 2028 | } |
mbed_official | 237:f3da66175598 | 2029 | |
mbed_official | 237:f3da66175598 | 2030 | /** |
mbed_official | 237:f3da66175598 | 2031 | * @brief This function handles the SDADC interrupts. |
mbed_official | 237:f3da66175598 | 2032 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 2033 | * @retval None |
mbed_official | 237:f3da66175598 | 2034 | */ |
mbed_official | 237:f3da66175598 | 2035 | void HAL_SDADC_IRQHandler(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 2036 | { |
mbed_official | 237:f3da66175598 | 2037 | /* Check if end of regular conversion */ |
mbed_official | 237:f3da66175598 | 2038 | if(((hsdadc->Instance->ISR & SDADC_ISR_REOCF) == SDADC_ISR_REOCF) && \ |
mbed_official | 237:f3da66175598 | 2039 | ((hsdadc->Instance->CR1 & SDADC_CR1_REOCIE) == SDADC_CR1_REOCIE)) |
mbed_official | 237:f3da66175598 | 2040 | { |
mbed_official | 237:f3da66175598 | 2041 | /* Call regular conversion complete callback */ |
mbed_official | 237:f3da66175598 | 2042 | HAL_SDADC_ConvCpltCallback(hsdadc); |
mbed_official | 237:f3da66175598 | 2043 | |
mbed_official | 237:f3da66175598 | 2044 | /* End of conversion if mode is not continuous and software trigger */ |
mbed_official | 237:f3da66175598 | 2045 | if((hsdadc->RegularContMode == SDADC_CONTINUOUS_CONV_OFF) && \ |
mbed_official | 237:f3da66175598 | 2046 | (hsdadc->RegularTrigger == SDADC_SOFTWARE_TRIGGER)) |
mbed_official | 237:f3da66175598 | 2047 | { |
mbed_official | 237:f3da66175598 | 2048 | /* Clear REOCIE and ROVRIE bits in SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 2049 | hsdadc->Instance->CR1 &= ~(SDADC_CR1_REOCIE | SDADC_CR1_ROVRIE); |
mbed_official | 237:f3da66175598 | 2050 | |
mbed_official | 237:f3da66175598 | 2051 | /* Update SDADC state */ |
mbed_official | 237:f3da66175598 | 2052 | hsdadc->State = (hsdadc->State == HAL_SDADC_STATE_REG) ? \ |
mbed_official | 237:f3da66175598 | 2053 | HAL_SDADC_STATE_READY : HAL_SDADC_STATE_INJ; |
mbed_official | 237:f3da66175598 | 2054 | } |
mbed_official | 237:f3da66175598 | 2055 | } |
mbed_official | 237:f3da66175598 | 2056 | /* Check if end of injected conversion */ |
mbed_official | 237:f3da66175598 | 2057 | else if(((hsdadc->Instance->ISR & SDADC_ISR_JEOCF) == SDADC_ISR_JEOCF) && \ |
mbed_official | 237:f3da66175598 | 2058 | ((hsdadc->Instance->CR1 & SDADC_CR1_JEOCIE) == SDADC_CR1_JEOCIE)) |
mbed_official | 237:f3da66175598 | 2059 | { |
mbed_official | 237:f3da66175598 | 2060 | /* Call injected conversion complete callback */ |
mbed_official | 237:f3da66175598 | 2061 | HAL_SDADC_InjectedConvCpltCallback(hsdadc); |
mbed_official | 237:f3da66175598 | 2062 | |
mbed_official | 237:f3da66175598 | 2063 | /* Update remaining injected conversions */ |
mbed_official | 237:f3da66175598 | 2064 | hsdadc->InjConvRemaining--; |
mbed_official | 237:f3da66175598 | 2065 | if(hsdadc->InjConvRemaining ==0) |
mbed_official | 237:f3da66175598 | 2066 | { |
mbed_official | 237:f3da66175598 | 2067 | /* end of injected sequence, reset the value */ |
mbed_official | 237:f3da66175598 | 2068 | hsdadc->InjConvRemaining = hsdadc->InjectedChannelsNbr; |
mbed_official | 237:f3da66175598 | 2069 | } |
mbed_official | 237:f3da66175598 | 2070 | /* End of conversion if mode is not continuous, software trigger */ |
mbed_official | 237:f3da66175598 | 2071 | /* and end of injected sequence */ |
mbed_official | 237:f3da66175598 | 2072 | if((hsdadc->InjectedContMode == SDADC_CONTINUOUS_CONV_OFF) && \ |
mbed_official | 237:f3da66175598 | 2073 | (hsdadc->InjectedTrigger == SDADC_SOFTWARE_TRIGGER) && \ |
mbed_official | 237:f3da66175598 | 2074 | (hsdadc->InjConvRemaining == hsdadc->InjectedChannelsNbr)) |
mbed_official | 237:f3da66175598 | 2075 | { |
mbed_official | 237:f3da66175598 | 2076 | /* Clear JEOCIE and JOVRIE bits in SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 2077 | hsdadc->Instance->CR1 &= ~(SDADC_CR1_JEOCIE | SDADC_CR1_JOVRIE); |
mbed_official | 237:f3da66175598 | 2078 | |
mbed_official | 237:f3da66175598 | 2079 | /* Update SDADC state */ |
mbed_official | 237:f3da66175598 | 2080 | hsdadc->State = (hsdadc->State == HAL_SDADC_STATE_INJ) ? \ |
mbed_official | 237:f3da66175598 | 2081 | HAL_SDADC_STATE_READY : HAL_SDADC_STATE_REG; |
mbed_official | 237:f3da66175598 | 2082 | } |
mbed_official | 237:f3da66175598 | 2083 | } |
mbed_official | 237:f3da66175598 | 2084 | /* Check if end of calibration */ |
mbed_official | 237:f3da66175598 | 2085 | else if(((hsdadc->Instance->ISR & SDADC_ISR_EOCALF) == SDADC_ISR_EOCALF) && \ |
mbed_official | 237:f3da66175598 | 2086 | ((hsdadc->Instance->CR1 & SDADC_CR1_EOCALIE) == SDADC_CR1_EOCALIE)) |
mbed_official | 237:f3da66175598 | 2087 | { |
mbed_official | 237:f3da66175598 | 2088 | /* Clear EOCALIE bit in SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 2089 | hsdadc->Instance->CR1 &= ~(SDADC_CR1_EOCALIE); |
mbed_official | 237:f3da66175598 | 2090 | |
mbed_official | 237:f3da66175598 | 2091 | /* Set CLREOCALF bit in SDADC_CLRISR register */ |
mbed_official | 237:f3da66175598 | 2092 | hsdadc->Instance->CLRISR |= SDADC_ISR_CLREOCALF; |
mbed_official | 237:f3da66175598 | 2093 | |
mbed_official | 237:f3da66175598 | 2094 | /* Call calibration callback */ |
mbed_official | 237:f3da66175598 | 2095 | HAL_SDADC_CalibrationCpltCallback(hsdadc); |
mbed_official | 237:f3da66175598 | 2096 | |
mbed_official | 237:f3da66175598 | 2097 | /* Update SDADC state */ |
mbed_official | 237:f3da66175598 | 2098 | hsdadc->State = HAL_SDADC_STATE_READY; |
mbed_official | 237:f3da66175598 | 2099 | } |
mbed_official | 237:f3da66175598 | 2100 | /* Check if overrun occurs during regular conversion */ |
mbed_official | 237:f3da66175598 | 2101 | else if(((hsdadc->Instance->ISR & SDADC_ISR_ROVRF) == SDADC_ISR_ROVRF) && \ |
mbed_official | 237:f3da66175598 | 2102 | ((hsdadc->Instance->CR1 & SDADC_CR1_ROVRIE) == SDADC_CR1_ROVRIE)) |
mbed_official | 237:f3da66175598 | 2103 | { |
mbed_official | 237:f3da66175598 | 2104 | /* Set CLRROVRF bit in SDADC_CLRISR register */ |
mbed_official | 237:f3da66175598 | 2105 | hsdadc->Instance->CLRISR |= SDADC_ISR_CLRROVRF; |
mbed_official | 237:f3da66175598 | 2106 | |
mbed_official | 237:f3da66175598 | 2107 | /* Update error code */ |
mbed_official | 237:f3da66175598 | 2108 | hsdadc->ErrorCode = SDADC_ERROR_REGULAR_OVERRUN; |
mbed_official | 237:f3da66175598 | 2109 | |
mbed_official | 237:f3da66175598 | 2110 | /* Call error callback */ |
mbed_official | 237:f3da66175598 | 2111 | HAL_SDADC_ErrorCallback(hsdadc); |
mbed_official | 237:f3da66175598 | 2112 | } |
mbed_official | 237:f3da66175598 | 2113 | /* Check if overrun occurs during injected conversion */ |
mbed_official | 237:f3da66175598 | 2114 | else if(((hsdadc->Instance->ISR & SDADC_ISR_JOVRF) == SDADC_ISR_JOVRF) && \ |
mbed_official | 237:f3da66175598 | 2115 | ((hsdadc->Instance->CR1 & SDADC_CR1_JOVRIE) == SDADC_CR1_JOVRIE)) |
mbed_official | 237:f3da66175598 | 2116 | { |
mbed_official | 237:f3da66175598 | 2117 | /* Set CLRJOVRF bit in SDADC_CLRISR register */ |
mbed_official | 237:f3da66175598 | 2118 | hsdadc->Instance->CLRISR |= SDADC_ISR_CLRJOVRF; |
mbed_official | 237:f3da66175598 | 2119 | |
mbed_official | 237:f3da66175598 | 2120 | /* Update error code */ |
mbed_official | 237:f3da66175598 | 2121 | hsdadc->ErrorCode = SDADC_ERROR_INJECTED_OVERRUN; |
mbed_official | 237:f3da66175598 | 2122 | |
mbed_official | 237:f3da66175598 | 2123 | /* Call error callback */ |
mbed_official | 237:f3da66175598 | 2124 | HAL_SDADC_ErrorCallback(hsdadc); |
mbed_official | 237:f3da66175598 | 2125 | } |
mbed_official | 237:f3da66175598 | 2126 | return; |
mbed_official | 237:f3da66175598 | 2127 | } |
mbed_official | 237:f3da66175598 | 2128 | |
mbed_official | 237:f3da66175598 | 2129 | /** |
mbed_official | 237:f3da66175598 | 2130 | * @brief Calibration complete callback. |
mbed_official | 237:f3da66175598 | 2131 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 2132 | * @retval None |
mbed_official | 237:f3da66175598 | 2133 | */ |
mbed_official | 237:f3da66175598 | 2134 | __weak void HAL_SDADC_CalibrationCpltCallback(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 2135 | { |
mbed_official | 237:f3da66175598 | 2136 | /* NOTE : This function should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 2137 | the HAL_SDADC_CalibrationCpltCallback could be implemented in the user file |
mbed_official | 237:f3da66175598 | 2138 | */ |
mbed_official | 237:f3da66175598 | 2139 | } |
mbed_official | 237:f3da66175598 | 2140 | |
mbed_official | 237:f3da66175598 | 2141 | /** |
mbed_official | 237:f3da66175598 | 2142 | * @brief Half regular conversion complete callback. |
mbed_official | 237:f3da66175598 | 2143 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 2144 | * @retval None |
mbed_official | 237:f3da66175598 | 2145 | */ |
mbed_official | 237:f3da66175598 | 2146 | __weak void HAL_SDADC_ConvHalfCpltCallback(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 2147 | { |
mbed_official | 237:f3da66175598 | 2148 | /* NOTE : This function should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 2149 | the HAL_SDADC_ConvHalfCpltCallback could be implemented in the user file |
mbed_official | 237:f3da66175598 | 2150 | */ |
mbed_official | 237:f3da66175598 | 2151 | } |
mbed_official | 237:f3da66175598 | 2152 | |
mbed_official | 237:f3da66175598 | 2153 | /** |
mbed_official | 237:f3da66175598 | 2154 | * @brief Regular conversion complete callback. |
mbed_official | 237:f3da66175598 | 2155 | * @note In interrupt mode, user has to read conversion value in this function |
mbed_official | 237:f3da66175598 | 2156 | using HAL_SDADC_GetValue or HAL_SDADC_MultiModeGetValue. |
mbed_official | 237:f3da66175598 | 2157 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 2158 | * @retval None |
mbed_official | 237:f3da66175598 | 2159 | */ |
mbed_official | 237:f3da66175598 | 2160 | __weak void HAL_SDADC_ConvCpltCallback(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 2161 | { |
mbed_official | 237:f3da66175598 | 2162 | /* NOTE : This function should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 2163 | the HAL_SDADC_ConvCpltCallback could be implemented in the user file. |
mbed_official | 237:f3da66175598 | 2164 | */ |
mbed_official | 237:f3da66175598 | 2165 | } |
mbed_official | 237:f3da66175598 | 2166 | |
mbed_official | 237:f3da66175598 | 2167 | /** |
mbed_official | 237:f3da66175598 | 2168 | * @brief Half injected conversion complete callback. |
mbed_official | 237:f3da66175598 | 2169 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 2170 | * @retval None |
mbed_official | 237:f3da66175598 | 2171 | */ |
mbed_official | 237:f3da66175598 | 2172 | __weak void HAL_SDADC_InjectedConvHalfCpltCallback(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 2173 | { |
mbed_official | 237:f3da66175598 | 2174 | /* NOTE : This function should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 2175 | the HAL_SDADC_InjectedConvHalfCpltCallback could be implemented in the user file. |
mbed_official | 237:f3da66175598 | 2176 | */ |
mbed_official | 237:f3da66175598 | 2177 | } |
mbed_official | 237:f3da66175598 | 2178 | |
mbed_official | 237:f3da66175598 | 2179 | /** |
mbed_official | 237:f3da66175598 | 2180 | * @brief Injected conversion complete callback. |
mbed_official | 237:f3da66175598 | 2181 | * @note In interrupt mode, user has to read conversion value in this function |
mbed_official | 237:f3da66175598 | 2182 | using HAL_SDADC_InjectedGetValue or HAL_SDADC_InjectedMultiModeGetValue. |
mbed_official | 237:f3da66175598 | 2183 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 2184 | * @retval None |
mbed_official | 237:f3da66175598 | 2185 | */ |
mbed_official | 237:f3da66175598 | 2186 | __weak void HAL_SDADC_InjectedConvCpltCallback(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 2187 | { |
mbed_official | 237:f3da66175598 | 2188 | /* NOTE : This function should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 2189 | the HAL_SDADC_InjectedConvCpltCallback could be implemented in the user file. |
mbed_official | 237:f3da66175598 | 2190 | */ |
mbed_official | 237:f3da66175598 | 2191 | } |
mbed_official | 237:f3da66175598 | 2192 | |
mbed_official | 237:f3da66175598 | 2193 | /** |
mbed_official | 237:f3da66175598 | 2194 | * @brief Error callback. |
mbed_official | 237:f3da66175598 | 2195 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 2196 | * @retval None |
mbed_official | 237:f3da66175598 | 2197 | */ |
mbed_official | 237:f3da66175598 | 2198 | __weak void HAL_SDADC_ErrorCallback(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 2199 | { |
mbed_official | 237:f3da66175598 | 2200 | /* NOTE : This function should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 2201 | the HAL_SDADC_ErrorCallback could be implemented in the user file. |
mbed_official | 237:f3da66175598 | 2202 | */ |
mbed_official | 237:f3da66175598 | 2203 | } |
mbed_official | 237:f3da66175598 | 2204 | |
mbed_official | 237:f3da66175598 | 2205 | /** |
mbed_official | 237:f3da66175598 | 2206 | * @brief DMA half transfer complete callback for regular conversion. |
mbed_official | 237:f3da66175598 | 2207 | * @param hdma : DMA handle. |
mbed_official | 237:f3da66175598 | 2208 | * @retval None |
mbed_official | 237:f3da66175598 | 2209 | */ |
mbed_official | 237:f3da66175598 | 2210 | static void SDADC_DMARegularHalfConvCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 237:f3da66175598 | 2211 | { |
mbed_official | 237:f3da66175598 | 2212 | /* Get SDADC handle */ |
mbed_official | 237:f3da66175598 | 2213 | SDADC_HandleTypeDef* hsdadc = (SDADC_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent; |
mbed_official | 237:f3da66175598 | 2214 | |
mbed_official | 237:f3da66175598 | 2215 | /* Call regular half conversion complete callback */ |
mbed_official | 237:f3da66175598 | 2216 | HAL_SDADC_ConvHalfCpltCallback(hsdadc); |
mbed_official | 237:f3da66175598 | 2217 | } |
mbed_official | 237:f3da66175598 | 2218 | |
mbed_official | 237:f3da66175598 | 2219 | /** |
mbed_official | 237:f3da66175598 | 2220 | * @brief DMA transfer complete callback for regular conversion. |
mbed_official | 237:f3da66175598 | 2221 | * @param hdma : DMA handle. |
mbed_official | 237:f3da66175598 | 2222 | * @retval None |
mbed_official | 237:f3da66175598 | 2223 | */ |
mbed_official | 237:f3da66175598 | 2224 | static void SDADC_DMARegularConvCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 237:f3da66175598 | 2225 | { |
mbed_official | 237:f3da66175598 | 2226 | /* Get SDADC handle */ |
mbed_official | 237:f3da66175598 | 2227 | SDADC_HandleTypeDef* hsdadc = (SDADC_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent; |
mbed_official | 237:f3da66175598 | 2228 | |
mbed_official | 237:f3da66175598 | 2229 | /* Call regular conversion complete callback */ |
mbed_official | 237:f3da66175598 | 2230 | HAL_SDADC_ConvCpltCallback(hsdadc); |
mbed_official | 237:f3da66175598 | 2231 | } |
mbed_official | 237:f3da66175598 | 2232 | |
mbed_official | 237:f3da66175598 | 2233 | /** |
mbed_official | 237:f3da66175598 | 2234 | * @brief DMA half transfer complete callback for injected conversion. |
mbed_official | 237:f3da66175598 | 2235 | * @param hdma : DMA handle. |
mbed_official | 237:f3da66175598 | 2236 | * @retval None |
mbed_official | 237:f3da66175598 | 2237 | */ |
mbed_official | 237:f3da66175598 | 2238 | static void SDADC_DMAInjectedHalfConvCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 237:f3da66175598 | 2239 | { |
mbed_official | 237:f3da66175598 | 2240 | /* Get SDADC handle */ |
mbed_official | 237:f3da66175598 | 2241 | SDADC_HandleTypeDef* hsdadc = (SDADC_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent; |
mbed_official | 237:f3da66175598 | 2242 | |
mbed_official | 237:f3da66175598 | 2243 | /* Call injected half conversion complete callback */ |
mbed_official | 237:f3da66175598 | 2244 | HAL_SDADC_InjectedConvHalfCpltCallback(hsdadc); |
mbed_official | 237:f3da66175598 | 2245 | } |
mbed_official | 237:f3da66175598 | 2246 | |
mbed_official | 237:f3da66175598 | 2247 | /** |
mbed_official | 237:f3da66175598 | 2248 | * @brief DMA transfer complete callback for injected conversion. |
mbed_official | 237:f3da66175598 | 2249 | * @param hdma : DMA handle. |
mbed_official | 237:f3da66175598 | 2250 | * @retval None |
mbed_official | 237:f3da66175598 | 2251 | */ |
mbed_official | 237:f3da66175598 | 2252 | static void SDADC_DMAInjectedConvCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 237:f3da66175598 | 2253 | { |
mbed_official | 237:f3da66175598 | 2254 | /* Get SDADC handle */ |
mbed_official | 237:f3da66175598 | 2255 | SDADC_HandleTypeDef* hsdadc = (SDADC_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent; |
mbed_official | 237:f3da66175598 | 2256 | |
mbed_official | 237:f3da66175598 | 2257 | /* Call injected conversion complete callback */ |
mbed_official | 237:f3da66175598 | 2258 | HAL_SDADC_InjectedConvCpltCallback(hsdadc); |
mbed_official | 237:f3da66175598 | 2259 | } |
mbed_official | 237:f3da66175598 | 2260 | |
mbed_official | 237:f3da66175598 | 2261 | /** |
mbed_official | 237:f3da66175598 | 2262 | * @brief DMA error callback. |
mbed_official | 237:f3da66175598 | 2263 | * @param hdma : DMA handle. |
mbed_official | 237:f3da66175598 | 2264 | * @retval None |
mbed_official | 237:f3da66175598 | 2265 | */ |
mbed_official | 237:f3da66175598 | 2266 | static void SDADC_DMAError(DMA_HandleTypeDef *hdma) |
mbed_official | 237:f3da66175598 | 2267 | { |
mbed_official | 237:f3da66175598 | 2268 | /* Get SDADC handle */ |
mbed_official | 237:f3da66175598 | 2269 | SDADC_HandleTypeDef* hsdadc = (SDADC_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent; |
mbed_official | 237:f3da66175598 | 2270 | |
mbed_official | 237:f3da66175598 | 2271 | /* Update error code */ |
mbed_official | 237:f3da66175598 | 2272 | hsdadc->ErrorCode = SDADC_ERROR_DMA; |
mbed_official | 237:f3da66175598 | 2273 | |
mbed_official | 237:f3da66175598 | 2274 | /* Call error callback */ |
mbed_official | 237:f3da66175598 | 2275 | HAL_SDADC_ErrorCallback(hsdadc); |
mbed_official | 237:f3da66175598 | 2276 | } |
mbed_official | 237:f3da66175598 | 2277 | |
mbed_official | 237:f3da66175598 | 2278 | /** |
mbed_official | 237:f3da66175598 | 2279 | * @} |
mbed_official | 237:f3da66175598 | 2280 | */ |
mbed_official | 237:f3da66175598 | 2281 | |
mbed_official | 237:f3da66175598 | 2282 | /** @defgroup SDADC_Group4 SDADC Peripheral State functions |
mbed_official | 237:f3da66175598 | 2283 | * @brief SDADC Peripheral State functions |
mbed_official | 237:f3da66175598 | 2284 | * |
mbed_official | 237:f3da66175598 | 2285 | @verbatim |
mbed_official | 237:f3da66175598 | 2286 | =============================================================================== |
mbed_official | 237:f3da66175598 | 2287 | ##### ADC Peripheral State functions ##### |
mbed_official | 237:f3da66175598 | 2288 | =============================================================================== |
mbed_official | 237:f3da66175598 | 2289 | [..] This subsection provides functions allowing to |
mbed_official | 237:f3da66175598 | 2290 | (+) Get the SDADC state |
mbed_official | 237:f3da66175598 | 2291 | (+) Get the SDADC Error |
mbed_official | 237:f3da66175598 | 2292 | |
mbed_official | 237:f3da66175598 | 2293 | @endverbatim |
mbed_official | 237:f3da66175598 | 2294 | * @{ |
mbed_official | 237:f3da66175598 | 2295 | */ |
mbed_official | 237:f3da66175598 | 2296 | |
mbed_official | 237:f3da66175598 | 2297 | /** |
mbed_official | 237:f3da66175598 | 2298 | * @brief This function allows to get the current SDADC state. |
mbed_official | 237:f3da66175598 | 2299 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 2300 | * @retval SDADC state. |
mbed_official | 237:f3da66175598 | 2301 | */ |
mbed_official | 237:f3da66175598 | 2302 | HAL_SDADC_StateTypeDef HAL_SDADC_GetState(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 2303 | { |
mbed_official | 237:f3da66175598 | 2304 | return hsdadc->State; |
mbed_official | 237:f3da66175598 | 2305 | } |
mbed_official | 237:f3da66175598 | 2306 | |
mbed_official | 237:f3da66175598 | 2307 | /** |
mbed_official | 237:f3da66175598 | 2308 | * @brief This function allows to get the current SDADC error code. |
mbed_official | 237:f3da66175598 | 2309 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 2310 | * @retval SDADC error code. |
mbed_official | 237:f3da66175598 | 2311 | */ |
mbed_official | 237:f3da66175598 | 2312 | uint32_t HAL_SDADC_GetError(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 2313 | { |
mbed_official | 237:f3da66175598 | 2314 | return hsdadc->ErrorCode; |
mbed_official | 237:f3da66175598 | 2315 | } |
mbed_official | 237:f3da66175598 | 2316 | |
mbed_official | 237:f3da66175598 | 2317 | /** |
mbed_official | 237:f3da66175598 | 2318 | * @} |
mbed_official | 237:f3da66175598 | 2319 | */ |
mbed_official | 237:f3da66175598 | 2320 | |
mbed_official | 237:f3da66175598 | 2321 | /** |
mbed_official | 237:f3da66175598 | 2322 | * @brief This function allows to enter in init mode for SDADC instance. |
mbed_official | 237:f3da66175598 | 2323 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 2324 | * @retval HAL status. |
mbed_official | 237:f3da66175598 | 2325 | */ |
mbed_official | 237:f3da66175598 | 2326 | static HAL_StatusTypeDef SDADC_EnterInitMode(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 2327 | { |
mbed_official | 237:f3da66175598 | 2328 | uint32_t tickstart = 0; |
mbed_official | 237:f3da66175598 | 2329 | |
mbed_official | 237:f3da66175598 | 2330 | /* Set INIT bit on SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 2331 | hsdadc->Instance->CR1 |= SDADC_CR1_INIT; |
mbed_official | 237:f3da66175598 | 2332 | |
mbed_official | 237:f3da66175598 | 2333 | /* Wait INITRDY bit on SDADC_ISR */ |
mbed_official | 237:f3da66175598 | 2334 | tickstart = HAL_GetTick(); |
mbed_official | 237:f3da66175598 | 2335 | while((hsdadc->Instance->ISR & SDADC_ISR_INITRDY) == (uint32_t)RESET) |
mbed_official | 237:f3da66175598 | 2336 | { |
mbed_official | 237:f3da66175598 | 2337 | if((HAL_GetTick()-tickstart) > SDADC_TIMEOUT) |
mbed_official | 237:f3da66175598 | 2338 | { |
mbed_official | 237:f3da66175598 | 2339 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 2340 | } |
mbed_official | 237:f3da66175598 | 2341 | } |
mbed_official | 237:f3da66175598 | 2342 | |
mbed_official | 237:f3da66175598 | 2343 | /* Return HAL status */ |
mbed_official | 237:f3da66175598 | 2344 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 2345 | } |
mbed_official | 237:f3da66175598 | 2346 | |
mbed_official | 237:f3da66175598 | 2347 | /** |
mbed_official | 237:f3da66175598 | 2348 | * @brief This function allows to exit from init mode for SDADC instance. |
mbed_official | 237:f3da66175598 | 2349 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 2350 | * @retval None. |
mbed_official | 237:f3da66175598 | 2351 | */ |
mbed_official | 237:f3da66175598 | 2352 | static void SDADC_ExitInitMode(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 2353 | { |
mbed_official | 237:f3da66175598 | 2354 | /* Reset INIT bit in SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 2355 | hsdadc->Instance->CR1 &= ~(SDADC_CR1_INIT); |
mbed_official | 237:f3da66175598 | 2356 | } |
mbed_official | 237:f3da66175598 | 2357 | |
mbed_official | 237:f3da66175598 | 2358 | /** |
mbed_official | 237:f3da66175598 | 2359 | * @brief This function allows to get the number of injected channels. |
mbed_official | 237:f3da66175598 | 2360 | * @param Channels : bitfield of injected channels. |
mbed_official | 237:f3da66175598 | 2361 | * @retval Number of injected channels. |
mbed_official | 237:f3da66175598 | 2362 | */ |
mbed_official | 237:f3da66175598 | 2363 | static uint32_t SDADC_GetInjChannelsNbr(uint32_t Channels) |
mbed_official | 237:f3da66175598 | 2364 | { |
mbed_official | 237:f3da66175598 | 2365 | uint32_t nbChannels = 0; |
mbed_official | 237:f3da66175598 | 2366 | uint32_t tmp,i; |
mbed_official | 237:f3da66175598 | 2367 | |
mbed_official | 237:f3da66175598 | 2368 | /* Get the number of channels from bitfield */ |
mbed_official | 237:f3da66175598 | 2369 | tmp = (uint32_t) (Channels & SDADC_LSB_MASK); |
mbed_official | 237:f3da66175598 | 2370 | for(i = 0 ; i < 9 ; i++) |
mbed_official | 237:f3da66175598 | 2371 | { |
mbed_official | 237:f3da66175598 | 2372 | if(tmp & 1) |
mbed_official | 237:f3da66175598 | 2373 | { |
mbed_official | 237:f3da66175598 | 2374 | nbChannels++; |
mbed_official | 237:f3da66175598 | 2375 | } |
mbed_official | 237:f3da66175598 | 2376 | tmp = (uint32_t) (tmp >> 1); |
mbed_official | 237:f3da66175598 | 2377 | } |
mbed_official | 237:f3da66175598 | 2378 | return nbChannels; |
mbed_official | 237:f3da66175598 | 2379 | } |
mbed_official | 237:f3da66175598 | 2380 | |
mbed_official | 237:f3da66175598 | 2381 | /** |
mbed_official | 237:f3da66175598 | 2382 | * @brief This function allows to really start regular conversion. |
mbed_official | 237:f3da66175598 | 2383 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 2384 | * @retval HAL status. |
mbed_official | 237:f3da66175598 | 2385 | */ |
mbed_official | 237:f3da66175598 | 2386 | static HAL_StatusTypeDef SDADC_RegConvStart(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 2387 | { |
mbed_official | 237:f3da66175598 | 2388 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 2389 | |
mbed_official | 237:f3da66175598 | 2390 | /* Check regular trigger */ |
mbed_official | 237:f3da66175598 | 2391 | if(hsdadc->RegularTrigger == SDADC_SOFTWARE_TRIGGER) |
mbed_official | 237:f3da66175598 | 2392 | { |
mbed_official | 237:f3da66175598 | 2393 | /* Set RSWSTART bit in SDADC_CR2 register */ |
mbed_official | 237:f3da66175598 | 2394 | hsdadc->Instance->CR2 |= SDADC_CR2_RSWSTART; |
mbed_official | 237:f3da66175598 | 2395 | } |
mbed_official | 237:f3da66175598 | 2396 | else /* synchronuous trigger */ |
mbed_official | 237:f3da66175598 | 2397 | { |
mbed_official | 237:f3da66175598 | 2398 | /* Enter init mode */ |
mbed_official | 237:f3da66175598 | 2399 | if(SDADC_EnterInitMode(hsdadc) != HAL_OK) |
mbed_official | 237:f3da66175598 | 2400 | { |
mbed_official | 237:f3da66175598 | 2401 | /* Set SDADC in error state */ |
mbed_official | 237:f3da66175598 | 2402 | hsdadc->State = HAL_SDADC_STATE_ERROR; |
mbed_official | 237:f3da66175598 | 2403 | status = HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 2404 | } |
mbed_official | 237:f3da66175598 | 2405 | else |
mbed_official | 237:f3da66175598 | 2406 | { |
mbed_official | 237:f3da66175598 | 2407 | /* Set RSYNC bit in SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 2408 | hsdadc->Instance->CR1 |= SDADC_CR1_RSYNC; |
mbed_official | 237:f3da66175598 | 2409 | |
mbed_official | 237:f3da66175598 | 2410 | /* Exit init mode */ |
mbed_official | 237:f3da66175598 | 2411 | SDADC_ExitInitMode(hsdadc); |
mbed_official | 237:f3da66175598 | 2412 | } |
mbed_official | 237:f3da66175598 | 2413 | } |
mbed_official | 237:f3da66175598 | 2414 | /* Update SDADC state only if status is OK */ |
mbed_official | 237:f3da66175598 | 2415 | if(status == HAL_OK) |
mbed_official | 237:f3da66175598 | 2416 | { |
mbed_official | 237:f3da66175598 | 2417 | hsdadc->State = (hsdadc->State == HAL_SDADC_STATE_READY) ? \ |
mbed_official | 237:f3da66175598 | 2418 | HAL_SDADC_STATE_REG : HAL_SDADC_STATE_REG_INJ; |
mbed_official | 237:f3da66175598 | 2419 | } |
mbed_official | 237:f3da66175598 | 2420 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 2421 | return status; |
mbed_official | 237:f3da66175598 | 2422 | } |
mbed_official | 237:f3da66175598 | 2423 | |
mbed_official | 237:f3da66175598 | 2424 | /** |
mbed_official | 237:f3da66175598 | 2425 | * @brief This function allows to really stop regular conversion. |
mbed_official | 237:f3da66175598 | 2426 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 2427 | * @retval HAL status. |
mbed_official | 237:f3da66175598 | 2428 | */ |
mbed_official | 237:f3da66175598 | 2429 | static HAL_StatusTypeDef SDADC_RegConvStop(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 2430 | { |
mbed_official | 237:f3da66175598 | 2431 | uint32_t tickstart; |
mbed_official | 237:f3da66175598 | 2432 | |
mbed_official | 237:f3da66175598 | 2433 | /* Check continuous mode */ |
mbed_official | 237:f3da66175598 | 2434 | if(hsdadc->RegularContMode == SDADC_CONTINUOUS_CONV_ON) |
mbed_official | 237:f3da66175598 | 2435 | { |
mbed_official | 237:f3da66175598 | 2436 | /* Clear REOCF by reading SDADC_RDATAR register */ |
mbed_official | 237:f3da66175598 | 2437 | hsdadc->Instance->RDATAR; |
mbed_official | 237:f3da66175598 | 2438 | |
mbed_official | 237:f3da66175598 | 2439 | /* Clear RCONT bit in SDADC_CR2 register */ |
mbed_official | 237:f3da66175598 | 2440 | hsdadc->Instance->CR2 &= ~(SDADC_CR2_RCONT); |
mbed_official | 237:f3da66175598 | 2441 | } |
mbed_official | 237:f3da66175598 | 2442 | /* Wait for the end of regular conversion */ |
mbed_official | 237:f3da66175598 | 2443 | tickstart = HAL_GetTick(); |
mbed_official | 237:f3da66175598 | 2444 | while((hsdadc->Instance->ISR & SDADC_ISR_RCIP) != 0) |
mbed_official | 237:f3da66175598 | 2445 | { |
mbed_official | 237:f3da66175598 | 2446 | if((HAL_GetTick()-tickstart) > SDADC_TIMEOUT) |
mbed_official | 237:f3da66175598 | 2447 | { |
mbed_official | 237:f3da66175598 | 2448 | /* Set SDADC in error state and return timeout status */ |
mbed_official | 237:f3da66175598 | 2449 | hsdadc->State = HAL_SDADC_STATE_ERROR; |
mbed_official | 237:f3da66175598 | 2450 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 2451 | } |
mbed_official | 237:f3da66175598 | 2452 | } |
mbed_official | 237:f3da66175598 | 2453 | /* Check if trigger is synchronuous */ |
mbed_official | 237:f3da66175598 | 2454 | if(hsdadc->RegularTrigger == SDADC_SYNCHRONOUS_TRIGGER) |
mbed_official | 237:f3da66175598 | 2455 | { |
mbed_official | 237:f3da66175598 | 2456 | /* Enter init mode */ |
mbed_official | 237:f3da66175598 | 2457 | if(SDADC_EnterInitMode(hsdadc) != HAL_OK) |
mbed_official | 237:f3da66175598 | 2458 | { |
mbed_official | 237:f3da66175598 | 2459 | /* Set SDADC in error state and return timeout status */ |
mbed_official | 237:f3da66175598 | 2460 | hsdadc->State = HAL_SDADC_STATE_ERROR; |
mbed_official | 237:f3da66175598 | 2461 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 2462 | } |
mbed_official | 237:f3da66175598 | 2463 | else |
mbed_official | 237:f3da66175598 | 2464 | { |
mbed_official | 237:f3da66175598 | 2465 | /* Clear RSYNC bit in SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 2466 | hsdadc->Instance->CR1 &= ~(SDADC_CR1_RSYNC); |
mbed_official | 237:f3da66175598 | 2467 | |
mbed_official | 237:f3da66175598 | 2468 | /* Exit init mode */ |
mbed_official | 237:f3da66175598 | 2469 | SDADC_ExitInitMode(hsdadc); |
mbed_official | 237:f3da66175598 | 2470 | } |
mbed_official | 237:f3da66175598 | 2471 | } |
mbed_official | 237:f3da66175598 | 2472 | /* Check if continuous mode */ |
mbed_official | 237:f3da66175598 | 2473 | if(hsdadc->RegularContMode == SDADC_CONTINUOUS_CONV_ON) |
mbed_official | 237:f3da66175598 | 2474 | { |
mbed_official | 237:f3da66175598 | 2475 | /* Restore RCONT bit in SDADC_CR2 register */ |
mbed_official | 237:f3da66175598 | 2476 | hsdadc->Instance->CR2 |= SDADC_CR2_RCONT; |
mbed_official | 237:f3da66175598 | 2477 | } |
mbed_official | 237:f3da66175598 | 2478 | /* Clear REOCF by reading SDADC_RDATAR register */ |
mbed_official | 237:f3da66175598 | 2479 | hsdadc->Instance->RDATAR; |
mbed_official | 237:f3da66175598 | 2480 | |
mbed_official | 237:f3da66175598 | 2481 | /* Set CLRROVRF bit in SDADC_CLRISR register */ |
mbed_official | 237:f3da66175598 | 2482 | hsdadc->Instance->CLRISR |= SDADC_ISR_CLRROVRF; |
mbed_official | 237:f3da66175598 | 2483 | |
mbed_official | 237:f3da66175598 | 2484 | /* Update SDADC state */ |
mbed_official | 237:f3da66175598 | 2485 | hsdadc->State = (hsdadc->State == HAL_SDADC_STATE_REG) ? \ |
mbed_official | 237:f3da66175598 | 2486 | HAL_SDADC_STATE_READY : HAL_SDADC_STATE_INJ; |
mbed_official | 237:f3da66175598 | 2487 | |
mbed_official | 237:f3da66175598 | 2488 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 2489 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 2490 | } |
mbed_official | 237:f3da66175598 | 2491 | |
mbed_official | 237:f3da66175598 | 2492 | /** |
mbed_official | 237:f3da66175598 | 2493 | * @brief This function allows to really start injected conversion. |
mbed_official | 237:f3da66175598 | 2494 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 2495 | * @retval HAL status. |
mbed_official | 237:f3da66175598 | 2496 | */ |
mbed_official | 237:f3da66175598 | 2497 | static HAL_StatusTypeDef SDADC_InjConvStart(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 2498 | { |
mbed_official | 237:f3da66175598 | 2499 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 2500 | |
mbed_official | 237:f3da66175598 | 2501 | /* Initialize number of injected conversions remaining */ |
mbed_official | 237:f3da66175598 | 2502 | hsdadc->InjConvRemaining = hsdadc->InjectedChannelsNbr; |
mbed_official | 237:f3da66175598 | 2503 | |
mbed_official | 237:f3da66175598 | 2504 | /* Check injected trigger */ |
mbed_official | 237:f3da66175598 | 2505 | if(hsdadc->InjectedTrigger == SDADC_SOFTWARE_TRIGGER) |
mbed_official | 237:f3da66175598 | 2506 | { |
mbed_official | 237:f3da66175598 | 2507 | /* Set JSWSTART bit in SDADC_CR2 register */ |
mbed_official | 237:f3da66175598 | 2508 | hsdadc->Instance->CR2 |= SDADC_CR2_JSWSTART; |
mbed_official | 237:f3da66175598 | 2509 | } |
mbed_official | 237:f3da66175598 | 2510 | else /* external or synchronuous trigger */ |
mbed_official | 237:f3da66175598 | 2511 | { |
mbed_official | 237:f3da66175598 | 2512 | /* Enter init mode */ |
mbed_official | 237:f3da66175598 | 2513 | if(SDADC_EnterInitMode(hsdadc) != HAL_OK) |
mbed_official | 237:f3da66175598 | 2514 | { |
mbed_official | 237:f3da66175598 | 2515 | /* Set SDADC in error state */ |
mbed_official | 237:f3da66175598 | 2516 | hsdadc->State = HAL_SDADC_STATE_ERROR; |
mbed_official | 237:f3da66175598 | 2517 | status = HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 2518 | } |
mbed_official | 237:f3da66175598 | 2519 | else |
mbed_official | 237:f3da66175598 | 2520 | { |
mbed_official | 237:f3da66175598 | 2521 | if(hsdadc->InjectedTrigger == SDADC_SYNCHRONOUS_TRIGGER) |
mbed_official | 237:f3da66175598 | 2522 | { |
mbed_official | 237:f3da66175598 | 2523 | /* Set JSYNC bit in SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 2524 | hsdadc->Instance->CR1 |= SDADC_CR1_JSYNC; |
mbed_official | 237:f3da66175598 | 2525 | } |
mbed_official | 237:f3da66175598 | 2526 | else /* external trigger */ |
mbed_official | 237:f3da66175598 | 2527 | { |
mbed_official | 237:f3da66175598 | 2528 | /* Set JEXTEN[1:0] bits in SDADC_CR2 register */ |
mbed_official | 237:f3da66175598 | 2529 | hsdadc->Instance->CR2 |= hsdadc->ExtTriggerEdge; |
mbed_official | 237:f3da66175598 | 2530 | } |
mbed_official | 237:f3da66175598 | 2531 | /* Exit init mode */ |
mbed_official | 237:f3da66175598 | 2532 | SDADC_ExitInitMode(hsdadc); |
mbed_official | 237:f3da66175598 | 2533 | } |
mbed_official | 237:f3da66175598 | 2534 | } |
mbed_official | 237:f3da66175598 | 2535 | /* Update SDADC state only if status is OK */ |
mbed_official | 237:f3da66175598 | 2536 | if(status == HAL_OK) |
mbed_official | 237:f3da66175598 | 2537 | { |
mbed_official | 237:f3da66175598 | 2538 | hsdadc->State = (hsdadc->State == HAL_SDADC_STATE_READY) ? \ |
mbed_official | 237:f3da66175598 | 2539 | HAL_SDADC_STATE_INJ : HAL_SDADC_STATE_REG_INJ; |
mbed_official | 237:f3da66175598 | 2540 | } |
mbed_official | 237:f3da66175598 | 2541 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 2542 | return status; |
mbed_official | 237:f3da66175598 | 2543 | } |
mbed_official | 237:f3da66175598 | 2544 | |
mbed_official | 237:f3da66175598 | 2545 | /** |
mbed_official | 237:f3da66175598 | 2546 | * @brief This function allows to really stop injected conversion. |
mbed_official | 237:f3da66175598 | 2547 | * @param hsdadc : SDADC handle. |
mbed_official | 237:f3da66175598 | 2548 | * @retval HAL status. |
mbed_official | 237:f3da66175598 | 2549 | */ |
mbed_official | 237:f3da66175598 | 2550 | static HAL_StatusTypeDef SDADC_InjConvStop(SDADC_HandleTypeDef* hsdadc) |
mbed_official | 237:f3da66175598 | 2551 | { |
mbed_official | 237:f3da66175598 | 2552 | uint32_t tickstart; |
mbed_official | 237:f3da66175598 | 2553 | |
mbed_official | 237:f3da66175598 | 2554 | /* Check continuous mode */ |
mbed_official | 237:f3da66175598 | 2555 | if(hsdadc->InjectedContMode == SDADC_CONTINUOUS_CONV_ON) |
mbed_official | 237:f3da66175598 | 2556 | { |
mbed_official | 237:f3da66175598 | 2557 | /* Clear JEOCF by reading SDADC_JDATAR register */ |
mbed_official | 237:f3da66175598 | 2558 | hsdadc->Instance->JDATAR; |
mbed_official | 237:f3da66175598 | 2559 | |
mbed_official | 237:f3da66175598 | 2560 | /* Clear JCONT bit in SDADC_CR2 register */ |
mbed_official | 237:f3da66175598 | 2561 | hsdadc->Instance->CR2 &= ~(SDADC_CR2_JCONT); |
mbed_official | 237:f3da66175598 | 2562 | } |
mbed_official | 237:f3da66175598 | 2563 | /* Wait for the end of injected conversion */ |
mbed_official | 237:f3da66175598 | 2564 | tickstart = HAL_GetTick(); |
mbed_official | 237:f3da66175598 | 2565 | while((hsdadc->Instance->ISR & SDADC_ISR_JCIP) != 0) |
mbed_official | 237:f3da66175598 | 2566 | { |
mbed_official | 237:f3da66175598 | 2567 | if((HAL_GetTick()-tickstart) > SDADC_TIMEOUT) |
mbed_official | 237:f3da66175598 | 2568 | { |
mbed_official | 237:f3da66175598 | 2569 | /* Set SDADC in error state and return timeout status */ |
mbed_official | 237:f3da66175598 | 2570 | hsdadc->State = HAL_SDADC_STATE_ERROR; |
mbed_official | 237:f3da66175598 | 2571 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 2572 | } |
mbed_official | 237:f3da66175598 | 2573 | } |
mbed_official | 237:f3da66175598 | 2574 | /* Check if trigger is not software */ |
mbed_official | 237:f3da66175598 | 2575 | if(hsdadc->InjectedTrigger != SDADC_SOFTWARE_TRIGGER) |
mbed_official | 237:f3da66175598 | 2576 | { |
mbed_official | 237:f3da66175598 | 2577 | /* Enter init mode */ |
mbed_official | 237:f3da66175598 | 2578 | if(SDADC_EnterInitMode(hsdadc) != HAL_OK) |
mbed_official | 237:f3da66175598 | 2579 | { |
mbed_official | 237:f3da66175598 | 2580 | /* Set SDADC in error state and return timeout status */ |
mbed_official | 237:f3da66175598 | 2581 | hsdadc->State = HAL_SDADC_STATE_ERROR; |
mbed_official | 237:f3da66175598 | 2582 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 2583 | } |
mbed_official | 237:f3da66175598 | 2584 | else |
mbed_official | 237:f3da66175598 | 2585 | { |
mbed_official | 237:f3da66175598 | 2586 | /* Check if trigger is synchronuous */ |
mbed_official | 237:f3da66175598 | 2587 | if(hsdadc->InjectedTrigger == SDADC_SYNCHRONOUS_TRIGGER) |
mbed_official | 237:f3da66175598 | 2588 | { |
mbed_official | 237:f3da66175598 | 2589 | /* Clear JSYNC bit in SDADC_CR1 register */ |
mbed_official | 237:f3da66175598 | 2590 | hsdadc->Instance->CR1 &= ~(SDADC_CR1_JSYNC); |
mbed_official | 237:f3da66175598 | 2591 | } |
mbed_official | 237:f3da66175598 | 2592 | else /* external trigger */ |
mbed_official | 237:f3da66175598 | 2593 | { |
mbed_official | 237:f3da66175598 | 2594 | /* Clear JEXTEN[1:0] bits in SDADC_CR2 register */ |
mbed_official | 237:f3da66175598 | 2595 | hsdadc->Instance->CR2 &= ~(SDADC_CR2_JEXTEN); |
mbed_official | 237:f3da66175598 | 2596 | } |
mbed_official | 237:f3da66175598 | 2597 | /* Exit init mode */ |
mbed_official | 237:f3da66175598 | 2598 | SDADC_ExitInitMode(hsdadc); |
mbed_official | 237:f3da66175598 | 2599 | } |
mbed_official | 237:f3da66175598 | 2600 | } |
mbed_official | 237:f3da66175598 | 2601 | /* Check if continuous mode */ |
mbed_official | 237:f3da66175598 | 2602 | if(hsdadc->InjectedContMode == SDADC_CONTINUOUS_CONV_ON) |
mbed_official | 237:f3da66175598 | 2603 | { |
mbed_official | 237:f3da66175598 | 2604 | /* Restore JCONT bit in SDADC_CR2 register */ |
mbed_official | 237:f3da66175598 | 2605 | hsdadc->Instance->CR2 |= SDADC_CR2_JCONT; |
mbed_official | 237:f3da66175598 | 2606 | } |
mbed_official | 237:f3da66175598 | 2607 | /* Clear JEOCF by reading SDADC_JDATAR register */ |
mbed_official | 237:f3da66175598 | 2608 | hsdadc->Instance->JDATAR; |
mbed_official | 237:f3da66175598 | 2609 | |
mbed_official | 237:f3da66175598 | 2610 | /* Set CLRJOVRF bit in SDADC_CLRISR register */ |
mbed_official | 237:f3da66175598 | 2611 | hsdadc->Instance->CLRISR |= SDADC_ISR_CLRJOVRF; |
mbed_official | 237:f3da66175598 | 2612 | |
mbed_official | 237:f3da66175598 | 2613 | /* Update SDADC state */ |
mbed_official | 237:f3da66175598 | 2614 | hsdadc->State = (hsdadc->State == HAL_SDADC_STATE_INJ) ? \ |
mbed_official | 237:f3da66175598 | 2615 | HAL_SDADC_STATE_READY : HAL_SDADC_STATE_REG; |
mbed_official | 237:f3da66175598 | 2616 | |
mbed_official | 237:f3da66175598 | 2617 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 2618 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 2619 | } |
mbed_official | 237:f3da66175598 | 2620 | |
mbed_official | 237:f3da66175598 | 2621 | /** |
mbed_official | 237:f3da66175598 | 2622 | * @} |
mbed_official | 237:f3da66175598 | 2623 | */ |
mbed_official | 237:f3da66175598 | 2624 | |
mbed_official | 237:f3da66175598 | 2625 | #endif /* defined(STM32F373xC) || defined(STM32F378xx) */ |
mbed_official | 237:f3da66175598 | 2626 | #endif /* HAL_SDADC_MODULE_ENABLED */ |
mbed_official | 237:f3da66175598 | 2627 | /** |
mbed_official | 237:f3da66175598 | 2628 | * @} |
mbed_official | 237:f3da66175598 | 2629 | */ |
mbed_official | 237:f3da66175598 | 2630 | |
mbed_official | 237:f3da66175598 | 2631 | /** |
mbed_official | 237:f3da66175598 | 2632 | * @} |
mbed_official | 237:f3da66175598 | 2633 | */ |
mbed_official | 237:f3da66175598 | 2634 | |
mbed_official | 237:f3da66175598 | 2635 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |