stm32f3xx_hal_dac_ex.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161
  1. /**
  2. ******************************************************************************
  3. * @file stm32f3xx_hal_dac_ex.c
  4. * @author MCD Application Team
  5. * @brief DACEx HAL module driver.
  6. * This file provides firmware functions to manage the extended
  7. * functionalities of the DAC peripheral.
  8. *
  9. *
  10. ******************************************************************************
  11. * @attention
  12. *
  13. * Copyright (c) 2016 STMicroelectronics.
  14. * All rights reserved.
  15. *
  16. * This software is licensed under terms that can be found in the LICENSE file
  17. * in the root directory of this software component.
  18. * If no LICENSE file comes with this software, it is provided AS-IS.
  19. *
  20. ******************************************************************************
  21. @verbatim
  22. ==============================================================================
  23. ##### How to use this driver #####
  24. ==============================================================================
  25. [..]
  26. (+) When Dual mode is enabled (i.e. DAC Channel1 and Channel2 are used simultaneously) :
  27. Use HAL_DACEx_DualGetValue() to get digital data to be converted and use
  28. HAL_DACEx_DualSetValue() to set digital value to converted simultaneously in Channel 1 and Channel 2.
  29. (+) Use HAL_DACEx_TriangleWaveGenerate() to generate Triangle signal.
  30. (+) Use HAL_DACEx_NoiseWaveGenerate() to generate Noise signal.
  31. @endverbatim
  32. ******************************************************************************
  33. */
  34. /* Includes ------------------------------------------------------------------*/
  35. #include "stm32f3xx_hal.h"
  36. /** @addtogroup STM32F3xx_HAL_Driver
  37. * @{
  38. */
  39. #ifdef HAL_DAC_MODULE_ENABLED
  40. /** @defgroup DACEx DACEx
  41. * @brief DAC HAL module driver
  42. * @{
  43. */
  44. /* Private typedef -----------------------------------------------------------*/
  45. /* Private define ------------------------------------------------------------*/
  46. /* Private macro -------------------------------------------------------------*/
  47. /* Private variables ---------------------------------------------------------*/
  48. /* Private function prototypes -----------------------------------------------*/
  49. /** @defgroup DACEx_Private_Functions DACEx Private Functions
  50. * @{
  51. */
  52. static void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma);
  53. static void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma);
  54. static void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma);
  55. #if defined(STM32F303xE) || defined(STM32F398xx) || \
  56. defined(STM32F303xC) || defined(STM32F358xx) || \
  57. defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) || \
  58. defined(STM32F373xC) || defined(STM32F378xx)
  59. /* DAC channel 2 is available on top of DAC channel 1U */
  60. static void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma);
  61. static void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma);
  62. static void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma);
  63. #endif /* STM32F303xE || STM32F398xx || */
  64. /* STM32F303xC || STM32F358xx || */
  65. /* STM32F303x8 || STM32F334x8 || STM32F328xx || */
  66. /* STM32F373xC || STM32F378xx */
  67. /**
  68. * @}
  69. */
  70. /* Exported functions ---------------------------------------------------------*/
  71. /** @defgroup DACEx_Exported_Functions DACEx Exported Functions
  72. * @{
  73. */
  74. /** @defgroup DACEx_Exported_Functions_Group3 DACEx Peripheral Control functions
  75. * @brief Peripheral Control functions
  76. *
  77. @verbatim
  78. ==============================================================================
  79. ##### Peripheral Control functions #####
  80. ==============================================================================
  81. [..] This section provides functions allowing to:
  82. (+) Set the specified data holding register value for DAC channel.
  83. (+) Set the specified data holding register value for dual DAC channel
  84. (when DAC channel 2 is present in DAC 1U)
  85. @endverbatim
  86. * @{
  87. */
  88. /**
  89. * @brief Set the specified data holding register value for DAC channel.
  90. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  91. * the configuration information for the specified DAC.
  92. * @param Channel The selected DAC channel.
  93. * @param Alignment Specifies the data alignment for DAC channel.
  94. * This parameter can be one of the following values:
  95. * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
  96. * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
  97. * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
  98. * @param Data Data to be loaded in the selected data holding register.
  99. * @retval HAL status
  100. */
  101. HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data)
  102. {
  103. __IO uint32_t tmp = 0U;
  104. /* Check the parameters */
  105. assert_param(IS_DAC_CHANNEL(Channel));
  106. assert_param(IS_DAC_ALIGN(Alignment));
  107. assert_param(IS_DAC_DATA(Data));
  108. tmp = (uint32_t) (hdac->Instance);
  109. /* DAC 1 has 1 or 2 channels - no DAC2 */
  110. /* DAC 1 has 2 channels 1U & 2U - DAC 2 has one channel 1U */
  111. if(Channel == DAC_CHANNEL_1)
  112. {
  113. tmp += DAC_DHR12R1_ALIGNMENT(Alignment);
  114. }
  115. #if defined(STM32F303xE) || defined(STM32F398xx) || \
  116. defined(STM32F303xC) || defined(STM32F358xx) || \
  117. defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) || \
  118. defined(STM32F373xC) || defined(STM32F378xx)
  119. else /* channel = DAC_CHANNEL_2 */
  120. {
  121. tmp += DAC_DHR12R2_ALIGNMENT(Alignment);
  122. }
  123. #endif /* STM32F303xE || STM32F398xx || */
  124. /* STM32F303xC || STM32F358xx || */
  125. /* STM32F303x8 || STM32F334x8 || STM32F328xx || */
  126. /* STM32F373xC || STM32F378xx */
  127. /* Set the DAC channel1 selected data holding register */
  128. *(__IO uint32_t *) tmp = Data;
  129. /* Return function status */
  130. return HAL_OK;
  131. }
  132. #if defined(STM32F303xE) || defined(STM32F398xx) || \
  133. defined(STM32F303xC) || defined(STM32F358xx) || \
  134. defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) || \
  135. defined(STM32F373xC) || defined(STM32F378xx)
  136. /* DAC channel 2 is present in DAC 1U */
  137. /**
  138. * @brief Set the specified data holding register value for dual DAC channel.
  139. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  140. * the configuration information for the specified DAC.
  141. * @param Alignment Specifies the data alignment for dual channel DAC.
  142. * This parameter can be one of the following values:
  143. * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
  144. * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
  145. * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
  146. * @param Data2: Data for DAC Channel2 to be loaded in the selected data holding register.
  147. * @param Data1: Data for DAC Channel1 to be loaded in the selected data holding register.
  148. * @note In dual mode, a unique register access is required to write in both
  149. * DAC channels at the same time.
  150. * @retval HAL status
  151. */
  152. HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef* hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2)
  153. {
  154. uint32_t data = 0U, tmp = 0U;
  155. /* Check the parameters */
  156. assert_param(IS_DAC_ALIGN(Alignment));
  157. assert_param(IS_DAC_DATA(Data1));
  158. assert_param(IS_DAC_DATA(Data2));
  159. /* Calculate and set dual DAC data holding register value */
  160. if (Alignment == DAC_ALIGN_8B_R)
  161. {
  162. data = ((uint32_t)Data2 << 8U) | Data1;
  163. }
  164. else
  165. {
  166. data = ((uint32_t)Data2 << 16U) | Data1;
  167. }
  168. tmp = (uint32_t) (hdac->Instance);
  169. tmp += DAC_DHR12RD_ALIGNMENT(Alignment);
  170. /* Set the dual DAC selected data holding register */
  171. *(__IO uint32_t *)tmp = data;
  172. /* Return function status */
  173. return HAL_OK;
  174. }
  175. #endif /* STM32F303xE || STM32F398xx || */
  176. /* STM32F303xC || STM32F358xx || */
  177. /* STM32F303x8 || STM32F334x8 || STM32F328xx || */
  178. /* STM32F373xC || STM32F378xx */
  179. /**
  180. * @}
  181. */
  182. /** @defgroup DACEx_Exported_Functions_Group2 DACEx Input and Output operation functions
  183. * @brief IO operation functions
  184. *
  185. @verbatim
  186. ==============================================================================
  187. ##### IO operation functions #####
  188. ==============================================================================
  189. [..] This section provides functions allowing to:
  190. (+) Start conversion.
  191. (+) Start conversion and enable DMA transfer.
  192. (+) Get result of conversion.
  193. (+) Handle DAC IRQ's.
  194. (+) Generate triangular-wave
  195. (+) Generate noise-wave
  196. (+) Callback functions for DAC1 Channel2 (when supported)
  197. @endverbatim
  198. * @{
  199. */
  200. #if defined(STM32F303xE) || defined(STM32F398xx) || \
  201. defined(STM32F303xC) || defined(STM32F358xx) || \
  202. defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) || \
  203. defined(STM32F373xC) || defined(STM32F378xx)
  204. /* DAC 1 has 2 channels 1U & 2U - DAC 2 has one channel 1U */
  205. /**
  206. * @brief Enables DAC and starts conversion of channel.
  207. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  208. * the configuration information for the specified DAC.
  209. * @param Channel The selected DAC channel.
  210. * This parameter can be one of the following values:
  211. * @arg DAC_CHANNEL_1: DAC1 Channel1 or DAC2 Channel1 selected
  212. * @arg DAC_CHANNEL_2: DAC1 Channel2 selected
  213. * @retval HAL status
  214. */
  215. HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel)
  216. {
  217. /* Check the parameters */
  218. assert_param(IS_DAC_CHANNEL_INSTANCE(hdac->Instance, Channel));
  219. /* Process locked */
  220. __HAL_LOCK(hdac);
  221. /* Change DAC state */
  222. hdac->State = HAL_DAC_STATE_BUSY;
  223. /* Enable the Peripheral */
  224. __HAL_DAC_ENABLE(hdac, Channel);
  225. if(Channel == DAC_CHANNEL_1)
  226. {
  227. /* Check if software trigger enabled */
  228. if((hdac->Instance->CR & (DAC_CR_TEN1 | DAC_CR_TSEL1)) == (DAC_CR_TEN1 | DAC_CR_TSEL1))
  229. {
  230. /* Enable the selected DAC software conversion */
  231. SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG1);
  232. }
  233. }
  234. else
  235. {
  236. /* Check if software trigger enabled */
  237. if((hdac->Instance->CR & (DAC_CR_TEN2 | DAC_CR_TSEL2)) == (DAC_CR_TEN2 | DAC_CR_TSEL2))
  238. {
  239. /* Enable the selected DAC software conversion */
  240. SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG2);
  241. }
  242. }
  243. /* Change DAC state */
  244. hdac->State = HAL_DAC_STATE_READY;
  245. /* Process unlocked */
  246. __HAL_UNLOCK(hdac);
  247. /* Return function status */
  248. return HAL_OK;
  249. }
  250. #endif /* STM32F303xE || STM32F398xx || */
  251. /* STM32F303xC || STM32F358xx || */
  252. /* STM32F303x8 || STM32F334x8 || STM32F328xx || */
  253. /* STM32F373xC || STM32F378xx */
  254. #if defined(STM32F302xE) || \
  255. defined(STM32F302xC) || \
  256. defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx)
  257. /* DAC 1 has 1 channels 1U */
  258. /**
  259. * @brief Enables DAC and starts conversion of channel.
  260. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  261. * the configuration information for the specified DAC.
  262. * @param Channel The selected DAC channel.
  263. * This parameter can be one of the following values:
  264. * @arg DAC_CHANNEL_1: DAC1 Channel1 selected
  265. * @retval HAL status
  266. */
  267. HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel)
  268. {
  269. /* Check the parameters */
  270. assert_param(IS_DAC_CHANNEL_INSTANCE(hdac->Instance, Channel));
  271. /* Process locked */
  272. __HAL_LOCK(hdac);
  273. /* Change DAC state */
  274. hdac->State = HAL_DAC_STATE_BUSY;
  275. /* Enable the Peripheral */
  276. __HAL_DAC_ENABLE(hdac, Channel);
  277. /* Check if software trigger enabled */
  278. if((hdac->Instance->CR & (DAC_CR_TEN1 | DAC_CR_TSEL1)) == (DAC_CR_TEN1 | DAC_CR_TSEL1))
  279. {
  280. /* Enable the selected DAC software conversion */
  281. SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG1);
  282. }
  283. /* Change DAC state */
  284. hdac->State = HAL_DAC_STATE_READY;
  285. /* Process unlocked */
  286. __HAL_UNLOCK(hdac);
  287. /* Return function status */
  288. return HAL_OK;
  289. }
  290. #endif /* STM32F302xE || */
  291. /* STM32F302xC || */
  292. /* STM32F301x8 || STM32F302x8 || STM32F318xx */
  293. /* DAC 1 has 2 channels 1U & 2U - DAC 2 has one channel 1U */
  294. #if defined(STM32F303xE) || defined(STM32F398xx) || \
  295. defined(STM32F303xC) || defined(STM32F358xx) || \
  296. defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) || \
  297. defined(STM32F373xC) || defined(STM32F378xx)
  298. /* DAC 1 has 2 channels 1U & 2U */
  299. /**
  300. * @brief Enables DAC and starts conversion of channel.
  301. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  302. * the configuration information for the specified DAC.
  303. * @param Channel The selected DAC channel.
  304. * This parameter can be one of the following values:
  305. * @arg DAC_CHANNEL_1: DAC1 Channel1 selected
  306. * @arg DAC_CHANNEL_2: DAC1 Channel2 selected
  307. * @param pData The destination peripheral Buffer address.
  308. * @param Length The length of data to be transferred from memory to DAC peripheral
  309. * @param Alignment Specifies the data alignment for DAC channel.
  310. * This parameter can be one of the following values:
  311. * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
  312. * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
  313. * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
  314. * @retval HAL status
  315. */
  316. HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment)
  317. {
  318. uint32_t tmpreg = 0U;
  319. /* Check the parameters */
  320. assert_param(IS_DAC_CHANNEL_INSTANCE(hdac->Instance, Channel));
  321. assert_param(IS_DAC_ALIGN(Alignment));
  322. /* Process locked */
  323. __HAL_LOCK(hdac);
  324. /* Change DAC state */
  325. hdac->State = HAL_DAC_STATE_BUSY;
  326. if(Channel == DAC_CHANNEL_1)
  327. {
  328. /* Set the DMA transfer complete callback for channel1 */
  329. hdac->DMA_Handle1->XferCpltCallback = DAC_DMAConvCpltCh1;
  330. /* Set the DMA half transfer complete callback for channel1 */
  331. hdac->DMA_Handle1->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh1;
  332. /* Set the DMA error callback for channel1 */
  333. hdac->DMA_Handle1->XferErrorCallback = DAC_DMAErrorCh1;
  334. /* Enable the selected DAC channel1 DMA request */
  335. SET_BIT(hdac->Instance->CR, DAC_CR_DMAEN1);
  336. /* Case of use of channel 1U */
  337. switch(Alignment)
  338. {
  339. case DAC_ALIGN_12B_R:
  340. /* Get DHR12R1 address */
  341. tmpreg = (uint32_t)&hdac->Instance->DHR12R1;
  342. break;
  343. case DAC_ALIGN_12B_L:
  344. /* Get DHR12L1 address */
  345. tmpreg = (uint32_t)&hdac->Instance->DHR12L1;
  346. break;
  347. case DAC_ALIGN_8B_R:
  348. /* Get DHR8R1 address */
  349. tmpreg = (uint32_t)&hdac->Instance->DHR8R1;
  350. break;
  351. default:
  352. break;
  353. }
  354. }
  355. else
  356. {
  357. /* Set the DMA transfer complete callback for channel2 */
  358. hdac->DMA_Handle2->XferCpltCallback = DAC_DMAConvCpltCh2;
  359. /* Set the DMA half transfer complete callback for channel2 */
  360. hdac->DMA_Handle2->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh2;
  361. /* Set the DMA error callback for channel2 */
  362. hdac->DMA_Handle2->XferErrorCallback = DAC_DMAErrorCh2;
  363. /* Enable the selected DAC channel2 DMA request */
  364. SET_BIT(hdac->Instance->CR, DAC_CR_DMAEN2);
  365. /* Case of use of channel 2U */
  366. switch(Alignment)
  367. {
  368. case DAC_ALIGN_12B_R:
  369. /* Get DHR12R2 address */
  370. tmpreg = (uint32_t)&hdac->Instance->DHR12R2;
  371. break;
  372. case DAC_ALIGN_12B_L:
  373. /* Get DHR12L2 address */
  374. tmpreg = (uint32_t)&hdac->Instance->DHR12L2;
  375. break;
  376. case DAC_ALIGN_8B_R:
  377. /* Get DHR8R2 address */
  378. tmpreg = (uint32_t)&hdac->Instance->DHR8R2;
  379. break;
  380. default:
  381. break;
  382. }
  383. }
  384. /* Enable the DMA Channel */
  385. if(Channel == DAC_CHANNEL_1)
  386. {
  387. /* Enable the DAC DMA underrun interrupt */
  388. __HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR1);
  389. /* Enable the DMA Channel */
  390. HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length);
  391. }
  392. else
  393. {
  394. /* Enable the DAC DMA underrun interrupt */
  395. __HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR2);
  396. /* Enable the DMA Channel */
  397. HAL_DMA_Start_IT(hdac->DMA_Handle2, (uint32_t)pData, tmpreg, Length);
  398. }
  399. /* Process Unlocked */
  400. __HAL_UNLOCK(hdac);
  401. /* Enable the Peripheral */
  402. __HAL_DAC_ENABLE(hdac, Channel);
  403. /* Return function status */
  404. return HAL_OK;
  405. }
  406. #endif /* STM32F303xE || STM32F398xx || */
  407. /* STM32F303xC || STM32F358xx || */
  408. /* STM32F303x8 || STM32F334x8 || STM32F328xx || */
  409. /* STM32F373xC || STM32F378xx */
  410. #if defined(STM32F302xE) || \
  411. defined(STM32F302xC) || \
  412. defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx)
  413. /* DAC 1 has 1 channel (channel 1U) */
  414. /**
  415. * @brief Enables DAC and starts conversion of channel.
  416. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  417. * the configuration information for the specified DAC.
  418. * @param Channel The selected DAC channel.
  419. * This parameter can be one of the following values:
  420. * @arg DAC_CHANNEL_1: DAC1 Channel1 selected
  421. * @param pData The destination peripheral Buffer address.
  422. * @param Length The length of data to be transferred from memory to DAC peripheral
  423. * @param Alignment Specifies the data alignment for DAC channel.
  424. * This parameter can be one of the following values:
  425. * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
  426. * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
  427. * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
  428. * @retval HAL status
  429. */
  430. HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment)
  431. {
  432. uint32_t tmpreg = 0U;
  433. /* Check the parameters */
  434. assert_param(IS_DAC_CHANNEL_INSTANCE(hdac->Instance, Channel));
  435. assert_param(IS_DAC_ALIGN(Alignment));
  436. /* Process locked */
  437. __HAL_LOCK(hdac);
  438. /* Change DAC state */
  439. hdac->State = HAL_DAC_STATE_BUSY;
  440. /* Set the DMA transfer complete callback for channel1 */
  441. hdac->DMA_Handle1->XferCpltCallback = DAC_DMAConvCpltCh1;
  442. /* Set the DMA half transfer complete callback for channel1 */
  443. hdac->DMA_Handle1->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh1;
  444. /* Set the DMA error callback for channel1 */
  445. hdac->DMA_Handle1->XferErrorCallback = DAC_DMAErrorCh1;
  446. /* Enable the selected DAC channel1 DMA request */
  447. SET_BIT(hdac->Instance->CR, DAC_CR_DMAEN1);
  448. /* Case of use of channel 1U */
  449. switch(Alignment)
  450. {
  451. case DAC_ALIGN_12B_R:
  452. /* Get DHR12R1 address */
  453. tmpreg = (uint32_t)&hdac->Instance->DHR12R1;
  454. break;
  455. case DAC_ALIGN_12B_L:
  456. /* Get DHR12L1 address */
  457. tmpreg = (uint32_t)&hdac->Instance->DHR12L1;
  458. break;
  459. case DAC_ALIGN_8B_R:
  460. /* Get DHR8R1 address */
  461. tmpreg = (uint32_t)&hdac->Instance->DHR8R1;
  462. break;
  463. default:
  464. break;
  465. }
  466. /* Enable the DMA Channel */
  467. /* Enable the DAC DMA underrun interrupt */
  468. __HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR1);
  469. /* Enable the DMA Channel */
  470. HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length);
  471. /* Process Unlocked */
  472. __HAL_UNLOCK(hdac);
  473. /* Enable the Peripheral */
  474. __HAL_DAC_ENABLE(hdac, Channel);
  475. /* Return function status */
  476. return HAL_OK;
  477. }
  478. #endif /* STM32F302xE || */
  479. /* STM32F302xC || */
  480. /* STM32F301x8 || STM32F302x8 || STM32F318xx */
  481. /* DAC 1 has 2 channels 1U & 2U - DAC 2 has one channel 1U */
  482. #if defined(STM32F303xE) || defined(STM32F398xx) || \
  483. defined(STM32F303xC) || defined(STM32F358xx) || \
  484. defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) || \
  485. defined(STM32F373xC) || defined(STM32F378xx)
  486. /* DAC 1 has 2 channels 1U & 2U */
  487. /**
  488. * @brief Returns the last data output value of the selected DAC channel.
  489. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  490. * the configuration information for the specified DAC.
  491. * @param Channel The selected DAC channel.
  492. * This parameter can be one of the following values:
  493. * @arg DAC_CHANNEL_1: DAC1 Channel1 selected
  494. * @arg DAC_CHANNEL_2: DAC1 Channel2 selected
  495. * @retval The selected DAC channel data output value.
  496. */
  497. uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel)
  498. {
  499. /* Check the parameters */
  500. assert_param(IS_DAC_CHANNEL_INSTANCE(hdac->Instance, Channel));
  501. /* Returns the DAC channel data output register value */
  502. if(Channel == DAC_CHANNEL_1)
  503. {
  504. return hdac->Instance->DOR1;
  505. }
  506. else /* channel = DAC_CHANNEL_2 */
  507. {
  508. return hdac->Instance->DOR2;
  509. }
  510. }
  511. #endif /* STM32F303xE || STM32F398xx || */
  512. /* STM32F303xC || STM32F358xx || */
  513. /* STM32F303x8 || STM32F334x8 || STM32F328xx || */
  514. /* STM32F373xC || STM32F378xx */
  515. #if defined(STM32F302xE) || \
  516. defined(STM32F302xC) || \
  517. defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx)
  518. /* DAC 1 has 1 channel (channel 1U) */
  519. /**
  520. * @brief Returns the last data output value of the selected DAC channel.
  521. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  522. * the configuration information for the specified DAC.
  523. * @param channel The selected DAC channel.
  524. * This parameter can be one of the following values:
  525. * @arg DAC_CHANNEL_1: DAC1 Channel1 selected
  526. * @retval The selected DAC channel data output value.
  527. */
  528. uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel)
  529. {
  530. /* Check the parameters */
  531. assert_param(IS_DAC_CHANNEL_INSTANCE(hdac->Instance, Channel));
  532. /* Returns the DAC channel data output register value */
  533. return hdac->Instance->DOR1;
  534. }
  535. #endif /* STM32F302xE || */
  536. /* STM32F302xC || */
  537. /* STM32F301x8 || STM32F302x8 || STM32F318xx */
  538. /**
  539. * @brief Return the last data output value of the selected DAC channel.
  540. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  541. * the configuration information for the specified DAC.
  542. * @retval The selected DAC channel data output value.
  543. */
  544. uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef* hdac)
  545. {
  546. uint32_t tmp = 0U;
  547. tmp |= hdac->Instance->DOR1;
  548. #if defined(STM32F303xE) || defined(STM32F398xx) || \
  549. defined(STM32F303xC) || defined(STM32F358xx) || \
  550. defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) || \
  551. defined(STM32F373xC) || defined(STM32F378xx)
  552. /* DAC channel 2 is present in DAC 1U */
  553. tmp |= hdac->Instance->DOR2 << 16U;
  554. #endif /* STM32F303xE || STM32F398xx || */
  555. /* STM32F303xC || STM32F358xx || */
  556. /* STM32F303x8 || STM32F334x8 || STM32F328xx || */
  557. /* STM32F373xC || STM32F378xx */
  558. /* Returns the DAC channel data output register value */
  559. return tmp;
  560. }
  561. #if defined(STM32F303xE) || defined(STM32F398xx) || \
  562. defined(STM32F303xC) || defined(STM32F358xx) || \
  563. defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) || \
  564. defined(STM32F373xC) || defined(STM32F378xx)
  565. /* DAC channel 2 is available on top of DAC channel 1U */
  566. /**
  567. * @brief Handles DAC interrupt request
  568. * This function uses the interruption of DMA
  569. * underrun.
  570. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  571. * the configuration information for the specified DAC.
  572. * @retval None
  573. */
  574. void HAL_DAC_IRQHandler(struct __DAC_HandleTypeDef* hdac)
  575. {
  576. if(__HAL_DAC_GET_IT_SOURCE(hdac, DAC_IT_DMAUDR1))
  577. {
  578. /* Check underrun flag of DAC channel 1U */
  579. if(__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR1))
  580. {
  581. /* Change DAC state to error state */
  582. hdac->State = HAL_DAC_STATE_ERROR;
  583. /* Set DAC error code to chanel1 DMA underrun error */
  584. SET_BIT(hdac->ErrorCode, HAL_DAC_ERROR_DMAUNDERRUNCH1);
  585. /* Clear the underrun flag */
  586. __HAL_DAC_CLEAR_FLAG(hdac,DAC_FLAG_DMAUDR1);
  587. /* Disable the selected DAC channel1 DMA request */
  588. CLEAR_BIT(hdac->Instance->CR, DAC_CR_DMAEN1);
  589. /* Error callback */
  590. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  591. hdac->DMAUnderrunCallbackCh1(hdac);
  592. #else
  593. HAL_DAC_DMAUnderrunCallbackCh1(hdac);
  594. #endif
  595. }
  596. }
  597. if(__HAL_DAC_GET_IT_SOURCE(hdac, DAC_IT_DMAUDR2))
  598. {
  599. /* Check underrun flag of DAC channel 2 */
  600. if (__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR2))
  601. {
  602. /* Change DAC state to error state */
  603. hdac->State = HAL_DAC_STATE_ERROR;
  604. /* Set DAC error code to channel2 DMA underrun error */
  605. SET_BIT(hdac->ErrorCode, HAL_DAC_ERROR_DMAUNDERRUNCH2);
  606. /* Clear the underrun flag */
  607. __HAL_DAC_CLEAR_FLAG(hdac,DAC_FLAG_DMAUDR2);
  608. /* Disable the selected DAC channel1 DMA request */
  609. CLEAR_BIT(hdac->Instance->CR, DAC_CR_DMAEN2);
  610. /* Error callback */
  611. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  612. hdac->DMAUnderrunCallbackCh2(hdac);
  613. #else
  614. HAL_DACEx_DMAUnderrunCallbackCh2(hdac);
  615. #endif
  616. }
  617. }
  618. }
  619. #endif /* STM32F303xE || STM32F398xx || */
  620. /* STM32F303xC || STM32F358xx || */
  621. /* STM32F303x8 || STM32F334x8 || STM32F328xx || */
  622. /* STM32F373xC || STM32F378xx */
  623. #if defined(STM32F302xE) || \
  624. defined(STM32F302xC) || \
  625. defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx)
  626. /* DAC channel 2 is NOT available. Only DAC channel 1 is available */
  627. /**
  628. * @brief Handles DAC interrupt request
  629. * This function uses the interruption of DMA
  630. * underrun.
  631. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  632. * the configuration information for the specified DAC.
  633. * @retval None
  634. */
  635. void HAL_DAC_IRQHandler(struct __DAC_HandleTypeDef* hdac)
  636. {
  637. if(__HAL_DAC_GET_IT_SOURCE(hdac, DAC_IT_DMAUDR1))
  638. {
  639. /* Check underrun flag of DAC channel 1U */
  640. if(__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR1))
  641. {
  642. /* Change DAC state to error state */
  643. hdac->State = HAL_DAC_STATE_ERROR;
  644. /* Set DAC error code to chanel1 DMA underrun error */
  645. SET_BIT(hdac->ErrorCode, HAL_DAC_ERROR_DMAUNDERRUNCH1);
  646. /* Clear the underrun flag */
  647. __HAL_DAC_CLEAR_FLAG(hdac,DAC_FLAG_DMAUDR1);
  648. /* Disable the selected DAC channel1 DMA request */
  649. CLEAR_BIT(hdac->Instance->CR, DAC_CR_DMAEN1);
  650. /* Error callback */
  651. HAL_DAC_DMAUnderrunCallbackCh1(hdac);
  652. }
  653. }
  654. }
  655. #endif /* STM32F302xE || */
  656. /* STM32F302xC || */
  657. /* STM32F301x8 || STM32F302x8 || STM32F318xx */
  658. /**
  659. * @brief Configures the selected DAC channel.
  660. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  661. * the configuration information for the specified DAC.
  662. * @param sConfig DAC configuration structure.
  663. * @param Channel The selected DAC channel.
  664. * This parameter can be one of the following values:
  665. * @arg DAC_CHANNEL_1: DAC1 Channel1 selected
  666. * @arg DAC_CHANNEL_2: DAC1 Channel2 selected
  667. * @arg DAC_CHANNEL_1: DAC2 Channel1 selected
  668. * @retval HAL status
  669. */
  670. HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel)
  671. {
  672. uint32_t tmpreg1 = 0U, tmpreg2 = 0U;
  673. /* Check the DAC parameters */
  674. assert_param(IS_DAC_TRIGGER(sConfig->DAC_Trigger));
  675. #if defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx)
  676. if ((hdac->Instance == DAC1) && (Channel == DAC_CHANNEL_1))
  677. {
  678. /* Output Buffer (BOFF1) control */
  679. assert_param(IS_DAC_OUTPUT_BUFFER_STATE(sConfig->DAC_OutputBuffer));
  680. }
  681. else /* DAC1 channel 2U & DAC2 channel 1U */
  682. {
  683. /* Output Switch (OUTEN) control */
  684. assert_param(IS_DAC_OUTPUT_SWITCH_STATE(sConfig->DAC_OutputSwitch));
  685. }
  686. #else
  687. assert_param(IS_DAC_OUTPUT_BUFFER_STATE(sConfig->DAC_OutputBuffer));
  688. #endif /* STM32F303x8 || STM32F334x8 || STM32F328xx || */
  689. assert_param(IS_DAC_CHANNEL(Channel));
  690. /* Process locked */
  691. __HAL_LOCK(hdac);
  692. /* Change DAC state */
  693. hdac->State = HAL_DAC_STATE_BUSY;
  694. /* Get the DAC CR value */
  695. tmpreg1 = hdac->Instance->CR;
  696. /* Clear BOFFx-OUTENx, TENx, TSELx, WAVEx and MAMPx bits */
  697. /* Configure for the selected DAC channel: buffer output or switch output, trigger */
  698. /* Set TSELx and TENx bits according to DAC_Trigger value */
  699. /* Set BOFFx bit according to DAC_OutputBuffer value OR */
  700. /* Set OUTEN bit according to DAC_OutputSwitch value */
  701. #if defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx)
  702. if ((hdac->Instance == DAC1) && (Channel == DAC_CHANNEL_1))
  703. {
  704. /* Output Buffer (BOFF1) control */
  705. tmpreg1 &= ~(((uint32_t)(DAC_CR_MAMP1 | DAC_CR_WAVE1 | DAC_CR_TSEL1 | DAC_CR_TEN1 | DAC_CR_BOFF1)) << Channel);
  706. tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputBuffer);
  707. }
  708. else /* DAC1 channel 2U & DAC2 channel 1U */
  709. {
  710. /* Output Switch (OUTEN) control */
  711. tmpreg1 &= ~(((uint32_t)(DAC_CR_MAMP1 | DAC_CR_WAVE1 | DAC_CR_TSEL1 | DAC_CR_TEN1 | DAC_CR_OUTEN1)) << Channel);
  712. tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputSwitch);
  713. }
  714. #else
  715. tmpreg1 &= ~(((uint32_t)(DAC_CR_MAMP1 | DAC_CR_WAVE1 | DAC_CR_TSEL1 | DAC_CR_TEN1 | DAC_CR_BOFF1)) << Channel);
  716. tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputBuffer);
  717. #endif /* STM32F303x8 || STM32F334x8 || STM32F328xx || */
  718. /* Calculate CR register value depending on DAC_Channel */
  719. tmpreg1 |= tmpreg2 << Channel;
  720. /* Write to DAC CR */
  721. hdac->Instance->CR = tmpreg1;
  722. /* Disable wave generation */
  723. hdac->Instance->CR &= ~(DAC_CR_WAVE1 << Channel);
  724. /* Change DAC state */
  725. hdac->State = HAL_DAC_STATE_READY;
  726. /* Process unlocked */
  727. __HAL_UNLOCK(hdac);
  728. /* Return function status */
  729. return HAL_OK;
  730. }
  731. /**
  732. * @brief Enables or disables the selected DAC channel wave generation.
  733. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  734. * the configuration information for the specified DAC.
  735. * @param Channel The selected DAC channel.
  736. * This parameter can be one of the following values:
  737. * @arg DAC_CHANNEL_1: DAC1 Channel1 selected
  738. * @arg DAC_CHANNEL_2: DAC1 Channel2 selected
  739. * @param Amplitude Select max triangle amplitude.
  740. * This parameter can be one of the following values:
  741. * @arg DAC_TRIANGLEAMPLITUDE_1: Select max triangle amplitude of 1
  742. * @arg DAC_TRIANGLEAMPLITUDE_3: Select max triangle amplitude of 3
  743. * @arg DAC_TRIANGLEAMPLITUDE_7: Select max triangle amplitude of 7
  744. * @arg DAC_TRIANGLEAMPLITUDE_15: Select max triangle amplitude of 15
  745. * @arg DAC_TRIANGLEAMPLITUDE_31: Select max triangle amplitude of 31
  746. * @arg DAC_TRIANGLEAMPLITUDE_63: Select max triangle amplitude of 63
  747. * @arg DAC_TRIANGLEAMPLITUDE_127: Select max triangle amplitude of 127
  748. * @arg DAC_TRIANGLEAMPLITUDE_255: Select max triangle amplitude of 255
  749. * @arg DAC_TRIANGLEAMPLITUDE_511: Select max triangle amplitude of 511
  750. * @arg DAC_TRIANGLEAMPLITUDE_1023: Select max triangle amplitude of 1023
  751. * @arg DAC_TRIANGLEAMPLITUDE_2047: Select max triangle amplitude of 2047
  752. * @arg DAC_TRIANGLEAMPLITUDE_4095: Select max triangle amplitude of 4095
  753. * @note Wave generation is not available in DAC2.
  754. * @retval HAL status
  755. */
  756. HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude)
  757. {
  758. /* Check the parameters */
  759. assert_param(IS_DAC_CHANNEL(Channel));
  760. assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
  761. /* Process locked */
  762. __HAL_LOCK(hdac);
  763. /* Change DAC state */
  764. hdac->State = HAL_DAC_STATE_BUSY;
  765. /* Enable the selected wave generation for the selected DAC channel */
  766. MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1)|(DAC_CR_MAMP1))<<Channel, (DAC_CR_WAVE1_1 | Amplitude) << Channel);
  767. /* Change DAC state */
  768. hdac->State = HAL_DAC_STATE_READY;
  769. /* Process unlocked */
  770. __HAL_UNLOCK(hdac);
  771. /* Return function status */
  772. return HAL_OK;
  773. }
  774. /**
  775. * @brief Enables or disables the selected DAC channel wave generation.
  776. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  777. * the configuration information for the specified DAC.
  778. * @param Channel The selected DAC channel.
  779. * This parameter can be one of the following values:
  780. * @arg DAC_CHANNEL_1: DAC1 Channel1 selected
  781. * @arg DAC_CHANNEL_2: DAC1 Channel2 selected
  782. * @param Amplitude Unmask DAC channel LFSR for noise wave generation.
  783. * This parameter can be one of the following values:
  784. * @arg DAC_LFSRUNMASK_BIT0: Unmask DAC channel LFSR bit0 for noise wave generation
  785. * @arg DAC_LFSRUNMASK_BITS1_0: Unmask DAC channel LFSR bit[1:0] for noise wave generation
  786. * @arg DAC_LFSRUNMASK_BITS2_0: Unmask DAC channel LFSR bit[2:0] for noise wave generation
  787. * @arg DAC_LFSRUNMASK_BITS3_0: Unmask DAC channel LFSR bit[3:0] for noise wave generation
  788. * @arg DAC_LFSRUNMASK_BITS4_0: Unmask DAC channel LFSR bit[4:0] for noise wave generation
  789. * @arg DAC_LFSRUNMASK_BITS5_0: Unmask DAC channel LFSR bit[5:0] for noise wave generation
  790. * @arg DAC_LFSRUNMASK_BITS6_0: Unmask DAC channel LFSR bit[6:0] for noise wave generation
  791. * @arg DAC_LFSRUNMASK_BITS7_0: Unmask DAC channel LFSR bit[7:0] for noise wave generation
  792. * @arg DAC_LFSRUNMASK_BITS8_0: Unmask DAC channel LFSR bit[8:0] for noise wave generation
  793. * @arg DAC_LFSRUNMASK_BITS9_0: Unmask DAC channel LFSR bit[9:0] for noise wave generation
  794. * @arg DAC_LFSRUNMASK_BITS10_0: Unmask DAC channel LFSR bit[10:0] for noise wave generation
  795. * @arg DAC_LFSRUNMASK_BITS11_0: Unmask DAC channel LFSR bit[11:0] for noise wave generation
  796. * @retval HAL status
  797. */
  798. HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude)
  799. {
  800. /* Check the parameters */
  801. assert_param(IS_DAC_CHANNEL(Channel));
  802. assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
  803. /* Process locked */
  804. __HAL_LOCK(hdac);
  805. /* Change DAC state */
  806. hdac->State = HAL_DAC_STATE_BUSY;
  807. /* Enable the selected wave generation for the selected DAC channel */
  808. MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1)|(DAC_CR_MAMP1))<<Channel, (DAC_CR_WAVE1_0 | Amplitude) << Channel);
  809. /* Change DAC state */
  810. hdac->State = HAL_DAC_STATE_READY;
  811. /* Process unlocked */
  812. __HAL_UNLOCK(hdac);
  813. /* Return function status */
  814. return HAL_OK;
  815. }
  816. #if defined(STM32F303xE) || defined(STM32F398xx) || \
  817. defined(STM32F303xC) || defined(STM32F358xx) || \
  818. defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) || \
  819. defined(STM32F373xC) || defined(STM32F378xx)
  820. /* DAC channel 2 is available on top of DAC channel 1U */
  821. /**
  822. * @brief Conversion complete callback in non blocking mode for Channel2
  823. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  824. * the configuration information for the specified DAC.
  825. * @retval None
  826. */
  827. __weak void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef* hdac)
  828. {
  829. /* Prevent unused argument(s) compilation warning */
  830. UNUSED(hdac);
  831. /* NOTE : This function Should not be modified, when the callback is needed,
  832. the HAL_DACEx_ConvCpltCallbackCh2 could be implemented in the user file
  833. */
  834. }
  835. /**
  836. * @brief Conversion half DMA transfer callback in non blocking mode for Channel2
  837. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  838. * the configuration information for the specified DAC.
  839. * @retval None
  840. */
  841. __weak void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef* hdac)
  842. {
  843. /* Prevent unused argument(s) compilation warning */
  844. UNUSED(hdac);
  845. /* NOTE : This function Should not be modified, when the callback is needed,
  846. the HAL_DACEx_ConvHalfCpltCallbackCh2 could be implemented in the user file
  847. */
  848. }
  849. /**
  850. * @brief Error DAC callback for Channel2.
  851. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  852. * the configuration information for the specified DAC.
  853. * @retval None
  854. */
  855. __weak void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef *hdac)
  856. {
  857. /* Prevent unused argument(s) compilation warning */
  858. UNUSED(hdac);
  859. /* NOTE : This function Should not be modified, when the callback is needed,
  860. the HAL_DACEx_ErrorCallbackCh2 could be implemented in the user file
  861. */
  862. }
  863. /**
  864. * @brief DMA underrun DAC callback for channel2.
  865. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  866. * the configuration information for the specified DAC.
  867. * @retval None
  868. */
  869. __weak void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef *hdac)
  870. {
  871. /* Prevent unused argument(s) compilation warning */
  872. UNUSED(hdac);
  873. /* NOTE : This function Should not be modified, when the callback is needed,
  874. the HAL_DACEx_DMAUnderrunCallbackCh2 could be implemented in the user file
  875. */
  876. }
  877. #endif /* STM32F303xE || STM32F398xx || */
  878. /* STM32F303xC || STM32F358xx || */
  879. /* STM32F303x8 || STM32F334x8 || STM32F328xx || */
  880. /* STM32F373xC || STM32F378xx */
  881. /**
  882. * @}
  883. */
  884. /**
  885. * @}
  886. */
  887. /** @addtogroup DACEx_Private_Functions
  888. * @{
  889. */
  890. /**
  891. * @brief DMA conversion complete callback.
  892. * @param hdma pointer to DMA handle.
  893. * @retval None
  894. */
  895. static void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma)
  896. {
  897. DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  898. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  899. hdac->ConvCpltCallbackCh1(hdac);
  900. #else
  901. HAL_DAC_ConvCpltCallbackCh1(hdac);
  902. #endif
  903. hdac->State= HAL_DAC_STATE_READY;
  904. }
  905. /**
  906. * @brief DMA half transfer complete callback.
  907. * @param hdma pointer to DMA handle.
  908. * @retval None
  909. */
  910. static void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma)
  911. {
  912. DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  913. /* Conversion complete callback */
  914. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  915. hdac->ConvHalfCpltCallbackCh1(hdac);
  916. #else
  917. HAL_DAC_ConvHalfCpltCallbackCh1(hdac);
  918. #endif
  919. }
  920. /**
  921. * @brief DMA error callback
  922. * @param hdma pointer to DMA handle.
  923. * @retval None
  924. */
  925. static void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma)
  926. {
  927. DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  928. /* Set DAC error code to DMA error */
  929. hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
  930. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  931. hdac->ErrorCallbackCh1(hdac);
  932. #else
  933. HAL_DAC_ErrorCallbackCh1(hdac);
  934. #endif
  935. hdac->State= HAL_DAC_STATE_READY;
  936. }
  937. #if defined(STM32F303xE) || defined(STM32F398xx) || \
  938. defined(STM32F303xC) || defined(STM32F358xx) || \
  939. defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) || \
  940. defined(STM32F373xC) || defined(STM32F378xx)
  941. /* DAC channel 2 is available on top of DAC channel 1U */
  942. /**
  943. * @brief DMA conversion complete callback.
  944. * @param hdma pointer to DMA handle.
  945. * @retval None
  946. */
  947. static void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma)
  948. {
  949. DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  950. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  951. hdac->ConvCpltCallbackCh2(hdac);
  952. #else
  953. HAL_DACEx_ConvCpltCallbackCh2(hdac);
  954. #endif
  955. hdac->State= HAL_DAC_STATE_READY;
  956. }
  957. /**
  958. * @brief DMA half transfer complete callback.
  959. * @param hdma pointer to DMA handle.
  960. * @retval None
  961. */
  962. static void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma)
  963. {
  964. DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  965. /* Conversion complete callback */
  966. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  967. hdac->ConvHalfCpltCallbackCh2(hdac);
  968. #else
  969. HAL_DACEx_ConvHalfCpltCallbackCh2(hdac);
  970. #endif
  971. }
  972. /**
  973. * @brief DMA error callback
  974. * @param hdma pointer to DMA handle.
  975. * @retval None
  976. */
  977. static void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma)
  978. {
  979. DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  980. /* Set DAC error code to DMA error */
  981. hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
  982. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  983. hdac->ErrorCallbackCh2(hdac);
  984. #else
  985. HAL_DACEx_ErrorCallbackCh2(hdac);
  986. #endif
  987. hdac->State= HAL_DAC_STATE_READY;
  988. }
  989. #endif /* STM32F303xE || STM32F398xx || */
  990. /* STM32F303xC || STM32F358xx || */
  991. /* STM32F303x8 || STM32F334x8 || STM32F328xx || */
  992. /* STM32F373xC || STM32F378xx */
  993. /**
  994. * @}
  995. */
  996. /**
  997. * @}
  998. */
  999. #endif /* HAL_DAC_MODULE_ENABLED */
  1000. /**
  1001. * @}
  1002. */