This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

watchdog does not reset when program get stuck in ' NRF_BREAKPOINT_COND; ' while in debug mode

hello Nordic

i work with nrf52832, sdk 16, s132.

I set a watchdog but when i try to create a fault by adding breakpoints after ble starts scanning then i get stuck in the '   NRF_BREAKPOINT_COND; ' but the watchdog does not restart.

can something like that happen in real run when not in debug mode ?? and if so then how can i protect my program from getting stuck ??

is it related to interrupt priority or something like that ??

also, i read somewhere that the softdevice has a watchdog of its own, so is there really a point on implementing my own watchdog ??

best regards

Ziv

  • Hello Ziv,

    Depending on the configuration, the WDT can be paused when your debugger halts on NRF_BREAKPOINT_COND. This can only happen in debug mode, please check out the register description here for more details: CONFIG

     The Softdevice does not implement a Watchdog.

    Best regards,

    Vidar

  • hi Vidar

    thanks for your reply

    i know i can configure watch dog to run also when debugging with a breakpoints 

    // <o> WDT_CONFIG_BEHAVIOUR  - WDT behavior in CPU SLEEP or HALT mode
     
    // <1=> Run in SLEEP, Pause in HALT 
    // <8=> Pause in SLEEP, Run in HALT 
    // <9=> Run in SLEEP and HALT 
    // <0=> Pause in SLEEP and HALT 
    
    #ifndef WDT_CONFIG_BEHAVIOUR
    #define WDT_CONFIG_BEHAVIOUR 9
    #endif
    

    in the sdk_config file i set the wdt to run at HALT and SLEEP (9), and i see that it does restart when i wait on a breakpoint when ble is not working but when i get to the ' NRF_BREAKPOINT_COND '  then it does not work, this is why i asked 

    and i guess i am also asking if in real run, when system is NOT in debug mode, can the program ever get to that line ' NRF_BREAKPOINT_COND ' (with or without a watchdog) ??

    best regards

    Ziv

  • Hi Ziv,

    I changed the default config to  "Run in SLEEP and HALT" in the WDT example in SDK 17.0.0 and added the NRF_BREAKPOINT_COND, but was not able to replicate the problem. Could you try the same?

    Here's the code I used:

    /**
     * Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
     *
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    /** @file
     * @defgroup nrf_dev_wdt_example_main main.c
     * @{
     * @ingroup nrf_dev_wdt_example
     * @brief WDT Example Application main file.
     *
     * This file contains the source code for a sample application using WDT.
     *
     */
    
    #include <stdbool.h>
    #include <stdint.h>
    
    #include "nrf.h"
    #include "bsp.h"
    #include "app_timer.h"
    #include "app_error.h"
    #include "nrf_drv_wdt.h"
    #include "nrf_drv_clock.h"
    #include "nrf_delay.h"
    #include "app_util_platform.h"
    
    #define FEED_BUTTON_ID          0                           /**< Button for feeding the dog. */
    
    nrf_drv_wdt_channel_id m_channel_id;
    
    /**
     * @brief WDT events handler.
     */
    void wdt_event_handler(void)
    {
        bsp_board_leds_off();
    
        //NOTE: The max amount of time we can spend in WDT interrupt is two cycles of 32768[Hz] clock - after that, reset occurs
    }
    
    /**
     * @brief Assert callback.
     *
     * @param[in] id    Fault identifier. See @ref NRF_FAULT_IDS.
     * @param[in] pc    The program counter of the instruction that triggered the fault, or 0 if
     *                  unavailable.
     * @param[in] info  Optional additional information regarding the fault. Refer to each fault
     *                  identifier for details.
     */
    void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
    {
        bsp_board_leds_off();
        NRF_BREAKPOINT_COND;
        while (1);
    }
    
    /**
     * @brief BSP events callback.
     */
    void bsp_event_callback(bsp_event_t event)
    {
        switch (event)
        {
            case BSP_EVENT_KEY_0:
                nrf_drv_wdt_channel_feed(m_channel_id);
                break;
    
            default :
                //Do nothing.
                break;
        }
    }
    
    /**
     * @brief Function for main application entry.
     */
    int main(void)
    {
        uint32_t err_code = NRF_SUCCESS;
    
        //BSP configuration for button support: button pushing will feed the dog.
        err_code = nrf_drv_clock_init();
        APP_ERROR_CHECK(err_code);
        nrf_drv_clock_lfclk_request(NULL);
    
        err_code = app_timer_init();
        APP_ERROR_CHECK(err_code);
    
        err_code = bsp_init(BSP_INIT_BUTTONS, bsp_event_callback);
        APP_ERROR_CHECK(err_code);
    
        //Configure all LEDs on board.
        bsp_board_init(BSP_INIT_LEDS);
    
        //Configure WDT.
        nrf_drv_wdt_config_t config = NRF_DRV_WDT_DEAFULT_CONFIG;
        err_code = nrf_drv_wdt_init(&config, wdt_event_handler);
        APP_ERROR_CHECK(err_code);
        err_code = nrf_drv_wdt_channel_alloc(&m_channel_id);
        APP_ERROR_CHECK(err_code);
        nrf_drv_wdt_enable();
    
        //Indicate program start on LEDs.
        for (uint32_t i = 0; i < LEDS_NUMBER; i++)
        {   nrf_delay_ms(200);
            bsp_board_led_on(i);
        }
         err_code = bsp_buttons_enable();
         APP_ERROR_CHECK(1);
    
        while (1)
        {
            __SEV();
            __WFE();
            __WFE();
        }
    }
    
    /** @} */
    

    Best regards,

    Vidar

  • hi Vidar 

    this is exactly what i have done .. i set the WDT to run at SLEEP and HALT 

    my observation is that  when i stop at a regular breakpoint then it gets stuck there and  after i press the continue it restarts but, with the NRF_BREAKPOINT_COND it just get stuck there (my assumption that it has something to do with interrupt priority but i am not sure )

    so again the question is, could this kind of stuckness accrue while running not in debug mode ??

    best regards

    Ziv

  • Hi Ziv,

    so again the question is, could this kind of stuckness accrue while running not in debug mode ??

    No, this can only occur in debug interface mode.

Related