Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "pulse_skipper.h"
#define NB_BITSTREAM_CLOCK_PERIOD
Private variables
TimDfsdm2Handle
TimDfsdm1Handle
Pulse_Skipper_Init()
Pulse_Skipper_Bitstream_Start()
Pulse_Skipper_Bitstream_Stop()
Pulse_Skipper_Generate_Pulse(PulseSkipper_InitTypeDef *)
Skipper_MspInit()
HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *)
Files
loading...
SourceVuSTM32 Libraries and SamplesDFSDM_PulseSkipperSrc/pulse_skipper.c
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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
189
190
191
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
245
246
247
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file DFSDM/DFSDM_PulseSkipper/Src/pulse_skipper.c * @author MCD Application Team * @brief This file provides a set of firmware functions to pulse skipper. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "pulse_skipper.h" /** @addtogroup STM32F4xx_HAL_Examples * @{ *//* ... */ /** @addtogroup DFSDM_PulseSkipper * @{ *//* ... */ Includes/* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ #define NB_BITSTREAM_CLOCK_PERIOD 4 /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Timer3 handler declaration for DFSDM2 */ TIM_HandleTypeDef TimDfsdm2Handle; /* Timer4 handler declaration for DFSDM1 */ TIM_HandleTypeDef TimDfsdm1Handle;Private variables /* Private function prototypes -----------------------------------------------*/ static void Skipper_MspInit(void); /* Private functions ---------------------------------------------------------*/ /** * @brief Enable Multi Channel clock Delay for DFSDM1 and DFSDM2 . * @param None * @retval None *//* ... */ void Pulse_Skipper_Init(void) { /* Configure TIM3 and TIM4 */ Skipper_MspInit(); /* Enable delay clock gating */ HAL_DFSDM_EnableDelayClock(HAL_MCHDLY_CLOCK_DFSDM1); HAL_DFSDM_EnableDelayClock(HAL_MCHDLY_CLOCK_DFSDM2); }{ ... } /** * @brief Inject DFSDM2 audio clock as clock source for the bitstream clock * @param None * @retval None *//* ... */ void Pulse_Skipper_Bitstream_Start(void) { HAL_DFSDM_BitstreamClock_Start(); }{ ... } /** * @brief Stop DFSDM2 audio clock as clock source for the bitstream clock. * @param None * @retval None *//* ... */ void Pulse_Skipper_Bitstream_Stop(void) { HAL_DFSDM_BitstreamClock_Stop(); }{ ... } /** * @brief Generate Pulse skipper on selected channel * @param skipperstruct: Structure for channel * @retval None *//* ... */ void Pulse_Skipper_Generate_Pulse(PulseSkipper_InitTypeDef* skipperstruct) { /*****************DFSDM1 Pulse Skipper Channel Generation ********************/ if (skipperstruct->DFSDM1PulseSkipperCh == DFSDM1_PULSE_SKIPPER_CH02) { /* Disable the Capture compare channel */ TIM_CCxChannelCmd(TimDfsdm1Handle.Instance, DFSDM1_TIM4_OC2, TIM_CCx_DISABLE); /* Enable the Capture compare channel */ TIM_CCxChannelCmd(TimDfsdm1Handle.Instance, DFSDM1_TIM4_OC2, TIM_CCx_ENABLE); /* Use TIM_Base in order to get interrupt once pulse ended */ /* Enable the TIM Update interrupt */ __HAL_TIM_ENABLE_IT(&TimDfsdm1Handle, TIM_IT_UPDATE); /* Enable the Peripheral */ __HAL_TIM_ENABLE(&TimDfsdm1Handle); }if (skipperstruct->DFSDM1PulseSkipperCh == DFSDM1_PULSE_SKIPPER_CH02) { ... } else if (skipperstruct->DFSDM1PulseSkipperCh == DFSDM1_PULSE_SKIPPER_CH13) { /* Disable the Capture compare channel */ TIM_CCxChannelCmd(TimDfsdm1Handle.Instance, DFSDM1_TIM4_OC1, TIM_CCx_DISABLE); /* Enable the Capture compare channel */ TIM_CCxChannelCmd(TimDfsdm1Handle.Instance, DFSDM1_TIM4_OC1, TIM_CCx_ENABLE); /* Use TIM_Base in order to get interrupt once pulse ended */ /* Enable the TIM Update interrupt */ __HAL_TIM_ENABLE_IT(&TimDfsdm1Handle, TIM_IT_UPDATE); /* Enable the Peripheral */ __HAL_TIM_ENABLE(&TimDfsdm1Handle); }else if (skipperstruct->DFSDM1PulseSkipperCh == DFSDM1_PULSE_SKIPPER_CH13) { ... } DFSDM1 Pulse Skipper Channel Generation /*****************DFSDM2 Pulse Skipper Channel Generation ********************/ if (skipperstruct->DFSDM2PulseSkipperCh == DFSDM2_PULSE_SKIPPER_CH04) { /* Disable the Capture compare channel */ TIM_CCxChannelCmd(TimDfsdm2Handle.Instance, DFSDM2_TIM3_OC4, TIM_CCx_DISABLE); /* Enable the Capture compare channel */ TIM_CCxChannelCmd(TimDfsdm2Handle.Instance, DFSDM2_TIM3_OC4, TIM_CCx_ENABLE); /* Use TIM_Base in order to get interrupt once pulse ended */ /* Enable the TIM Update interrupt */ __HAL_TIM_ENABLE_IT(&TimDfsdm2Handle, TIM_IT_UPDATE); /* Enable the Peripheral */ __HAL_TIM_ENABLE(&TimDfsdm2Handle); }if (skipperstruct->DFSDM2PulseSkipperCh == DFSDM2_PULSE_SKIPPER_CH04) { ... } else if (skipperstruct->DFSDM2PulseSkipperCh == DFSDM2_PULSE_SKIPPER_CH15) { /* Disable the Capture compare channel */ TIM_CCxChannelCmd(TimDfsdm2Handle.Instance, DFSDM2_TIM3_OC3, TIM_CCx_DISABLE); /* Enable the Capture compare channel */ TIM_CCxChannelCmd(TimDfsdm2Handle.Instance, DFSDM2_TIM3_OC3, TIM_CCx_ENABLE); /* Use TIM_Base in order to get interrupt once pulse ended */ /* Enable the TIM Update interrupt */ __HAL_TIM_ENABLE_IT(&TimDfsdm2Handle, TIM_IT_UPDATE); /* Enable the Peripheral */ __HAL_TIM_ENABLE(&TimDfsdm2Handle); }else if (skipperstruct->DFSDM2PulseSkipperCh == DFSDM2_PULSE_SKIPPER_CH15) { ... } else if (skipperstruct->DFSDM2PulseSkipperCh == DFSDM2_PULSE_SKIPPER_CH26) { /* Disable the Capture compare channel */ TIM_CCxChannelCmd(TimDfsdm2Handle.Instance, DFSDM2_TIM3_OC2, TIM_CCx_DISABLE); /* Enable the Capture compare channel */ TIM_CCxChannelCmd(TimDfsdm2Handle.Instance, DFSDM2_TIM3_OC2, TIM_CCx_ENABLE); /* Use TIM_Base in order to get interrupt once pulse ended */ /* Enable the TIM Update interrupt */ __HAL_TIM_ENABLE_IT(&TimDfsdm2Handle, TIM_IT_UPDATE); /* Enable the Peripheral */ __HAL_TIM_ENABLE(&TimDfsdm2Handle); }else if (skipperstruct->DFSDM2PulseSkipperCh == DFSDM2_PULSE_SKIPPER_CH26) { ... } else if (skipperstruct->DFSDM2PulseSkipperCh == DFSDM2_PULSE_SKIPPER_CH37) { /* Disable the Capture compare channel */ TIM_CCxChannelCmd(TimDfsdm2Handle.Instance, DFSDM2_TIM3_OC1, TIM_CCx_DISABLE); /* Enable the Capture compare channel */ TIM_CCxChannelCmd(TimDfsdm2Handle.Instance, DFSDM2_TIM3_OC1, TIM_CCx_ENABLE); /* Use TIM_Base in order to get interrupt once pulse ended */ /* Enable the TIM Update interrupt */ __HAL_TIM_ENABLE_IT(&TimDfsdm2Handle, TIM_IT_UPDATE); /* Enable the Peripheral */ __HAL_TIM_ENABLE(&TimDfsdm2Handle); }else if (skipperstruct->DFSDM2PulseSkipperCh == DFSDM2_PULSE_SKIPPER_CH37) { ... } }{ ... } /** * @brief Turns selected LED Off. * @param Led: LED to be set off * This parameter can be one of the following values: * @arg LED5 * @arg LED8 * @retval None *//* ... */ static void Skipper_MspInit(void) { /* Output compare structure */ TIM_OC_InitTypeDef sOCConfig; /* Slave configuration structure */ TIM_SlaveConfigTypeDef sSlaveConfig; /* Timers Configuration */ TimDfsdm2Handle.Instance = TIM3; TimDfsdm1Handle.Instance = TIM4; /*====================== TIM3 configuration =======================*/ /* Initialize TIM3 peripheral in PWM mode */ TimDfsdm2Handle.Init.Period = NB_BITSTREAM_CLOCK_PERIOD ; TimDfsdm2Handle.Init.Prescaler = 0; TimDfsdm2Handle.Init.ClockDivision = 0; TimDfsdm2Handle.Init.CounterMode = TIM_COUNTERMODE_UP; TimDfsdm2Handle.Init.RepetitionCounter = 0; if (HAL_TIM_PWM_Init(&TimDfsdm2Handle) != HAL_OK) { /* Initialization Error */ while(1); }if (HAL_TIM_PWM_Init(&TimDfsdm2Handle) != HAL_OK) { ... } /* Configure the OPM Mode */ HAL_TIM_OnePulse_Init(&TimDfsdm2Handle, TIM_OPMODE_SINGLE); /* Configure the PWM_channel_1 */ sOCConfig.OCMode = TIM_OCMODE_PWM1; sOCConfig.OCPolarity = TIM_OCPOLARITY_LOW; sOCConfig.Pulse = 1; sOCConfig.OCFastMode = TIM_OCFAST_DISABLE ; if (HAL_TIM_PWM_ConfigChannel(&TimDfsdm2Handle, &sOCConfig, TIM_CHANNEL_1) != HAL_OK) { /* Initialization Error */ while(1); }if (HAL_TIM_PWM_ConfigChannel(&TimDfsdm2Handle, &sOCConfig, TIM_CHANNEL_1) != HAL_OK) { ... } if (HAL_TIM_PWM_ConfigChannel(&TimDfsdm2Handle, &sOCConfig, TIM_CHANNEL_2) != HAL_OK) { /* Initialization Error */ while(1); }if (HAL_TIM_PWM_ConfigChannel(&TimDfsdm2Handle, &sOCConfig, TIM_CHANNEL_2) != HAL_OK) { ... } if (HAL_TIM_PWM_ConfigChannel(&TimDfsdm2Handle, &sOCConfig, TIM_CHANNEL_3) != HAL_OK) { /* Initialization Error */ while(1);; }if (HAL_TIM_PWM_ConfigChannel(&TimDfsdm2Handle, &sOCConfig, TIM_CHANNEL_3) != HAL_OK) { ... } if (HAL_TIM_PWM_ConfigChannel(&TimDfsdm2Handle, &sOCConfig, TIM_CHANNEL_4) != HAL_OK) { /* Initialization Error */ while(1); }if (HAL_TIM_PWM_ConfigChannel(&TimDfsdm2Handle, &sOCConfig, TIM_CHANNEL_4) != HAL_OK) { ... } /* Configure TIM3 in Gated slave mode & use the Internal Trigger 0 (ITR1) as trigger source *//* ... */ sSlaveConfig.SlaveMode = TIM_SLAVEMODE_EXTERNAL1; sSlaveConfig.InputTrigger = TIM_TS_ETRF; sSlaveConfig.TriggerPolarity = TIM_TRIGGERPOLARITY_NONINVERTED; sSlaveConfig.TriggerPrescaler = TIM_TRIGGERPRESCALER_DIV1; sSlaveConfig.TriggerFilter = 0; if (HAL_TIM_SlaveConfigSynchronization(&TimDfsdm2Handle, &sSlaveConfig) != HAL_OK) { /* Initialization Error */ while(1); }if (HAL_TIM_SlaveConfigSynchronization(&TimDfsdm2Handle, &sSlaveConfig) != HAL_OK) { ... } /*====================== TIM4 configuration =======================*/ /* Initialize TIM4 peripheral in PWM mode */ TimDfsdm1Handle.Init.Period = NB_BITSTREAM_CLOCK_PERIOD; TimDfsdm1Handle.Init.Prescaler = 0; TimDfsdm1Handle.Init.ClockDivision = 0; TimDfsdm1Handle.Init.CounterMode = TIM_COUNTERMODE_UP; TimDfsdm1Handle.Init.RepetitionCounter = 0; if (HAL_TIM_PWM_Init(&TimDfsdm1Handle) != HAL_OK) { /* Initialization Error */ while(1); }if (HAL_TIM_PWM_Init(&TimDfsdm1Handle) != HAL_OK) { ... } /* Configure the OPM Mode */ HAL_TIM_OnePulse_Init(&TimDfsdm1Handle, TIM_OPMODE_SINGLE); /* Configure the PWM_channel_1 */ sOCConfig.OCMode = TIM_OCMODE_PWM1; sOCConfig.OCPolarity = TIM_OCPOLARITY_LOW; sOCConfig.Pulse = 1; sOCConfig.OCFastMode = TIM_OCFAST_DISABLE ; if (HAL_TIM_PWM_ConfigChannel(&TimDfsdm1Handle, &sOCConfig, TIM_CHANNEL_1) != HAL_OK) { /* Initialization Error */ while(1); }if (HAL_TIM_PWM_ConfigChannel(&TimDfsdm1Handle, &sOCConfig, TIM_CHANNEL_1) != HAL_OK) { ... } if (HAL_TIM_PWM_ConfigChannel(&TimDfsdm1Handle, &sOCConfig, TIM_CHANNEL_2) != HAL_OK) { /* Initialization Error */ while(1); }if (HAL_TIM_PWM_ConfigChannel(&TimDfsdm1Handle, &sOCConfig, TIM_CHANNEL_2) != HAL_OK) { ... } /* Configure TIM4 in Gated slave mode & use the Internal Trigger 0 (ITR1) as trigger source *//* ... */ sSlaveConfig.SlaveMode = TIM_SLAVEMODE_EXTERNAL1; sSlaveConfig.InputTrigger = TIM_TS_ETRF; sSlaveConfig.TriggerPolarity = TIM_TRIGGERPOLARITY_NONINVERTED; sSlaveConfig.TriggerPrescaler = TIM_TRIGGERPRESCALER_DIV1; sSlaveConfig.TriggerFilter = 0; if (HAL_TIM_SlaveConfigSynchronization(&TimDfsdm1Handle, &sSlaveConfig) != HAL_OK) { /* Initialization Error */ while(1); }if (HAL_TIM_SlaveConfigSynchronization(&TimDfsdm1Handle, &sSlaveConfig) != HAL_OK) { ... } }{ ... } /** * @brief TIM MSP Initialization * This function configures the hardware resources used in this example: * - Peripheral's clock enable * - Peripheral's GPIO Configuration * @param htim: TIM handle pointer * @retval None *//* ... */ void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim) { GPIO_InitTypeDef GPIO_InitStruct; /* Enable TIM4, TIM3 clocks */ __HAL_RCC_TIM3_CLK_ENABLE(); __HAL_RCC_TIM4_CLK_ENABLE(); /* Enable GPIOB, GPIOD clocks */ __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLDOWN; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; /* Configure PB.04 (TIM3_Channel1): pin D12 from CN6 */ GPIO_InitStruct.Alternate = GPIO_AF2_TIM3; GPIO_InitStruct.Pin = GPIO_PIN_4; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* Configure PB.05 (TIM3_Channel2): pin D11 from CN6 */ GPIO_InitStruct.Alternate = GPIO_AF2_TIM3; GPIO_InitStruct.Pin = GPIO_PIN_5; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* Configure PB.00 (TIM3_Channel3): pin D6 from CN8 */ GPIO_InitStruct.Alternate = GPIO_AF2_TIM3; GPIO_InitStruct.Pin = GPIO_PIN_0; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* Configure PB.01 (TIM3_Channel4): pin A4 from CN9 */ GPIO_InitStruct.Alternate = GPIO_AF2_TIM3; GPIO_InitStruct.Pin = GPIO_PIN_1; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* Configure PB.06 (TIM4_Channel1) : pin D4 from CN8 */ GPIO_InitStruct.Alternate = GPIO_AF2_TIM4; GPIO_InitStruct.Pin = GPIO_PIN_6; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* Configure PD.13 (TIM4_Channel2) */ GPIO_InitStruct.Alternate = GPIO_AF2_TIM4; GPIO_InitStruct.Pin = GPIO_PIN_13; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); HAL_NVIC_SetPriority(TIM3_IRQn, 0, 0); HAL_NVIC_EnableIRQ(TIM3_IRQn); HAL_NVIC_SetPriority(TIM4_IRQn, 0, 0); HAL_NVIC_EnableIRQ(TIM4_IRQn); }{ ... } /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.