How to correctly change the system clock frequency during work?
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);
}
