#include "clock.h" #include "gd32e23x_rcu.h" static uint32_t delay; /** * @brief * */ void Clock_Config(void) { rcu_deinit(); rcu_osci_on(RCU_IRC8M); //ʹÓÃÄÚ²¿8MRCʱÖÓ rcu_osci_stab_wait(RCU_IRC8M); rcu_system_clock_source_config(RCU_CKSYSSRC_PLL); //sysclk is PLL rcu_pll_config(RCU_PLLSRC_IRC8M_DIV2, RCU_PLL_MUL16); //8MHz/2 =4MHz PLL =4MHz*16 =64MHz rcu_ahb_clock_config(RCU_AHB_CKSYS_DIV1); //AHB 64M rcu_apb1_clock_config(RCU_APB1_CKAHB_DIV1); //APB1 64M rcu_apb2_clock_config(RCU_APB2_CKAHB_DIV1); //APB2 64M rcu_adc_clock_config(RCU_ADCCK_APB2_DIV4); //max 14M,current:64/4=16M rcu_usart_clock_config(RCU_USART0SRC_IRC8M); //USART0 8M rcu_rtc_clock_config(RCU_RTCSRC_NONE); rcu_osci_on(RCU_PLL_CK); rcu_osci_stab_wait(RCU_PLL_CK); SystemCoreClockUpdate(); } /** * @brief * */ void Ostick_config(void) { /* setup systick timer for 1000Hz interrupts */ if (SysTick_Config(SYSTEM_CLOCK / 1000U)) { /* capture error */ while (1) ; } /* configure the systick handler priority */ NVIC_SetPriority(SysTick_IRQn, 0x00); } /*! \brief delay a time in milliseconds \param[in] count: count in milliseconds \param[out] none \retval none */ void delay_1ms(uint32_t count) { delay = count; while (0 != delay) ; } /*! \brief delay decrement \param[in] none \param[out] none \retval none */ void delay_decrement(void) { if (0 != delay) { delay--; } }