From e8378e832ab736320e9b54dae324519e2a59ddeb Mon Sep 17 00:00:00 2001 From: Kizarm Date: Fri, 18 Oct 2024 14:32:41 +0200 Subject: [PATCH] set system clock to 144MHz --- V203/usb/ch32v203/system.cpp | 15 ++++++--------- V203/usb/ch32v203/system.h | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/V203/usb/ch32v203/system.cpp b/V203/usb/ch32v203/system.cpp index d94ffbe..68818bd 100644 --- a/V203/usb/ch32v203/system.cpp +++ b/V203/usb/ch32v203/system.cpp @@ -10,14 +10,13 @@ enum CLKSRC : uint32_t { static constexpr unsigned HSI_VALUE = 8000000u; /* Value of the Internal oscillator in Hz */ static constexpr unsigned HSE_VALUE = 8000000u; /* Value of the External oscillator in Hz */ /* In the following line adjust the External High Speed oscillator (HSE) Startup Timeout value */ -static constexpr unsigned SYSCLK_FREQ_96MHz_HSE = SYSTEM_CORE_CLOCK; static constexpr unsigned HSE_STARTUP_TIMEOUT = 0x1000u; /* Time out for HSE start up */ // HSE i HSI mají frekvenci 8 MHz static constexpr uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; -uint32_t SystemCoreClock = SYSCLK_FREQ_96MHz_HSE; /* System Clock Frequency (Core Clock) */ +uint32_t SystemCoreClock = SYSTEM_CORE_CLOCK; /* System Clock Frequency (Core Clock) */ -static void SetSysClockTo96_HSE(void) { +static void SetSysClock_HSE(void) { __IO uint32_t StartUpCounter = 0, HSEStatus = 0; RCC.CTLR.B.HSEON = SET; @@ -45,7 +44,7 @@ static void SetSysClockTo96_HSE(void) { */ r.B.PLLSRC = SET; r.B.PLLXTPRE = RESET; - r.B.PLLMUL = 10u; + r.B.PLLMUL = 15u; // or 10u for 96 MHz return r.R; }); /* Enable PLL */ @@ -71,7 +70,7 @@ void SystemInit(void) { RCC.CTLR.R &= 0xFFFBFFFFu; RCC.CFGR0.R &= 0xFF00FFFFu; RCC.INTR.R = 0x009F0000u; - SetSysClockTo96_HSE(); + SetSysClock_HSE(); } /********************************************************************* * @fn SystemCoreClockUpdate @@ -81,7 +80,7 @@ void SystemInit(void) { * @return none */ void SystemCoreClockUpdate (void) { - uint32_t tmp = 0, pllmull = 0, pllsource = 0, Pll_6_5 = 0; + uint32_t tmp = 0, pllmull = 0, pllsource = 0; tmp = RCC.CFGR0.B.SWS; @@ -112,9 +111,6 @@ void SystemCoreClockUpdate (void) { SystemCoreClock = HSE_VALUE * pllmull; } } - - if(Pll_6_5 == 1) SystemCoreClock = (SystemCoreClock / 2); - break; default: SystemCoreClock = HSI_VALUE; @@ -128,6 +124,7 @@ void SystemCoreClockUpdate (void) { static uint32_t p_us = 0u; static bool timeout; void delay_init () { + // default clock is HCLK / 8 p_us = SystemCoreClock / 8000000; } void delay_us (const unsigned dly) { diff --git a/V203/usb/ch32v203/system.h b/V203/usb/ch32v203/system.h index 9a57c76..b44ccf1 100644 --- a/V203/usb/ch32v203/system.h +++ b/V203/usb/ch32v203/system.h @@ -79,7 +79,7 @@ struct SysTick_Type { } }; static SysTick_Type & SysTick = * reinterpret_cast (0xE000F000); -static constexpr unsigned SYSTEM_CORE_CLOCK = 96'000'000u; +static constexpr unsigned SYSTEM_CORE_CLOCK = 144'000'000u; // or 96'000'000u extern "C" { extern uint32_t SystemCoreClock; extern void SystemCoreClockUpdate (void);