RISC-V/ch32v003/system.cpp
2024-02-29 12:22:16 +01:00

24 lines
573 B
C++

#include "CH32V00xxx.h"
extern "C" void SystemInit ();
enum CLKSRC : uint32_t {
CLK_HSI = 0u,
CLK_HSE,
CLK_PLL,
};
void SystemInit(void) {
RCC.CFGR0.R = 0u; // prescaler OFF
RCC.CTLR.modify([](RCC_Type::CTLR_DEF & r) -> auto {
r.B.HSITRIM = 0x10u;
r.B.HSION = SET;
r.B.HSEBYP = SET;
r.B.CSSON = SET;
r.B.PLLON = SET;
return r.R;
});
FLASH.ACTLR.B.LATENCY = SET;
RCC.INTR.R = 0x009F0000u; // clear interrupts
while (RCC.CTLR.B.PLLRDY == RESET);
RCC.CFGR0.B.SW = CLK_PLL;
while (RCC.CFGR0.B.SWS != CLK_PLL);
}