Skip to main content
Explorer II
May 20, 2024
Solved

DFSDM change clock divider at runtime

  • May 20, 2024
  • 1 reply
  • 1973 views

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:

  1. Deinit the filter and channel.
  2. Change the clock divider
  3. 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

    This topic has been closed for replies.
    Best answer by AScha.3

    from rm :

    AScha3_0-1716201922863.png

    So set ..try:

    hdfsdm1_channel2.Instance->CHCFGR1 &= 0x7FFFFFFF ; // dfs off
    hdfsdm1_channel2.Instance->CHCFGR1 = (hdfsdm1_channel2.Instance->CHCFGR1 & 0xFF00FFFF)|0x00130000 ;
    hdfsdm1_channel2.Instance->CHCFGR1 |= 0x80000000 ; // dfs on

    1 reply

    Super User
    May 20, 2024

    Hi,

    i didnt much with DFSDM1 ....

     

    You OR your new value (20) to the old (is ? bigger ?) , so maybe still the bigger value stays there.

    +

    but did you try just to write your new clock setting to CHCFGR1 ?

    about like this:

     

     

    hdfsdm1_channel2.Instance->CHCFGR1 = (hdfsdm1_channel2.Instance->CHCFGR1 & 0xFF00FFFF)|0x00130000 ;

     

     

     

     

     

    WolframGAuthor
    Explorer II
    May 20, 2024

    Thank you for your input.
    I have tried your suggested way in setting the register. However, the clock remains unchanged.
    Is there some way I need to restart it using the new values or are they constantly read from the register?

    AScha.3Answer
    Super User
    May 20, 2024

    from rm :

    AScha3_0-1716201922863.png

    So set ..try:

    hdfsdm1_channel2.Instance->CHCFGR1 &= 0x7FFFFFFF ; // dfs off
    hdfsdm1_channel2.Instance->CHCFGR1 = (hdfsdm1_channel2.Instance->CHCFGR1 & 0xFF00FFFF)|0x00130000 ;
    hdfsdm1_channel2.Instance->CHCFGR1 |= 0x80000000 ; // dfs on