提交 | 用户 | age
|
bfc108
|
1 |
/**
|
Q |
2 |
******************************************************************************
|
|
3 |
* @file stm32f0xx_hal_dac_ex.c
|
|
4 |
* @author MCD Application Team
|
|
5 |
* @brief DAC HAL module driver.
|
|
6 |
* This file provides firmware functions to manage the extended
|
|
7 |
* functionalities of the DAC peripheral.
|
|
8 |
*
|
|
9 |
*
|
|
10 |
@verbatim
|
|
11 |
==============================================================================
|
|
12 |
##### How to use this driver #####
|
|
13 |
==============================================================================
|
|
14 |
[..]
|
|
15 |
(+) When Dual mode is enabled (i.e. DAC Channel1 and Channel2 are used simultaneously) :
|
|
16 |
Use HAL_DACEx_DualGetValue() to get digital data to be converted and use
|
|
17 |
HAL_DACEx_DualSetValue() to set digital value to converted simultaneously in Channel 1 and Channel 2.
|
|
18 |
(+) Use HAL_DACEx_TriangleWaveGenerate() to generate Triangle signal.
|
|
19 |
(+) Use HAL_DACEx_NoiseWaveGenerate() to generate Noise signal.
|
|
20 |
|
|
21 |
@endverbatim
|
|
22 |
******************************************************************************
|
|
23 |
* @attention
|
|
24 |
*
|
|
25 |
* <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
|
|
26 |
*
|
|
27 |
* Redistribution and use in source and binary forms, with or without modification,
|
|
28 |
* are permitted provided that the following conditions are met:
|
|
29 |
* 1. Redistributions of source code must retain the above copyright notice,
|
|
30 |
* this list of conditions and the following disclaimer.
|
|
31 |
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
32 |
* this list of conditions and the following disclaimer in the documentation
|
|
33 |
* and/or other materials provided with the distribution.
|
|
34 |
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
|
35 |
* may be used to endorse or promote products derived from this software
|
|
36 |
* without specific prior written permission.
|
|
37 |
*
|
|
38 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
39 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
40 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
41 |
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
42 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
43 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
44 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
45 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
46 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
47 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
48 |
*
|
|
49 |
******************************************************************************
|
|
50 |
*/
|
|
51 |
|
|
52 |
|
|
53 |
/* Includes ------------------------------------------------------------------*/
|
|
54 |
#include "stm32f0xx_hal.h"
|
|
55 |
|
|
56 |
/** @addtogroup STM32F0xx_HAL_Driver
|
|
57 |
* @{
|
|
58 |
*/
|
|
59 |
|
|
60 |
#ifdef HAL_DAC_MODULE_ENABLED
|
|
61 |
|
|
62 |
/** @addtogroup DAC
|
|
63 |
* @{
|
|
64 |
*/
|
|
65 |
|
|
66 |
#if defined(STM32F051x8) || defined(STM32F058xx) || \
|
|
67 |
defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
|
|
68 |
defined(STM32F091xC) || defined(STM32F098xx)
|
|
69 |
|
|
70 |
/** @addtogroup DAC_Private_Functions
|
|
71 |
* @{
|
|
72 |
*/
|
|
73 |
static void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma);
|
|
74 |
static void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma);
|
|
75 |
static void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma);
|
|
76 |
/**
|
|
77 |
* @}
|
|
78 |
*/
|
|
79 |
|
|
80 |
#endif /* STM32F051x8 STM32F058xx */
|
|
81 |
/* STM32F071xB STM32F072xB STM32F078xx */
|
|
82 |
/* STM32F091xC STM32F098xx */
|
|
83 |
|
|
84 |
#if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
|
|
85 |
defined(STM32F091xC) || defined(STM32F098xx)
|
|
86 |
|
|
87 |
/** @addtogroup DAC_Private_Functions
|
|
88 |
* @{
|
|
89 |
*/
|
|
90 |
|
|
91 |
/* DAC_DMAConvCpltCh2 / DAC_DMAErrorCh2 / DAC_DMAHalfConvCpltCh2 */
|
|
92 |
/* are set by HAL_DAC_Start_DMA */
|
|
93 |
|
|
94 |
void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma);
|
|
95 |
void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma);
|
|
96 |
void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma);
|
|
97 |
/**
|
|
98 |
* @}
|
|
99 |
*/
|
|
100 |
|
|
101 |
#endif /* STM32F071xB STM32F072xB STM32F078xx */
|
|
102 |
/* STM32F091xC STM32F098xx */
|
|
103 |
|
|
104 |
/** @addtogroup DAC_Exported_Functions
|
|
105 |
* @{
|
|
106 |
*/
|
|
107 |
|
|
108 |
/** @addtogroup DAC_Exported_Functions_Group3
|
|
109 |
* @{
|
|
110 |
*/
|
|
111 |
|
|
112 |
#if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
|
|
113 |
defined(STM32F091xC) || defined(STM32F098xx)
|
|
114 |
|
|
115 |
/**
|
|
116 |
* @brief Configures the selected DAC channel.
|
|
117 |
* @param hdac pointer to a DAC_HandleTypeDef structure that contains
|
|
118 |
* the configuration information for the specified DAC.
|
|
119 |
* @param sConfig DAC configuration structure.
|
|
120 |
* @param Channel The selected DAC channel.
|
|
121 |
* This parameter can be one of the following values:
|
|
122 |
* @arg DAC_CHANNEL_1: DAC Channel1 selected
|
|
123 |
* @arg DAC_CHANNEL_2: DAC Channel2 selected
|
|
124 |
* @retval HAL status
|
|
125 |
*/
|
|
126 |
HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel)
|
|
127 |
{
|
|
128 |
uint32_t tmpreg1 = 0U, tmpreg2 = 0U;
|
|
129 |
|
|
130 |
/* Check the DAC parameters */
|
|
131 |
assert_param(IS_DAC_TRIGGER(sConfig->DAC_Trigger));
|
|
132 |
assert_param(IS_DAC_OUTPUT_BUFFER_STATE(sConfig->DAC_OutputBuffer));
|
|
133 |
assert_param(IS_DAC_TRIGGER(sConfig->DAC_Trigger));
|
|
134 |
assert_param(IS_DAC_CHANNEL(Channel));
|
|
135 |
|
|
136 |
/* Process locked */
|
|
137 |
__HAL_LOCK(hdac);
|
|
138 |
|
|
139 |
/* Change DAC state */
|
|
140 |
hdac->State = HAL_DAC_STATE_BUSY;
|
|
141 |
|
|
142 |
/* Get the DAC CR value */
|
|
143 |
tmpreg1 = hdac->Instance->CR;
|
|
144 |
/* Clear BOFFx, TENx, TSELx, WAVEx and MAMPx bits */
|
|
145 |
tmpreg1 &= ~(((uint32_t)(DAC_CR_MAMP1 | DAC_CR_WAVE1 | DAC_CR_TSEL1 | DAC_CR_TEN1 | DAC_CR_BOFF1)) << Channel);
|
|
146 |
/* Configure for the selected DAC channel: buffer output, trigger */
|
|
147 |
/* Set TSELx and TENx bits according to DAC_Trigger value */
|
|
148 |
/* Set BOFFx bit according to DAC_OutputBuffer value */
|
|
149 |
tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputBuffer);
|
|
150 |
/* Calculate CR register value depending on DAC_Channel */
|
|
151 |
tmpreg1 |= tmpreg2 << Channel;
|
|
152 |
/* Write to DAC CR */
|
|
153 |
hdac->Instance->CR = tmpreg1;
|
|
154 |
|
|
155 |
/* Change DAC state */
|
|
156 |
hdac->State = HAL_DAC_STATE_READY;
|
|
157 |
|
|
158 |
/* Process unlocked */
|
|
159 |
__HAL_UNLOCK(hdac);
|
|
160 |
|
|
161 |
/* Return function status */
|
|
162 |
return HAL_OK;
|
|
163 |
}
|
|
164 |
|
|
165 |
#endif /* STM32F071xB STM32F072xB STM32F078xx */
|
|
166 |
/* STM32F091xC STM32F098xx */
|
|
167 |
|
|
168 |
#if defined (STM32F051x8) || defined (STM32F058xx)
|
|
169 |
|
|
170 |
/**
|
|
171 |
* @brief Configures the selected DAC channel.
|
|
172 |
* @param hdac pointer to a DAC_HandleTypeDef structure that contains
|
|
173 |
* the configuration information for the specified DAC.
|
|
174 |
* @param sConfig DAC configuration structure.
|
|
175 |
* @param Channel The selected DAC channel.
|
|
176 |
* This parameter can be one of the following values:
|
|
177 |
* @arg DAC_CHANNEL_1: DAC Channel1 selected
|
|
178 |
* @retval HAL status
|
|
179 |
*/
|
|
180 |
HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel)
|
|
181 |
{
|
|
182 |
uint32_t tmpreg1 = 0U, tmpreg2 = 0U;
|
|
183 |
|
|
184 |
/* Check the DAC parameters */
|
|
185 |
assert_param(IS_DAC_TRIGGER(sConfig->DAC_Trigger));
|
|
186 |
assert_param(IS_DAC_OUTPUT_BUFFER_STATE(sConfig->DAC_OutputBuffer));
|
|
187 |
assert_param(IS_DAC_TRIGGER(sConfig->DAC_Trigger));
|
|
188 |
assert_param(IS_DAC_CHANNEL(Channel));
|
|
189 |
|
|
190 |
/* Process locked */
|
|
191 |
__HAL_LOCK(hdac);
|
|
192 |
|
|
193 |
/* Change DAC state */
|
|
194 |
hdac->State = HAL_DAC_STATE_BUSY;
|
|
195 |
|
|
196 |
/* Get the DAC CR value */
|
|
197 |
tmpreg1 = hdac->Instance->CR;
|
|
198 |
/* Clear BOFFx, TENx, TSELx, WAVEx and MAMPx bits */
|
|
199 |
tmpreg1 &= ~(((uint32_t)(DAC_CR_TSEL1 | DAC_CR_TEN1 | DAC_CR_BOFF1)) << Channel);
|
|
200 |
/* Configure for the selected DAC channel: buffer output, trigger */
|
|
201 |
/* Set TSELx and TENx bits according to DAC_Trigger value */
|
|
202 |
/* Set BOFFx bit according to DAC_OutputBuffer value */
|
|
203 |
tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputBuffer);
|
|
204 |
/* Calculate CR register value depending on DAC_Channel */
|
|
205 |
tmpreg1 |= tmpreg2 << Channel;
|
|
206 |
/* Write to DAC CR */
|
|
207 |
hdac->Instance->CR = tmpreg1;
|
|
208 |
|
|
209 |
/* Change DAC state */
|
|
210 |
hdac->State = HAL_DAC_STATE_READY;
|
|
211 |
|
|
212 |
/* Process unlocked */
|
|
213 |
__HAL_UNLOCK(hdac);
|
|
214 |
|
|
215 |
/* Return function status */
|
|
216 |
return HAL_OK;
|
|
217 |
}
|
|
218 |
|
|
219 |
#endif /* STM32F051x8 STM32F058xx */
|
|
220 |
|
|
221 |
#if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
|
|
222 |
defined(STM32F091xC) || defined(STM32F098xx)
|
|
223 |
/* DAC 1 has 2 channels 1 & 2 */
|
|
224 |
|
|
225 |
/**
|
|
226 |
* @brief Returns the last data output value of the selected DAC channel.
|
|
227 |
* @param hdac pointer to a DAC_HandleTypeDef structure that contains
|
|
228 |
* the configuration information for the specified DAC.
|
|
229 |
* @param Channel The selected DAC channel.
|
|
230 |
* This parameter can be one of the following values:
|
|
231 |
* @arg DAC_CHANNEL_1: DAC Channel1 selected
|
|
232 |
* @arg DAC_CHANNEL_2: DAC Channel2 selected
|
|
233 |
* @retval The selected DAC channel data output value.
|
|
234 |
*/
|
|
235 |
uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel)
|
|
236 |
{
|
|
237 |
/* Check the parameters */
|
|
238 |
assert_param(IS_DAC_CHANNEL(Channel));
|
|
239 |
|
|
240 |
/* Returns the DAC channel data output register value */
|
|
241 |
if(Channel == DAC_CHANNEL_1)
|
|
242 |
{
|
|
243 |
return hdac->Instance->DOR1;
|
|
244 |
}
|
|
245 |
else
|
|
246 |
{
|
|
247 |
return hdac->Instance->DOR2;
|
|
248 |
}
|
|
249 |
}
|
|
250 |
|
|
251 |
#endif /* STM32F071xB STM32F072xB STM32F078xx */
|
|
252 |
/* STM32F091xC STM32F098xx */
|
|
253 |
|
|
254 |
#if defined (STM32F051x8) || defined (STM32F058xx)
|
|
255 |
|
|
256 |
/* DAC 1 has 1 channels */
|
|
257 |
|
|
258 |
/**
|
|
259 |
* @brief Returns the last data output value of the selected DAC 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: DAC Channel1 selected
|
|
265 |
* @retval The selected DAC channel data output value.
|
|
266 |
*/
|
|
267 |
uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel)
|
|
268 |
{
|
|
269 |
/* Check the parameters */
|
|
270 |
assert_param(IS_DAC_CHANNEL(Channel));
|
|
271 |
|
|
272 |
/* Returns the DAC channel data output register value */
|
|
273 |
return hdac->Instance->DOR1;
|
|
274 |
}
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
#endif /* STM32F051x8 STM32F058xx */
|
|
279 |
|
|
280 |
/**
|
|
281 |
* @}
|
|
282 |
*/
|
|
283 |
|
|
284 |
/** @addtogroup DAC_Exported_Functions_Group2
|
|
285 |
* @{
|
|
286 |
*/
|
|
287 |
|
|
288 |
#if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
|
|
289 |
defined(STM32F091xC) || defined(STM32F098xx)
|
|
290 |
|
|
291 |
/**
|
|
292 |
* @brief Enables DAC and starts conversion of channel.
|
|
293 |
* @param hdac pointer to a DAC_HandleTypeDef structure that contains
|
|
294 |
* the configuration information for the specified DAC.
|
|
295 |
* @param Channel The selected DAC channel.
|
|
296 |
* This parameter can be one of the following values:
|
|
297 |
* @arg DAC_CHANNEL_1: DAC Channel1 selected
|
|
298 |
* @arg DAC_CHANNEL_2: DAC Channel2 selected
|
|
299 |
* @retval HAL status
|
|
300 |
*/
|
|
301 |
HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel)
|
|
302 |
{
|
|
303 |
/* Check the parameters */
|
|
304 |
assert_param(IS_DAC_CHANNEL(Channel));
|
|
305 |
|
|
306 |
/* Process locked */
|
|
307 |
__HAL_LOCK(hdac);
|
|
308 |
|
|
309 |
/* Change DAC state */
|
|
310 |
hdac->State = HAL_DAC_STATE_BUSY;
|
|
311 |
|
|
312 |
/* Enable the Peripharal */
|
|
313 |
__HAL_DAC_ENABLE(hdac, Channel);
|
|
314 |
|
|
315 |
if(Channel == DAC_CHANNEL_1)
|
|
316 |
{
|
|
317 |
/* Check if software trigger enabled */
|
|
318 |
if((hdac->Instance->CR & (DAC_CR_TEN1 | DAC_CR_TSEL1)) == (DAC_CR_TEN1 | DAC_CR_TSEL1))
|
|
319 |
{
|
|
320 |
/* Enable the selected DAC software conversion */
|
|
321 |
SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG1);
|
|
322 |
}
|
|
323 |
}
|
|
324 |
else
|
|
325 |
{
|
|
326 |
/* Check if software trigger enabled */
|
|
327 |
if((hdac->Instance->CR & (DAC_CR_TEN2 | DAC_CR_TSEL2)) == (DAC_CR_TEN2 | DAC_CR_TSEL2))
|
|
328 |
{
|
|
329 |
/* Enable the selected DAC software conversion*/
|
|
330 |
SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG2);
|
|
331 |
}
|
|
332 |
}
|
|
333 |
|
|
334 |
/* Change DAC state */
|
|
335 |
hdac->State = HAL_DAC_STATE_READY;
|
|
336 |
|
|
337 |
/* Process unlocked */
|
|
338 |
__HAL_UNLOCK(hdac);
|
|
339 |
|
|
340 |
/* Return function status */
|
|
341 |
return HAL_OK;
|
|
342 |
}
|
|
343 |
|
|
344 |
/**
|
|
345 |
* @brief Enables DAC and starts conversion of channel.
|
|
346 |
* @param hdac pointer to a DAC_HandleTypeDef structure that contains
|
|
347 |
* the configuration information for the specified DAC.
|
|
348 |
* @param Channel The selected DAC channel.
|
|
349 |
* This parameter can be one of the following values:
|
|
350 |
* @arg DAC_CHANNEL_1: DAC Channel1 selected
|
|
351 |
* @arg DAC_CHANNEL_2: DAC Channel2 selected
|
|
352 |
* @param pData The destination peripheral Buffer address.
|
|
353 |
* @param Length The length of data to be transferred from memory to DAC peripheral
|
|
354 |
* @param Alignment Specifies the data alignment for DAC channel.
|
|
355 |
* This parameter can be one of the following values:
|
|
356 |
* @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
|
|
357 |
* @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
|
|
358 |
* @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
|
|
359 |
* @retval HAL status
|
|
360 |
*/
|
|
361 |
HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment)
|
|
362 |
{
|
|
363 |
uint32_t tmpreg = 0U;
|
|
364 |
|
|
365 |
/* Check the parameters */
|
|
366 |
assert_param(IS_DAC_CHANNEL(Channel));
|
|
367 |
assert_param(IS_DAC_ALIGN(Alignment));
|
|
368 |
|
|
369 |
/* Process locked */
|
|
370 |
__HAL_LOCK(hdac);
|
|
371 |
|
|
372 |
/* Change DAC state */
|
|
373 |
hdac->State = HAL_DAC_STATE_BUSY;
|
|
374 |
|
|
375 |
if(Channel == DAC_CHANNEL_1)
|
|
376 |
{
|
|
377 |
/* Set the DMA transfer complete callback for channel1 */
|
|
378 |
hdac->DMA_Handle1->XferCpltCallback = DAC_DMAConvCpltCh1;
|
|
379 |
|
|
380 |
/* Set the DMA half transfer complete callback for channel1 */
|
|
381 |
hdac->DMA_Handle1->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh1;
|
|
382 |
|
|
383 |
/* Set the DMA error callback for channel1 */
|
|
384 |
hdac->DMA_Handle1->XferErrorCallback = DAC_DMAErrorCh1;
|
|
385 |
|
|
386 |
/* Enable the selected DAC channel1 DMA request */
|
|
387 |
SET_BIT(hdac->Instance->CR, DAC_CR_DMAEN1);
|
|
388 |
|
|
389 |
/* Case of use of channel 1 */
|
|
390 |
switch(Alignment)
|
|
391 |
{
|
|
392 |
case DAC_ALIGN_12B_R:
|
|
393 |
/* Get DHR12R1 address */
|
|
394 |
tmpreg = (uint32_t)&hdac->Instance->DHR12R1;
|
|
395 |
break;
|
|
396 |
case DAC_ALIGN_12B_L:
|
|
397 |
/* Get DHR12L1 address */
|
|
398 |
tmpreg = (uint32_t)&hdac->Instance->DHR12L1;
|
|
399 |
break;
|
|
400 |
case DAC_ALIGN_8B_R:
|
|
401 |
/* Get DHR8R1 address */
|
|
402 |
tmpreg = (uint32_t)&hdac->Instance->DHR8R1;
|
|
403 |
break;
|
|
404 |
default:
|
|
405 |
break;
|
|
406 |
}
|
|
407 |
}
|
|
408 |
else
|
|
409 |
{
|
|
410 |
/* Set the DMA transfer complete callback for channel2 */
|
|
411 |
hdac->DMA_Handle2->XferCpltCallback = DAC_DMAConvCpltCh2;
|
|
412 |
|
|
413 |
/* Set the DMA half transfer complete callback for channel2 */
|
|
414 |
hdac->DMA_Handle2->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh2;
|
|
415 |
|
|
416 |
/* Set the DMA error callback for channel2 */
|
|
417 |
hdac->DMA_Handle2->XferErrorCallback = DAC_DMAErrorCh2;
|
|
418 |
|
|
419 |
/* Enable the selected DAC channel2 DMA request */
|
|
420 |
SET_BIT(hdac->Instance->CR, DAC_CR_DMAEN2);
|
|
421 |
|
|
422 |
/* Case of use of channel 2 */
|
|
423 |
switch(Alignment)
|
|
424 |
{
|
|
425 |
case DAC_ALIGN_12B_R:
|
|
426 |
/* Get DHR12R2 address */
|
|
427 |
tmpreg = (uint32_t)&hdac->Instance->DHR12R2;
|
|
428 |
break;
|
|
429 |
case DAC_ALIGN_12B_L:
|
|
430 |
/* Get DHR12L2 address */
|
|
431 |
tmpreg = (uint32_t)&hdac->Instance->DHR12L2;
|
|
432 |
break;
|
|
433 |
case DAC_ALIGN_8B_R:
|
|
434 |
/* Get DHR8R2 address */
|
|
435 |
tmpreg = (uint32_t)&hdac->Instance->DHR8R2;
|
|
436 |
break;
|
|
437 |
default:
|
|
438 |
break;
|
|
439 |
}
|
|
440 |
}
|
|
441 |
|
|
442 |
/* Enable the DMA channel */
|
|
443 |
if(Channel == DAC_CHANNEL_1)
|
|
444 |
{
|
|
445 |
/* Enable the DAC DMA underrun interrupt */
|
|
446 |
__HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR1);
|
|
447 |
|
|
448 |
/* Enable the DMA channel */
|
|
449 |
HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length);
|
|
450 |
}
|
|
451 |
else
|
|
452 |
{
|
|
453 |
/* Enable the DAC DMA underrun interrupt */
|
|
454 |
__HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR2);
|
|
455 |
|
|
456 |
/* Enable the DMA channel */
|
|
457 |
HAL_DMA_Start_IT(hdac->DMA_Handle2, (uint32_t)pData, tmpreg, Length);
|
|
458 |
}
|
|
459 |
|
|
460 |
/* Enable the Peripharal */
|
|
461 |
__HAL_DAC_ENABLE(hdac, Channel);
|
|
462 |
|
|
463 |
/* Process Unlocked */
|
|
464 |
__HAL_UNLOCK(hdac);
|
|
465 |
|
|
466 |
/* Return function status */
|
|
467 |
return HAL_OK;
|
|
468 |
}
|
|
469 |
|
|
470 |
|
|
471 |
|
|
472 |
#endif /* STM32F071xB STM32F072xB STM32F078xx */
|
|
473 |
/* STM32F091xC STM32F098xx */
|
|
474 |
|
|
475 |
#if defined (STM32F051x8) || defined (STM32F058xx)
|
|
476 |
|
|
477 |
HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel)
|
|
478 |
{
|
|
479 |
/* Check the parameters */
|
|
480 |
assert_param(IS_DAC_CHANNEL(Channel));
|
|
481 |
|
|
482 |
/* Process locked */
|
|
483 |
__HAL_LOCK(hdac);
|
|
484 |
|
|
485 |
/* Change DAC state */
|
|
486 |
hdac->State = HAL_DAC_STATE_BUSY;
|
|
487 |
|
|
488 |
/* Enable the Peripharal */
|
|
489 |
__HAL_DAC_ENABLE(hdac, Channel);
|
|
490 |
|
|
491 |
if(Channel == DAC_CHANNEL_1)
|
|
492 |
{
|
|
493 |
/* Check if software trigger enabled */
|
|
494 |
if((hdac->Instance->CR & (DAC_CR_TEN1 | DAC_CR_TSEL1)) == (DAC_CR_TEN1 | DAC_CR_TSEL1))
|
|
495 |
{
|
|
496 |
/* Enable the selected DAC software conversion */
|
|
497 |
SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG1);
|
|
498 |
}
|
|
499 |
}
|
|
500 |
|
|
501 |
/* Change DAC state */
|
|
502 |
hdac->State = HAL_DAC_STATE_READY;
|
|
503 |
|
|
504 |
/* Process unlocked */
|
|
505 |
__HAL_UNLOCK(hdac);
|
|
506 |
|
|
507 |
/* Return function status */
|
|
508 |
return HAL_OK;
|
|
509 |
}
|
|
510 |
|
|
511 |
/**
|
|
512 |
* @brief Enables DAC and starts conversion of channel.
|
|
513 |
* @param hdac pointer to a DAC_HandleTypeDef structure that contains
|
|
514 |
* the configuration information for the specified DAC.
|
|
515 |
* @param Channel The selected DAC channel.
|
|
516 |
* This parameter can be one of the following values:
|
|
517 |
* @arg DAC_CHANNEL_1: DAC Channel1 selected
|
|
518 |
* @param pData The destination peripheral Buffer address.
|
|
519 |
* @param Length The length of data to be transferred from memory to DAC peripheral
|
|
520 |
* @param Alignment Specifies the data alignment for DAC channel.
|
|
521 |
* This parameter can be one of the following values:
|
|
522 |
* @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
|
|
523 |
* @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
|
|
524 |
* @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
|
|
525 |
* @retval HAL status
|
|
526 |
*/
|
|
527 |
HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment)
|
|
528 |
{
|
|
529 |
uint32_t tmpreg = 0U;
|
|
530 |
|
|
531 |
/* Check the parameters */
|
|
532 |
assert_param(IS_DAC_CHANNEL(Channel));
|
|
533 |
assert_param(IS_DAC_ALIGN(Alignment));
|
|
534 |
|
|
535 |
/* Process locked */
|
|
536 |
__HAL_LOCK(hdac);
|
|
537 |
|
|
538 |
/* Change DAC state */
|
|
539 |
hdac->State = HAL_DAC_STATE_BUSY;
|
|
540 |
|
|
541 |
/* Set the DMA transfer complete callback for channel1 */
|
|
542 |
hdac->DMA_Handle1->XferCpltCallback = DAC_DMAConvCpltCh1;
|
|
543 |
|
|
544 |
/* Set the DMA half transfer complete callback for channel1 */
|
|
545 |
hdac->DMA_Handle1->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh1;
|
|
546 |
|
|
547 |
/* Set the DMA error callback for channel1 */
|
|
548 |
hdac->DMA_Handle1->XferErrorCallback = DAC_DMAErrorCh1;
|
|
549 |
|
|
550 |
/* Enable the selected DAC channel1 DMA request */
|
|
551 |
SET_BIT(hdac->Instance->CR, DAC_CR_DMAEN1);
|
|
552 |
|
|
553 |
/* Case of use of channel 1 */
|
|
554 |
switch(Alignment)
|
|
555 |
{
|
|
556 |
case DAC_ALIGN_12B_R:
|
|
557 |
/* Get DHR12R1 address */
|
|
558 |
tmpreg = (uint32_t)&hdac->Instance->DHR12R1;
|
|
559 |
break;
|
|
560 |
case DAC_ALIGN_12B_L:
|
|
561 |
/* Get DHR12L1 address */
|
|
562 |
tmpreg = (uint32_t)&hdac->Instance->DHR12L1;
|
|
563 |
break;
|
|
564 |
case DAC_ALIGN_8B_R:
|
|
565 |
/* Get DHR8R1 address */
|
|
566 |
tmpreg = (uint32_t)&hdac->Instance->DHR8R1;
|
|
567 |
break;
|
|
568 |
default:
|
|
569 |
break;
|
|
570 |
}
|
|
571 |
|
|
572 |
/* Enable the DMA channel */
|
|
573 |
/* Enable the DAC DMA underrun interrupt */
|
|
574 |
__HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR1);
|
|
575 |
|
|
576 |
/* Enable the DMA channel */
|
|
577 |
HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length);
|
|
578 |
|
|
579 |
/* Enable the DAC DMA underrun interrupt */
|
|
580 |
__HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR1);
|
|
581 |
|
|
582 |
/* Enable the DMA channel */
|
|
583 |
HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length);
|
|
584 |
|
|
585 |
/* Enable the Peripharal */
|
|
586 |
__HAL_DAC_ENABLE(hdac, Channel);
|
|
587 |
|
|
588 |
/* Process Unlocked */
|
|
589 |
__HAL_UNLOCK(hdac);
|
|
590 |
|
|
591 |
/* Return function status */
|
|
592 |
return HAL_OK;
|
|
593 |
}
|
|
594 |
|
|
595 |
#endif /* STM32F051x8 STM32F058xx */
|
|
596 |
|
|
597 |
#if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
|
|
598 |
defined(STM32F091xC) || defined(STM32F098xx)
|
|
599 |
/* DAC channel 2 is available on top of DAC channel 1 */
|
|
600 |
|
|
601 |
/**
|
|
602 |
* @brief Handles DAC interrupt request
|
|
603 |
* @param hdac pointer to a DAC_HandleTypeDef structure that contains
|
|
604 |
* the configuration information for the specified DAC.
|
|
605 |
* @retval None
|
|
606 |
*/
|
|
607 |
void HAL_DAC_IRQHandler(DAC_HandleTypeDef* hdac)
|
|
608 |
{
|
|
609 |
if(__HAL_DAC_GET_IT_SOURCE(hdac, DAC_IT_DMAUDR1))
|
|
610 |
{
|
|
611 |
/* Check underrun channel 1 flag */
|
|
612 |
if(__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR1))
|
|
613 |
{
|
|
614 |
/* Change DAC state to error state */
|
|
615 |
hdac->State = HAL_DAC_STATE_ERROR;
|
|
616 |
|
|
617 |
/* Set DAC error code to channel1 DMA underrun error */
|
|
618 |
hdac->ErrorCode |= HAL_DAC_ERROR_DMAUNDERRUNCH1;
|
|
619 |
|
|
620 |
/* Clear the underrun flag */
|
|
621 |
__HAL_DAC_CLEAR_FLAG(hdac,DAC_FLAG_DMAUDR1);
|
|
622 |
|
|
623 |
/* Disable the selected DAC channel1 DMA request */
|
|
624 |
hdac->Instance->CR &= ~DAC_CR_DMAEN1;
|
|
625 |
|
|
626 |
/* Error callback */
|
|
627 |
HAL_DAC_DMAUnderrunCallbackCh1(hdac);
|
|
628 |
}
|
|
629 |
}
|
|
630 |
if(__HAL_DAC_GET_IT_SOURCE(hdac, DAC_IT_DMAUDR2))
|
|
631 |
{
|
|
632 |
/* Check underrun channel 2 flag */
|
|
633 |
if(__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR2))
|
|
634 |
{
|
|
635 |
/* Change DAC state to error state */
|
|
636 |
hdac->State = HAL_DAC_STATE_ERROR;
|
|
637 |
|
|
638 |
/* Set DAC error code to channel2 DMA underrun error */
|
|
639 |
hdac->ErrorCode |= HAL_DAC_ERROR_DMAUNDERRUNCH2;
|
|
640 |
|
|
641 |
/* Clear the underrun flag */
|
|
642 |
__HAL_DAC_CLEAR_FLAG(hdac,DAC_FLAG_DMAUDR2);
|
|
643 |
|
|
644 |
/* Disable the selected DAC channel1 DMA request */
|
|
645 |
hdac->Instance->CR &= ~DAC_CR_DMAEN2;
|
|
646 |
|
|
647 |
/* Error callback */
|
|
648 |
HAL_DACEx_DMAUnderrunCallbackCh2(hdac);
|
|
649 |
}
|
|
650 |
}
|
|
651 |
}
|
|
652 |
|
|
653 |
#endif /* STM32F071xB STM32F072xB STM32F078xx */
|
|
654 |
/* STM32F091xC STM32F098xx */
|
|
655 |
|
|
656 |
#if defined (STM32F051x8) || defined (STM32F058xx)
|
|
657 |
/* DAC channel 2 is NOT available. Only DAC channel 1 is available */
|
|
658 |
|
|
659 |
/**
|
|
660 |
* @brief Handles DAC interrupt request
|
|
661 |
* @param hdac pointer to a DAC_HandleTypeDef structure that contains
|
|
662 |
* the configuration information for the specified DAC.
|
|
663 |
* @retval None
|
|
664 |
*/
|
|
665 |
void HAL_DAC_IRQHandler(DAC_HandleTypeDef* hdac)
|
|
666 |
{
|
|
667 |
if(__HAL_DAC_GET_IT_SOURCE(hdac, DAC_IT_DMAUDR1))
|
|
668 |
{
|
|
669 |
/* Check Overrun flag */
|
|
670 |
if(__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR1))
|
|
671 |
{
|
|
672 |
/* Change DAC state to error state */
|
|
673 |
hdac->State = HAL_DAC_STATE_ERROR;
|
|
674 |
|
|
675 |
/* Set DAC error code to chanel1 DMA underrun error */
|
|
676 |
hdac->ErrorCode |= HAL_DAC_ERROR_DMAUNDERRUNCH1;
|
|
677 |
|
|
678 |
/* Clear the underrun flag */
|
|
679 |
__HAL_DAC_CLEAR_FLAG(hdac,DAC_FLAG_DMAUDR1);
|
|
680 |
|
|
681 |
/* Disable the selected DAC channel1 DMA request */
|
|
682 |
hdac->Instance->CR &= ~DAC_CR_DMAEN1;
|
|
683 |
|
|
684 |
/* Error callback */
|
|
685 |
HAL_DAC_DMAUnderrunCallbackCh1(hdac);
|
|
686 |
}
|
|
687 |
}
|
|
688 |
}
|
|
689 |
|
|
690 |
#endif /* STM32F051x8 STM32F058xx */
|
|
691 |
|
|
692 |
/**
|
|
693 |
* @}
|
|
694 |
*/
|
|
695 |
|
|
696 |
/**
|
|
697 |
* @}
|
|
698 |
*/
|
|
699 |
|
|
700 |
#if defined(STM32F051x8) || defined(STM32F058xx) || \
|
|
701 |
defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
|
|
702 |
defined(STM32F091xC) || defined(STM32F098xx)
|
|
703 |
|
|
704 |
/** @addtogroup DAC_Private_Functions
|
|
705 |
* @{
|
|
706 |
*/
|
|
707 |
|
|
708 |
/**
|
|
709 |
* @brief DMA conversion complete callback.
|
|
710 |
* @param hdma pointer to a DMA_HandleTypeDef structure that contains
|
|
711 |
* the configuration information for the specified DMA module.
|
|
712 |
* @retval None
|
|
713 |
*/
|
|
714 |
static void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma)
|
|
715 |
{
|
|
716 |
DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
|
|
717 |
|
|
718 |
HAL_DAC_ConvCpltCallbackCh1(hdac);
|
|
719 |
|
|
720 |
hdac->State= HAL_DAC_STATE_READY;
|
|
721 |
}
|
|
722 |
|
|
723 |
/**
|
|
724 |
* @brief DMA half transfer complete callback.
|
|
725 |
* @param hdma pointer to a DMA_HandleTypeDef structure that contains
|
|
726 |
* the configuration information for the specified DMA module.
|
|
727 |
* @retval None
|
|
728 |
*/
|
|
729 |
static void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma)
|
|
730 |
{
|
|
731 |
DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
|
|
732 |
/* Conversion complete callback */
|
|
733 |
HAL_DAC_ConvHalfCpltCallbackCh1(hdac);
|
|
734 |
}
|
|
735 |
|
|
736 |
/**
|
|
737 |
* @brief DMA error callback
|
|
738 |
* @param hdma pointer to a DMA_HandleTypeDef structure that contains
|
|
739 |
* the configuration information for the specified DMA module.
|
|
740 |
* @retval None
|
|
741 |
*/
|
|
742 |
static void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma)
|
|
743 |
{
|
|
744 |
DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
|
|
745 |
|
|
746 |
/* Set DAC error code to DMA error */
|
|
747 |
hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
|
|
748 |
|
|
749 |
HAL_DAC_ErrorCallbackCh1(hdac);
|
|
750 |
|
|
751 |
hdac->State= HAL_DAC_STATE_READY;
|
|
752 |
}
|
|
753 |
/**
|
|
754 |
* @}
|
|
755 |
*/
|
|
756 |
#endif /* STM32F051x8 STM32F058xx */
|
|
757 |
/* STM32F071xB STM32F072xB STM32F078xx */
|
|
758 |
/* STM32F091xC STM32F098xx */
|
|
759 |
|
|
760 |
#if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
|
|
761 |
defined(STM32F091xC) || defined(STM32F098xx)
|
|
762 |
|
|
763 |
/** @addtogroup DAC_Private_Functions
|
|
764 |
* @{
|
|
765 |
*/
|
|
766 |
|
|
767 |
/**
|
|
768 |
* @brief DMA conversion complete callback.
|
|
769 |
* @param hdma pointer to a DMA_HandleTypeDef structure that contains
|
|
770 |
* the configuration information for the specified DMA module.
|
|
771 |
* @retval None
|
|
772 |
*/
|
|
773 |
void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma)
|
|
774 |
{
|
|
775 |
DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
|
|
776 |
|
|
777 |
HAL_DACEx_ConvCpltCallbackCh2(hdac);
|
|
778 |
|
|
779 |
hdac->State= HAL_DAC_STATE_READY;
|
|
780 |
}
|
|
781 |
|
|
782 |
/**
|
|
783 |
* @brief DMA half transfer complete callback.
|
|
784 |
* @param hdma pointer to a DMA_HandleTypeDef structure that contains
|
|
785 |
* the configuration information for the specified DMA module.
|
|
786 |
* @retval None
|
|
787 |
*/
|
|
788 |
void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma)
|
|
789 |
{
|
|
790 |
DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
|
|
791 |
/* Conversion complete callback */
|
|
792 |
HAL_DACEx_ConvHalfCpltCallbackCh2(hdac);
|
|
793 |
}
|
|
794 |
|
|
795 |
/**
|
|
796 |
* @brief DMA error callback
|
|
797 |
* @param hdma pointer to a DMA_HandleTypeDef structure that contains
|
|
798 |
* the configuration information for the specified DMA module.
|
|
799 |
* @retval None
|
|
800 |
*/
|
|
801 |
void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma)
|
|
802 |
{
|
|
803 |
DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
|
|
804 |
|
|
805 |
/* Set DAC error code to DMA error */
|
|
806 |
hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
|
|
807 |
|
|
808 |
HAL_DACEx_ErrorCallbackCh2(hdac);
|
|
809 |
|
|
810 |
hdac->State= HAL_DAC_STATE_READY;
|
|
811 |
}
|
|
812 |
|
|
813 |
/**
|
|
814 |
* @}
|
|
815 |
*/
|
|
816 |
|
|
817 |
#endif /* STM32F071xB STM32F072xB STM32F078xx */
|
|
818 |
/* STM32F091xC STM32F098xx */
|
|
819 |
|
|
820 |
/**
|
|
821 |
* @}
|
|
822 |
*/
|
|
823 |
|
|
824 |
/** @defgroup DACEx DACEx
|
|
825 |
* @brief DACEx driver module
|
|
826 |
* @{
|
|
827 |
*/
|
|
828 |
|
|
829 |
/* Private typedef -----------------------------------------------------------*/
|
|
830 |
/* Private define ------------------------------------------------------------*/
|
|
831 |
/* Private macro -------------------------------------------------------------*/
|
|
832 |
/** @defgroup DACEx_Private_Macros DACEx Private Macros
|
|
833 |
* @{
|
|
834 |
*/
|
|
835 |
/**
|
|
836 |
* @}
|
|
837 |
*/
|
|
838 |
|
|
839 |
/* Private variables ---------------------------------------------------------*/
|
|
840 |
/* Private function prototypes -----------------------------------------------*/
|
|
841 |
/* Private functions ---------------------------------------------------------*/
|
|
842 |
|
|
843 |
/** @defgroup DACEx_Exported_Functions DACEx Exported Functions
|
|
844 |
* @{
|
|
845 |
*/
|
|
846 |
|
|
847 |
/** @defgroup DACEx_Exported_Functions_Group1 Extended features functions
|
|
848 |
* @brief Extended features functions
|
|
849 |
*
|
|
850 |
@verbatim
|
|
851 |
==============================================================================
|
|
852 |
##### Extended features functions #####
|
|
853 |
==============================================================================
|
|
854 |
[..] This section provides functions allowing to:
|
|
855 |
(+) Start conversion.
|
|
856 |
(+) Stop conversion.
|
|
857 |
(+) Start conversion and enable DMA transfer.
|
|
858 |
(+) Stop conversion and disable DMA transfer.
|
|
859 |
(+) Get result of conversion.
|
|
860 |
(+) Get result of dual mode conversion.
|
|
861 |
|
|
862 |
@endverbatim
|
|
863 |
* @{
|
|
864 |
*/
|
|
865 |
|
|
866 |
#if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
|
|
867 |
defined(STM32F091xC) || defined(STM32F098xx)
|
|
868 |
|
|
869 |
/**
|
|
870 |
* @brief Returns the last data output value of the selected DAC channel.
|
|
871 |
* @param hdac pointer to a DAC_HandleTypeDef structure that contains
|
|
872 |
* the configuration information for the specified DAC.
|
|
873 |
* @retval The selected DAC channel data output value.
|
|
874 |
*/
|
|
875 |
uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef* hdac)
|
|
876 |
{
|
|
877 |
uint32_t tmp = 0U;
|
|
878 |
|
|
879 |
tmp |= hdac->Instance->DOR1;
|
|
880 |
|
|
881 |
/* DAC channel 2 is present in DAC 1 */
|
|
882 |
tmp |= hdac->Instance->DOR2 << 16U;
|
|
883 |
|
|
884 |
/* Returns the DAC channel data output register value */
|
|
885 |
return tmp;
|
|
886 |
}
|
|
887 |
|
|
888 |
#endif /* STM32F071xB STM32F072xB STM32F078xx */
|
|
889 |
/* STM32F091xC STM32F098xx */
|
|
890 |
|
|
891 |
#if defined (STM32F051x8) || defined (STM32F058xx)
|
|
892 |
|
|
893 |
/**
|
|
894 |
* @brief Returns the last data output value of the selected DAC channel.
|
|
895 |
* @param hdac pointer to a DAC_HandleTypeDef structure that contains
|
|
896 |
* the configuration information for the specified DAC.
|
|
897 |
* @retval The selected DAC channel data output value.
|
|
898 |
*/
|
|
899 |
uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef* hdac)
|
|
900 |
{
|
|
901 |
uint32_t tmp = 0U;
|
|
902 |
|
|
903 |
tmp |= hdac->Instance->DOR1;
|
|
904 |
|
|
905 |
/* Returns the DAC channel data output register value */
|
|
906 |
return tmp;
|
|
907 |
}
|
|
908 |
|
|
909 |
#endif /* STM32F051x8 STM32F058xx */
|
|
910 |
|
|
911 |
#if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
|
|
912 |
defined(STM32F091xC) || defined(STM32F098xx)
|
|
913 |
|
|
914 |
/**
|
|
915 |
* @brief Enables or disables the selected DAC channel wave generation.
|
|
916 |
* @param hdac pointer to a DAC_HandleTypeDef structure that contains
|
|
917 |
* the configuration information for the specified DAC.
|
|
918 |
* @param Channel The selected DAC channel.
|
|
919 |
* This parameter can be one of the following values:
|
|
920 |
* DAC_CHANNEL_1 / DAC_CHANNEL_2
|
|
921 |
* @param Amplitude Select max triangle amplitude.
|
|
922 |
* This parameter can be one of the following values:
|
|
923 |
* @arg DAC_TRIANGLEAMPLITUDE_1: Select max triangle amplitude of 1
|
|
924 |
* @arg DAC_TRIANGLEAMPLITUDE_3: Select max triangle amplitude of 3
|
|
925 |
* @arg DAC_TRIANGLEAMPLITUDE_7: Select max triangle amplitude of 7
|
|
926 |
* @arg DAC_TRIANGLEAMPLITUDE_15: Select max triangle amplitude of 15
|
|
927 |
* @arg DAC_TRIANGLEAMPLITUDE_31: Select max triangle amplitude of 31
|
|
928 |
* @arg DAC_TRIANGLEAMPLITUDE_63: Select max triangle amplitude of 63
|
|
929 |
* @arg DAC_TRIANGLEAMPLITUDE_127: Select max triangle amplitude of 127
|
|
930 |
* @arg DAC_TRIANGLEAMPLITUDE_255: Select max triangle amplitude of 255
|
|
931 |
* @arg DAC_TRIANGLEAMPLITUDE_511: Select max triangle amplitude of 511
|
|
932 |
* @arg DAC_TRIANGLEAMPLITUDE_1023: Select max triangle amplitude of 1023
|
|
933 |
* @arg DAC_TRIANGLEAMPLITUDE_2047: Select max triangle amplitude of 2047
|
|
934 |
* @arg DAC_TRIANGLEAMPLITUDE_4095: Select max triangle amplitude of 4095
|
|
935 |
* @retval HAL status
|
|
936 |
*/
|
|
937 |
HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude)
|
|
938 |
{
|
|
939 |
/* Check the parameters */
|
|
940 |
assert_param(IS_DAC_CHANNEL(Channel));
|
|
941 |
assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
|
|
942 |
|
|
943 |
/* Process locked */
|
|
944 |
__HAL_LOCK(hdac);
|
|
945 |
|
|
946 |
/* Change DAC state */
|
|
947 |
hdac->State = HAL_DAC_STATE_BUSY;
|
|
948 |
|
|
949 |
/* Enable the selected wave generation for the selected DAC channel */
|
|
950 |
MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1)|(DAC_CR_MAMP1))<<Channel, (DAC_CR_WAVE1_1 | Amplitude) << Channel);
|
|
951 |
|
|
952 |
/* Change DAC state */
|
|
953 |
hdac->State = HAL_DAC_STATE_READY;
|
|
954 |
|
|
955 |
/* Process unlocked */
|
|
956 |
__HAL_UNLOCK(hdac);
|
|
957 |
|
|
958 |
/* Return function status */
|
|
959 |
return HAL_OK;
|
|
960 |
}
|
|
961 |
|
|
962 |
/**
|
|
963 |
* @brief Enables or disables the selected DAC channel wave generation.
|
|
964 |
* @param hdac pointer to a DAC_HandleTypeDef structure that contains
|
|
965 |
* the configuration information for the specified DAC.
|
|
966 |
* @param Channel The selected DAC channel.
|
|
967 |
* This parameter can be one of the following values:
|
|
968 |
* DAC_CHANNEL_1 / DAC_CHANNEL_2
|
|
969 |
* @param Amplitude Unmask DAC channel LFSR for noise wave generation.
|
|
970 |
* This parameter can be one of the following values:
|
|
971 |
* @arg DAC_LFSRUNMASK_BIT0: Unmask DAC channel LFSR bit0 for noise wave generation
|
|
972 |
* @arg DAC_LFSRUNMASK_BITS1_0: Unmask DAC channel LFSR bit[1:0] for noise wave generation
|
|
973 |
* @arg DAC_LFSRUNMASK_BITS2_0: Unmask DAC channel LFSR bit[2:0] for noise wave generation
|
|
974 |
* @arg DAC_LFSRUNMASK_BITS3_0: Unmask DAC channel LFSR bit[3:0] for noise wave generation
|
|
975 |
* @arg DAC_LFSRUNMASK_BITS4_0: Unmask DAC channel LFSR bit[4:0] for noise wave generation
|
|
976 |
* @arg DAC_LFSRUNMASK_BITS5_0: Unmask DAC channel LFSR bit[5:0] for noise wave generation
|
|
977 |
* @arg DAC_LFSRUNMASK_BITS6_0: Unmask DAC channel LFSR bit[6:0] for noise wave generation
|
|
978 |
* @arg DAC_LFSRUNMASK_BITS7_0: Unmask DAC channel LFSR bit[7:0] for noise wave generation
|
|
979 |
* @arg DAC_LFSRUNMASK_BITS8_0: Unmask DAC channel LFSR bit[8:0] for noise wave generation
|
|
980 |
* @arg DAC_LFSRUNMASK_BITS9_0: Unmask DAC channel LFSR bit[9:0] for noise wave generation
|
|
981 |
* @arg DAC_LFSRUNMASK_BITS10_0: Unmask DAC channel LFSR bit[10:0] for noise wave generation
|
|
982 |
* @arg DAC_LFSRUNMASK_BITS11_0: Unmask DAC channel LFSR bit[11:0] for noise wave generation
|
|
983 |
* @retval HAL status
|
|
984 |
*/
|
|
985 |
HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude)
|
|
986 |
{
|
|
987 |
/* Check the parameters */
|
|
988 |
assert_param(IS_DAC_CHANNEL(Channel));
|
|
989 |
assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
|
|
990 |
|
|
991 |
/* Process locked */
|
|
992 |
__HAL_LOCK(hdac);
|
|
993 |
|
|
994 |
/* Change DAC state */
|
|
995 |
hdac->State = HAL_DAC_STATE_BUSY;
|
|
996 |
|
|
997 |
/* Enable the selected wave generation for the selected DAC channel */
|
|
998 |
MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1)|(DAC_CR_MAMP1))<<Channel, (DAC_CR_WAVE1_0 | Amplitude) << Channel);
|
|
999 |
|
|
1000 |
/* Change DAC state */
|
|
1001 |
hdac->State = HAL_DAC_STATE_READY;
|
|
1002 |
|
|
1003 |
/* Process unlocked */
|
|
1004 |
__HAL_UNLOCK(hdac);
|
|
1005 |
|
|
1006 |
/* Return function status */
|
|
1007 |
return HAL_OK;
|
|
1008 |
}
|
|
1009 |
|
|
1010 |
#endif /* STM32F071xB STM32F072xB STM32F078xx */
|
|
1011 |
/* STM32F091xC STM32F098xx */
|
|
1012 |
|
|
1013 |
/**
|
|
1014 |
* @}
|
|
1015 |
*/
|
|
1016 |
|
|
1017 |
/**
|
|
1018 |
* @}
|
|
1019 |
*/
|
|
1020 |
|
|
1021 |
#if defined(STM32F051x8) || defined(STM32F058xx) || \
|
|
1022 |
defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
|
|
1023 |
defined(STM32F091xC) || defined(STM32F098xx)
|
|
1024 |
|
|
1025 |
/** @addtogroup DACEx_Exported_Functions
|
|
1026 |
* @{
|
|
1027 |
*/
|
|
1028 |
|
|
1029 |
/** @addtogroup DACEx_Exported_Functions_Group1
|
|
1030 |
* @brief Extended features functions
|
|
1031 |
* @{
|
|
1032 |
*/
|
|
1033 |
|
|
1034 |
/**
|
|
1035 |
* @brief Set the specified data holding register value for dual DAC channel.
|
|
1036 |
* @param hdac pointer to a DAC_HandleTypeDef structure that contains
|
|
1037 |
* the configuration information for the specified DAC.
|
|
1038 |
* @param Alignment Specifies the data alignment for dual channel DAC.
|
|
1039 |
* This parameter can be one of the following values:
|
|
1040 |
* DAC_ALIGN_8B_R: 8bit right data alignment selected
|
|
1041 |
* DAC_ALIGN_12B_L: 12bit left data alignment selected
|
|
1042 |
* DAC_ALIGN_12B_R: 12bit right data alignment selected
|
|
1043 |
* @param Data1 Data for DAC Channel2 to be loaded in the selected data holding register.
|
|
1044 |
* @param Data2 Data for DAC Channel1 to be loaded in the selected data holding register.
|
|
1045 |
* @note In dual mode, a unique register access is required to write in both
|
|
1046 |
* DAC channels at the same time.
|
|
1047 |
* @retval HAL status
|
|
1048 |
*/
|
|
1049 |
HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef* hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2)
|
|
1050 |
{
|
|
1051 |
uint32_t data = 0U, tmp = 0U;
|
|
1052 |
|
|
1053 |
/* Check the parameters */
|
|
1054 |
assert_param(IS_DAC_ALIGN(Alignment));
|
|
1055 |
assert_param(IS_DAC_DATA(Data1));
|
|
1056 |
assert_param(IS_DAC_DATA(Data2));
|
|
1057 |
|
|
1058 |
/* Calculate and set dual DAC data holding register value */
|
|
1059 |
if (Alignment == DAC_ALIGN_8B_R)
|
|
1060 |
{
|
|
1061 |
data = ((uint32_t)Data2 << 8U) | Data1;
|
|
1062 |
}
|
|
1063 |
else
|
|
1064 |
{
|
|
1065 |
data = ((uint32_t)Data2 << 16U) | Data1;
|
|
1066 |
}
|
|
1067 |
|
|
1068 |
tmp = (uint32_t)hdac->Instance;
|
|
1069 |
tmp += DAC_DHR12RD_ALIGNMENT(Alignment);
|
|
1070 |
|
|
1071 |
/* Set the dual DAC selected data holding register */
|
|
1072 |
*(__IO uint32_t *)tmp = data;
|
|
1073 |
|
|
1074 |
/* Return function status */
|
|
1075 |
return HAL_OK;
|
|
1076 |
}
|
|
1077 |
|
|
1078 |
/**
|
|
1079 |
* @}
|
|
1080 |
*/
|
|
1081 |
|
|
1082 |
/**
|
|
1083 |
* @}
|
|
1084 |
*/
|
|
1085 |
|
|
1086 |
#endif /* STM32F051x8 STM32F058xx */
|
|
1087 |
/* STM32F071xB STM32F072xB STM32F078xx */
|
|
1088 |
/* STM32F091xC STM32F098xx */
|
|
1089 |
|
|
1090 |
#if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
|
|
1091 |
defined(STM32F091xC) || defined(STM32F098xx)
|
|
1092 |
|
|
1093 |
/** @addtogroup DACEx_Exported_Functions
|
|
1094 |
* @{
|
|
1095 |
*/
|
|
1096 |
|
|
1097 |
/** @addtogroup DACEx_Exported_Functions_Group1
|
|
1098 |
* @brief Extended features functions
|
|
1099 |
* @{
|
|
1100 |
*/
|
|
1101 |
|
|
1102 |
/**
|
|
1103 |
* @brief Conversion complete callback in non blocking mode for Channel2
|
|
1104 |
* @param hdac pointer to a DAC_HandleTypeDef structure that contains
|
|
1105 |
* the configuration information for the specified DAC.
|
|
1106 |
* @retval None
|
|
1107 |
*/
|
|
1108 |
__weak void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef* hdac)
|
|
1109 |
{
|
|
1110 |
/* Prevent unused argument(s) compilation warning */
|
|
1111 |
UNUSED(hdac);
|
|
1112 |
|
|
1113 |
/* NOTE : This function Should not be modified, when the callback is needed,
|
|
1114 |
the HAL_DAC_ConvCpltCallback could be implemented in the user file
|
|
1115 |
*/
|
|
1116 |
}
|
|
1117 |
|
|
1118 |
/**
|
|
1119 |
* @brief Conversion half DMA transfer callback in non blocking mode for Channel2
|
|
1120 |
* @param hdac pointer to a DAC_HandleTypeDef structure that contains
|
|
1121 |
* the configuration information for the specified DAC.
|
|
1122 |
* @retval None
|
|
1123 |
*/
|
|
1124 |
__weak void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef* hdac)
|
|
1125 |
{
|
|
1126 |
/* Prevent unused argument(s) compilation warning */
|
|
1127 |
UNUSED(hdac);
|
|
1128 |
|
|
1129 |
/* NOTE : This function Should not be modified, when the callback is needed,
|
|
1130 |
the HAL_DAC_ConvHalfCpltCallbackCh2 could be implemented in the user file
|
|
1131 |
*/
|
|
1132 |
}
|
|
1133 |
|
|
1134 |
/**
|
|
1135 |
* @brief Error DAC callback for Channel2.
|
|
1136 |
* @param hdac pointer to a DAC_HandleTypeDef structure that contains
|
|
1137 |
* the configuration information for the specified DAC.
|
|
1138 |
* @retval None
|
|
1139 |
*/
|
|
1140 |
__weak void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef *hdac)
|
|
1141 |
{
|
|
1142 |
/* Prevent unused argument(s) compilation warning */
|
|
1143 |
UNUSED(hdac);
|
|
1144 |
|
|
1145 |
/* NOTE : This function Should not be modified, when the callback is needed,
|
|
1146 |
the HAL_DAC_ErrorCallback could be implemented in the user file
|
|
1147 |
*/
|
|
1148 |
}
|
|
1149 |
|
|
1150 |
/**
|
|
1151 |
* @brief DMA underrun DAC callback for channel2.
|
|
1152 |
* @param hdac pointer to a DAC_HandleTypeDef structure that contains
|
|
1153 |
* the configuration information for the specified DAC.
|
|
1154 |
* @retval None
|
|
1155 |
*/
|
|
1156 |
__weak void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef *hdac)
|
|
1157 |
{
|
|
1158 |
/* Prevent unused argument(s) compilation warning */
|
|
1159 |
UNUSED(hdac);
|
|
1160 |
|
|
1161 |
/* NOTE : This function Should not be modified, when the callback is needed,
|
|
1162 |
the HAL_DAC_DMAUnderrunCallbackCh2 could be implemented in the user file
|
|
1163 |
*/
|
|
1164 |
}
|
|
1165 |
|
|
1166 |
/**
|
|
1167 |
* @}
|
|
1168 |
*/
|
|
1169 |
|
|
1170 |
/**
|
|
1171 |
* @}
|
|
1172 |
*/
|
|
1173 |
|
|
1174 |
#endif /* STM32F071xB STM32F072xB STM32F078xx */
|
|
1175 |
/* STM32F091xC STM32F098xx */
|
|
1176 |
|
|
1177 |
/**
|
|
1178 |
* @}
|
|
1179 |
*/
|
|
1180 |
|
|
1181 |
#endif /* HAL_DAC_MODULE_ENABLED */
|
|
1182 |
|
|
1183 |
/**
|
|
1184 |
* @}
|
|
1185 |
*/
|
|
1186 |
|
|
1187 |
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|