annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_adc.c @ 59:00e70b60c69f

language updates
author heinrichsweikamp
date Fri, 10 Aug 2018 19:22:12 +0200
parents 5f11787b4f42
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file stm32f4xx_hal_adc.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author MCD Application Team
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @version V1.2.0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 26-December-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @brief This file provides firmware functions to manage the following
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 * functionalities of the Analog to Digital Convertor (ADC) peripheral:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 * + Initialization and de-initialization functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 * + IO operation functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 * + State and errors functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 ##### ADC Peripheral features #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 (#) 12-bit, 10-bit, 8-bit or 6-bit configurable resolution.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 (#) Interrupt generation at the end of conversion, end of injected conversion,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 and in case of analog watchdog or overrun events
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 (#) Single and continuous conversion modes.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 (#) Scan mode for automatic conversion of channel 0 to channel x.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 (#) Data alignment with in-built data coherency.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 (#) Channel-wise programmable sampling time.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 (#) External trigger option with configurable polarity for both regular and
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 injected conversion.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 (#) Dual/Triple mode (on devices with 2 ADCs or more).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 (#) Configurable DMA data storage in Dual/Triple ADC mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 (#) Configurable delay between conversions in Dual/Triple interleaved mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 (#) ADC conversion type (refer to the datasheets).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 (#) ADC supply requirements: 2.4 V to 3.6 V at full speed and down to 1.8 V at
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 slower speed.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33 (#) ADC input range: VREF(minus) = VIN = VREF(plus).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 (#) DMA request generation during regular channel conversion.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 ##### How to use this driver #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 (#)Initialize the ADC low level resources by implementing the HAL_ADC_MspInit():
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 (##) Enable the ADC interface clock using __HAL_RCC_ADC_CLK_ENABLE()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 (##) ADC pins configuration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 (+++) Enable the clock for the ADC GPIOs using the following function:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 __HAL_RCC_GPIOx_CLK_ENABLE()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 (+++) Configure these ADC pins in analog mode using HAL_GPIO_Init()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 (##) In case of using interrupts (e.g. HAL_ADC_Start_IT())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 (+++) Configure the ADC interrupt priority using HAL_NVIC_SetPriority()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 (+++) Enable the ADC IRQ handler using HAL_NVIC_EnableIRQ()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 (+++) In ADC IRQ handler, call HAL_ADC_IRQHandler()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 (##) In case of using DMA to control data transfer (e.g. HAL_ADC_Start_DMA())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 (+++) Enable the DMAx interface clock using __HAL_RCC_DMAx_CLK_ENABLE()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 (+++) Configure and enable two DMA streams stream for managing data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 transfer from peripheral to memory (output stream)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 (+++) Associate the initialized DMA handle to the CRYP DMA handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 using __HAL_LINKDMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 (+++) Configure the priority and enable the NVIC for the transfer complete
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 interrupt on the two DMA Streams. The output stream should have higher
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 priority than the input stream.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 (#) Configure the ADC Prescaler, conversion resolution and data alignment
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 using the HAL_ADC_Init() function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 (#) Configure the ADC regular channels group features, use HAL_ADC_Init()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 and HAL_ADC_ConfigChannel() functions.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 (#) Three operation modes are available within this driver :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 *** Polling mode IO operation ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 =================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 (+) Start the ADC peripheral using HAL_ADC_Start()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 (+) Wait for end of conversion using HAL_ADC_PollForConversion(), at this stage
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 user can specify the value of timeout according to his end application
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 (+) To read the ADC converted values, use the HAL_ADC_GetValue() function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 (+) Stop the ADC peripheral using HAL_ADC_Stop()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 *** Interrupt mode IO operation ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 ===================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 (+) Start the ADC peripheral using HAL_ADC_Start_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 (+) Use HAL_ADC_IRQHandler() called under ADC_IRQHandler() Interrupt subroutine
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 (+) At ADC end of conversion HAL_ADC_ConvCpltCallback() function is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 add his own code by customization of function pointer HAL_ADC_ConvCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 (+) In case of ADC Error, HAL_ADC_ErrorCallback() function is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 add his own code by customization of function pointer HAL_ADC_ErrorCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 (+) Stop the ADC peripheral using HAL_ADC_Stop_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 *** DMA mode IO operation ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 ==============================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 (+) Start the ADC peripheral using HAL_ADC_Start_DMA(), at this stage the user specify the length
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 of data to be transferred at each end of conversion
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 (+) At The end of data transfer by HAL_ADC_ConvCpltCallback() function is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 add his own code by customization of function pointer HAL_ADC_ConvCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 (+) In case of transfer Error, HAL_ADC_ErrorCallback() function is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 add his own code by customization of function pointer HAL_ADC_ErrorCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 (+) Stop the ADC peripheral using HAL_ADC_Stop_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 *** ADC HAL driver macros list ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 =============================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 Below the list of most used macros in ADC HAL driver.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 (+) __HAL_ADC_ENABLE : Enable the ADC peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 (+) __HAL_ADC_DISABLE : Disable the ADC peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 (+) __HAL_ADC_ENABLE_IT: Enable the ADC end of conversion interrupt
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 (+) __HAL_ADC_DISABLE_IT: Disable the ADC end of conversion interrupt
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 (+) __HAL_ADC_GET_IT_SOURCE: Check if the specified ADC interrupt source is enabled or disabled
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 (+) __HAL_ADC_CLEAR_FLAG: Clear the ADC's pending flags
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 (+) __HAL_ADC_GET_FLAG: Get the selected ADC's flag status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 (+) ADC_GET_RESOLUTION: Return resolution bits in CR1 register
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 (@) You can refer to the ADC HAL driver header file for more useful macros
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 * Redistribution and use in source and binary forms, with or without modification,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 * are permitted provided that the following conditions are met:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124 * 1. Redistributions of source code must retain the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 * this list of conditions and the following disclaimer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 * 2. Redistributions in binary form must reproduce the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 * this list of conditions and the following disclaimer in the documentation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 * and/or other materials provided with the distribution.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 * 3. Neither the name of STMicroelectronics nor the names of its contributors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 * may be used to endorse or promote products derived from this software
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 * without specific prior written permission.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 /** @addtogroup STM32F4xx_HAL_Driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 /** @defgroup ADC ADC
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 * @brief ADC driver modules
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 #ifdef HAL_ADC_MODULE_ENABLED
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 /* Private typedef -----------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 /* Private define ------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 /* Private macro -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 /** @addtogroup ADC_Private_Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 /* Private function prototypes -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 static void ADC_Init(ADC_HandleTypeDef* hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 static void ADC_DMAConvCplt(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 static void ADC_DMAError(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 static void ADC_DMAHalfConvCplt(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 /* Exported functions --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 /** @defgroup ADC_Exported_Functions ADC Exported Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 /** @defgroup ADC_Exported_Functions_Group1 Initialization and de-initialization functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 * @brief Initialization and Configuration functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 ##### Initialization and de-initialization functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 [..] This section provides functions allowing to:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 (+) Initialize and configure the ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 (+) De-initialize the ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 * @brief Initializes the ADCx peripheral according to the specified parameters
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 * in the ADC_InitStruct and initializes the ADC MSP.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 * @note This function is used to configure the global features of the ADC (
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 * ClockPrescaler, Resolution, Data Alignment and number of conversion), however,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 * the rest of the configuration parameters are specific to the regular
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 * channels group (scan mode activation, continuous mode activation,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 * External trigger source and edge, DMA continuous request after the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 * last transfer and End of conversion selection).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 /* Check ADC handle */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 if(hadc == NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 assert_param(IS_ADC_CLOCKPRESCALER(hadc->Init.ClockPrescaler));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 assert_param(IS_ADC_RESOLUTION(hadc->Init.Resolution));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ScanConvMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224 assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ContinuousConvMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 assert_param(IS_ADC_EXT_TRIG_EDGE(hadc->Init.ExternalTrigConvEdge));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 assert_param(IS_ADC_EXT_TRIG(hadc->Init.ExternalTrigConv));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 assert_param(IS_ADC_DATA_ALIGN(hadc->Init.DataAlign));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 assert_param(IS_ADC_REGULAR_LENGTH(hadc->Init.NbrOfConversion));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 assert_param(IS_FUNCTIONAL_STATE(hadc->Init.DMAContinuousRequests));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 assert_param(IS_ADC_EOCSelection(hadc->Init.EOCSelection));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 assert_param(IS_FUNCTIONAL_STATE(hadc->Init.DiscontinuousConvMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 if(hadc->State == HAL_ADC_STATE_RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 /* Init the low level hardware */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236 HAL_ADC_MspInit(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 /* Initialize the ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 hadc->State = HAL_ADC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 /* Set ADC parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 ADC_Init(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 /* Set ADC error code to none */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 hadc->ErrorCode = HAL_ADC_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 /* Initialize the ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 hadc->State = HAL_ADC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 /* Release Lock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 __HAL_UNLOCK(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 * @brief Deinitializes the ADCx peripheral registers to their default reset values.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef* hadc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 /* Check ADC handle */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 if(hadc == NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 /* Change ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 hadc->State = HAL_ADC_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 /* DeInit the low level hardware */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 HAL_ADC_MspDeInit(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 /* Set ADC error code to none */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 hadc->ErrorCode = HAL_ADC_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 /* Change ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 hadc->State = HAL_ADC_STATE_RESET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 * @brief Initializes the ADC MSP.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 __weak void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 the HAL_ADC_MspInit could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 * @brief DeInitializes the ADC MSP.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 __weak void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 the HAL_ADC_MspDeInit could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 /** @defgroup ADC_Exported_Functions_Group2 IO operation functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 * @brief IO operation functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 ##### IO operation functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 [..] This section provides functions allowing to:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 (+) Start conversion of regular channel.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330 (+) Stop conversion of regular channel.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 (+) Start conversion of regular channel and enable interrupt.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 (+) Stop conversion of regular channel and disable interrupt.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 (+) Start conversion of regular channel and enable DMA transfer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 (+) Stop conversion of regular channel and disable DMA transfer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 (+) Handle ADC interrupt request.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 * @brief Enables ADC and starts conversion of the regular channels.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 uint16_t i = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ContinuousConvMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 assert_param(IS_ADC_EXT_TRIG_EDGE(hadc->Init.ExternalTrigConvEdge));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 /* Process locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356 __HAL_LOCK(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 /* Check if an injected conversion is ongoing */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 if(hadc->State == HAL_ADC_STATE_BUSY_INJ)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 /* Change ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 hadc->State = HAL_ADC_STATE_BUSY_INJ_REG;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 /* Change ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 hadc->State = HAL_ADC_STATE_BUSY_REG;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 /* Check if ADC peripheral is disabled in order to enable it and wait during
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 Tstab time the ADC's stabilization */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 /* Enable the Peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 __HAL_ADC_ENABLE(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 /* Delay inserted to wait during Tstab time the ADC's stabilization */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 for(; i <= 540; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 __NOP();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 /* Check if Multimode enabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 if(HAL_IS_BIT_CLR(ADC->CCR, ADC_CCR_MULTI))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 /* if no external trigger present enable software conversion of regular channels */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 if(hadc->Init.ExternalTrigConvEdge == ADC_EXTERNALTRIGCONVEDGE_NONE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 /* Enable the selected ADC software conversion for regular group */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 hadc->Instance->CR2 |= (uint32_t)ADC_CR2_SWSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 /* if instance of handle correspond to ADC1 and no external trigger present enable software conversion of regular channels */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 if((hadc->Instance == ADC1) && (hadc->Init.ExternalTrigConvEdge == ADC_EXTERNALTRIGCONVEDGE_NONE))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 /* Enable the selected ADC software conversion for regular group */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 hadc->Instance->CR2 |= (uint32_t)ADC_CR2_SWSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 /* Process unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 __HAL_UNLOCK(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 * @brief Disables ADC and stop conversion of regular channels.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 * @note Caution: This function will stop also injected channels.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 * @retval HAL status.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef* hadc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 /* Disable the Peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424 __HAL_ADC_DISABLE(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426 /* Change ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 hadc->State = HAL_ADC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 * @brief Poll for regular conversion complete
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 * @param Timeout: Timeout value in millisecond.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 /* Check End of conversion flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 while(!(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_EOC)))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 hadc->State= HAL_ADC_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 /* Process unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457 __HAL_UNLOCK(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 /* Check if an injected conversion is ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 if(hadc->State == HAL_ADC_STATE_EOC_INJ)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466 /* Change ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 hadc->State = HAL_ADC_STATE_EOC_INJ_REG;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 /* Change ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 hadc->State = HAL_ADC_STATE_EOC_REG;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 /* Return ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 * @brief Poll for conversion event
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 * @param EventType: the ADC event type.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485 * @arg ADC_AWD_EVENT: ADC Analog watch Dog event.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486 * @arg ADC_OVR_EVENT: ADC Overrun event.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487 * @param Timeout: Timeout value in millisecond.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490 HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495 assert_param(IS_ADC_EVENT_TYPE(EventType));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500 /* Check selected event flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501 while(!(__HAL_ADC_GET_FLAG(hadc,EventType)))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 hadc->State= HAL_ADC_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509 /* Process unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510 __HAL_UNLOCK(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516 /* Check analog watchdog flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517 if(EventType == ADC_AWD_EVENT)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519 /* Change ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520 hadc->State = HAL_ADC_STATE_AWD;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 /* Clear the ADCx's analog watchdog flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523 __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_AWD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527 /* Change ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528 hadc->State = HAL_ADC_STATE_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
530 /* Clear the ADCx's Overrun flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
531 __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_OVR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534 /* Return ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540 * @brief Enables the interrupt and starts ADC conversion of regular channels.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543 * @retval HAL status.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545 HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547 uint16_t i = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
549 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550 assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ContinuousConvMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
551 assert_param(IS_ADC_EXT_TRIG_EDGE(hadc->Init.ExternalTrigConvEdge));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
552
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
553 /* Process locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554 __HAL_LOCK(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
556 /* Check if an injected conversion is ongoing */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
557 if(hadc->State == HAL_ADC_STATE_BUSY_INJ)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
558 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559 /* Change ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
560 hadc->State = HAL_ADC_STATE_BUSY_INJ_REG;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564 /* Change ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565 hadc->State = HAL_ADC_STATE_BUSY_REG;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568 /* Set ADC error code to none */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 hadc->ErrorCode = HAL_ADC_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
570
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571 /* Check if ADC peripheral is disabled in order to enable it and wait during
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
572 Tstab time the ADC's stabilization */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573 if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575 /* Enable the Peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
576 __HAL_ADC_ENABLE(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 /* Delay inserted to wait during Tstab time the ADC's stabilization */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579 for(; i <= 540; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581 __NOP();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
585 /* Enable the ADC overrun interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586 __HAL_ADC_ENABLE_IT(hadc, ADC_IT_OVR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588 /* Enable the ADC end of conversion interrupt for regular group */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589 __HAL_ADC_ENABLE_IT(hadc, ADC_IT_EOC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591 /* Check if Multimode enabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
592 if(HAL_IS_BIT_CLR(ADC->CCR, ADC_CCR_MULTI))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
593 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
594 /* if no external trigger present enable software conversion of regular channels */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
595 if (hadc->Init.ExternalTrigConvEdge == ADC_EXTERNALTRIGCONVEDGE_NONE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
596 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
597 /* Enable the selected ADC software conversion for regular group */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
598 hadc->Instance->CR2 |= (uint32_t)ADC_CR2_SWSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
599 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
600 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
601 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
602 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
603 /* if instance of handle correspond to ADC1 and no external trigger present enable software conversion of regular channels */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
604 if ((hadc->Instance == (ADC_TypeDef*)0x40012000) && (hadc->Init.ExternalTrigConvEdge == ADC_EXTERNALTRIGCONVEDGE_NONE))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
606 /* Enable the selected ADC software conversion for regular group */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
607 hadc->Instance->CR2 |= (uint32_t)ADC_CR2_SWSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611 /* Process unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
612 __HAL_UNLOCK(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
613
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
614 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
615 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
617
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
619 * @brief Disables the interrupt and stop ADC conversion of regular channels.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
620 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
621 * @note Caution: This function will stop also injected channels.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
622 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
623 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
624 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
625 * @retval HAL status.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
626 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
627 HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
628 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
629 /* Disable the ADC end of conversion interrupt for regular group */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
630 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_EOC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
631
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
632 /* Disable the ADC end of conversion interrupt for injected group */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
633 __HAL_ADC_DISABLE_IT(hadc, ADC_CR1_JEOCIE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
634
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
635 /* Enable the Peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
636 __HAL_ADC_DISABLE(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
637
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
638 /* Change ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
639 hadc->State = HAL_ADC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
640
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
641 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
642 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
643 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
644
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
645 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
646 * @brief Handles ADC interrupt request
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
647 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
648 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
649 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
650 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
651 void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
652 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
653 uint32_t tmp1 = 0, tmp2 = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
656 assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ContinuousConvMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
657 assert_param(IS_ADC_REGULAR_LENGTH(hadc->Init.NbrOfConversion));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658 assert_param(IS_ADC_EOCSelection(hadc->Init.EOCSelection));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660 tmp1 = __HAL_ADC_GET_FLAG(hadc, ADC_FLAG_EOC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661 tmp2 = __HAL_ADC_GET_IT_SOURCE(hadc, ADC_IT_EOC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662 /* Check End of conversion flag for regular channels */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663 if(tmp1 && tmp2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665 /* Check if an injected conversion is ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
666 if(hadc->State == HAL_ADC_STATE_EOC_INJ)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
667 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668 /* Change ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669 hadc->State = HAL_ADC_STATE_EOC_INJ_REG;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673 /* Change ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674 hadc->State = HAL_ADC_STATE_EOC_REG;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 if((hadc->Init.ContinuousConvMode == DISABLE) && (hadc->Init.ExternalTrigConvEdge == ADC_EXTERNALTRIGCONVEDGE_NONE))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679 if(hadc->Init.EOCSelection == ADC_EOC_SEQ_CONV)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681 /* DISABLE the ADC end of conversion interrupt for regular group */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_EOC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684 /* DISABLE the ADC overrun interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 if (hadc->NbrOfCurrentConversionRank == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691 hadc->NbrOfCurrentConversionRank = hadc->Init.NbrOfConversion;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
692 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694 /* Decrement the number of conversion when an interrupt occurs */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695 hadc->NbrOfCurrentConversionRank--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697 /* Check if all conversions are finished */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698 if(hadc->NbrOfCurrentConversionRank == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700 /* DISABLE the ADC end of conversion interrupt for regular group */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_EOC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 /* DISABLE the ADC overrun interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709 /* Conversion complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710 HAL_ADC_ConvCpltCallback(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
712 /* Clear the ADCx flag for regular end of conversion */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713 __HAL_ADC_CLEAR_FLAG(hadc,ADC_FLAG_EOC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716 tmp1 = __HAL_ADC_GET_FLAG(hadc, ADC_FLAG_JEOC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 tmp2 = __HAL_ADC_GET_IT_SOURCE(hadc, ADC_IT_JEOC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718 /* Check End of conversion flag for injected channels */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719 if(tmp1 && tmp2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
720 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721 /* Check if a regular conversion is ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722 if(hadc->State == HAL_ADC_STATE_EOC_REG)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
724 /* Change ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725 hadc->State = HAL_ADC_STATE_EOC_INJ_REG;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
727 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
729 /* Change ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
730 hadc->State = HAL_ADC_STATE_EOC_INJ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733 tmp1 = HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
734 tmp2 = HAL_IS_BIT_CLR(hadc->Instance->CR2, ADC_CR2_JEXTEN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735 if(((hadc->Init.ContinuousConvMode == DISABLE) || tmp1) && tmp2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
737 /* DISABLE the ADC end of conversion interrupt for injected group */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
738 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741 /* Conversion complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742 HAL_ADCEx_InjectedConvCpltCallback(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744 /* Clear the ADCx flag for injected end of conversion */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 __HAL_ADC_CLEAR_FLAG(hadc,ADC_FLAG_JEOC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748 tmp1 = __HAL_ADC_GET_FLAG(hadc, ADC_FLAG_AWD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749 tmp2 = __HAL_ADC_GET_IT_SOURCE(hadc, ADC_IT_AWD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 /* Check Analog watchdog flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
751 if(tmp1 && tmp2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
752 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
753 /* Change ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754 hadc->State = HAL_ADC_STATE_AWD;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756 /* Clear the ADCx's Analog watchdog flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757 __HAL_ADC_CLEAR_FLAG(hadc,ADC_FLAG_AWD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759 /* Level out of window callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
760 HAL_ADC_LevelOutOfWindowCallback(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
761 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763 tmp1 = __HAL_ADC_GET_FLAG(hadc, ADC_FLAG_OVR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
764 tmp2 = __HAL_ADC_GET_IT_SOURCE(hadc, ADC_IT_OVR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765 /* Check Overrun flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766 if(tmp1 && tmp2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
767 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768 /* Change ADC state to overrun state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769 hadc->State = HAL_ADC_STATE_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
770
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
771 /* Set ADC error code to overrun */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
772 hadc->ErrorCode |= HAL_ADC_ERROR_OVR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774 /* Clear the Overrun flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
775 __HAL_ADC_CLEAR_FLAG(hadc,ADC_FLAG_OVR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
776
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
777 /* Error callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
778 HAL_ADC_ErrorCallback(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
779 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
780 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
782 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
783 * @brief Enables ADC DMA request after last transfer (Single-ADC mode) and enables ADC peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
784 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
786 * @param pData: The destination Buffer address.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
787 * @param Length: The length of data to be transferred from ADC peripheral to memory.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
788 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
789 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790 HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
791 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792 uint16_t i = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
793
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
795 assert_param(IS_FUNCTIONAL_STATE(hadc->Init.ContinuousConvMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796 assert_param(IS_ADC_EXT_TRIG_EDGE(hadc->Init.ExternalTrigConvEdge));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
797
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
798 /* Process locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
799 __HAL_LOCK(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
800
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
801 /* Enable ADC overrun interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
802 __HAL_ADC_ENABLE_IT(hadc, ADC_IT_OVR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804 /* Enable ADC DMA mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805 hadc->Instance->CR2 |= ADC_CR2_DMA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
807 /* Set the DMA transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
808 hadc->DMA_Handle->XferCpltCallback = ADC_DMAConvCplt;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
809
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
810 /* Set the DMA half transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
811 hadc->DMA_Handle->XferHalfCpltCallback = ADC_DMAHalfConvCplt;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813 /* Set the DMA error callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
814 hadc->DMA_Handle->XferErrorCallback = ADC_DMAError ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
815
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816 /* Enable the DMA Stream */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817 HAL_DMA_Start_IT(hadc->DMA_Handle, (uint32_t)&hadc->Instance->DR, (uint32_t)pData, Length);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819 /* Change ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820 hadc->State = HAL_ADC_STATE_BUSY_REG;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822 /* Check if ADC peripheral is disabled in order to enable it and wait during
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823 Tstab time the ADC's stabilization */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824 if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
825 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826 /* Enable the Peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827 __HAL_ADC_ENABLE(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829 /* Delay inserted to wait during Tstab time the ADC's stabilization */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830 for(; i <= 540; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832 __NOP();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836 /* if no external trigger present enable software conversion of regular channels */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837 if (hadc->Init.ExternalTrigConvEdge == ADC_EXTERNALTRIGCONVEDGE_NONE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839 /* Enable the selected ADC software conversion for regular group */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840 hadc->Instance->CR2 |= ADC_CR2_SWSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843 /* Process unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844 __HAL_UNLOCK(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851 * @brief Disables ADC DMA (Single-ADC mode) and disables ADC peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
854 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856 HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
857 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
858 /* Disable the Peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
859 __HAL_ADC_DISABLE(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
860
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
861 /* Disable ADC overrun interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
862 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
863
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
864 /* Disable the selected ADC DMA mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
865 hadc->Instance->CR2 &= ~ADC_CR2_DMA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
866
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
867 /* Disable the ADC DMA Stream */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
868 HAL_DMA_Abort(hadc->DMA_Handle);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
869
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
870 /* Change ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
871 hadc->State = HAL_ADC_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
872
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
873 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
874 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
875 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
876
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
877 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
878 * @brief Gets the converted value from data register of regular channel.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
879 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
880 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
881 * @retval Converted value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
882 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
883 uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef* hadc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
884 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
885 /* Return the selected ADC converted value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
886 return hadc->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
887 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
888
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
889 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
890 * @brief Regular conversion complete callback in non blocking mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
891 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
892 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
893 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
894 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
895 __weak void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
896 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
897 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
898 the HAL_ADC_ConvCpltCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
899 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
900 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
901
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
902 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
903 * @brief Regular conversion half DMA transfer callback in non blocking mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
904 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
905 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
906 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
907 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
908 __weak void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
909 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
910 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
911 the HAL_ADC_ConvHalfCpltCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
912 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
913 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
914
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
915 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
916 * @brief Analog watchdog callback in non blocking mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
917 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
918 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
919 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
920 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
921 __weak void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
922 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
923 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
924 the HAL_ADC_LevelOoutOfWindowCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
925 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
926 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
927
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
928 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
929 * @brief Error ADC callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
930 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
931 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
932 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
933 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
934 __weak void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
935 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
936 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
937 the HAL_ADC_ErrorCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
938 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
939 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
940
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
941 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
942 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
943 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
944
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
945 /** @defgroup ADC_Exported_Functions_Group3 Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
946 * @brief Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
947 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
948 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
949 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
950 ##### Peripheral Control functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
951 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
952 [..] This section provides functions allowing to:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
953 (+) Configure regular channels.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
954 (+) Configure injected channels.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
955 (+) Configure multimode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
956 (+) Configure the analog watch dog.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
957
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
958 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
959 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
960 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
961
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
962 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
963 * @brief Configures for the selected ADC regular channel its corresponding
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
964 * rank in the sequencer and its sample time.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
965 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
966 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
967 * @param sConfig: ADC configuration structure.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
968 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
969 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
970 HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
971 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
972 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
973 assert_param(IS_ADC_CHANNEL(sConfig->Channel));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
974 assert_param(IS_ADC_REGULAR_RANK(sConfig->Rank));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
975 assert_param(IS_ADC_SAMPLE_TIME(sConfig->SamplingTime));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
976
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
977 /* Process locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
978 __HAL_LOCK(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
979
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
980 /* if ADC_Channel_10 ... ADC_Channel_18 is selected */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
981 if (sConfig->Channel > ADC_CHANNEL_9)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
982 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
983 /* Clear the old sample time */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
984 hadc->Instance->SMPR1 &= ~ADC_SMPR1(ADC_SMPR1_SMP10, sConfig->Channel);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
985
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
986 /* Set the new sample time */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
987 hadc->Instance->SMPR1 |= ADC_SMPR1(sConfig->SamplingTime, sConfig->Channel);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
988 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
989 else /* ADC_Channel include in ADC_Channel_[0..9] */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
990 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
991 /* Clear the old sample time */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
992 hadc->Instance->SMPR2 &= ~ADC_SMPR2(ADC_SMPR2_SMP0, sConfig->Channel);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
993
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
994 /* Set the new sample time */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
995 hadc->Instance->SMPR2 |= ADC_SMPR2(sConfig->SamplingTime, sConfig->Channel);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
996 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
997
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
998 /* For Rank 1 to 6 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
999 if (sConfig->Rank < 7)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1000 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1001 /* Clear the old SQx bits for the selected rank */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1002 hadc->Instance->SQR3 &= ~ADC_SQR3_RK(ADC_SQR3_SQ1, sConfig->Rank);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1003
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1004 /* Set the SQx bits for the selected rank */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1005 hadc->Instance->SQR3 |= ADC_SQR3_RK(sConfig->Channel, sConfig->Rank);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1006 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1007 /* For Rank 7 to 12 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1008 else if (sConfig->Rank < 13)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1009 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1010 /* Clear the old SQx bits for the selected rank */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1011 hadc->Instance->SQR2 &= ~ADC_SQR2_RK(ADC_SQR2_SQ7, sConfig->Rank);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1012
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1013 /* Set the SQx bits for the selected rank */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1014 hadc->Instance->SQR2 |= ADC_SQR2_RK(sConfig->Channel, sConfig->Rank);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1015 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1016 /* For Rank 13 to 16 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1017 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1018 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1019 /* Clear the old SQx bits for the selected rank */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1020 hadc->Instance->SQR1 &= ~ADC_SQR1_RK(ADC_SQR1_SQ13, sConfig->Rank);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1021
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1022 /* Set the SQx bits for the selected rank */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1023 hadc->Instance->SQR1 |= ADC_SQR1_RK(sConfig->Channel, sConfig->Rank);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1024 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1025
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1026 /* if ADC1 Channel_18 is selected enable VBAT Channel */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1027 if ((hadc->Instance == ADC1) && (sConfig->Channel == ADC_CHANNEL_VBAT))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1028 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1029 /* Enable the VBAT channel*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1030 ADC->CCR |= ADC_CCR_VBATE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1031 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1032
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1033 /* if ADC1 Channel_16 or Channel_17 is selected enable TSVREFE Channel(Temperature sensor and VREFINT) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1034 if ((hadc->Instance == ADC1) && ((sConfig->Channel == ADC_CHANNEL_TEMPSENSOR) || (sConfig->Channel == ADC_CHANNEL_VREFINT)))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1035 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1036 /* Enable the TSVREFE channel*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1037 ADC->CCR |= ADC_CCR_TSVREFE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1038 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1039
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1040 /* Process unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1041 __HAL_UNLOCK(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1042
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1043 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1044 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1045 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1046
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1047 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1048 * @brief Configures the analog watchdog.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1049 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1050 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1051 * @param AnalogWDGConfig : pointer to an ADC_AnalogWDGConfTypeDef structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1052 * that contains the configuration information of ADC analog watchdog.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1053 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1054 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1055 HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1056 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1057 #ifdef USE_FULL_ASSERT
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1058 uint32_t tmp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1059 #endif /* USE_FULL_ASSERT */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1060
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1061 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1062 assert_param(IS_ADC_ANALOG_WATCHDOG(AnalogWDGConfig->WatchdogMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1063 assert_param(IS_ADC_CHANNEL(AnalogWDGConfig->Channel));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1064 assert_param(IS_FUNCTIONAL_STATE(AnalogWDGConfig->ITMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1065
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1066 #ifdef USE_FULL_ASSERT
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1067 tmp = ADC_GET_RESOLUTION(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1068 assert_param(IS_ADC_RANGE(tmp, AnalogWDGConfig->HighThreshold));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1069 assert_param(IS_ADC_RANGE(tmp, AnalogWDGConfig->LowThreshold));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1070 #endif /* USE_FULL_ASSERT */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1071
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1072 /* Process locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1073 __HAL_LOCK(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1074
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1075 if(AnalogWDGConfig->ITMode == ENABLE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1076 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1077 /* Enable the ADC Analog watchdog interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1078 __HAL_ADC_ENABLE_IT(hadc, ADC_IT_AWD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1079 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1080 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1081 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1082 /* Disable the ADC Analog watchdog interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1083 __HAL_ADC_DISABLE_IT(hadc, ADC_IT_AWD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1084 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1085
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1086 /* Clear AWDEN, JAWDEN and AWDSGL bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1087 hadc->Instance->CR1 &= ~(ADC_CR1_AWDSGL | ADC_CR1_JAWDEN | ADC_CR1_AWDEN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1088
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1089 /* Set the analog watchdog enable mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1090 hadc->Instance->CR1 |= AnalogWDGConfig->WatchdogMode;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1091
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1092 /* Set the high threshold */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1093 hadc->Instance->HTR = AnalogWDGConfig->HighThreshold;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1094
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1095 /* Set the low threshold */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1096 hadc->Instance->LTR = AnalogWDGConfig->LowThreshold;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1097
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1098 /* Clear the Analog watchdog channel select bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1099 hadc->Instance->CR1 &= ~ADC_CR1_AWDCH;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1100
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1101 /* Set the Analog watchdog channel */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1102 hadc->Instance->CR1 |= (uint32_t)((uint16_t)(AnalogWDGConfig->Channel));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1103
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1104 /* Process unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1105 __HAL_UNLOCK(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1106
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1107 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1108 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1109 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1110
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1111 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1112 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1113 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1114
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1115 /** @defgroup ADC_Exported_Functions_Group4 ADC Peripheral State functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1116 * @brief ADC Peripheral State functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1117 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1118 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1119 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1120 ##### Peripheral State and errors functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1121 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1122 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1123 This subsection provides functions allowing to
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1124 (+) Check the ADC state
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1125 (+) Check the ADC Error
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1126
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1127 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1128 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1129 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1130
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1131 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1132 * @brief return the ADC state
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1133 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1134 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1135 * @retval HAL state
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1136 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1137 HAL_ADC_StateTypeDef HAL_ADC_GetState(ADC_HandleTypeDef* hadc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1138 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1139 /* Return ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1140 return hadc->State;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1141 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1142
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1143 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1144 * @brief Return the ADC error code
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1145 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1146 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1147 * @retval ADC Error Code
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1148 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1149 uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1150 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1151 return hadc->ErrorCode;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1152 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1153
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1154 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1155 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1156 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1157
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1158 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1159 * @brief Initializes the ADCx peripheral according to the specified parameters
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1160 * in the ADC_InitStruct without initializing the ADC MSP.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1161 * @param hadc: pointer to a ADC_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1162 * the configuration information for the specified ADC.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1163 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1164 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1165 static void ADC_Init(ADC_HandleTypeDef* hadc)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1166 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1167
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1168 /* Set ADC parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1169 /* Set the ADC clock prescaler */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1170 ADC->CCR &= ~(ADC_CCR_ADCPRE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1171 ADC->CCR |= hadc->Init.ClockPrescaler;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1172
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1173 /* Set ADC scan mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1174 hadc->Instance->CR1 &= ~(ADC_CR1_SCAN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1175 hadc->Instance->CR1 |= ADC_CR1_SCANCONV(hadc->Init.ScanConvMode);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1176
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1177 /* Set ADC resolution */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1178 hadc->Instance->CR1 &= ~(ADC_CR1_RES);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1179 hadc->Instance->CR1 |= hadc->Init.Resolution;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1180
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1181 /* Set ADC data alignment */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1182 hadc->Instance->CR2 &= ~(ADC_CR2_ALIGN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1183 hadc->Instance->CR2 |= hadc->Init.DataAlign;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1184
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1185 /* Select external trigger to start conversion */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1186 hadc->Instance->CR2 &= ~(ADC_CR2_EXTSEL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1187 hadc->Instance->CR2 |= hadc->Init.ExternalTrigConv;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1188
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1189 /* Select external trigger polarity */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1190 hadc->Instance->CR2 &= ~(ADC_CR2_EXTEN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1191 hadc->Instance->CR2 |= hadc->Init.ExternalTrigConvEdge;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1192
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1193 /* Enable or disable ADC continuous conversion mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1194 hadc->Instance->CR2 &= ~(ADC_CR2_CONT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1195 hadc->Instance->CR2 |= ADC_CR2_CONTINUOUS(hadc->Init.ContinuousConvMode);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1196
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1197 if (hadc->Init.DiscontinuousConvMode != DISABLE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1198 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1199 assert_param(IS_ADC_REGULAR_DISC_NUMBER(hadc->Init.NbrOfDiscConversion));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1200
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1201 /* Enable the selected ADC regular discontinuous mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1202 hadc->Instance->CR1 |= (uint32_t)ADC_CR1_DISCEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1203
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1204 /* Set the number of channels to be converted in discontinuous mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1205 hadc->Instance->CR1 &= ~(ADC_CR1_DISCNUM);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1206 hadc->Instance->CR1 |= ADC_CR1_DISCONTINUOUS(hadc->Init.NbrOfDiscConversion);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1207 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1208 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1209 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1210 /* Disable the selected ADC regular discontinuous mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1211 hadc->Instance->CR1 &= ~(ADC_CR1_DISCEN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1212 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1213
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1214 /* Set ADC number of conversion */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1215 hadc->Instance->SQR1 &= ~(ADC_SQR1_L);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1216 hadc->Instance->SQR1 |= ADC_SQR1(hadc->Init.NbrOfConversion);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1217
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1218 /* Enable or disable ADC DMA continuous request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1219 hadc->Instance->CR2 &= ~(ADC_CR2_DDS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1220 hadc->Instance->CR2 |= ADC_CR2_DMAContReq(hadc->Init.DMAContinuousRequests);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1221
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1222 /* Enable or disable ADC end of conversion selection */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1223 hadc->Instance->CR2 &= ~(ADC_CR2_EOCS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1224 hadc->Instance->CR2 |= ADC_CR2_EOCSelection(hadc->Init.EOCSelection);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1225 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1226
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1227 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1228 * @brief DMA transfer complete callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1229 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1230 * the configuration information for the specified DMA module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1231 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1232 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1233 static void ADC_DMAConvCplt(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1234 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1235 ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1236
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1237 /* Check if an injected conversion is ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1238 if(hadc->State == HAL_ADC_STATE_EOC_INJ)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1239 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1240 /* Change ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1241 hadc->State = HAL_ADC_STATE_EOC_INJ_REG;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1242 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1243 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1244 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1245 /* Change ADC state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1246 hadc->State = HAL_ADC_STATE_EOC_REG;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1247 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1248
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1249 HAL_ADC_ConvCpltCallback(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1250 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1251
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1252 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1253 * @brief DMA half transfer complete callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1254 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1255 * the configuration information for the specified DMA module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1256 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1257 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1258 static void ADC_DMAHalfConvCplt(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1259 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1260 ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1261 /* Conversion complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1262 HAL_ADC_ConvHalfCpltCallback(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1263 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1264
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1265 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1266 * @brief DMA error callback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1267 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1268 * the configuration information for the specified DMA module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1269 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1270 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1271 static void ADC_DMAError(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1272 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1273 ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1274 hadc->State= HAL_ADC_STATE_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1275 /* Set ADC error code to DMA error */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1276 hadc->ErrorCode |= HAL_ADC_ERROR_DMA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1277 HAL_ADC_ErrorCallback(hadc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1278 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1279
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1280
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1281 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1282 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1283 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1284
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1285 #endif /* HAL_ADC_MODULE_ENABLED */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1286 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1287 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1288 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1289
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1290 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1291 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1292 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1293
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1294 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/