stm32f3xx_hal_adc.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  1. /**
  2. ******************************************************************************
  3. * @file stm32f3xx_hal_adc.c
  4. * @author MCD Application Team
  5. * @brief This file provides firmware functions to manage the following
  6. * functionalities of the Analog to Digital Convertor (ADC)
  7. * peripheral:
  8. * + Initialization and de-initialization functions
  9. * ++ Initialization and Configuration of ADC
  10. * + Operation functions
  11. * ++ Start, stop, get result of conversions of regular
  12. * group, using 3 possible modes: polling, interruption or DMA.
  13. * + Control functions
  14. * ++ Channels configuration on regular group
  15. * ++ Channels configuration on injected group
  16. * ++ Analog Watchdog configuration
  17. * + State functions
  18. * ++ ADC state machine management
  19. * ++ Interrupts and flags management
  20. * Other functions (extended functions) are available in file
  21. * "stm32f3xx_hal_adc_ex.c".
  22. *
  23. @verbatim
  24. ==============================================================================
  25. ##### ADC peripheral features #####
  26. ==============================================================================
  27. [..]
  28. (+) 12-bit, 10-bit, 8-bit or 6-bit configurable resolution (available only on
  29. STM32F30xxC devices).
  30. (+) Interrupt generation at the end of regular conversion, end of injected
  31. conversion, and in case of analog watchdog or overrun events.
  32. (+) Single and continuous conversion modes.
  33. (+) Scan mode for conversion of several channels sequentially.
  34. (+) Data alignment with in-built data coherency.
  35. (+) Programmable sampling time (channel wise)
  36. (+) ADC conversion of regular group and injected group.
  37. (+) External trigger (timer or EXTI) with configurable polarity
  38. for both regular and injected groups.
  39. (+) DMA request generation for transfer of conversions data of regular group.
  40. (+) Multimode dual mode (available on devices with 2 ADCs or more).
  41. (+) Configurable DMA data storage in Multimode Dual mode (available on devices
  42. with 2 DCs or more).
  43. (+) Configurable delay between conversions in Dual interleaved mode (available
  44. on devices with 2 DCs or more).
  45. (+) ADC calibration
  46. (+) ADC channels selectable single/differential input (available only on
  47. STM32F30xxC devices)
  48. (+) ADC Injected sequencer&channels configuration context queue (available
  49. only on STM32F30xxC devices)
  50. (+) ADC offset on injected and regular groups (offset on regular group
  51. available only on STM32F30xxC devices)
  52. (+) ADC supply requirements: 2.4 V to 3.6 V at full speed and down to 1.8 V at
  53. slower speed.
  54. (+) ADC input range: from Vref- (connected to Vssa) to Vref+ (connected to
  55. Vdda or to an external voltage reference).
  56. ##### How to use this driver #####
  57. ==============================================================================
  58. [..]
  59. *** Configuration of top level parameters related to ADC ***
  60. ============================================================
  61. [..]
  62. (#) Enable the ADC interface
  63. (++) As prerequisite, ADC clock must be configured at RCC top level.
  64. (++) For STM32F30x/STM32F33x devices:
  65. Two possible clock sources: synchronous clock derived from AHB clock
  66. or asynchronous clock derived from ADC dedicated PLL 72MHz.
  67. - Synchronous clock is mandatory since used as ADC core clock.
  68. Synchronous clock can be used optionally as ADC conversion clock, depending on ADC init structure clock setting.
  69. Synchronous clock is configured using macro __ADCx_CLK_ENABLE().
  70. - Asynchronous can be used optionally as ADC conversion clock, depending on ADC init structure clock setting.
  71. Asynchronous clock is configured using function HAL_RCCEx_PeriphCLKConfig().
  72. (+++) For example, in case of device with a single ADC:
  73. Into HAL_ADC_MspInit() (recommended code location) or with
  74. other device clock parameters configuration:
  75. (+++) __HAL_RCC_ADC1_CLK_ENABLE() (mandatory)
  76. (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC (optional, if ADC conversion from asynchronous clock)
  77. (+++) PeriphClkInit.Adc1ClockSelection = RCC_ADC1PLLCLK_DIV1 (optional, if ADC conversion from asynchronous clock)
  78. (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure) (optional, if ADC conversion from asynchronous clock)
  79. (+++) For example, in case of device with 4 ADCs:
  80. (+++) if((hadc->Instance == ADC1) || (hadc->Instance == ADC2))
  81. (+++) {
  82. (+++) __HAL_RCC_ADC12_CLK_ENABLE() (mandatory)
  83. (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC (optional, if ADC conversion from asynchronous clock)
  84. (+++) PeriphClkInit.Adc12ClockSelection = RCC_ADC12PLLCLK_DIV1 (optional, if ADC conversion from asynchronous clock)
  85. (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure) (optional, if ADC conversion from asynchronous clock)
  86. (+++) }
  87. (+++) else
  88. (+++) {
  89. (+++) __HAL_RCC_ADC34_CLK_ENABLE() (mandatory)
  90. (+++) PeriphClkInit.Adc34ClockSelection = RCC_ADC34PLLCLK_DIV1; (optional, if ADC conversion from asynchronous clock)
  91. (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure); (optional, if ADC conversion from asynchronous clock)
  92. (+++) }
  93. (++) For STM32F37x devices:
  94. One clock setting is mandatory:
  95. ADC clock (core and conversion clock) from APB2 clock.
  96. (+++) Example:
  97. Into HAL_ADC_MspInit() (recommended code location) or with
  98. other device clock parameters configuration:
  99. (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC
  100. (+++) PeriphClkInit.AdcClockSelection = RCC_ADCPLLCLK_DIV2
  101. (+++) HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit)
  102. (#) ADC pins configuration
  103. (++) Enable the clock for the ADC GPIOs
  104. using macro __HAL_RCC_GPIOx_CLK_ENABLE()
  105. (++) Configure these ADC pins in analog mode
  106. using function HAL_GPIO_Init()
  107. (#) Optionally, in case of usage of ADC with interruptions:
  108. (++) Configure the NVIC for ADC
  109. using function HAL_NVIC_EnableIRQ(ADCx_IRQn)
  110. (++) Insert the ADC interruption handler function HAL_ADC_IRQHandler()
  111. into the function of corresponding ADC interruption vector
  112. ADCx_IRQHandler().
  113. (#) Optionally, in case of usage of DMA:
  114. (++) Configure the DMA (DMA channel, mode normal or circular, ...)
  115. using function HAL_DMA_Init().
  116. (++) Configure the NVIC for DMA
  117. using function HAL_NVIC_EnableIRQ(DMAx_Channelx_IRQn)
  118. (++) Insert the ADC interruption handler function HAL_ADC_IRQHandler()
  119. into the function of corresponding DMA interruption vector
  120. DMAx_Channelx_IRQHandler().
  121. *** Configuration of ADC, groups regular/injected, channels parameters ***
  122. ==========================================================================
  123. [..]
  124. (#) Configure the ADC parameters (resolution, data alignment, ...)
  125. and regular group parameters (conversion trigger, sequencer, ...)
  126. using function HAL_ADC_Init().
  127. (#) Configure the channels for regular group parameters (channel number,
  128. channel rank into sequencer, ..., into regular group)
  129. using function HAL_ADC_ConfigChannel().
  130. (#) Optionally, configure the injected group parameters (conversion trigger,
  131. sequencer, ..., of injected group)
  132. and the channels for injected group parameters (channel number,
  133. channel rank into sequencer, ..., into injected group)
  134. using function HAL_ADCEx_InjectedConfigChannel().
  135. (#) Optionally, configure the analog watchdog parameters (channels
  136. monitored, thresholds, ...)
  137. using function HAL_ADC_AnalogWDGConfig().
  138. (#) Optionally, for devices with several ADC instances: configure the
  139. multimode parameters
  140. using function HAL_ADCEx_MultiModeConfigChannel().
  141. *** Execution of ADC conversions ***
  142. ====================================
  143. [..]
  144. (#) Optionally, perform an automatic ADC calibration to improve the
  145. conversion accuracy
  146. using function HAL_ADCEx_Calibration_Start().
  147. (#) ADC driver can be used among three modes: polling, interruption,
  148. transfer by DMA.
  149. (++) ADC conversion by polling:
  150. (+++) Activate the ADC peripheral and start conversions
  151. using function HAL_ADC_Start()
  152. (+++) Wait for ADC conversion completion
  153. using function HAL_ADC_PollForConversion()
  154. (or for injected group: HAL_ADCEx_InjectedPollForConversion() )
  155. (+++) Retrieve conversion results
  156. using function HAL_ADC_GetValue()
  157. (or for injected group: HAL_ADCEx_InjectedGetValue() )
  158. (+++) Stop conversion and disable the ADC peripheral
  159. using function HAL_ADC_Stop()
  160. (++) ADC conversion by interruption:
  161. (+++) Activate the ADC peripheral and start conversions
  162. using function HAL_ADC_Start_IT()
  163. (+++) Wait for ADC conversion completion by call of function
  164. HAL_ADC_ConvCpltCallback()
  165. (this function must be implemented in user program)
  166. (or for injected group: HAL_ADCEx_InjectedConvCpltCallback() )
  167. (+++) Retrieve conversion results
  168. using function HAL_ADC_GetValue()
  169. (or for injected group: HAL_ADCEx_InjectedGetValue() )
  170. (+++) Stop conversion and disable the ADC peripheral
  171. using function HAL_ADC_Stop_IT()
  172. (++) ADC conversion with transfer by DMA:
  173. (+++) Activate the ADC peripheral and start conversions
  174. using function HAL_ADC_Start_DMA()
  175. (+++) Wait for ADC conversion completion by call of function
  176. HAL_ADC_ConvCpltCallback() or HAL_ADC_ConvHalfCpltCallback()
  177. (these functions must be implemented in user program)
  178. (+++) Conversion results are automatically transferred by DMA into
  179. destination variable address.
  180. (+++) Stop conversion and disable the ADC peripheral
  181. using function HAL_ADC_Stop_DMA()
  182. (++) For devices with several ADCs: ADC multimode conversion
  183. with transfer by DMA:
  184. (+++) Activate the ADC peripheral (slave)
  185. using function HAL_ADC_Start()
  186. (conversion start pending ADC master)
  187. (+++) Activate the ADC peripheral (master) and start conversions
  188. using function HAL_ADCEx_MultiModeStart_DMA()
  189. (+++) Wait for ADC conversion completion by call of function
  190. HAL_ADC_ConvCpltCallback() or HAL_ADC_ConvHalfCpltCallback()
  191. (these functions must be implemented in user program)
  192. (+++) Conversion results are automatically transferred by DMA into
  193. destination variable address.
  194. (+++) Stop conversion and disable the ADC peripheral (master)
  195. using function HAL_ADCEx_MultiModeStop_DMA()
  196. (+++) Stop conversion and disable the ADC peripheral (slave)
  197. using function HAL_ADC_Stop_IT()
  198. [..]
  199. (@) Callback functions must be implemented in user program:
  200. (+@) HAL_ADC_ErrorCallback()
  201. (+@) HAL_ADC_LevelOutOfWindowCallback() (callback of analog watchdog)
  202. (+@) HAL_ADC_ConvCpltCallback()
  203. (+@) HAL_ADC_ConvHalfCpltCallback
  204. (+@) HAL_ADCEx_InjectedConvCpltCallback()
  205. (+@) HAL_ADCEx_InjectedQueueOverflowCallback() (for STM32F30x/STM32F33x devices)
  206. *** Deinitialization of ADC ***
  207. ============================================================
  208. [..]
  209. (#) Disable the ADC interface
  210. (++) ADC clock can be hard reset and disabled at RCC top level.
  211. (++) Hard reset of ADC peripherals
  212. using macro __ADCx_FORCE_RESET(), __ADCx_RELEASE_RESET().
  213. (++) ADC clock disable
  214. using the equivalent macro/functions as configuration step.
  215. (++) For STM32F30x/STM32F33x devices:
  216. Caution: For devices with several ADCs:
  217. These settings impact both ADC of common group: ADC1&ADC2, ADC3&ADC4
  218. if available (ADC2, ADC3, ADC4 availability depends on STM32 product)
  219. (+++) For example, in case of device with a single ADC:
  220. Into HAL_ADC_MspDeInit() (recommended code location) or with
  221. other device clock parameters configuration:
  222. (+++) __HAL_RCC_ADC1_FORCE_RESET() (optional)
  223. (+++) __HAL_RCC_ADC1_RELEASE_RESET() (optional)
  224. (+++) __HAL_RCC_ADC1_CLK_DISABLE() (mandatory)
  225. (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC (optional, if configured before)
  226. (+++) PeriphClkInit.Adc1ClockSelection = RCC_ADC1PLLCLK_OFF (optional, if configured before)
  227. (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure) (optional, if configured before)
  228. (+++) For example, in case of device with 4 ADCs:
  229. (+++) if((hadc->Instance == ADC1) || (hadc->Instance == ADC2))
  230. (+++) {
  231. (+++) __HAL_RCC_ADC12_FORCE_RESET() (optional)
  232. (+++) __HAL_RCC_ADC12_RELEASE_RESET() (optional)
  233. (+++) __HAL_RCC_ADC12_CLK_DISABLE() (mandatory)
  234. (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC (optional, if configured before)
  235. (+++) PeriphClkInit.Adc12ClockSelection = RCC_ADC12PLLCLK_OFF (optional, if configured before)
  236. (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure) (optional, if configured before)
  237. (+++) }
  238. (+++) else
  239. (+++) {
  240. (+++) __HAL_RCC_ADC32_FORCE_RESET() (optional)
  241. (+++) __HAL_RCC_ADC32_RELEASE_RESET() (optional)
  242. (+++) __HAL_RCC_ADC34_CLK_DISABLE() (mandatory)
  243. (+++) PeriphClkInit.Adc34ClockSelection = RCC_ADC34PLLCLK_OFF (optional, if configured before)
  244. (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure) (optional, if configured before)
  245. (+++) }
  246. (++) For STM32F37x devices:
  247. (+++) Example:
  248. Into HAL_ADC_MspDeInit() (recommended code location) or with
  249. other device clock parameters configuration:
  250. (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC
  251. (+++) PeriphClkInit.AdcClockSelection = RCC_ADCPLLCLK_OFF
  252. (+++) HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit)
  253. (#) ADC pins configuration
  254. (++) Disable the clock for the ADC GPIOs
  255. using macro __HAL_RCC_GPIOx_CLK_DISABLE()
  256. (#) Optionally, in case of usage of ADC with interruptions:
  257. (++) Disable the NVIC for ADC
  258. using function HAL_NVIC_EnableIRQ(ADCx_IRQn)
  259. (#) Optionally, in case of usage of DMA:
  260. (++) Deinitialize the DMA
  261. using function HAL_DMA_Init().
  262. (++) Disable the NVIC for DMA
  263. using function HAL_NVIC_EnableIRQ(DMAx_Channelx_IRQn)
  264. [..]
  265. @endverbatim
  266. ******************************************************************************
  267. * @attention
  268. *
  269. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  270. *
  271. * Redistribution and use in source and binary forms, with or without modification,
  272. * are permitted provided that the following conditions are met:
  273. * 1. Redistributions of source code must retain the above copyright notice,
  274. * this list of conditions and the following disclaimer.
  275. * 2. Redistributions in binary form must reproduce the above copyright notice,
  276. * this list of conditions and the following disclaimer in the documentation
  277. * and/or other materials provided with the distribution.
  278. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  279. * may be used to endorse or promote products derived from this software
  280. * without specific prior written permission.
  281. *
  282. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  283. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  284. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  285. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  286. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  287. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  288. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  289. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  290. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  291. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  292. *
  293. ******************************************************************************
  294. */
  295. /* Includes ------------------------------------------------------------------*/
  296. #include "stm32f3xx_hal.h"
  297. /** @addtogroup STM32F3xx_HAL_Driver
  298. * @{
  299. */
  300. /** @defgroup ADC ADC
  301. * @brief ADC HAL module driver
  302. * @{
  303. */
  304. #ifdef HAL_ADC_MODULE_ENABLED
  305. /* Private typedef -----------------------------------------------------------*/
  306. /* Private define ------------------------------------------------------------*/
  307. /* Private macro -------------------------------------------------------------*/
  308. /* Private variables ---------------------------------------------------------*/
  309. /* Private function prototypes -----------------------------------------------*/
  310. /* Exported functions --------------------------------------------------------*/
  311. /** @defgroup ADC_Exported_Functions ADC Exported Functions
  312. * @{
  313. */
  314. /** @defgroup ADC_Exported_Functions_Group1 Initialization and de-initialization functions
  315. * @brief Initialization and Configuration functions
  316. *
  317. @verbatim
  318. ===============================================================================
  319. ##### Initialization and de-initialization functions #####
  320. ===============================================================================
  321. [..] This section provides functions allowing to:
  322. (+) Initialize and configure the ADC.
  323. (+) De-initialize the ADC.
  324. @endverbatim
  325. * @{
  326. */
  327. /**
  328. * @brief Initializes the ADC peripheral and regular group according to
  329. * parameters specified in structure "ADC_InitTypeDef".
  330. * @note As prerequisite, ADC clock must be configured at RCC top level
  331. * depending on both possible clock sources: PLL clock or AHB clock.
  332. * See commented example code below that can be copied and uncommented
  333. * into HAL_ADC_MspInit().
  334. * @note Possibility to update parameters on the fly:
  335. * This function initializes the ADC MSP (HAL_ADC_MspInit()) only when
  336. * coming from ADC state reset. Following calls to this function can
  337. * be used to reconfigure some parameters of ADC_InitTypeDef
  338. * structure on the fly, without modifying MSP configuration. If ADC
  339. * MSP has to be modified again, HAL_ADC_DeInit() must be called
  340. * before HAL_ADC_Init().
  341. * The setting of these parameters is conditioned to ADC state.
  342. * For parameters constraints, see comments of structure
  343. * "ADC_InitTypeDef".
  344. * @note This function configures the ADC within 2 scopes: scope of entire
  345. * ADC and scope of regular group. For parameters details, see comments
  346. * of structure "ADC_InitTypeDef".
  347. * @note For devices with several ADCs: parameters related to common ADC
  348. * registers (ADC clock mode) are set only if all ADCs sharing the
  349. * same common group are disabled.
  350. * If this is not the case, these common parameters setting are
  351. * bypassed without error reporting: it can be the intended behaviour in
  352. * case of update of a parameter of ADC_InitTypeDef on the fly,
  353. * without disabling the other ADCs sharing the same common group.
  354. * @param hadc ADC handle
  355. * @retval HAL status
  356. */
  357. __weak HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc)
  358. {
  359. /* Prevent unused argument(s) compilation warning */
  360. UNUSED(hadc);
  361. /* Note : This function is defined into this file for library reference. */
  362. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  363. /* Return function status */
  364. return HAL_ERROR;
  365. }
  366. /**
  367. * @brief Deinitialize the ADC peripheral registers to their default reset
  368. * values, with deinitialization of the ADC MSP.
  369. * @note For devices with several ADCs: reset of ADC common registers is done
  370. * only if all ADCs sharing the same common group are disabled.
  371. * If this is not the case, reset of these common parameters reset is
  372. * bypassed without error reporting: it can be the intended behaviour in
  373. * case of reset of a single ADC while the other ADCs sharing the same
  374. * common group is still running.
  375. * @note For devices with several ADCs: Global reset of all ADCs sharing a
  376. * common group is possible.
  377. * As this function is intended to reset a single ADC, to not impact
  378. * other ADCs, instructions for global reset of multiple ADCs have been
  379. * let commented below.
  380. * If needed, the example code can be copied and uncommented into
  381. * function HAL_ADC_MspDeInit().
  382. * @param hadc ADC handle
  383. * @retval HAL status
  384. */
  385. __weak HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef* hadc)
  386. {
  387. /* Prevent unused argument(s) compilation warning */
  388. UNUSED(hadc);
  389. /* Note : This function is defined into this file for library reference. */
  390. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  391. /* Return function status */
  392. return HAL_ERROR;
  393. }
  394. /**
  395. * @brief Initializes the ADC MSP.
  396. * @param hadc ADC handle
  397. * @retval None
  398. */
  399. __weak void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
  400. {
  401. /* Prevent unused argument(s) compilation warning */
  402. UNUSED(hadc);
  403. /* NOTE : This function should not be modified. When the callback is needed,
  404. function HAL_ADC_MspInit must be implemented in the user file.
  405. */
  406. }
  407. /**
  408. * @brief DeInitializes the ADC MSP.
  409. * @param hadc ADC handle
  410. * @retval None
  411. */
  412. __weak void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
  413. {
  414. /* Prevent unused argument(s) compilation warning */
  415. UNUSED(hadc);
  416. /* NOTE : This function should not be modified. When the callback is needed,
  417. function HAL_ADC_MspDeInit must be implemented in the user file.
  418. */
  419. }
  420. /**
  421. * @}
  422. */
  423. /** @defgroup ADC_Exported_Functions_Group2 Input and Output operation functions
  424. * @brief IO operation functions
  425. *
  426. @verbatim
  427. ===============================================================================
  428. ##### IO operation functions #####
  429. ===============================================================================
  430. [..] This section provides functions allowing to:
  431. (+) Start conversion of regular group.
  432. (+) Stop conversion of regular group.
  433. (+) Poll for conversion complete on regular group.
  434. (+) Poll for conversion event.
  435. (+) Get result of regular channel conversion.
  436. (+) Start conversion of regular group and enable interruptions.
  437. (+) Stop conversion of regular group and disable interruptions.
  438. (+) Handle ADC interrupt request
  439. (+) Start conversion of regular group and enable DMA transfer.
  440. (+) Stop conversion of regular group and disable ADC DMA transfer.
  441. @endverbatim
  442. * @{
  443. */
  444. /**
  445. * @brief Enables ADC, starts conversion of regular group.
  446. * Interruptions enabled in this function: None.
  447. * @note: Case of multimode enabled (for devices with several ADCs): This
  448. * function must be called for ADC slave first, then ADC master.
  449. * For ADC slave, ADC is enabled only (conversion is not started).
  450. * For ADC master, ADC is enabled and multimode conversion is started.
  451. * @param hadc ADC handle
  452. * @retval HAL status
  453. */
  454. __weak HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc)
  455. {
  456. /* Prevent unused argument(s) compilation warning */
  457. UNUSED(hadc);
  458. /* Return function status */
  459. return HAL_ERROR;
  460. }
  461. /**
  462. * @brief Stop ADC conversion of regular group (and injected group in
  463. * case of auto_injection mode), disable ADC peripheral.
  464. * @note: ADC peripheral disable is forcing stop of potential
  465. * conversion on injected group. If injected group is under use, it
  466. * should be preliminarily stopped using HAL_ADCEx_InjectedStop function.
  467. * @note: Case of multimode enabled (for devices with several ADCs): This
  468. * function must be called for ADC master first, then ADC slave.
  469. * For ADC master, converson is stopped and ADC is disabled.
  470. * For ADC slave, ADC is disabled only (conversion stop of ADC master
  471. * has already stopped conversion of ADC slave).
  472. * @param hadc ADC handle
  473. * @retval HAL status.
  474. */
  475. __weak HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef* hadc)
  476. {
  477. /* Prevent unused argument(s) compilation warning */
  478. UNUSED(hadc);
  479. /* Note : This function is defined into this file for library reference. */
  480. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  481. /* Return function status */
  482. return HAL_ERROR;
  483. }
  484. /**
  485. * @brief Wait for regular group conversion to be completed.
  486. * @param hadc ADC handle
  487. * @param Timeout Timeout value in millisecond.
  488. * @retval HAL status
  489. */
  490. __weak HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout)
  491. {
  492. /* Prevent unused argument(s) compilation warning */
  493. UNUSED(hadc);
  494. UNUSED(Timeout);
  495. /* Note : This function is defined into this file for library reference. */
  496. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  497. /* Return function status */
  498. return HAL_ERROR;
  499. }
  500. /**
  501. * @brief Poll for conversion event.
  502. * @param hadc ADC handle
  503. * @param EventType the ADC event type.
  504. * This parameter can be one of the following values:
  505. * @arg ADC_AWD_EVENT: ADC Analog watchdog 1 event (main analog watchdog, present on all STM32 devices)
  506. * @arg ADC_AWD2_EVENT: ADC Analog watchdog 2 event (additional analog watchdog, present only on STM32F3 devices)
  507. * @arg ADC_AWD3_EVENT: ADC Analog watchdog 3 event (additional analog watchdog, present only on STM32F3 devices)
  508. * @arg ADC_OVR_EVENT: ADC Overrun event
  509. * @arg ADC_JQOVF_EVENT: ADC Injected context queue overflow event
  510. * @param Timeout Timeout value in millisecond.
  511. * @retval HAL status
  512. */
  513. __weak HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout)
  514. {
  515. /* Prevent unused argument(s) compilation warning */
  516. UNUSED(hadc);
  517. UNUSED(EventType);
  518. UNUSED(Timeout);
  519. /* Note : This function is defined into this file for library reference. */
  520. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  521. /* Return function status */
  522. return HAL_ERROR;
  523. }
  524. /**
  525. * @brief Enables ADC, starts conversion of regular group with interruption.
  526. * Interruptions enabled in this function:
  527. * - EOC (end of conversion of regular group) or EOS (end of
  528. * sequence of regular group) depending on ADC initialization
  529. * parameter "EOCSelection" (if available)
  530. * - overrun (if available)
  531. * Each of these interruptions has its dedicated callback function.
  532. * @note: Case of multimode enabled (for devices with several ADCs): This
  533. * function must be called for ADC slave first, then ADC master.
  534. * For ADC slave, ADC is enabled only (conversion is not started).
  535. * For ADC master, ADC is enabled and multimode conversion is started.
  536. * @param hadc ADC handle
  537. * @retval HAL status
  538. */
  539. __weak HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc)
  540. {
  541. /* Prevent unused argument(s) compilation warning */
  542. UNUSED(hadc);
  543. /* Note : This function is defined into this file for library reference. */
  544. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  545. /* Return function status */
  546. return HAL_ERROR;
  547. }
  548. /**
  549. * @brief Stop ADC conversion of regular group (and injected group in
  550. * case of auto_injection mode), disable interruption of
  551. * end-of-conversion, disable ADC peripheral.
  552. * @note: ADC peripheral disable is forcing stop of potential
  553. * conversion on injected group. If injected group is under use, it
  554. * should be preliminarily stopped using HAL_ADCEx_InjectedStop function.
  555. * @note: Case of multimode enabled (for devices with several ADCs): This
  556. * function must be called for ADC master first, then ADC slave.
  557. * For ADC master, conversion is stopped and ADC is disabled.
  558. * For ADC slave, ADC is disabled only (conversion stop of ADC master
  559. * has already stopped conversion of ADC slave).
  560. * @param hadc ADC handle
  561. * @retval HAL status.
  562. */
  563. __weak HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc)
  564. {
  565. /* Prevent unused argument(s) compilation warning */
  566. UNUSED(hadc);
  567. /* Note : This function is defined into this file for library reference. */
  568. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  569. /* Return function status */
  570. return HAL_ERROR;
  571. }
  572. /**
  573. * @brief Enables ADC, starts conversion of regular group and transfers result
  574. * through DMA.
  575. * Interruptions enabled in this function:
  576. * - DMA transfer complete
  577. * - DMA half transfer
  578. * - overrun (if available)
  579. * Each of these interruptions has its dedicated callback function.
  580. * @note: Case of multimode enabled (for devices with several ADCs): This
  581. * function is for single-ADC mode only. For multimode, use the
  582. * dedicated MultimodeStart function.
  583. * @param hadc ADC handle
  584. * @param pData The destination Buffer address.
  585. * @param Length The length of data to be transferred from ADC peripheral to memory.
  586. * @retval None
  587. */
  588. __weak HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length)
  589. {
  590. /* Prevent unused argument(s) compilation warning */
  591. UNUSED(hadc);
  592. UNUSED(pData);
  593. UNUSED(Length);
  594. /* Note : This function is defined into this file for library reference. */
  595. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  596. /* Return function status */
  597. return HAL_ERROR;
  598. }
  599. /**
  600. * @brief Stop ADC conversion of regular group (and injected group in
  601. * case of auto_injection mode), disable ADC DMA transfer, disable
  602. * ADC peripheral.
  603. * @note: ADC peripheral disable is forcing stop of potential
  604. * conversion on injected group. If injected group is under use, it
  605. * should be preliminarily stopped using HAL_ADCEx_InjectedStop function.
  606. * @note: Case of multimode enabled (for devices with several ADCs): This
  607. * function is for single-ADC mode only. For multimode, use the
  608. * dedicated MultimodeStop function.
  609. * @param hadc ADC handle
  610. * @retval HAL status.
  611. */
  612. __weak HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc)
  613. {
  614. /* Prevent unused argument(s) compilation warning */
  615. UNUSED(hadc);
  616. /* Note : This function is defined into this file for library reference. */
  617. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  618. /* Return function status */
  619. return HAL_ERROR;
  620. }
  621. /**
  622. * @brief Get ADC regular group conversion result.
  623. * @note Reading DR register automatically clears EOC (end of conversion of
  624. * regular group) flag.
  625. * Additionally, this functions clears EOS (end of sequence of
  626. * regular group) flag, in case of the end of the sequence is reached.
  627. * @param hadc ADC handle
  628. * @retval Converted value
  629. */
  630. __weak uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef* hadc)
  631. {
  632. /* Note : This function is defined into this file for library reference. */
  633. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  634. /* Return ADC converted value */
  635. return hadc->Instance->DR;
  636. }
  637. /**
  638. * @brief Handles ADC interrupt request.
  639. * @param hadc ADC handle
  640. * @retval None
  641. */
  642. __weak void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc)
  643. {
  644. /* Prevent unused argument(s) compilation warning */
  645. UNUSED(hadc);
  646. /* Note : This function is defined into this file for library reference. */
  647. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  648. }
  649. /**
  650. * @brief Conversion complete callback in non blocking mode
  651. * @param hadc ADC handle
  652. * @retval None
  653. */
  654. __weak void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
  655. {
  656. /* Prevent unused argument(s) compilation warning */
  657. UNUSED(hadc);
  658. /* NOTE : This function should not be modified. When the callback is needed,
  659. function HAL_ADC_ConvCpltCallback must be implemented in the user file.
  660. */
  661. }
  662. /**
  663. * @brief Conversion DMA half-transfer callback in non blocking mode
  664. * @param hadc ADC handle
  665. * @retval None
  666. */
  667. __weak void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc)
  668. {
  669. /* Prevent unused argument(s) compilation warning */
  670. UNUSED(hadc);
  671. /* NOTE : This function should not be modified. When the callback is needed,
  672. function HAL_ADC_ConvHalfCpltCallback must be implemented in the user file.
  673. */
  674. }
  675. /**
  676. * @brief Analog watchdog callback in non blocking mode.
  677. * @param hadc ADC handle
  678. * @retval None
  679. */
  680. __weak void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc)
  681. {
  682. /* Prevent unused argument(s) compilation warning */
  683. UNUSED(hadc);
  684. /* NOTE : This function should not be modified. When the callback is needed,
  685. function HAL_ADC_LevelOoutOfWindowCallback must be implemented in the user file.
  686. */
  687. }
  688. /**
  689. * @brief ADC error callback in non blocking mode
  690. * (ADC conversion with interruption or transfer by DMA)
  691. * @param hadc ADC handle
  692. * @retval None
  693. */
  694. __weak void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc)
  695. {
  696. /* Prevent unused argument(s) compilation warning */
  697. UNUSED(hadc);
  698. /* NOTE : This function should not be modified. When the callback is needed,
  699. function HAL_ADC_ErrorCallback must be implemented in the user file.
  700. */
  701. }
  702. /**
  703. * @}
  704. */
  705. /** @defgroup ADC_Exported_Functions_Group3 Peripheral Control functions
  706. * @brief Peripheral Control functions
  707. *
  708. @verbatim
  709. ===============================================================================
  710. ##### Peripheral Control functions #####
  711. ===============================================================================
  712. [..] This section provides functions allowing to:
  713. (+) Configure channels on regular group
  714. (+) Configure the analog watchdog
  715. @endverbatim
  716. * @{
  717. */
  718. /**
  719. * @brief Configures the the selected channel to be linked to the regular
  720. * group.
  721. * @note In case of usage of internal measurement channels:
  722. * Vbat/VrefInt/TempSensor.
  723. * The recommended sampling time is at least:
  724. * - For devices STM32F37x: 17.1us for temperature sensor
  725. * - For the other STM32F3 devices: 2.2us for each of channels
  726. * Vbat/VrefInt/TempSensor.
  727. * These internal paths can be be disabled using function
  728. * HAL_ADC_DeInit().
  729. * @note Possibility to update parameters on the fly:
  730. * This function initializes channel into regular group, following
  731. * calls to this function can be used to reconfigure some parameters
  732. * of structure "ADC_ChannelConfTypeDef" on the fly, without reseting
  733. * the ADC.
  734. * The setting of these parameters is conditioned to ADC state.
  735. * For parameters constraints, see comments of structure
  736. * "ADC_ChannelConfTypeDef".
  737. * @param hadc ADC handle
  738. * @param sConfig Structure of ADC channel for regular group.
  739. * @retval HAL status
  740. */
  741. __weak HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig)
  742. {
  743. /* Prevent unused argument(s) compilation warning */
  744. UNUSED(hadc);
  745. UNUSED(sConfig);
  746. /* Note : This function is defined into this file for library reference. */
  747. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  748. /* Return function status */
  749. return HAL_ERROR;
  750. }
  751. /**
  752. * @brief Configures the analog watchdog.
  753. * @note Possibility to update parameters on the fly:
  754. * This function initializes the selected analog watchdog, following
  755. * calls to this function can be used to reconfigure some parameters
  756. * of structure "ADC_AnalogWDGConfTypeDef" on the fly, without reseting
  757. * the ADC.
  758. * The setting of these parameters is conditioned to ADC state.
  759. * For parameters constraints, see comments of structure
  760. * "ADC_AnalogWDGConfTypeDef".
  761. * @param hadc ADC handle
  762. * @param AnalogWDGConfig Structure of ADC analog watchdog configuration
  763. * @retval HAL status
  764. */
  765. __weak HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig)
  766. {
  767. /* Prevent unused argument(s) compilation warning */
  768. UNUSED(hadc);
  769. UNUSED(AnalogWDGConfig);
  770. /* Note : This function is defined into this file for library reference. */
  771. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  772. /* Return function status */
  773. return HAL_ERROR;
  774. }
  775. /**
  776. * @}
  777. */
  778. /** @defgroup ADC_Exported_Functions_Group4 Peripheral State functions
  779. * @brief ADC Peripheral State functions
  780. *
  781. @verbatim
  782. ===============================================================================
  783. ##### Peripheral state and errors functions #####
  784. ===============================================================================
  785. [..]
  786. This subsection provides functions to get in run-time the status of the
  787. peripheral.
  788. (+) Check the ADC state
  789. (+) Check the ADC error code
  790. @endverbatim
  791. * @{
  792. */
  793. /**
  794. * @brief return the ADC state
  795. * @note ADC state machine is managed by bitfield, state must be compared
  796. * with bit by bit.
  797. * For example:
  798. * " if (HAL_IS_BIT_SET(HAL_ADC_GetState(hadc1), HAL_ADC_STATE_REG_BUSY)) "
  799. * " if (HAL_IS_BIT_SET(HAL_ADC_GetState(hadc1), HAL_ADC_STATE_AWD1) ) "
  800. * @param hadc ADC handle
  801. * @retval HAL state
  802. */
  803. uint32_t HAL_ADC_GetState(ADC_HandleTypeDef* hadc)
  804. {
  805. /* Check the parameters */
  806. assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
  807. /* Return ADC state */
  808. return hadc->State;
  809. }
  810. /**
  811. * @brief Return the ADC error code
  812. * @param hadc ADC handle
  813. * @retval ADC Error Code
  814. */
  815. uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc)
  816. {
  817. return hadc->ErrorCode;
  818. }
  819. /**
  820. * @}
  821. */
  822. /**
  823. * @}
  824. */
  825. #endif /* HAL_ADC_MODULE_ENABLED */
  826. /**
  827. * @}
  828. */
  829. /**
  830. * @}
  831. */
  832. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/