Skip to content
Snippets Groups Projects
Commit c01ffcd2 authored by Alexander Mandera's avatar Alexander Mandera
Browse files

Add 80MHz init for V103

parent bcaf9581
No related branches found
No related tags found
No related merge requests found
...@@ -1352,6 +1352,65 @@ void SystemInit72HSE( void ) ...@@ -1352,6 +1352,65 @@ void SystemInit72HSE( void )
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) {} while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) {}
} }
void SystemInit80HSI( void )
{
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
/* Enable Prefetch Buffer */
FLASH->ACTLR |= FLASH_ACTLR_PRFTBE;
/* Flash 1 wait state */
FLASH->ACTLR &= (uint32_t)((uint32_t)~FLASH_ACTLR_LATENCY);
FLASH->ACTLR |= (uint32_t)FLASH_ACTLR_LATENCY_1;
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_PLLMULL10);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0) {}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) {}
}
void SystemInit80HSE( void )
{
RCC->CTLR |= ((uint32_t)RCC_HSEON);
while(!(RCC->CTLR&RCC_HSERDY));
/* Enable Prefetch Buffer */
FLASH->ACTLR |= FLASH_ACTLR_PRFTBE;
/* Flash 2 wait state */
FLASH->ACTLR &= (uint32_t)((uint32_t)~FLASH_ACTLR_LATENCY);
FLASH->ACTLR |= (uint32_t)FLASH_ACTLR_LATENCY_2;
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_HSE | RCC_PLLMULL10);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0) {}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) {}
}
#endif // defined(CH32V10x) #endif // defined(CH32V10x)
#ifdef CH32V003 #ifdef CH32V003
......
...@@ -12173,6 +12173,8 @@ void SystemInit144HSE( void ); ...@@ -12173,6 +12173,8 @@ void SystemInit144HSE( void );
// Initialization functions // Initialization functions
void SystemInit72HSI( void ); void SystemInit72HSI( void );
void SystemInit72HSE( void ); void SystemInit72HSE( void );
void SystemInit80HSI( void );
void SystemInit80HSE( void );
   
#endif #endif
   
......
// Could be defined here, or in the processor defines. // Could be defined here, or in the processor defines.
#define SYSTEM_CORE_CLOCK 72000000 #define SYSTEM_CORE_CLOCK 80000000
#include "ch32v003fun.h" #include "ch32v003fun.h"
#include <stdio.h> #include <stdio.h>
int main() int main()
{ {
SystemInit72HSE(); SystemInit80HSE();
// Enable GPIOs // Enable GPIOs
//RCC->APB2PCENR |= RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOC; //RCC->APB2PCENR |= RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOC;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment