How to enable QN902X watchdog and set its timer?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to enable QN902X watchdog and set its timer?

1,863 Views
tedwu1
Contributor III

Hello,

My project uses the MCU of QN9021 and SDK 1.0.0. I define CFG_9020_B2 at usr_config.h

I saw some defines at this file like following.

/// ADV watchdog timer
#if (defined(CFG_9020_B0))
#define CFG_ADV_WDT
#endif

Can CFG_9020_B2 use watchdog? Now I want to turn on the watchdog and set a specific timer. How to enable QN902X watchdog and set its timer? Do anyone has an example code? Will Watchdog have any adverse effects in MCU deep sleep? Will it wake up the MCU in deep sleep?

Thank you in advance.

Ted Wu

0 Kudos
9 Replies

1,776 Views
tedwu1
Contributor III

Hi @mario_castaneda 

I ported the project you mentioned of C:\nxp\QN902x_SDK_1.4.0\Projects\Driver\wdt to my project. The watchdog doesn't not work properly if my program enter sleep then it wake up. How to make the watchdog works properly? My project with BLE and It needs to go to sleep to save power consumption.

Thank you very much.
Ted Wu

0 Kudos

1,722 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi @tedwu1,

Did you check the next BLE example?

C:\nxp\QN902x_SDK_1.4.0\Projects\BLE\prj_ancsc

The example implements the wdt, please define the next define in the usr.config.h file

//[MC]
#define QN_ADV_WDT 1

Regards,

Mario

0 Kudos

1,699 Views
tedwu1
Contributor III

Hi @mario_castaneda 

Yes, I ported these code about watchdog to my project and add the code "#define QN_ADV_WDT" at the file of usr_config.h. But the problem of watchdog sleeping still exists.

Thank you very much.

Ted Wu

 

0 Kudos

1,789 Views
tedwu1
Contributor III

Hi @mario_castaneda 

 

Why are all my reply messages deleted? I ported the project you mentioned of C:\nxp\QN902x_SDK_1.4.0\Projects\Driver\wdt to my project. The watchdog doesn't not work properly if my program enter sleep then it wake up. How to make the watchdog works properly? My project with BLE and It needs to go to sleep to save power consumption.

Thank you very much.
Ted Wu

0 Kudos

1,810 Views
tedwu1
Contributor III

Hi @mario_castaneda 

Yes, it still has problems. I ported the project you mentioned to my project as the previous post. The watchdog becomes invalid when the MCU enters sleep mode then it wakes up. The watchdog works correctly if I don't let the MCU enter sleep. How to make the MCU wake up and the watchdog can still work correctly?

Thank you for your support.

Ted Wu

0 Kudos

1,822 Views
tedwu1
Contributor III

Hi @mario_castaneda 

Yes, I download the SDK_140 and porting it to my project as last post. The project of C:\nxp\QN902x_SDK_1.4.0\Projects\Driver\wdt is no BLE firmware. My project is BLE project and the code snippet is as previous post. The watchdog cannot reset the system if I #define SLEEP_TEST 1. But The watchdog reset the system if I comment "#define SLEEP_TEST 1". It seems enter sleep will disable the watchdog function. How to enable watchdog function when the system wake up? Can CFG_9020_B2 use watchdog function?

Thank you.

Ted Wu

0 Kudos

1,827 Views
tedwu1
Contributor III

Hi Mario,

My system has 2 MCU. One is QN9021 and the other is FXTH8709. FXTH8709  will send data to QN9021 through I2C if FXTH8709 got LF (125KHz) data. And QN9021 send i-beacon out.

My code snippet is as follows. The watchdog cannot reset the system if I #define SLEEP_TEST 1. But The watchdog reset the system if I comment "#define SLEEP_TEST 1". It seems enter sleep will disable the watchdog function. How to enable watchdog function when the system wake up?

Thanks

Ted Wu

 

At the file of app_config.h, enable watchdog
/// ADV watchdog timer
//#if (defined(CFG_ADV_WDT))
#define QN_ADV_WDT
//#endif

At the file of app_util.h
uint8_t app_set_adv_data(uint16_t disc_mode)
{
    uint8_t len;
    //lock system for test
    while(1)
    {}	
    if (GAP_BROADCASTER == (disc_mode & GAP_BROADCASTER))	// beacon mode
    {
....

At the file of usr_design.h
void usr_sleep_restore(void)
{
#if QN_DBG_PRINT
    uart_init(QN_DEBUG_UART, USARTx_CLK(0), UART_9600);
    uart_tx_enable(QN_DEBUG_UART, MASK_ENABLE);
    uart_rx_enable(QN_DEBUG_UART, MASK_ENABLE);
#endif
#if (defined(QN_ADV_WDT))
    if(usr_env.adv_wdt_enable)
    {
        wdt_init(65536, WDT_INT_MOD); // 2s
    }
#endif
}

At the file of app_main.h
#define SLEEP_TEST  1
int main(void)
{
    int ble_sleep_st, usr_sleep_st;
    // DC-DC
    dc_dc_enable(QN_DC_DC_ENABLE);
    rf_tx_power_level_set (TX_GAIN_LEVLE12); // 4dbm
    // QN platform initialization
#if QN_NVDS_WRITE
    plf_init(QN_POWER_MODE, __XTAL, QN_32K_RCO, nvds_tmp_buf, NVDS_TMP_BUF_SIZE);
#else
    plf_init(QN_POWER_MODE, __XTAL, QN_32K_RCO, NULL, 0);
#endif
#if (defined(QN_9020_B1) && (!QN_PMU_VOLTAGE))
    disable_patch_b1();
#endif
    // System initialization, user configuration
    SystemInit();
    wdt_init(65536, WDT_RESET_MOD); // 2s
    // Profiles register
#if (QN_WORK_MODE != WORK_MODE_HCI)
    prf_register();
#endif
        button_init();
        // Work mode defined in the usr_config.h
        ble_init((enum WORK_MODE)QN_WORK_MODE, QN_HCI_UART, QN_HCI_UART_RD, QN_HCI_UART_WR, ble_heap, BLE_HEAP_SIZE, QN_BLE_SLEEP);
    set_max_sleep_duration(QN_BLE_MAX_SLEEP_DUR);
    // If QN902x works on wireless SoC mode, initialize APP task
#if (QN_WORK_MODE == WORK_MODE_SOC)
    app_init();
#endif

    usr_init();
    sleep_init();
    wakeup_by_sleep_timer(__32K_TYPE);
    GLOBAL_INT_START();
    QPRINTF("power on\r\n");
    while(1)
    {
// comment it for test
//        wdt_set(65536); // 2s
        ke_schedule();

        // Checks for sleep have to be done with interrupt disabled
        GLOBAL_INT_DISABLE_WITHOUT_TUNER();

        // Check whether the chip can enters sleep mode
        //
        // Chip enter sleep condition:
        // +--------+--------+--------+--------+--------+
        // |    USR |        |        |        |        |
        // | BLE    | ACTIVE | IDLE   | SLEEP  | DEEP   |
        // +--------+--------+--------+--------+--------+
        // | ACTIVE | active | active | active | active |
        // | IDLE   | active | idle   | idle   | idle   |
        // | SLEEP  | active | idle   | sleep  | deep   |
        // +--------+--------+--------+--------+--------+
#ifdef SLEEP_TEST
        // Obtain the status of the user program
        usr_sleep_st = usr_sleep();

        // If the user program can be sleep or deep sleep then check ble status
        if(usr_sleep_st != PM_ACTIVE)
        {
            // Obtain the status of ble sleep mode
            ble_sleep_st = ble_sleep(usr_sleep_st);

            // Check if the processor clock can be gated
            if(((ble_sleep_st == PM_IDLE) || (usr_sleep_st == PM_IDLE))
             && (ble_sleep_st != PM_ACTIVE))
            {
                enter_sleep(SLEEP_CPU_CLK_OFF,
                            WAKEUP_BY_ALL_IRQ_SOURCE,
                            NULL);
            }

            // Check if the processor can be power down
            else if((ble_sleep_st == PM_SLEEP) && (usr_sleep_st == PM_SLEEP))
            {
                enter_sleep(SLEEP_NORMAL,
                            (WAKEUP_BY_OSC_EN | WAKEUP_BY_GPIO),
                            sleep_cb);
            }

            // Check if the system can be deep sleep
            else if((ble_sleep_st == PM_SLEEP) && (usr_sleep_st == PM_DEEP_SLEEP))
            {
                enter_sleep(SLEEP_DEEP,
                            WAKEUP_BY_GPIO,
                            sleep_cb);
            }
        }
#endif
        // Checks for sleep have to be done with interrupt disabled
        GLOBAL_INT_RESTORE_WITHOUT_TUNER();
    }
}

 

 

0 Kudos

1,846 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi @tedwu1,

 

Please look at the watchdog example. You can download the last SDK that we provide on our web page.

QN9020 SDK

C:\nxp\QN902x_SDK_1.4.0\Projects\Driver\wdt

Let me know if you have any further questions.

Regards,

Mario

0 Kudos

1,767 Views
tedwu1
Contributor III

Hi @mario_castaneda 

I ported the project you mentioned of C:\nxp\QN902x_SDK_1.4.0\Projects\Driver\wdt to my project. The watchdog doesn't not work properly if my program enter sleep then it wake up. How to make the watchdog works properly? My project with BLE and It needs to go to sleep to save power consumption.

Thank you very much.
Ted Wu

0 Kudos