cancel
Showing results for 
Search instead for 
Did you mean: 

How to correctly change the system clock frequency during work?

xhan.11
Associate II

HI:

Due to special needs, the system clock frequency needs to be changed during work, switching between 72M and 48M.

Using STM32F103, the USB CDC Virtual COM Port cannot function properly after switching the clock.Using STM32F407 to dynamically change the system frequency, the entire function of the chip is working normally. No issues similar to STM32F103 have occurred.

The important thing is that the USB CDC Virtual COM Port is broken. STM32F103 is still running. After switching the frequency, there is a program that lights up the LED, which is working.

Computer Device Manager reports an error:Device Not Migrated due to Partial or Ambiguous Match.Windows has stopped this device Code 43.

thanks

My code(F103):

__HAL_RCC_SYSCLK_CONFIG(RCC_SYSCLKSOURCE_HSE);  

__HAL_RCC_PLL_DISABLE();         

                            

switch(UserRxBufferFS[i + 2])

                {   

                   case 0:

                                __HAL_RCC_PLL_CONFIG( RCC_PLLSOURCE_HSE,RCC_PLL_MUL9);    

                                __HAL_RCC_USB_CONFIG( RCC_USBCLKSOURCE_PLL_DIV1_5);

                                break;    

                     case 1:

                                __HAL_RCC_PLL_CONFIG( RCC_PLLSOURCE_HSE,RCC_PLL_MUL6);     

                                __HAL_RCC_USB_CONFIG( RCC_USBCLKSOURCE_PLL);

                                break;    

                  }

                 __HAL_RCC_PLL_ENABLE();   

                  /* Wait till PLL is ready */ 

                while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)

                  {

                   }

                    // SystemClock_Config();

                     /* Select PLL as system clock source */

                   __HAL_RCC_SYSCLK_CONFIG(RCC_SYSCLKSOURCE_PLLCLK);  

  My code(F407):

__HAL_RCC_SYSCLK_CONFIG(RCC_SYSCLKSOURCE_HSE);                

__HAL_RCC_PLL_DISABLE();                                                

 switch(UserRxBufferFS[i + 2])

  {

          case 0:

            __HAL_RCC_PLL_CONFIG( RCC_PLLSOURCE_HSE,4,168,RCC_PLLP_DIV2,7);    

                   break;    

            //.......

         case 4:

                   __HAL_RCC_PLL_CONFIG( RCC_PLLSOURCE_HSE,4, 72,RCC_PLLP_DIV2,3);     

                   break;   

//..............

  }

   __HAL_RCC_PLL_ENABLE();                                      

   /* Wait till PLL is ready */ 

    while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)

    {

}

     // SystemClock_Config();

     /* Select PLL as system clock source */

      __HAL_RCC_SYSCLK_CONFIG(RCC_SYSCLKSOURCE_PLLCLK);       

     }

1 REPLY 1
Bubbles
ST Employee

Hi @xhan.1​,

In case of the STM32F1 you simply need to reconfigure the USART with another BRR value.

With most newer MCU you'd simply have another clock for USART and different for the system, but the F1 is old and simple design.

BR,

J

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.