From 2e801412cced0d52508bf2d9b936f082b52dc5bb Mon Sep 17 00:00:00 2001
From: Alexander Mandera <alexander@mandera.eu>
Date: Thu, 22 Jun 2023 14:17:27 +0200
Subject: [PATCH] Use 144 MHz HSI

---
 ch32v203fun/ch32v203fun.c   | 5 ++---
 ch32v203fun/ch32v203fun.h   | 2 +-
 examples_v203/blink/blink.c | 8 ++++----
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/ch32v203fun/ch32v203fun.c b/ch32v203fun/ch32v203fun.c
index fb4e9ca..e95da26 100644
--- a/ch32v203fun/ch32v203fun.c
+++ b/ch32v203fun/ch32v203fun.c
@@ -905,14 +905,13 @@ void handle_reset( void )
 "	mret\n" : : [main]"r"(main) );
 }
 
-void SystemInit48HSI( void )
+void SystemInit144HSI( void )
 {
 	EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
 
 	RCC->CFGR0 = RCC_HPRE_DIV1 | RCC_PPRE2_DIV1 | RCC_PPRE1_DIV2;
 	RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
-	RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL6);
-	RCC->INTR = 0x009F0000;
+	RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL18);
 
 	/* Enable PLL */
 	RCC->CTLR |= RCC_PLLON;
diff --git a/ch32v203fun/ch32v203fun.h b/ch32v203fun/ch32v203fun.h
index eea1d52..17fbddb 100644
--- a/ch32v203fun/ch32v203fun.h
+++ b/ch32v203fun/ch32v203fun.h
@@ -7368,7 +7368,7 @@ int main() __attribute__((used));
 void SystemInit(void) __attribute__((used));
 
 // Initialization functions
-void SystemInit48HSI( void );
+void SystemInit144HSI( void );
 
 // TODO: Debug and UART
 
diff --git a/examples_v203/blink/blink.c b/examples_v203/blink/blink.c
index 0610d47..1b9bf74 100644
--- a/examples_v203/blink/blink.c
+++ b/examples_v203/blink/blink.c
@@ -1,12 +1,12 @@
 // Could be defined here, or in the processor defines.
-#define SYSTEM_CORE_CLOCK 48000000
+#define SYSTEM_CORE_CLOCK 144000000
 
 #include "ch32v203fun.h"
 #include <stdio.h>
 
 int main()
 {
-	SystemInit48HSI();
+	SystemInit144HSI();
 
 	// Enable GPIOs
 	//RCC->APB2PCENR |= RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOC;
@@ -19,8 +19,8 @@ int main()
 	while(1)
 	{
 		GPIOA->BSHR = (1<<15);	 // Turn on GPIO
-		Delay_Ms( 250 );
+		Delay_Ms( 1000 );
 		GPIOA->BSHR = (1<<(16+15)); // Turn off GPIO
-		Delay_Ms( 250 );
+		Delay_Ms( 1000 );
 	}
 }
-- 
GitLab