<?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>How to modify an app to be updated and update  from it with MCUBoot.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/95990/how-to-modify-an-app-to-be-updated-and-update-from-it-with-mcuboot</link><description>I need to upgrade firmware with MCUBoot (buttonless). I have read these tutorials: 
 https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.1.0/zephyr/samples/subsys/mgmt/mcumgr/smp_svr/README.html#smp-svr-sample-build 
 https://devzone.nordicsemi.com</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 24 Jan 2023 12:16:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/95990/how-to-modify-an-app-to-be-updated-and-update-from-it-with-mcuboot" /><item><title>RE: How to modify an app to be updated and update  from it with MCUBoot.</title><link>https://devzone.nordicsemi.com/thread/406222?ContentTypeID=1</link><pubDate>Tue, 24 Jan 2023 12:16:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:60fc3a36-f91f-4c26-bb48-a8f8e65026fc</guid><dc:creator>JuanAlm</dc:creator><description>&lt;p&gt;Resolved!&lt;/p&gt;
&lt;p&gt;I have to add this to the&amp;nbsp;&amp;quot;nrf52840dk_nrf52840.overlay&amp;quot;:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/ {
	chosen {
		zephyr,uart-mcumgr = &amp;amp;cdc_acm_uart0;
	};
};

zephyr_udc0: &amp;amp;usbd {
	compatible = &amp;quot;nordic,nrf-usbd&amp;quot;;
	status = &amp;quot;okay&amp;quot;;
};

&amp;amp;zephyr_udc0 {
	cdc_acm_uart0: cdc_acm_uart0 {
		compatible = &amp;quot;zephyr,cdc-acm-uart&amp;quot;;
	};
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The main.c would be:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2016 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;
#include &amp;quot;os_mgmt/os_mgmt.h&amp;quot;
#include &amp;quot;img_mgmt/img_mgmt.h&amp;quot;
#include &amp;lt;zephyr/usb/usb_device.h&amp;gt;

/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS   100

/* The devicetree node identifier for the &amp;quot;led0&amp;quot; alias. */
#define LED0_NODE DT_ALIAS(led0)

/*
 * A build error on this line means your board is unsupported.
 * See the sample documentation for information on how to fix this.
 */
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);

void main(void)
{
	int ret;

	os_mgmt_register_group();
	img_mgmt_register_group();
	
	if (IS_ENABLED(CONFIG_USB_DEVICE_STACK)) {
		int rc = usb_enable(NULL);
		if (rc) {
			//LOG_ERR(&amp;quot;Failed to enable USB&amp;quot;);
			return;
		}
	}

	if (!device_is_ready(led.port)) {
		return;
	}

	ret = gpio_pin_configure_dt(&amp;amp;led, GPIO_OUTPUT_ACTIVE);
	if (ret &amp;lt; 0) {
		return;
	}

	while (1) {
		ret = gpio_pin_toggle_dt(&amp;amp;led);
		if (ret &amp;lt; 0) {
			return;
		}
		k_msleep(SLEEP_TIME_MS);
	}
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And the prj.conf:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_GPIO=y

### overlay-cdc.conf
# Enable USB subsystem
CONFIG_USB_DEVICE_STACK=y
CONFIG_SERIAL=y
CONFIG_UART_LINE_CTRL=y
# USB backend is serial device
CONFIG_MCUMGR_SMP_UART=y
###

# Enable mcumgr.
CONFIG_MCUMGR=y

# Enable most core commands.
CONFIG_MCUMGR_CMD_IMG_MGMT=y
CONFIG_MCUMGR_CMD_OS_MGMT=y

# Ensure an MCUboot-compatible binary is generated.
CONFIG_BOOTLOADER_MCUBOOT=y
# Enable the serial mcumgr transport.
CONFIG_MCUMGR_SMP_UART=y

# Disable UART Console and enable the RTT console
CONFIG_UART_CONSOLE=n
CONFIG_RTT_CONSOLE=y
CONFIG_USE_SEGGER_RTT=y

# Some command handlers require a large stack.
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Now it works!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>