Skip to content

8002 Use external crystal oscillator configuration*

1. Find the board level that you want to modify*

  • The 8002b_dev board is used as an example
    • Find lvp_tws/boards/nationalchip/grus_gx8002b_dev_1v/clock_board c , only need to configure this file can use external crystals.

2. Modifying configuration Procedure*

  • The following modifications are made inlvp_tws/boards/nationalchip/grus_gx8002b_dev_1v/clock_board.c Modification in file

2.1 Modifying the clock source*

  • The external clock source is configured by setting the second parameter of the two highlighted lines to 1 and leaving the rest of the lines unchanged
     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
    /******************* CLOCK SOURCE CONFIG *******************/
    static GX_CLOCK_SOURCE_TABLE clk_src_xtal_table[] = {
    /*       id            source      source0            source1     */
        {CLOCK_SOURCE_32K_PLL     , 0}, /* CLOCK_SOURCE_OSC_32K    | CLOCK_SOURCE_XTAL_32K */
        {CLOCK_SOURCE_1M_INPUT    , 0}, /* CLOCK_SOURCE_PDM_IN     | CLOCK_SOURCE_PWM_IN   */
        {CLOCK_SOURCE_1M          , 0}, /* CLOCK_SOURCE_OSC_1M     | CLOCK_SOURCE_1M_INPUT */
        {CLOCK_SOURCE_OSC_PLL     , 0}, /* CLOCK_SOURCE_32K_PLL    | CLOCK_SOURCE_1M       */
    
        {CLOCK_SOURCE_PIN_IN      , 1}, /* CLOCK_SOURCE_AUDIO_MCLK | CLOCK_SOURCE_PWM_IN   */
        {CLOCK_SOURCE_24M         , 1}, /* CLOCK_SOURCE_OSC_24M    | CLOCK_SOURCE_PIN_IN   */
        {CLOCK_SOURCE_PLL_DTO     , 0}, /* CLOCK_SOURCE_OSC_PLL    | CLOCK_SOURCE_PIN_IN   */
    
        {CLOCK_SOURCE_1M_12M      , 1}, /* CLOCK_SOURCE_OSC_24M    | CLOCK_SOURCE_1M       */
        {CLOCK_SOURCE_24M_PLL     , 0}, /* CLOCK_SOURCE_24M        | CLOCK_SOURCE_PLL_DTO  */
        {CLOCK_SOURCE_32K         , 0}, /* CLOCK_SOURCE_OSC_32K    | CLOCK_SOURCE_XTAL_32K */
    };
    
    /******************* CLOCK SOURCE CONFIG *******************/
    static GX_CLOCK_SOURCE_TABLE clk_src_osc_table[] = {
    /*       id            source      source0            source1     */
        {CLOCK_SOURCE_32K_PLL     , 1}, /* CLOCK_SOURCE_OSC_32K    | CLOCK_SOURCE_XTAL_32K */
        {CLOCK_SOURCE_1M_INPUT    , 0}, /* CLOCK_SOURCE_PDM_IN     | CLOCK_SOURCE_PWM_IN   */
        {CLOCK_SOURCE_1M          , 0}, /* CLOCK_SOURCE_OSC_1M     | CLOCK_SOURCE_1M_INPUT */
        {CLOCK_SOURCE_OSC_PLL     , 0}, /* CLOCK_SOURCE_32K_PLL    | CLOCK_SOURCE_1M       */
    
        {CLOCK_SOURCE_PIN_IN      , 0}, /* CLOCK_SOURCE_AUDIO_MCLK | CLOCK_SOURCE_PWM_IN   */
        {CLOCK_SOURCE_24M         , 0}, /* CLOCK_SOURCE_OSC_24M    | CLOCK_SOURCE_PIN_IN   */
        {CLOCK_SOURCE_PLL_DTO     , 0}, /* CLOCK_SOURCE_OSC_PLL    | CLOCK_SOURCE_PIN_IN   */
    
        {CLOCK_SOURCE_1M_12M      , 1}, /* CLOCK_SOURCE_OSC_24M/2  | CLOCK_SOURCE_1M       */
        {CLOCK_SOURCE_24M_PLL     , 1}, /* CLOCK_SOURCE_24M        | CLOCK_SOURCE_PLL_DTO  */
        {CLOCK_SOURCE_32K         , 1}, /* CLOCK_SOURCE_OSC_32K    | CLOCK_SOURCE_XTAL_32K */
    };
    

2.2 Enable clock*

  • To enable the external crystal oscillator, locate the clk_init interface
  • Add the code to enable external crystal at the beginning of the interface ( as in the first highlighted part ) and mask the code to turn off external crystal ( as in the second highlighted part ).

notice

The position of the enabled and disabled code does not change, such as the example modification, the enabled code must be first.

 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
void clk_init(void)
{
    //open 32k xtal
    *(volatile int*)0xa0005084 |= (1<<0);   // Enable external crystal oscillator
    GX_START_MODE start_mode = gx_pmu_get_start_mode();

    ...
    ...

    _clk_mod_normal_init();

    _clk_pmu_normal_div_dto();

    _clk_mcu_normal_div_dto();

    if (start_mode == GX_START_MODE_SRAM) {
        for (int module = CLOCK_MODULE_AUDIO_PLAY; module < CLOCK_MODULE_MAX; module++)
            gx_clock_set_module_enable(module, (s_clk_mod_gate >> module) & 0x1);
    }

    gx_clock_set_module_enable(CLOCK_MODULE_HW_I2C, 1);
    //close 32k xtal
    // *(volatile int*)0xa0005084 &= ~(1<<0);   // Mask the code that turns off the clock

    //close 24M osc
    *(volatile int*)0xa0005060 &= ~(1<<1);

    // flash power down
    //*(volatile int*)0xa000003c = 1;

#ifdef CONFIG_ENABLE_BYPASS_CORE_LDO
    gx_analog_set_ldo_dig_ctrl(LDO_SW_CTRL_BYPASS);

#else

    ...
    ...
}