tao_z
2021-06-30 945ba42f7550d5a203e43d82b43ed82dc981d9e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
 
#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_MUL12); //8MHz/2 =4MHz  PLL =4MHz*12 =48MHz
    rcu_ahb_clock_config(RCU_AHB_CKSYS_DIV1);             //AHB 48M
    rcu_apb1_clock_config(RCU_APB1_CKAHB_DIV1);           //APB1 48M
    rcu_apb2_clock_config(RCU_APB2_CKAHB_DIV1);           //APB2 48M
    rcu_adc_clock_config(RCU_ADCCK_APB2_DIV4);            //max 14M,current:48/4=12M
    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--;
    }
}