diff --git a/ch32v003fun/ch32v003fun.c b/ch32v003fun/ch32v003fun.c index 66c96cce690b99c2e8beaa531b9259081bb14711..0d3812687d89ded516bf9f7b54b3d5f21506fa86 100644 --- a/ch32v003fun/ch32v003fun.c +++ b/ch32v003fun/ch32v003fun.c @@ -807,10 +807,10 @@ asm volatile( void SystemInit48HSI( void ) { // Values lifted from the EVT. There is little to no documentation on what this does. - RCC->CTLR = RCC_HSION | RCC_PLLON; // Use HSI, but enable PLL. - RCC->CFGR0 = RCC_HPRE_DIV1 | RCC_PLLSRC_HSI_Mul2; // PLLCLK = HSI * 2 = 48 MHz; HCLK = SYSCLK = APB1 - FLASH->ACTLR = FLASH_ACTLR_LATENCY_1; // 1 Cycle Latency - RCC->INTR = 0x009F0000; // Clear PLL, CSSC, HSE, HSI and LSI ready flags. + RCC->CFGR0 = RCC_HPRE_DIV1 | RCC_PLLSRC_HSI_Mul2; // PLLCLK = HSI * 2 = 48 MHz; HCLK = SYSCLK = APB1 + RCC->CTLR = RCC_HSION | RCC_PLLON | ((HSITRIM) << 3); // Use HSI, but enable PLL. + FLASH->ACTLR = FLASH_ACTLR_LATENCY_1; // 1 Cycle Latency + RCC->INTR = 0x009F0000; // Clear PLL, CSSC, HSE, HSI and LSI ready flags. // From SetSysClockTo_48MHZ_HSI while((RCC->CTLR & RCC_PLLRDY) == 0); // Wait till PLL is ready diff --git a/ch32v003fun/ch32v003fun.h b/ch32v003fun/ch32v003fun.h index 9f0e97aa83bbf2d550ad5bb1735be074a081b745..628640f1b3e861f855d1b11a3c17c531a1787571 100644 --- a/ch32v003fun/ch32v003fun.h +++ b/ch32v003fun/ch32v003fun.h @@ -56,6 +56,9 @@ extern "C" { #define HSI_VALUE ((uint32_t)24000000) /* Value of the Internal oscillator in Hz */ +#ifndef HSITRIM + #define HSITRIM 0x10 +#endif /* Interrupt Number Definition, according to the selected device */ typedef enum IRQn