annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_adc_ex.c @ 75:2b3f8ed4a0b8

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