1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
43
44
45
46
47
48
52
53
54
55
56
57
58
59
60
61
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
100
101
102
103
104
105
106
107
108
109
110
111
112
113
117
121
122
123
124
125
126
127
128
129
130
131
132
133
134
140
141
142
143
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
299
300
301
302
303
304
305
306
310
314
315
316
317
318
319
320
321
322
323
324
325
331
340
341
347
356
357
363
372
373
379
388
389
390
391
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
432
435
436
437
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
468
469
470
471
472
473
474
475
476
477
478
479
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
505
506
509
510
511
512
513
514
/* ... */
#include "stm32f4xx_hal.h"
/* ... */
#ifdef HAL_DAC_MODULE_ENABLED
#if defined(DAC)
/* ... */
/* ... */
/* ... */
#if defined(DAC_CHANNEL2_SUPPORT)
/* ... */
HAL_StatusTypeDef HAL_DACEx_DualStart(DAC_HandleTypeDef *hdac)
{
uint32_t tmp_swtrig = 0UL;
if (hdac == NULL)
{
return HAL_ERROR;
}if (hdac == NULL) { ... }
__HAL_LOCK(hdac);
hdac->State = HAL_DAC_STATE_BUSY;
__HAL_DAC_ENABLE(hdac, DAC_CHANNEL_1);
__HAL_DAC_ENABLE(hdac, DAC_CHANNEL_2);
if ((hdac->Instance->CR & (DAC_CR_TEN1 | DAC_CR_TSEL1)) == DAC_TRIGGER_SOFTWARE)
{
tmp_swtrig |= DAC_SWTRIGR_SWTRIG1;
}if ((hdac->Instance->CR & (DAC_CR_TEN1 | DAC_CR_TSEL1)) == DAC_TRIGGER_SOFTWARE) { ... }
if ((hdac->Instance->CR & (DAC_CR_TEN2 | DAC_CR_TSEL2)) == (DAC_TRIGGER_SOFTWARE << (DAC_CHANNEL_2 & 0x10UL)))
{
tmp_swtrig |= DAC_SWTRIGR_SWTRIG2;
}if ((hdac->Instance->CR & (DAC_CR_TEN2 | DAC_CR_TSEL2)) == (DAC_TRIGGER_SOFTWARE << (DAC_CHANNEL_2 & 0x10UL))) { ... }
SET_BIT(hdac->Instance->SWTRIGR, tmp_swtrig);
hdac->State = HAL_DAC_STATE_READY;
__HAL_UNLOCK(hdac);
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_DACEx_DualStop(DAC_HandleTypeDef *hdac)
{
if (hdac == NULL)
{
return HAL_ERROR;
}if (hdac == NULL) { ... }
__HAL_DAC_DISABLE(hdac, DAC_CHANNEL_1);
__HAL_DAC_DISABLE(hdac, DAC_CHANNEL_2);
hdac->State = HAL_DAC_STATE_READY;
return HAL_OK;
}{ ... }
#endif/* ... */
/* ... */
HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude)
{
if (hdac == NULL)
{
return HAL_ERROR;
}if (hdac == NULL) { ... }
assert_param(IS_DAC_CHANNEL(Channel));
assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
__HAL_LOCK(hdac);
hdac->State = HAL_DAC_STATE_BUSY;
MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1) | (DAC_CR_MAMP1)) << (Channel & 0x10UL),
(DAC_CR_WAVE1_1 | Amplitude) << (Channel & 0x10UL));
hdac->State = HAL_DAC_STATE_READY;
__HAL_UNLOCK(hdac);
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude)
{
if (hdac == NULL)
{
return HAL_ERROR;
}if (hdac == NULL) { ... }
assert_param(IS_DAC_CHANNEL(Channel));
assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
__HAL_LOCK(hdac);
hdac->State = HAL_DAC_STATE_BUSY;
MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1) | (DAC_CR_MAMP1)) << (Channel & 0x10UL),
(DAC_CR_WAVE1_0 | Amplitude) << (Channel & 0x10UL));
hdac->State = HAL_DAC_STATE_READY;
__HAL_UNLOCK(hdac);
return HAL_OK;
}{ ... }
#if defined(DAC_CHANNEL2_SUPPORT)
/* ... */
HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef *hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2)
{
uint32_t data;
uint32_t tmp;
if (hdac == NULL)
{
return HAL_ERROR;
}if (hdac == NULL) { ... }
assert_param(IS_DAC_ALIGN(Alignment));
assert_param(IS_DAC_DATA(Data1));
assert_param(IS_DAC_DATA(Data2));
if (Alignment == DAC_ALIGN_8B_R)
{
data = ((uint32_t)Data2 << 8U) | Data1;
}if (Alignment == DAC_ALIGN_8B_R) { ... }
else
{
data = ((uint32_t)Data2 << 16U) | Data1;
}else { ... }
tmp = (uint32_t)hdac->Instance;
tmp += DAC_DHR12RD_ALIGNMENT(Alignment);
*(__IO uint32_t *)tmp = data;
return HAL_OK;
}{ ... }
/* ... */
__weak void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef *hdac)
{
UNUSED(hdac);
/* ... */
}{ ... }
/* ... */
__weak void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef *hdac)
{
UNUSED(hdac);
/* ... */
}{ ... }
/* ... */
__weak void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef *hdac)
{
UNUSED(hdac);
/* ... */
}{ ... }
/* ... */
__weak void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef *hdac)
{
UNUSED(hdac);
/* ... */
}{ ... }
#endif/* ... */
/* ... */
/* ... */
#if defined(DAC_CHANNEL2_SUPPORT)
/* ... */
uint32_t HAL_DACEx_DualGetValue(const DAC_HandleTypeDef *hdac)
{
uint32_t tmp = 0UL;
tmp |= hdac->Instance->DOR1;
tmp |= hdac->Instance->DOR2 << 16UL;
return tmp;
}{ ... }
#endif/* ... */
/* ... */
/* ... */
Exported functions
/* ... */
#if defined(DAC_CHANNEL2_SUPPORT)
/* ... */
void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma)
{
DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
hdac->ConvCpltCallbackCh2(hdac);
#else
HAL_DACEx_ConvCpltCallbackCh2(hdac);
#endif
hdac->State = HAL_DAC_STATE_READY;
}{ ... }
/* ... */
void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma)
{
DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
hdac->ConvHalfCpltCallbackCh2(hdac);
#else
HAL_DACEx_ConvHalfCpltCallbackCh2(hdac);
#endif
}{ ... }
/* ... */
void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma)
{
DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
hdac->ErrorCallbackCh2(hdac);
#else
HAL_DACEx_ErrorCallbackCh2(hdac);
#endif
hdac->State = HAL_DAC_STATE_READY;
}{ ... }
#endif/* ... */
/* ... */
/* ... */
/* ... */
#endif
/* ... */
#endif
/* ... */