<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Watchdog in BLE NUS example sdk 2.4.0</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/117808/watchdog-in-ble-nus-example-sdk-2-4-0</link><description>Hello everyone, 
 I am developing a ble project that builds on the peripheral Uart example using the sdk 2.4.0 for nrf5340. 
 I want to implement a watchdog since I sometimes run into corners where the code does not otherwise recover itself. I found the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 09 Jan 2025 10:29:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/117808/watchdog-in-ble-nus-example-sdk-2-4-0" /><item><title>RE: Watchdog in BLE NUS example sdk 2.4.0</title><link>https://devzone.nordicsemi.com/thread/517651?ContentTypeID=1</link><pubDate>Thu, 09 Jan 2025 10:29:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8967aace-051f-45f5-a13d-4517c42efdba</guid><dc:creator>Kenneth</dc:creator><description>[quote user="Paul M."]So basically what I am afraid of is that the main thread keeps working without problem, which would keep feeding the wtd, but the bluetooth thread might have a problem.[/quote]
&lt;p&gt;Ah, in such case watchdog wouldn&amp;#39;t help no. You can just also periodically call the api to start advertisement, and just ignore the potential error code it will return if it&amp;#39;s already advertising. I am not aware of any reason why it would stop advertising on it&amp;#39;s own no.&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Watchdog in BLE NUS example sdk 2.4.0</title><link>https://devzone.nordicsemi.com/thread/517474?ContentTypeID=1</link><pubDate>Wed, 08 Jan 2025 13:15:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:838c5537-c861-436a-ba20-1f5f046beb7f</guid><dc:creator>Paul M.</dc:creator><description>&lt;p&gt;Hello Kenneth,&lt;/p&gt;
&lt;p&gt;We had the problem, which is however very hard to replicate, that when we get a disconnect event it does not return to advertising. I dont know if we return into the main loop and just lack the advertising, or the code in genereall gets blocked. So I wanted to make sure that advertising will always resume. I did not find however where I could put the wtd feed function to ensure that. My idea was to do that in the same code part where the advertisement is handled, I could not find where that happens however, or if that is eaven&amp;nbsp;recommended to do.&lt;br /&gt;&lt;br /&gt;So basically what I am afraid of is that the main thread keeps working without problem, which would keep feeding the wtd, but the bluetooth thread might have a problem.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for your help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Watchdog in BLE NUS example sdk 2.4.0</title><link>https://devzone.nordicsemi.com/thread/517471?ContentTypeID=1</link><pubDate>Wed, 08 Jan 2025 13:07:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5bedb700-1b88-4739-be0e-c1e43220169f</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t have any good pointers here than you need to ensure to feed the watchdog (one way or the other) faster than the watchdog timeout. I think your proposol to put it in the inifinite while loop in main is a good idea, this will ensure that if any thread go into a block state, that it will eventually reset.&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Watchdog in BLE NUS example sdk 2.4.0</title><link>https://devzone.nordicsemi.com/thread/517385?ContentTypeID=1</link><pubDate>Wed, 08 Jan 2025 07:10:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc5157c0-04eb-4a4d-9af6-c94293c1d083</guid><dc:creator>Paul M.</dc:creator><description>&lt;p&gt;More specifically, this is my main:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void main(void)
{
	int err = 0;
	// weight_arr = calculate_weighted_arr(weight_arr);

	
	// int wdt_channel_id;
	// const struct device *const wdt = DEVICE_DT_GET(DT_ALIAS(watchdog0));

	

	if (!device_is_ready(wdt)) {
		
		return 0;
	}

	struct wdt_timeout_cfg wdt_config = {
		/* Reset SoC when watchdog timer expires. */
		.flags = WDT_FLAG_RESET_SOC,

		/* Expire watchdog after max window */
		.window.min = WDT_MIN_WINDOW,
		.window.max = WDT_MAX_WINDOW,
	};

	wdt_channel_id = wdt_install_timeout(wdt, &amp;amp;wdt_config);
	if (wdt_channel_id == -ENOTSUP) {
		/* IWDG driver for STM32 doesn&amp;#39;t support callback */
		//printk(&amp;quot;Callback support rejected, continuing anyway\n&amp;quot;);
		wdt_config.callback = NULL;
		wdt_channel_id = wdt_install_timeout(wdt, &amp;amp;wdt_config);
	}
	if (wdt_channel_id &amp;lt; 0) {
		//printk(&amp;quot;Watchdog install error\n&amp;quot;);
		return 0;
	}

	err = wdt_setup(wdt, WDT_OPT_PAUSE_HALTED_BY_DBG);
	if (err &amp;lt; 0) {
		//printk(&amp;quot;Watchdog setup error\n&amp;quot;);
		return 0;
	}

	uint32_t led2_pin = NRF_GPIO_PIN_MAP(1, 1);
	uint32_t enable_pin = NRF_GPIO_PIN_MAP(0, 16);

	uint8_t spec_hello_check[] = {0x03, 0xBB, CMD_HELLO, 0x00, 0x41};
	uint8_t *spec_hello_return;

	pin_configure(button);
	// calculate_weighted_arr(weight_arr);
	// because of DFU/OTA configs one time SPI communication
	nrf_gpio_pin_set(enable_pin);
	spec_hello_return = cmd_hello(spispec);
	for(int i = 0; i &amp;lt; 5; i++){
		if(spec_hello_check[i] == spec_hello_return[i]){
			nrf_gpio_pin_clear(enable_pin);
		}
	}
	nrf_gpio_pin_clear(enable_pin);

	nrf_gpio_cfg_output(led2_pin);
	
	nrf_gpio_pin_set(led2_pin);
	k_msleep(500);
	nrf_gpio_pin_clear(led2_pin);
	k_msleep(500);

	// for (int i = 0; i &amp;lt; sizeof(m_camera1_framebuffer); i++)
	// {
	// 	m_camera1_framebuffer[i] = 10;
	// }

	// camera initialisation
	k_sem_init(&amp;amp;m_camera_1_sem, 0, 1);

	//Configure camera
	// LOG_INF(&amp;quot;Configure camera 1&amp;quot;);
	err = camera_osirism_init(&amp;amp;m_camera_1, &amp;amp;m_camera_1_config);
	if(err != 0) {
		// LOG_ERR(&amp;quot;Failed to setup camera 1: %d&amp;quot;, result);
		return;
	}
	
	gpio_pin_configure_dt(&amp;amp;interrupt1, GPIO_INPUT);
	ISM330DLC_powerdown(i2c_dev);
	// gpio_pin_interrupt_configure_dt(&amp;amp;interrupt1, GPIO_INT_EDGE_TO_ACTIVE);
	// gpio_init_callback(&amp;amp;interrupt1_cb, interrupt1_handler, BIT(interrupt1.pin));
	// gpio_add_callback(interrupt1.port, &amp;amp;interrupt1_cb);


	bt_conn_cb_register(&amp;amp;conn_callbacks);
	err = bt_enable(NULL);
	if (err) {
 		printk(&amp;quot;Failed to initialize UEnable BT (err: %d)\n&amp;quot;, err);
		return;
	}
	
	err = bt_nus_init(&amp;amp;nus_cb);
	printk(&amp;quot;BLE initialized\n&amp;quot;);
	if (err) {
 		printk(&amp;quot;Failed to initialize UART service (err: %d)\n&amp;quot;, err);
		return;
	}
 
	err = bt_le_adv_start(BT_LE_ADV_CONN_SLOW, ad, ARRAY_SIZE(ad), sd,
			      ARRAY_SIZE(sd));

	

	if (err) {
		printk(&amp;quot;Advertising failed to start (err %d)\n&amp;quot;, err);
	}
	
	printk(&amp;quot;Starting BLE NUS\n&amp;quot;);

	while (true)
	{	
		wdt_feed(wdt, wdt_channel_id);
		k_msleep(3000);
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I added the while loop at the end for the watchdog but otherwise would not have it. I dont know if that is the best way to do it however.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>