From bf7a62055ec829f00bd9c3a129e327b6a67ac55b Mon Sep 17 00:00:00 2001 From: Jie Feng Date: Sat, 25 Jul 2026 11:37:33 +0800 Subject: Run APM32F0 CPU and USB from 48 MHz PLL --- hw/bsp/apm32f0xx/family.c | 18 +++++------------- hw/bsp/apm32f0xx/family.cmake | 1 - hw/bsp/apm32f0xx/family.mk | 1 - 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/hw/bsp/apm32f0xx/family.c b/hw/bsp/apm32f0xx/family.c index 9caa0207c..643490797 100644 --- a/hw/bsp/apm32f0xx/family.c +++ b/hw/bsp/apm32f0xx/family.c @@ -32,7 +32,6 @@ #include "apm32f0xx_rcm.h" #include "apm32f0xx_gpio.h" #include "apm32f0xx_misc.h" -#include "apm32f0xx_crs.h" #include "bsp/board_api.h" #include "board.h" @@ -56,18 +55,11 @@ void USBD_IRQHandler(void) { // Board Init //--------------------------------------------------------------------+ void board_init(void) { - // Enable HSI48 for USB clock - RCM_EnableHSI48(); - while (RCM_ReadStatusFlag(RCM_FLAG_HSI48RDY) == RESET) {} - - // Select HSI48 as USB clock source - RCM_ConfigUSBCLK(RCM_USBCLK_HSI48); - - // Enable CRS for automatic HSI48 calibration from USB SOF - RCM_EnableAPB1PeriphClock(RCM_APB1_PERIPH_CRS); - CRS_ConfigSynchronizationSource(CRS_SYNC_SOURCE_USB); - CRS_EnableAutomaticCalibration(); - CRS_EnableFrequencyErrorCounter(); + // Configure HSE and PLL for a 48 MHz system clock + SystemClockConfig(); + + // Route the 48 MHz PLL clock to USB + RCM_ConfigUSBCLK(RCM_USBCLK_PLLCLK); // Enable USB peripheral clock RCM_EnableAPB1PeriphClock(RCM_APB1_PERIPH_USB); diff --git a/hw/bsp/apm32f0xx/family.cmake b/hw/bsp/apm32f0xx/family.cmake index 0cf199f26..199ba7cb5 100644 --- a/hw/bsp/apm32f0xx/family.cmake +++ b/hw/bsp/apm32f0xx/family.cmake @@ -31,7 +31,6 @@ function(family_add_board BOARD_TARGET) ${APM32_SDK}/APM32F0xx_StdPeriphDriver/src/apm32f0xx_gpio.c ${APM32_SDK}/APM32F0xx_StdPeriphDriver/src/apm32f0xx_misc.c ${APM32_SDK}/APM32F0xx_StdPeriphDriver/src/apm32f0xx_rcm.c - ${APM32_SDK}/APM32F0xx_StdPeriphDriver/src/apm32f0xx_crs.c ) target_include_directories(${BOARD_TARGET} PUBLIC ${CMAKE_CURRENT_FUNCTION_LIST_DIR} diff --git a/hw/bsp/apm32f0xx/family.mk b/hw/bsp/apm32f0xx/family.mk index 735c83f90..7e26918c2 100644 --- a/hw/bsp/apm32f0xx/family.mk +++ b/hw/bsp/apm32f0xx/family.mk @@ -20,7 +20,6 @@ SRC_C += \ $(APM32_SDK)/APM32F0xx_StdPeriphDriver/src/apm32f0xx_gpio.c \ $(APM32_SDK)/APM32F0xx_StdPeriphDriver/src/apm32f0xx_misc.c \ $(APM32_SDK)/APM32F0xx_StdPeriphDriver/src/apm32f0xx_rcm.c \ - $(APM32_SDK)/APM32F0xx_StdPeriphDriver/src/apm32f0xx_crs.c \ $(APM32_SDK)/Device/Geehy/APM32F0xx/Source/system_apm32f0xx.c INC += \ -- cgit v1.3.1