stm32f3xx_hal_adc.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  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. * + Peripheral Control functions
  10. * + Peripheral State functions
  11. * Other functions (extended functions) are available in file
  12. * "stm32f3xx_hal_adc_ex.c".
  13. *
  14. ******************************************************************************
  15. * @attention
  16. *
  17. * Copyright (c) 2016 STMicroelectronics.
  18. * All rights reserved.
  19. *
  20. * This software is licensed under terms that can be found in the LICENSE file
  21. * in the root directory of this software component.
  22. * If no LICENSE file comes with this software, it is provided AS-IS.
  23. *
  24. ******************************************************************************
  25. @verbatim
  26. ==============================================================================
  27. ##### ADC peripheral features #####
  28. ==============================================================================
  29. [..]
  30. (+) 12-bit, 10-bit, 8-bit or 6-bit configurable resolution (available only on
  31. STM32F30xxC devices).
  32. (+) Interrupt generation at the end of regular conversion, end of injected
  33. conversion, and in case of analog watchdog or overrun events.
  34. (+) Single and continuous conversion modes.
  35. (+) Scan mode for conversion of several channels sequentially.
  36. (+) Data alignment with in-built data coherency.
  37. (+) Programmable sampling time (channel wise)
  38. (+) ADC conversion of regular group and injected group.
  39. (+) External trigger (timer or EXTI) with configurable polarity
  40. for both regular and injected groups.
  41. (+) DMA request generation for transfer of conversions data of regular group.
  42. (+) Multimode dual mode (available on devices with 2 ADCs or more).
  43. (+) Configurable DMA data storage in Multimode Dual mode (available on devices
  44. with 2 DCs or more).
  45. (+) Configurable delay between conversions in Dual interleaved mode (available
  46. on devices with 2 DCs or more).
  47. (+) ADC calibration
  48. (+) ADC channels selectable single/differential input (available only on
  49. STM32F30xxC devices)
  50. (+) ADC Injected sequencer&channels configuration context queue (available
  51. only on STM32F30xxC devices)
  52. (+) ADC offset on injected and regular groups (offset on regular group
  53. available only on STM32F30xxC devices)
  54. (+) ADC supply requirements: 2.4 V to 3.6 V at full speed and down to 1.8 V at
  55. slower speed.
  56. (+) ADC input range: from Vref- (connected to Vssa) to Vref+ (connected to
  57. Vdda or to an external voltage reference).
  58. ##### How to use this driver #####
  59. ==============================================================================
  60. [..]
  61. *** Configuration of top level parameters related to ADC ***
  62. ============================================================
  63. [..]
  64. (#) Enable the ADC interface
  65. (++) As prerequisite, ADC clock must be configured at RCC top level.
  66. (++) For STM32F30x/STM32F33x devices:
  67. Two possible clock sources: synchronous clock derived from AHB clock
  68. or asynchronous clock derived from ADC dedicated PLL 72MHz.
  69. - Synchronous clock is mandatory since used as ADC core clock.
  70. Synchronous clock can be used optionally as ADC conversion clock, depending on ADC init structure clock setting.
  71. Synchronous clock is configured using macro __ADCx_CLK_ENABLE().
  72. - Asynchronous can be used optionally as ADC conversion clock, depending on ADC init structure clock setting.
  73. Asynchronous clock is configured using function HAL_RCCEx_PeriphCLKConfig().
  74. (+++) For example, in case of device with a single ADC:
  75. Into HAL_ADC_MspInit() (recommended code location) or with
  76. other device clock parameters configuration:
  77. (+++) __HAL_RCC_ADC1_CLK_ENABLE() (mandatory)
  78. (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC (optional, if ADC conversion from asynchronous clock)
  79. (+++) PeriphClkInit.Adc1ClockSelection = RCC_ADC1PLLCLK_DIV1 (optional, if ADC conversion from asynchronous clock)
  80. (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure) (optional, if ADC conversion from asynchronous clock)
  81. (+++) For example, in case of device with 4 ADCs:
  82. (+++) if((hadc->Instance == ADC1) || (hadc->Instance == ADC2))
  83. (+++) {
  84. (+++) __HAL_RCC_ADC12_CLK_ENABLE() (mandatory)
  85. (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC (optional, if ADC conversion from asynchronous clock)
  86. (+++) PeriphClkInit.Adc12ClockSelection = RCC_ADC12PLLCLK_DIV1 (optional, if ADC conversion from asynchronous clock)
  87. (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure) (optional, if ADC conversion from asynchronous clock)
  88. (+++) }
  89. (+++) else
  90. (+++) {
  91. (+++) __HAL_RCC_ADC34_CLK_ENABLE() (mandatory)
  92. (+++) PeriphClkInit.Adc34ClockSelection = RCC_ADC34PLLCLK_DIV1; (optional, if ADC conversion from asynchronous clock)
  93. (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure); (optional, if ADC conversion from asynchronous clock)
  94. (+++) }
  95. (++) For STM32F37x devices:
  96. One clock setting is mandatory:
  97. ADC clock (core and conversion clock) from APB2 clock.
  98. (+++) Example:
  99. Into HAL_ADC_MspInit() (recommended code location) or with
  100. other device clock parameters configuration:
  101. (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC
  102. (+++) PeriphClkInit.AdcClockSelection = RCC_ADCPLLCLK_DIV2
  103. (+++) HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit)
  104. (#) ADC pins configuration
  105. (++) Enable the clock for the ADC GPIOs
  106. using macro __HAL_RCC_GPIOx_CLK_ENABLE()
  107. (++) Configure these ADC pins in analog mode
  108. using function HAL_GPIO_Init()
  109. (#) Optionally, in case of usage of ADC with interruptions:
  110. (++) Configure the NVIC for ADC
  111. using function HAL_NVIC_EnableIRQ(ADCx_IRQn)
  112. (++) Insert the ADC interruption handler function HAL_ADC_IRQHandler()
  113. into the function of corresponding ADC interruption vector
  114. ADCx_IRQHandler().
  115. (#) Optionally, in case of usage of DMA:
  116. (++) Configure the DMA (DMA channel, mode normal or circular, ...)
  117. using function HAL_DMA_Init().
  118. (++) Configure the NVIC for DMA
  119. using function HAL_NVIC_EnableIRQ(DMAx_Channelx_IRQn)
  120. (++) Insert the ADC interruption handler function HAL_ADC_IRQHandler()
  121. into the function of corresponding DMA interruption vector
  122. DMAx_Channelx_IRQHandler().
  123. *** Configuration of ADC, groups regular/injected, channels parameters ***
  124. ==========================================================================
  125. [..]
  126. (#) Configure the ADC parameters (resolution, data alignment, ...)
  127. and regular group parameters (conversion trigger, sequencer, ...)
  128. using function HAL_ADC_Init().
  129. (#) Configure the channels for regular group parameters (channel number,
  130. channel rank into sequencer, ..., into regular group)
  131. using function HAL_ADC_ConfigChannel().
  132. (#) Optionally, configure the injected group parameters (conversion trigger,
  133. sequencer, ..., of injected group)
  134. and the channels for injected group parameters (channel number,
  135. channel rank into sequencer, ..., into injected group)
  136. using function HAL_ADCEx_InjectedConfigChannel().
  137. (#) Optionally, configure the analog watchdog parameters (channels
  138. monitored, thresholds, ...)
  139. using function HAL_ADC_AnalogWDGConfig().
  140. (#) Optionally, for devices with several ADC instances: configure the
  141. multimode parameters
  142. using function HAL_ADCEx_MultiModeConfigChannel().
  143. *** Execution of ADC conversions ***
  144. ====================================
  145. [..]
  146. (#) Optionally, perform an automatic ADC calibration to improve the
  147. conversion accuracy
  148. using function HAL_ADCEx_Calibration_Start().
  149. (#) ADC driver can be used among three modes: polling, interruption,
  150. transfer by DMA.
  151. (++) ADC conversion by polling:
  152. (+++) Activate the ADC peripheral and start conversions
  153. using function HAL_ADC_Start()
  154. (+++) Wait for ADC conversion completion
  155. using function HAL_ADC_PollForConversion()
  156. (or for injected group: HAL_ADCEx_InjectedPollForConversion() )
  157. (+++) Retrieve conversion results
  158. using function HAL_ADC_GetValue()
  159. (or for injected group: HAL_ADCEx_InjectedGetValue() )
  160. (+++) Stop conversion and disable the ADC peripheral
  161. using function HAL_ADC_Stop()
  162. (++) ADC conversion by interruption:
  163. (+++) Activate the ADC peripheral and start conversions
  164. using function HAL_ADC_Start_IT()
  165. (+++) Wait for ADC conversion completion by call of function
  166. HAL_ADC_ConvCpltCallback()
  167. (this function must be implemented in user program)
  168. (or for injected group: HAL_ADCEx_InjectedConvCpltCallback() )
  169. (+++) Retrieve conversion results
  170. using function HAL_ADC_GetValue()
  171. (or for injected group: HAL_ADCEx_InjectedGetValue() )
  172. (+++) Stop conversion and disable the ADC peripheral
  173. using function HAL_ADC_Stop_IT()
  174. (++) ADC conversion with transfer by DMA:
  175. (+++) Activate the ADC peripheral and start conversions
  176. using function HAL_ADC_Start_DMA()
  177. (+++) Wait for ADC conversion completion by call of function
  178. HAL_ADC_ConvCpltCallback() or HAL_ADC_ConvHalfCpltCallback()
  179. (these functions must be implemented in user program)
  180. (+++) Conversion results are automatically transferred by DMA into
  181. destination variable address.
  182. (+++) Stop conversion and disable the ADC peripheral
  183. using function HAL_ADC_Stop_DMA()
  184. (++) For devices with several ADCs: ADC multimode conversion
  185. with transfer by DMA:
  186. (+++) Activate the ADC peripheral (slave)
  187. using function HAL_ADC_Start()
  188. (conversion start pending ADC master)
  189. (+++) Activate the ADC peripheral (master) and start conversions
  190. using function HAL_ADCEx_MultiModeStart_DMA()
  191. (+++) Wait for ADC conversion completion by call of function
  192. HAL_ADC_ConvCpltCallback() or HAL_ADC_ConvHalfCpltCallback()
  193. (these functions must be implemented in user program)
  194. (+++) Conversion results are automatically transferred by DMA into
  195. destination variable address.
  196. (+++) Stop conversion and disable the ADC peripheral (master)
  197. using function HAL_ADCEx_MultiModeStop_DMA()
  198. (+++) Stop conversion and disable the ADC peripheral (slave)
  199. using function HAL_ADC_Stop_IT()
  200. [..]
  201. (@) Callback functions must be implemented in user program:
  202. (+@) HAL_ADC_ErrorCallback()
  203. (+@) HAL_ADC_LevelOutOfWindowCallback() (callback of analog watchdog)
  204. (+@) HAL_ADC_ConvCpltCallback()
  205. (+@) HAL_ADC_ConvHalfCpltCallback
  206. (+@) HAL_ADCEx_InjectedConvCpltCallback()
  207. (+@) HAL_ADCEx_InjectedQueueOverflowCallback() (for STM32F30x/STM32F33x devices)
  208. *** Deinitialization of ADC ***
  209. ============================================================
  210. [..]
  211. (#) Disable the ADC interface
  212. (++) ADC clock can be hard reset and disabled at RCC top level.
  213. (++) Hard reset of ADC peripherals
  214. using macro __ADCx_FORCE_RESET(), __ADCx_RELEASE_RESET().
  215. (++) ADC clock disable
  216. using the equivalent macro/functions as configuration step.
  217. (++) For STM32F30x/STM32F33x devices:
  218. Caution: For devices with several ADCs:
  219. These settings impact both ADC of common group: ADC1&ADC2, ADC3&ADC4
  220. if available (ADC2, ADC3, ADC4 availability depends on STM32 product)
  221. (+++) For example, in case of device with a single ADC:
  222. Into HAL_ADC_MspDeInit() (recommended code location) or with
  223. other device clock parameters configuration:
  224. (+++) __HAL_RCC_ADC1_FORCE_RESET() (optional)
  225. (+++) __HAL_RCC_ADC1_RELEASE_RESET() (optional)
  226. (+++) __HAL_RCC_ADC1_CLK_DISABLE() (mandatory)
  227. (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC (optional, if configured before)
  228. (+++) PeriphClkInit.Adc1ClockSelection = RCC_ADC1PLLCLK_OFF (optional, if configured before)
  229. (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure) (optional, if configured before)
  230. (+++) For example, in case of device with 4 ADCs:
  231. (+++) if((hadc->Instance == ADC1) || (hadc->Instance == ADC2))
  232. (+++) {
  233. (+++) __HAL_RCC_ADC12_FORCE_RESET() (optional)
  234. (+++) __HAL_RCC_ADC12_RELEASE_RESET() (optional)
  235. (+++) __HAL_RCC_ADC12_CLK_DISABLE() (mandatory)
  236. (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC (optional, if configured before)
  237. (+++) PeriphClkInit.Adc12ClockSelection = RCC_ADC12PLLCLK_OFF (optional, if configured before)
  238. (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure) (optional, if configured before)
  239. (+++) }
  240. (+++) else
  241. (+++) {
  242. (+++) __HAL_RCC_ADC32_FORCE_RESET() (optional)
  243. (+++) __HAL_RCC_ADC32_RELEASE_RESET() (optional)
  244. (+++) __HAL_RCC_ADC34_CLK_DISABLE() (mandatory)
  245. (+++) PeriphClkInit.Adc34ClockSelection = RCC_ADC34PLLCLK_OFF (optional, if configured before)
  246. (+++) HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInitStructure) (optional, if configured before)
  247. (+++) }
  248. (++) For STM32F37x devices:
  249. (+++) Example:
  250. Into HAL_ADC_MspDeInit() (recommended code location) or with
  251. other device clock parameters configuration:
  252. (+++) PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC
  253. (+++) PeriphClkInit.AdcClockSelection = RCC_ADCPLLCLK_OFF
  254. (+++) HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit)
  255. (#) ADC pins configuration
  256. (++) Disable the clock for the ADC GPIOs
  257. using macro __HAL_RCC_GPIOx_CLK_DISABLE()
  258. (#) Optionally, in case of usage of ADC with interruptions:
  259. (++) Disable the NVIC for ADC
  260. using function HAL_NVIC_DisableIRQ(ADCx_IRQn)
  261. (#) Optionally, in case of usage of DMA:
  262. (++) Deinitialize the DMA
  263. using function HAL_DMA_DeInit().
  264. (++) Disable the NVIC for DMA
  265. using function HAL_NVIC_DisableIRQ(DMAx_Channelx_IRQn)
  266. [..]
  267. *** Callback registration ***
  268. =============================================
  269. [..]
  270. The compilation flag USE_HAL_ADC_REGISTER_CALLBACKS, when set to 1,
  271. allows the user to configure dynamically the driver callbacks.
  272. Use Functions HAL_ADC_RegisterCallback()
  273. to register an interrupt callback.
  274. [..]
  275. Function HAL_ADC_RegisterCallback() allows to register following callbacks:
  276. (+) ConvCpltCallback : ADC conversion complete callback
  277. (+) ConvHalfCpltCallback : ADC conversion DMA half-transfer callback
  278. (+) LevelOutOfWindowCallback : ADC analog watchdog 1 callback
  279. (+) ErrorCallback : ADC error callback
  280. (+) InjectedConvCpltCallback : ADC group injected conversion complete callback
  281. (+) MspInitCallback : ADC Msp Init callback
  282. (+) MspDeInitCallback : ADC Msp DeInit callback
  283. This function takes as parameters the HAL peripheral handle, the Callback ID
  284. and a pointer to the user callback function.
  285. [..]
  286. Use function HAL_ADC_UnRegisterCallback to reset a callback to the default
  287. weak function.
  288. [..]
  289. HAL_ADC_UnRegisterCallback takes as parameters the HAL peripheral handle,
  290. and the Callback ID.
  291. This function allows to reset following callbacks:
  292. (+) ConvCpltCallback : ADC conversion complete callback
  293. (+) ConvHalfCpltCallback : ADC conversion DMA half-transfer callback
  294. (+) LevelOutOfWindowCallback : ADC analog watchdog 1 callback
  295. (+) ErrorCallback : ADC error callback
  296. (+) InjectedConvCpltCallback : ADC group injected conversion complete callback
  297. (+) MspInitCallback : ADC Msp Init callback
  298. (+) MspDeInitCallback : ADC Msp DeInit callback
  299. [..]
  300. By default, after the HAL_ADC_Init() and when the state is HAL_ADC_STATE_RESET
  301. all callbacks are set to the corresponding weak functions:
  302. examples HAL_ADC_ConvCpltCallback(), HAL_ADC_ErrorCallback().
  303. Exception done for MspInit and MspDeInit functions that are
  304. reset to the legacy weak functions in the HAL_ADC_Init()/ HAL_ADC_DeInit() only when
  305. these callbacks are null (not registered beforehand).
  306. [..]
  307. If MspInit or MspDeInit are not null, the HAL_ADC_Init()/ HAL_ADC_DeInit()
  308. keep and use the user MspInit/MspDeInit callbacks (registered beforehand) whatever the state.
  309. [..]
  310. Callbacks can be registered/unregistered in HAL_ADC_STATE_READY state only.
  311. Exception done MspInit/MspDeInit functions that can be registered/unregistered
  312. in HAL_ADC_STATE_READY or HAL_ADC_STATE_RESET state,
  313. thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
  314. [..]
  315. Then, the user first registers the MspInit/MspDeInit user callbacks
  316. using HAL_ADC_RegisterCallback() before calling HAL_ADC_DeInit()
  317. or HAL_ADC_Init() function.
  318. [..]
  319. When the compilation flag USE_HAL_ADC_REGISTER_CALLBACKS is set to 0 or
  320. not defined, the callback registration feature is not available and all callbacks
  321. are set to the corresponding weak functions.
  322. @endverbatim
  323. */
  324. /* Includes ------------------------------------------------------------------*/
  325. #include "stm32f3xx_hal.h"
  326. /** @addtogroup STM32F3xx_HAL_Driver
  327. * @{
  328. */
  329. /** @defgroup ADC ADC
  330. * @brief ADC HAL module driver
  331. * @{
  332. */
  333. #ifdef HAL_ADC_MODULE_ENABLED
  334. /* Private typedef -----------------------------------------------------------*/
  335. /* Private define ------------------------------------------------------------*/
  336. /* Private macro -------------------------------------------------------------*/
  337. /* Private variables ---------------------------------------------------------*/
  338. /* Private function prototypes -----------------------------------------------*/
  339. /* Exported functions --------------------------------------------------------*/
  340. /** @defgroup ADC_Exported_Functions ADC Exported Functions
  341. * @{
  342. */
  343. /** @defgroup ADC_Exported_Functions_Group1 Initialization and de-initialization functions
  344. * @brief Initialization and Configuration functions
  345. *
  346. @verbatim
  347. ===============================================================================
  348. ##### Initialization and de-initialization functions #####
  349. ===============================================================================
  350. [..] This section provides functions allowing to:
  351. (+) Initialize and configure the ADC.
  352. (+) De-initialize the ADC.
  353. @endverbatim
  354. * @{
  355. */
  356. /**
  357. * @brief Initializes the ADC peripheral and regular group according to
  358. * parameters specified in structure "ADC_InitTypeDef".
  359. * @note As prerequisite, ADC clock must be configured at RCC top level
  360. * depending on both possible clock sources: PLL clock or AHB clock.
  361. * See commented example code below that can be copied and uncommented
  362. * into HAL_ADC_MspInit().
  363. * @note Possibility to update parameters on the fly:
  364. * This function initializes the ADC MSP (HAL_ADC_MspInit()) only when
  365. * coming from ADC state reset. Following calls to this function can
  366. * be used to reconfigure some parameters of ADC_InitTypeDef
  367. * structure on the fly, without modifying MSP configuration. If ADC
  368. * MSP has to be modified again, HAL_ADC_DeInit() must be called
  369. * before HAL_ADC_Init().
  370. * The setting of these parameters is conditioned to ADC state.
  371. * For parameters constraints, see comments of structure
  372. * "ADC_InitTypeDef".
  373. * @note This function configures the ADC within 2 scopes: scope of entire
  374. * ADC and scope of regular group. For parameters details, see comments
  375. * of structure "ADC_InitTypeDef".
  376. * @note For devices with several ADCs: parameters related to common ADC
  377. * registers (ADC clock mode) are set only if all ADCs sharing the
  378. * same common group are disabled.
  379. * If this is not the case, these common parameters setting are
  380. * bypassed without error reporting: it can be the intended behaviour in
  381. * case of update of a parameter of ADC_InitTypeDef on the fly,
  382. * without disabling the other ADCs sharing the same common group.
  383. * @param hadc ADC handle
  384. * @retval HAL status
  385. */
  386. __weak HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc)
  387. {
  388. /* Prevent unused argument(s) compilation warning */
  389. UNUSED(hadc);
  390. /* Note : This function is defined into this file for library reference. */
  391. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  392. /* Return function status */
  393. return HAL_ERROR;
  394. }
  395. /**
  396. * @brief Deinitialize the ADC peripheral registers to their default reset
  397. * values, with deinitialization of the ADC MSP.
  398. * @note For devices with several ADCs: reset of ADC common registers is done
  399. * only if all ADCs sharing the same common group are disabled.
  400. * If this is not the case, reset of these common parameters reset is
  401. * bypassed without error reporting: it can be the intended behaviour in
  402. * case of reset of a single ADC while the other ADCs sharing the same
  403. * common group is still running.
  404. * @note For devices with several ADCs: Global reset of all ADCs sharing a
  405. * common group is possible.
  406. * As this function is intended to reset a single ADC, to not impact
  407. * other ADCs, instructions for global reset of multiple ADCs have been
  408. * let commented below.
  409. * If needed, the example code can be copied and uncommented into
  410. * function HAL_ADC_MspDeInit().
  411. * @param hadc ADC handle
  412. * @retval HAL status
  413. */
  414. __weak HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef* hadc)
  415. {
  416. /* Prevent unused argument(s) compilation warning */
  417. UNUSED(hadc);
  418. /* Note : This function is defined into this file for library reference. */
  419. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  420. /* Return function status */
  421. return HAL_ERROR;
  422. }
  423. /**
  424. * @brief Initializes the ADC MSP.
  425. * @param hadc ADC handle
  426. * @retval None
  427. */
  428. __weak void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
  429. {
  430. /* Prevent unused argument(s) compilation warning */
  431. UNUSED(hadc);
  432. /* NOTE : This function should not be modified. When the callback is needed,
  433. function HAL_ADC_MspInit must be implemented in the user file.
  434. */
  435. }
  436. /**
  437. * @brief DeInitializes the ADC MSP.
  438. * @param hadc ADC handle
  439. * @retval None
  440. */
  441. __weak void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
  442. {
  443. /* Prevent unused argument(s) compilation warning */
  444. UNUSED(hadc);
  445. /* NOTE : This function should not be modified. When the callback is needed,
  446. function HAL_ADC_MspDeInit must be implemented in the user file.
  447. */
  448. }
  449. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  450. /**
  451. * @brief Register a User ADC Callback
  452. * To be used instead of the weak predefined callback
  453. * @param hadc Pointer to a ADC_HandleTypeDef structure that contains
  454. * the configuration information for the specified ADC.
  455. * @param CallbackID ID of the callback to be registered
  456. * This parameter can be one of the following values:
  457. * @arg @ref HAL_ADC_CONVERSION_COMPLETE_CB_ID ADC conversion complete callback ID
  458. * @arg @ref HAL_ADC_CONVERSION_HALF_CB_ID ADC conversion complete callback ID
  459. * @arg @ref HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID ADC analog watchdog 1 callback ID
  460. * @arg @ref HAL_ADC_ERROR_CB_ID ADC error callback ID
  461. * @arg @ref HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID ADC group injected conversion complete callback ID
  462. * @arg @ref HAL_ADC_MSPINIT_CB_ID ADC Msp Init callback ID
  463. * @arg @ref HAL_ADC_MSPDEINIT_CB_ID ADC Msp DeInit callback ID
  464. * @arg @ref HAL_ADC_MSPINIT_CB_ID MspInit callback ID
  465. * @arg @ref HAL_ADC_MSPDEINIT_CB_ID MspDeInit callback ID
  466. * @param pCallback pointer to the Callback function
  467. * @retval HAL status
  468. */
  469. HAL_StatusTypeDef HAL_ADC_RegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID, pADC_CallbackTypeDef pCallback)
  470. {
  471. HAL_StatusTypeDef status = HAL_OK;
  472. if (pCallback == NULL)
  473. {
  474. /* Update the error code */
  475. hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK;
  476. return HAL_ERROR;
  477. }
  478. if ((hadc->State & HAL_ADC_STATE_READY) != 0)
  479. {
  480. switch (CallbackID)
  481. {
  482. case HAL_ADC_CONVERSION_COMPLETE_CB_ID :
  483. hadc->ConvCpltCallback = pCallback;
  484. break;
  485. case HAL_ADC_CONVERSION_HALF_CB_ID :
  486. hadc->ConvHalfCpltCallback = pCallback;
  487. break;
  488. case HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID :
  489. hadc->LevelOutOfWindowCallback = pCallback;
  490. break;
  491. case HAL_ADC_ERROR_CB_ID :
  492. hadc->ErrorCallback = pCallback;
  493. break;
  494. case HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID :
  495. hadc->InjectedConvCpltCallback = pCallback;
  496. break;
  497. case HAL_ADC_MSPINIT_CB_ID :
  498. hadc->MspInitCallback = pCallback;
  499. break;
  500. case HAL_ADC_MSPDEINIT_CB_ID :
  501. hadc->MspDeInitCallback = pCallback;
  502. break;
  503. default :
  504. /* Update the error code */
  505. hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK;
  506. /* Return error status */
  507. status = HAL_ERROR;
  508. break;
  509. }
  510. }
  511. else if (HAL_ADC_STATE_RESET == hadc->State)
  512. {
  513. switch (CallbackID)
  514. {
  515. case HAL_ADC_MSPINIT_CB_ID :
  516. hadc->MspInitCallback = pCallback;
  517. break;
  518. case HAL_ADC_MSPDEINIT_CB_ID :
  519. hadc->MspDeInitCallback = pCallback;
  520. break;
  521. default :
  522. /* Update the error code */
  523. hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK;
  524. /* Return error status */
  525. status = HAL_ERROR;
  526. break;
  527. }
  528. }
  529. else
  530. {
  531. /* Update the error code */
  532. hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK;
  533. /* Return error status */
  534. status = HAL_ERROR;
  535. }
  536. return status;
  537. }
  538. /**
  539. * @brief Unregister a ADC Callback
  540. * ADC callback is redirected to the weak predefined callback
  541. * @param hadc Pointer to a ADC_HandleTypeDef structure that contains
  542. * the configuration information for the specified ADC.
  543. * @param CallbackID ID of the callback to be unregistered
  544. * This parameter can be one of the following values:
  545. * @arg @ref HAL_ADC_CONVERSION_COMPLETE_CB_ID ADC conversion complete callback ID
  546. * @arg @ref HAL_ADC_CONVERSION_HALF_CB_ID ADC conversion complete callback ID
  547. * @arg @ref HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID ADC analog watchdog 1 callback ID
  548. * @arg @ref HAL_ADC_ERROR_CB_ID ADC error callback ID
  549. * @arg @ref HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID ADC group injected conversion complete callback ID
  550. * @arg @ref HAL_ADC_MSPINIT_CB_ID ADC Msp Init callback ID
  551. * @arg @ref HAL_ADC_MSPDEINIT_CB_ID ADC Msp DeInit callback ID
  552. * @arg @ref HAL_ADC_MSPINIT_CB_ID MspInit callback ID
  553. * @arg @ref HAL_ADC_MSPDEINIT_CB_ID MspDeInit callback ID
  554. * @retval HAL status
  555. */
  556. HAL_StatusTypeDef HAL_ADC_UnRegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID)
  557. {
  558. HAL_StatusTypeDef status = HAL_OK;
  559. if ((hadc->State & HAL_ADC_STATE_READY) != 0)
  560. {
  561. switch (CallbackID)
  562. {
  563. case HAL_ADC_CONVERSION_COMPLETE_CB_ID :
  564. hadc->ConvCpltCallback = HAL_ADC_ConvCpltCallback;
  565. break;
  566. case HAL_ADC_CONVERSION_HALF_CB_ID :
  567. hadc->ConvHalfCpltCallback = HAL_ADC_ConvHalfCpltCallback;
  568. break;
  569. case HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID :
  570. hadc->LevelOutOfWindowCallback = HAL_ADC_LevelOutOfWindowCallback;
  571. break;
  572. case HAL_ADC_ERROR_CB_ID :
  573. hadc->ErrorCallback = HAL_ADC_ErrorCallback;
  574. break;
  575. case HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID :
  576. hadc->InjectedConvCpltCallback = HAL_ADCEx_InjectedConvCpltCallback;
  577. break;
  578. case HAL_ADC_MSPINIT_CB_ID :
  579. hadc->MspInitCallback = HAL_ADC_MspInit; /* Legacy weak MspInit */
  580. break;
  581. case HAL_ADC_MSPDEINIT_CB_ID :
  582. hadc->MspDeInitCallback = HAL_ADC_MspDeInit; /* Legacy weak MspDeInit */
  583. break;
  584. default :
  585. /* Update the error code */
  586. hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK;
  587. /* Return error status */
  588. status = HAL_ERROR;
  589. break;
  590. }
  591. }
  592. else if (HAL_ADC_STATE_RESET == hadc->State)
  593. {
  594. switch (CallbackID)
  595. {
  596. case HAL_ADC_MSPINIT_CB_ID :
  597. hadc->MspInitCallback = HAL_ADC_MspInit; /* Legacy weak MspInit */
  598. break;
  599. case HAL_ADC_MSPDEINIT_CB_ID :
  600. hadc->MspDeInitCallback = HAL_ADC_MspDeInit; /* Legacy weak MspDeInit */
  601. break;
  602. default :
  603. /* Update the error code */
  604. hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK;
  605. /* Return error status */
  606. status = HAL_ERROR;
  607. break;
  608. }
  609. }
  610. else
  611. {
  612. /* Update the error code */
  613. hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK;
  614. /* Return error status */
  615. status = HAL_ERROR;
  616. }
  617. return status;
  618. }
  619. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  620. /**
  621. * @}
  622. */
  623. /** @defgroup ADC_Exported_Functions_Group2 Input and Output operation functions
  624. * @brief IO operation functions
  625. *
  626. @verbatim
  627. ===============================================================================
  628. ##### IO operation functions #####
  629. ===============================================================================
  630. [..] This section provides functions allowing to:
  631. (+) Start conversion of regular group.
  632. (+) Stop conversion of regular group.
  633. (+) Poll for conversion complete on regular group.
  634. (+) Poll for conversion event.
  635. (+) Get result of regular channel conversion.
  636. (+) Start conversion of regular group and enable interruptions.
  637. (+) Stop conversion of regular group and disable interruptions.
  638. (+) Handle ADC interrupt request
  639. (+) Start conversion of regular group and enable DMA transfer.
  640. (+) Stop conversion of regular group and disable ADC DMA transfer.
  641. @endverbatim
  642. * @{
  643. */
  644. /**
  645. * @brief Enables ADC, starts conversion of regular group.
  646. * Interruptions enabled in this function: None.
  647. * @note: Case of multimode enabled (for devices with several ADCs): This
  648. * function must be called for ADC slave first, then ADC master.
  649. * For ADC slave, ADC is enabled only (conversion is not started).
  650. * For ADC master, ADC is enabled and multimode conversion is started.
  651. * @param hadc ADC handle
  652. * @retval HAL status
  653. */
  654. __weak HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc)
  655. {
  656. /* Prevent unused argument(s) compilation warning */
  657. UNUSED(hadc);
  658. /* Return function status */
  659. return HAL_ERROR;
  660. }
  661. /**
  662. * @brief Stop ADC conversion of regular group (and injected group in
  663. * case of auto_injection mode), disable ADC peripheral.
  664. * @note: ADC peripheral disable is forcing stop of potential
  665. * conversion on injected group. If injected group is under use, it
  666. * should be preliminarily stopped using HAL_ADCEx_InjectedStop function.
  667. * @note: Case of multimode enabled (for devices with several ADCs): This
  668. * function must be called for ADC master first, then ADC slave.
  669. * For ADC master, conversion is stopped and ADC is disabled.
  670. * For ADC slave, ADC is disabled only (conversion stop of ADC master
  671. * has already stopped conversion of ADC slave).
  672. * @param hadc ADC handle
  673. * @retval HAL status.
  674. */
  675. __weak HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef* hadc)
  676. {
  677. /* Prevent unused argument(s) compilation warning */
  678. UNUSED(hadc);
  679. /* Note : This function is defined into this file for library reference. */
  680. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  681. /* Return function status */
  682. return HAL_ERROR;
  683. }
  684. /**
  685. * @brief Wait for regular group conversion to be completed.
  686. * @param hadc ADC handle
  687. * @param Timeout Timeout value in millisecond.
  688. * @retval HAL status
  689. */
  690. __weak HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout)
  691. {
  692. /* Prevent unused argument(s) compilation warning */
  693. UNUSED(hadc);
  694. UNUSED(Timeout);
  695. /* Note : This function is defined into this file for library reference. */
  696. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  697. /* Return function status */
  698. return HAL_ERROR;
  699. }
  700. /**
  701. * @brief Poll for conversion event.
  702. * @param hadc ADC handle
  703. * @param EventType the ADC event type.
  704. * This parameter can be one of the following values:
  705. * @arg ADC_AWD_EVENT: ADC Analog watchdog 1 event (main analog watchdog, present on all STM32 devices)
  706. * @arg ADC_AWD2_EVENT: ADC Analog watchdog 2 event (additional analog watchdog, present only on STM32F3 devices)
  707. * @arg ADC_AWD3_EVENT: ADC Analog watchdog 3 event (additional analog watchdog, present only on STM32F3 devices)
  708. * @arg ADC_OVR_EVENT: ADC Overrun event
  709. * @arg ADC_JQOVF_EVENT: ADC Injected context queue overflow event
  710. * @param Timeout Timeout value in millisecond.
  711. * @retval HAL status
  712. */
  713. __weak HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout)
  714. {
  715. /* Prevent unused argument(s) compilation warning */
  716. UNUSED(hadc);
  717. UNUSED(EventType);
  718. UNUSED(Timeout);
  719. /* Note : This function is defined into this file for library reference. */
  720. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  721. /* Return function status */
  722. return HAL_ERROR;
  723. }
  724. /**
  725. * @brief Enables ADC, starts conversion of regular group with interruption.
  726. * Interruptions enabled in this function:
  727. * - EOC (end of conversion of regular group) or EOS (end of
  728. * sequence of regular group) depending on ADC initialization
  729. * parameter "EOCSelection" (if available)
  730. * - overrun (if available)
  731. * Each of these interruptions has its dedicated callback function.
  732. * @note: Case of multimode enabled (for devices with several ADCs): This
  733. * function must be called for ADC slave first, then ADC master.
  734. * For ADC slave, ADC is enabled only (conversion is not started).
  735. * For ADC master, ADC is enabled and multimode conversion is started.
  736. * @param hadc ADC handle
  737. * @retval HAL status
  738. */
  739. __weak HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc)
  740. {
  741. /* Prevent unused argument(s) compilation warning */
  742. UNUSED(hadc);
  743. /* Note : This function is defined into this file for library reference. */
  744. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  745. /* Return function status */
  746. return HAL_ERROR;
  747. }
  748. /**
  749. * @brief Stop ADC conversion of regular group (and injected group in
  750. * case of auto_injection mode), disable interruption of
  751. * end-of-conversion, disable ADC peripheral.
  752. * @note: ADC peripheral disable is forcing stop of potential
  753. * conversion on injected group. If injected group is under use, it
  754. * should be preliminarily stopped using HAL_ADCEx_InjectedStop function.
  755. * @note: Case of multimode enabled (for devices with several ADCs): This
  756. * function must be called for ADC master first, then ADC slave.
  757. * For ADC master, conversion is stopped and ADC is disabled.
  758. * For ADC slave, ADC is disabled only (conversion stop of ADC master
  759. * has already stopped conversion of ADC slave).
  760. * @param hadc ADC handle
  761. * @retval HAL status.
  762. */
  763. __weak HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc)
  764. {
  765. /* Prevent unused argument(s) compilation warning */
  766. UNUSED(hadc);
  767. /* Note : This function is defined into this file for library reference. */
  768. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  769. /* Return function status */
  770. return HAL_ERROR;
  771. }
  772. /**
  773. * @brief Enables ADC, starts conversion of regular group and transfers result
  774. * through DMA.
  775. * Interruptions enabled in this function:
  776. * - DMA transfer complete
  777. * - DMA half transfer
  778. * - overrun (if available)
  779. * Each of these interruptions has its dedicated callback function.
  780. * @note: Case of multimode enabled (for devices with several ADCs): This
  781. * function is for single-ADC mode only. For multimode, use the
  782. * dedicated MultimodeStart function.
  783. * @param hadc ADC handle
  784. * @param pData The destination Buffer address.
  785. * @param Length The length of data to be transferred from ADC peripheral to memory.
  786. * @retval None
  787. */
  788. __weak HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length)
  789. {
  790. /* Prevent unused argument(s) compilation warning */
  791. UNUSED(hadc);
  792. UNUSED(pData);
  793. UNUSED(Length);
  794. /* Note : This function is defined into this file for library reference. */
  795. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  796. /* Return function status */
  797. return HAL_ERROR;
  798. }
  799. /**
  800. * @brief Stop ADC conversion of regular group (and injected group in
  801. * case of auto_injection mode), disable ADC DMA transfer, disable
  802. * ADC peripheral.
  803. * @note: ADC peripheral disable is forcing stop of potential
  804. * conversion on injected group. If injected group is under use, it
  805. * should be preliminarily stopped using HAL_ADCEx_InjectedStop function.
  806. * @note: Case of multimode enabled (for devices with several ADCs): This
  807. * function is for single-ADC mode only. For multimode, use the
  808. * dedicated MultimodeStop function.
  809. * @param hadc ADC handle
  810. * @retval HAL status.
  811. */
  812. __weak HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc)
  813. {
  814. /* Prevent unused argument(s) compilation warning */
  815. UNUSED(hadc);
  816. /* Note : This function is defined into this file for library reference. */
  817. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  818. /* Return function status */
  819. return HAL_ERROR;
  820. }
  821. /**
  822. * @brief Get ADC regular group conversion result.
  823. * @note Reading DR register automatically clears EOC (end of conversion of
  824. * regular group) flag.
  825. * Additionally, this functions clears EOS (end of sequence of
  826. * regular group) flag, in case of the end of the sequence is reached.
  827. * @param hadc ADC handle
  828. * @retval Converted value
  829. */
  830. __weak uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef* hadc)
  831. {
  832. /* Note : This function is defined into this file for library reference. */
  833. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  834. /* Return ADC converted value */
  835. return hadc->Instance->DR;
  836. }
  837. /**
  838. * @brief Handles ADC interrupt request.
  839. * @param hadc ADC handle
  840. * @retval None
  841. */
  842. __weak void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc)
  843. {
  844. /* Prevent unused argument(s) compilation warning */
  845. UNUSED(hadc);
  846. /* Note : This function is defined into this file for library reference. */
  847. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  848. }
  849. /**
  850. * @brief Conversion complete callback in non blocking mode
  851. * @param hadc ADC handle
  852. * @retval None
  853. */
  854. __weak void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
  855. {
  856. /* Prevent unused argument(s) compilation warning */
  857. UNUSED(hadc);
  858. /* NOTE : This function should not be modified. When the callback is needed,
  859. function HAL_ADC_ConvCpltCallback must be implemented in the user file.
  860. */
  861. }
  862. /**
  863. * @brief Conversion DMA half-transfer callback in non blocking mode
  864. * @param hadc ADC handle
  865. * @retval None
  866. */
  867. __weak void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc)
  868. {
  869. /* Prevent unused argument(s) compilation warning */
  870. UNUSED(hadc);
  871. /* NOTE : This function should not be modified. When the callback is needed,
  872. function HAL_ADC_ConvHalfCpltCallback must be implemented in the user file.
  873. */
  874. }
  875. /**
  876. * @brief Analog watchdog callback in non blocking mode.
  877. * @param hadc ADC handle
  878. * @retval None
  879. */
  880. __weak void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc)
  881. {
  882. /* Prevent unused argument(s) compilation warning */
  883. UNUSED(hadc);
  884. /* NOTE : This function should not be modified. When the callback is needed,
  885. function HAL_ADC_LevelOoutOfWindowCallback must be implemented in the user file.
  886. */
  887. }
  888. /**
  889. * @brief ADC error callback in non blocking mode
  890. * (ADC conversion with interruption or transfer by DMA)
  891. * @param hadc ADC handle
  892. * @retval None
  893. */
  894. __weak void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc)
  895. {
  896. /* Prevent unused argument(s) compilation warning */
  897. UNUSED(hadc);
  898. /* NOTE : This function should not be modified. When the callback is needed,
  899. function HAL_ADC_ErrorCallback must be implemented in the user file.
  900. */
  901. }
  902. /**
  903. * @}
  904. */
  905. /** @defgroup ADC_Exported_Functions_Group3 Peripheral Control functions
  906. * @brief Peripheral Control functions
  907. *
  908. @verbatim
  909. ===============================================================================
  910. ##### Peripheral Control functions #####
  911. ===============================================================================
  912. [..] This section provides functions allowing to:
  913. (+) Configure channels on regular group
  914. (+) Configure the analog watchdog
  915. @endverbatim
  916. * @{
  917. */
  918. /**
  919. * @brief Configures the the selected channel to be linked to the regular
  920. * group.
  921. * @note In case of usage of internal measurement channels:
  922. * Vbat/VrefInt/TempSensor.
  923. * The recommended sampling time is at least:
  924. * - For devices STM32F37x: 17.1us for temperature sensor
  925. * - For the other STM32F3 devices: 2.2us for each of channels
  926. * Vbat/VrefInt/TempSensor.
  927. * These internal paths can be be disabled using function
  928. * HAL_ADC_DeInit().
  929. * @note Possibility to update parameters on the fly:
  930. * This function initializes channel into regular group, following
  931. * calls to this function can be used to reconfigure some parameters
  932. * of structure "ADC_ChannelConfTypeDef" on the fly, without resetting
  933. * the ADC.
  934. * The setting of these parameters is conditioned to ADC state.
  935. * For parameters constraints, see comments of structure
  936. * "ADC_ChannelConfTypeDef".
  937. * @param hadc ADC handle
  938. * @param sConfig Structure of ADC channel for regular group.
  939. * @retval HAL status
  940. */
  941. __weak HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig)
  942. {
  943. /* Prevent unused argument(s) compilation warning */
  944. UNUSED(hadc);
  945. UNUSED(sConfig);
  946. /* Note : This function is defined into this file for library reference. */
  947. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  948. /* Return function status */
  949. return HAL_ERROR;
  950. }
  951. /**
  952. * @brief Configures the analog watchdog.
  953. * @note Possibility to update parameters on the fly:
  954. * This function initializes the selected analog watchdog, following
  955. * calls to this function can be used to reconfigure some parameters
  956. * of structure "ADC_AnalogWDGConfTypeDef" on the fly, without resetting
  957. * the ADC.
  958. * The setting of these parameters is conditioned to ADC state.
  959. * For parameters constraints, see comments of structure
  960. * "ADC_AnalogWDGConfTypeDef".
  961. * @param hadc ADC handle
  962. * @param AnalogWDGConfig Structure of ADC analog watchdog configuration
  963. * @retval HAL status
  964. */
  965. __weak HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig)
  966. {
  967. /* Prevent unused argument(s) compilation warning */
  968. UNUSED(hadc);
  969. UNUSED(AnalogWDGConfig);
  970. /* Note : This function is defined into this file for library reference. */
  971. /* Function content is located into file stm32f3xx_hal_adc_ex.c */
  972. /* Return function status */
  973. return HAL_ERROR;
  974. }
  975. /**
  976. * @}
  977. */
  978. /** @defgroup ADC_Exported_Functions_Group4 Peripheral State functions
  979. * @brief ADC Peripheral State functions
  980. *
  981. @verbatim
  982. ===============================================================================
  983. ##### Peripheral state and errors functions #####
  984. ===============================================================================
  985. [..]
  986. This subsection provides functions to get in run-time the status of the
  987. peripheral.
  988. (+) Check the ADC state
  989. (+) Check the ADC error code
  990. @endverbatim
  991. * @{
  992. */
  993. /**
  994. * @brief return the ADC state
  995. * @note ADC state machine is managed by bitfield, state must be compared
  996. * with bit by bit.
  997. * For example:
  998. * " if (HAL_IS_BIT_SET(HAL_ADC_GetState(hadc1), HAL_ADC_STATE_REG_BUSY)) "
  999. * " if (HAL_IS_BIT_SET(HAL_ADC_GetState(hadc1), HAL_ADC_STATE_AWD1) ) "
  1000. * @param hadc ADC handle
  1001. * @retval HAL state
  1002. */
  1003. uint32_t HAL_ADC_GetState(ADC_HandleTypeDef* hadc)
  1004. {
  1005. /* Check the parameters */
  1006. assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance));
  1007. /* Return ADC state */
  1008. return hadc->State;
  1009. }
  1010. /**
  1011. * @brief Return the ADC error code
  1012. * @param hadc ADC handle
  1013. * @retval ADC Error Code
  1014. */
  1015. uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc)
  1016. {
  1017. return hadc->ErrorCode;
  1018. }
  1019. /**
  1020. * @}
  1021. */
  1022. /**
  1023. * @}
  1024. */
  1025. #endif /* HAL_ADC_MODULE_ENABLED */
  1026. /**
  1027. * @}
  1028. */
  1029. /**
  1030. * @}
  1031. */