DFSDM change clock divider at runtime
Hello,
I am trying to change the clock divider of my DFSDM channel at runtime. What I try to achieve with this is starting my microphone in standard mode and then increasing the clock rate to go into performance mode. This procedure is recommended by the manufacturer.
The auto generated code to initialize the DFSDM first initializes the filters, then the channels, while setting all the parameters I defined in CubeIDE. Based on that I was trying to:
- Deinit the filter and channel.
- Change the clock divider
- Re-Init the filter and channel with the new settings.
My issue is that within the Msp methods HAL_DFSDM_FilterMspDeInit and HAL_DFSDM_ChannelMspDeInit some flags are used. When I deinitialize channel and filter the flag for DFSDM1_Init "underflows" and jumps to max value since its unsigned. Since all of the Msp init methods check for if(DFSDM1_Init == 0) they wont execute anymore afterwards. Therefore I am left without a clock. Is there a specific order?
I also tried setting the clock divider directly using:
__HAL_RCC_DFSDM1_CLK_DISABLE();
hdfsdm1_channel2.Init.OutputClock.Divider = 20;
hdfsdm1_channel2.Instance->CHCFGR1 |= (uint32_t)((hdfsdm1_channel2.Init.OutputClock.Divider - 1U) <<
DFSDM_CHCFGR1_CKOUTDIV_Pos);
__HAL_RCC_DFSDM1_CLK_ENABLE();
This deactivated my clock, changed the divider and re-enabled the clock. However, the clock I measured with the oscilloscope stayed unchanged. So the divider is not applied. What am I missing?
Any help in this is greatly appreciated.
Kind regards
Wolf

