Hello,
NCS2.0.2, nRF5340, VScode, watchdog
i want to uninstall watch dog before sys_reboot(0) for DFU;
but as follow no use. it will Restart twice.
Hello,
NCS2.0.2, nRF5340, VScode, watchdog
i want to uninstall watch dog before sys_reboot(0) for DFU;
but as follow no use. it will Restart twice.
Hi, Sigurd Hellesvik
wdt_disable return value: -1
Best regards
Hi,
-1 is EPERM.
From wdt_disable():
"-EPERM – If watchdog can not be disabled directly by application code. "
Maybe an easier way to achieve what you need is to save a Non-Volatile variable keeping track of the watchdog status.
Then enable the watchdog if the variables says so.
Did that make sense?
Regards,
Sigurd Hellesvik
Hi
i've no idea.
Best regards
Hi,
You can not call wdt_disable from you application.
I suggest you do something like this in your code instead:
#define WDT_TMP_DISABLE_ID 1 int wdt_tmp_disabled[1]; nvs_read(fs,WDT_TMP_DISABLE_ID,wdt_tmp_disabled,sizeof(wdt_tmp_disabled)); if(wdt_tmp_disabled){ wdt_tmp_disabled = 0; nvs_write(fs,WDT_TMP_DISABLE_ID,wdt_tmp_disabled,sizeof(wdt_tmp_disabled)); } else{ wdt_install_timeout(...) wdt_setup(...) } // ... // ... //If you want to restart temporary withour watchdog: wdt_tmp_disabled = 1 nvs_write(fs,WDT_TMP_DISABLE_ID,wdt_tmp_disabled,sizeof(wdt_tmp_disabled)); sys_reboot(0)
Did the code example help your understanding?
Regards,
Sigurd Hellesvik
Hi, Sigurd Hellesvik
thanks for reply, i konw your means.
go to sleep mode, dog will disable auto.
but when i will go to DFU,
dog will restart 3sec later,
however, i need restart now by call sys_reboot(0),
so it will restart twice.
maybe i can't call sys_reboot(0), only wait dog restart....
Best regards
Hi Yo,
yoyou said:maybe i can't call sys_reboot(0), only wait dog restart....
Try this.
Does it fix the problem?
Regards,
Sigurd Hellesvik
Hi Yo,
yoyou said:maybe i can't call sys_reboot(0), only wait dog restart....
Try this.
Does it fix the problem?
Regards,
Sigurd Hellesvik
Hi
yes,fix the problem by wait dog restart,
but take time, Not timely enough.
Best regards
Hi Yo,
How do you do the DFU?
Serial or Bluetooth Low Energy?
Regards,
Sigurd Hellesvik
Hi
Serial or Bluetooth Low Energy?
Bluetooth for DFU.
Best regards
Hi Yo,
I took the SMP Server Sample and added a Watchdog to it.
Then I tested to do DFU over Bluetooth using the nRF Connect for Mobile app.
This seems to work fine for me.
Do you get the same issue if you try this?
Regards,
Sigurd Hellesvik
Hi,
thanks for reply,
your zip project no problem. it running DFU mode anytime.
but my means not that, see pic
static bool will_ota=false,grunning=true; //---------------------------------------------------------------------------------------- static const struct gpio_dt_spec button0 = GPIO_DT_SPEC_GET_OR(DT_ALIAS(sw0), gpios,{0}); static struct gpio_callback button_cb_data1; void button_pressed0(const struct device *dev, struct gpio_callback *cb,uint32_t pins) { gpio_remove_callback(button0.port, &button_cb_data1); printk("button_pressed0\n"); grunning=false; will_ota=true; } void init_button_led(void) { if (!device_is_ready(button0.port)) { printk("Error: button device %s is not ready\n",button0.port->name); return; } int ret = gpio_pin_configure_dt(&button0, GPIO_INPUT); if (ret != 0) { printk("Error %d: failed to configure %s pin %d\n",ret, button0.port->name, button0.pin); return; } ret = gpio_pin_interrupt_configure_dt(&button0,GPIO_INT_EDGE_TO_ACTIVE); if (ret != 0) { printk("Error %d: failed to configure interrupt on %s pin %d\n", ret, button0.port->name, button0.pin); return; } gpio_init_callback(&button_cb_data1, button_pressed0, BIT(button0.pin)); gpio_add_callback(button0.port, &button_cb_data1); } //---------------------------------------------------------------------------------------- void ota(void) { os_mgmt_register_group(); img_mgmt_register_group(); smp_bt_register(); int err = bt_enable(NULL); if (err) { printk("Bluetooth init failed (err %d)\n", err); return; } if (IS_ENABLED(CONFIG_SETTINGS)) { settings_load(); } err = bt_le_adv_start(BT_LE_ADV_CONN, upad, ARRAY_SIZE(upad),upsd, ARRAY_SIZE(upsd)); if (err) { printk("Advertising failed to start (err %d)\n", err); return; } printk(" OTA Advertising started: %s\n",bt_get_name()); // if wait no OTA start, timeout 3min will reboot for (int i=0;i<180;i++) { k_sleep(K_MSEC(1000)); } printk("\n---------------OTA timeout---------------\n\n"); sys_reboot(0); } void main(void) { printk("Hello World!\n" ); mcu_flash_init(); if(mcu_flash_need_ota()) { mcu_flash_write_ota(0);//clear ota tag ota(); return; }else printk("Starting Advertising\n"); init_button_led(); // ... bt_le_per_adv_start(...);// doing another type bluetooth init_dog(); while(grunning){ // ..... k_msleep(1000); feed_dog(); } //-------------------------------------- bt_le_per_adv_stop(...); uninit_dog(); if(will_ota) sys_reboot(0); else go_system_off(); }
dog set to 3s.
Normal situation, app not start DFU, doing another type bluetooth,
when button down will mak to flash and reboot device,
when app start, first check mak,
if got mak will start DFU and not do other anything.
becuse unintidog -1,sys_reboot(0) will case reboot twice.
why dog uninit failed?
so i only must wait long time for dog reboot.
Best regards