stm32f3xx_hal_sdadc.c 88 KB

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