Skip to content

Commit 3955f72

Browse files
committed
Nicla Vision: make PDM frequency actually configurable
1 parent 0c04207 commit 3955f72

File tree

1 file changed

+4
-4
lines changed
  • libraries/PDM/src/nicla_vision

1 file changed

+4
-4
lines changed

libraries/PDM/src/nicla_vision/audio.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ void dfsdm_init()
279279
HAL_GPIO_Init(AUDIO_DFSDM1_D1_PORT, &GPIO_InitStruct);
280280
}
281281

282-
static int DFSDM_Init(void)
282+
static int DFSDM_Init(uint32_t frequency)
283283
{
284284
__HAL_DFSDM_CHANNEL_RESET_HANDLE_STATE(&hdfsdm1_channel2);
285285
hdfsdm1_channel2.Instance = DFSDM1_Channel2;
@@ -292,7 +292,7 @@ static int DFSDM_Init(void)
292292
hdfsdm1_channel2.Init.SerialInterface.Type = DFSDM_CHANNEL_SPI_RISING;
293293
hdfsdm1_channel2.Init.SerialInterface.SpiClock = DFSDM_CHANNEL_SPI_CLOCK_INTERNAL;
294294
hdfsdm1_channel2.Init.Awd.FilterOrder = DFSDM_CHANNEL_FASTSINC_ORDER;
295-
hdfsdm1_channel2.Init.Awd.Oversampling = 125; /* 2MHz/125 = 16kHz */
295+
hdfsdm1_channel2.Init.Awd.Oversampling = 2000000/frequency; /* 2MHz/125 = 16kHz */
296296
hdfsdm1_channel2.Init.Offset = 0;
297297
hdfsdm1_channel2.Init.RightBitShift = 0;
298298
if(HAL_OK != HAL_DFSDM_ChannelInit(&hdfsdm1_channel2))
@@ -311,7 +311,7 @@ static int DFSDM_Init(void)
311311
hdfsdm1_filter0.Init.InjectedParam.ExtTrigger = DFSDM_FILTER_EXT_TRIG_TIM1_TRGO;
312312
hdfsdm1_filter0.Init.InjectedParam.ExtTriggerEdge = DFSDM_FILTER_EXT_TRIG_RISING_EDGE;
313313
hdfsdm1_filter0.Init.FilterParam.SincOrder = DFSDM_FILTER_FASTSINC_ORDER;
314-
hdfsdm1_filter0.Init.FilterParam.Oversampling = 125; /* 2MHz/125 = 16kHz */
314+
hdfsdm1_filter0.Init.FilterParam.Oversampling = 2000000/frequency; /* 2MHz/125 = 16kHz */
315315
hdfsdm1_filter0.Init.FilterParam.IntOversampling = 1;
316316
if(HAL_OK != HAL_DFSDM_FilterInit(&hdfsdm1_filter0))
317317
{
@@ -363,7 +363,7 @@ int py_audio_init(size_t channels, uint32_t frequency)
363363

364364
dfsdm_init();
365365

366-
if (!DFSDM_Init()) {
366+
if (!DFSDM_Init(frequency)) {
367367
return 0;
368368
}
369369

0 commit comments

Comments
 (0)