<?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>Not able use UART in bootloader example code</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/106853/not-able-use-uart-in-bootloader-example-code</link><description>Hi, 
 I&amp;#39;m using nrf connect SDK2.3.0 and I wanted to develop a cutom bootloader, i&amp;#39;m trying to add a UART to it but &amp;quot;uart_callback_set&amp;quot; returning &amp;quot;ENOTSUP&amp;quot;, If I configured &amp;quot;CONFIG_UART_ASYNC_API=y&amp;quot; it&amp;#39;s failing to build with &amp;quot;undefined reference to </description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 09 Jan 2024 14:59:01 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/106853/not-able-use-uart-in-bootloader-example-code" /><item><title>RE: Not able use UART in bootloader example code</title><link>https://devzone.nordicsemi.com/thread/463392?ContentTypeID=1</link><pubDate>Tue, 09 Jan 2024 14:59:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f05fbe6c-696e-476e-887b-fe11d32ba2d6</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi again,&amp;nbsp;&lt;br /&gt;What I found is that in MCUBoot, after the serial recovery is finished it will simply reboot and on the next boot it will not enter serial recovery and booting to the application instead. This way the UART is not initialized on the next booting.&amp;nbsp;&lt;br /&gt;What are you planning to do with using UART in the bootloader ?&amp;nbsp;&lt;br /&gt;You can find the source code for MCUBoot in&amp;nbsp;\bootloader\mcuboot\boot\zephyr&lt;/p&gt;
&lt;p&gt;Here is when it enter serial recovery mode:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-mcuboot/blob/main/boot/zephyr/main.c#L615"&gt;https://github.com/nrfconnect/sdk-mcuboot/blob/main/boot/zephyr/main.c#L615&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able use UART in bootloader example code</title><link>https://devzone.nordicsemi.com/thread/463302?ContentTypeID=1</link><pubDate>Tue, 09 Jan 2024 09:04:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:77ecf8e5-344b-42e1-982e-60930dbfeebf</guid><dc:creator>Theja</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote userid="2121" url="~/f/nordic-q-a/106853/not-able-use-uart-in-bootloader-example-code/463284"]From my point of view, you may need to de-initialize UART or any peripheral that you use inside the bootloader before you jump to the application.&amp;nbsp;[/quote]
&lt;p&gt;I&amp;#39;m trying to deinit the UART but i didn&amp;#39;t find any direct API or Do I need to clear register?&amp;nbsp;&lt;/p&gt;
[quote userid="2121" url="~/f/nordic-q-a/106853/not-able-use-uart-in-bootloader-example-code/463284"]I think you may want to take a look at the MCUBoot to see how it&amp;#39;s implemented. The MCUBoot uses UART when you do serial recovery.&amp;nbsp;[/quote]
&lt;p&gt;How can I access the MCUBoot code?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able use UART in bootloader example code</title><link>https://devzone.nordicsemi.com/thread/463284?ContentTypeID=1</link><pubDate>Tue, 09 Jan 2024 08:16:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5f42b10d-7e77-4bd5-826d-c61bd53d5acf</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Have you checked where it&amp;#39;s stopped or what&amp;#39;s the error ?&lt;br /&gt;We need to see where it&amp;#39;s stuck, inside the bootloader or at the application.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Do you use UART in your application ? Could you try to boot a very simple application ? That only blink an LED.&lt;/p&gt;
&lt;p&gt;From my point of view, you may need to de-initialize UART or any peripheral that you use inside the bootloader before you jump to the application.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I think you may want to take a look at the MCUBoot to see how it&amp;#39;s implemented. The MCUBoot uses UART when you do serial recovery.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able use UART in bootloader example code</title><link>https://devzone.nordicsemi.com/thread/463265?ContentTypeID=1</link><pubDate>Tue, 09 Jan 2024 06:23:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c07cc983-b08a-4fe3-a967-a932dd9ec728</guid><dc:creator>Theja</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve managed to get uart to work, but it&amp;#39;s not booting the application.&lt;br /&gt;To make UART work, I require &amp;quot;CONFIG_UART_ASYNC_API=y&amp;quot; but it&amp;#39;s not booting the application, if I disable &amp;quot;CONFIG_UART_ASYNC_API=n&amp;quot; it boots the application but uart is not working, I&amp;#39;ve been trapped with this for a few days. Is there any way to fix this?&lt;/p&gt;
&lt;p&gt;I have shared my sample Please check&lt;/p&gt;
&lt;p&gt;main file&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2018 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */

#include &amp;lt;zephyr/types.h&amp;gt;
#include &amp;lt;zephyr/kernel.h&amp;gt;
// #include &amp;lt;zephyr/sys/printk.h&amp;gt;
#include &amp;lt;pm_config.h&amp;gt;
#include &amp;lt;fw_info.h&amp;gt;
#include &amp;lt;fprotect.h&amp;gt;
#include &amp;lt;bl_storage.h&amp;gt;
#include &amp;lt;bl_boot.h&amp;gt;
#include &amp;lt;bl_validation.h&amp;gt;
#include &amp;lt;nrfx_nvmc.h&amp;gt;
#include &amp;quot;uart_app.h&amp;quot;

#define FLASH_CHECK		0

uint8_t rx_buf[2048] = {&amp;#39;\0&amp;#39;};

const uint32_t address_to_boot = 0x20000;

void main(void)
{
	uart_cfg();
	uart_init();

	send_through_uart(&amp;quot;boot loader started\r\n&amp;quot;);
	#if FLASH_CHECK
		uint32_t write_address = 0x50000;
		uint8_t write_value[5] = {0x01,0x02,0x03,0x04,0x05};
		// nrfx_nvmc_word_write(write_address, write_value);
		nrfx_nvmc_bytes_write(write_address, write_value, 5);
		uint32_t read_val = nrfx_nvmc_uicr_word_read(&amp;amp;write_address);
		// printk(&amp;quot;%d&amp;quot;, read_val);
		send_through_uart(&amp;quot;Booting a application\r\n&amp;quot;);
	#endif

	bl_boot_appl(address_to_boot);
	printk(&amp;quot;No bootable image found. Aborting boot.\n\r&amp;quot;);
	
	return;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;UART file&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;quot;uart_app.h&amp;quot;

uint8_t length = 0;
uint8_t host_data[100] = {&amp;#39;\0&amp;#39;};
uint8_t data_from_host = 0;


const struct device *uart = DEVICE_DT_GET(DT_NODELABEL(uart0));

const struct uart_config uart0_cfg = 
{
	.baudrate = 115200,
	.parity = UART_CFG_PARITY_NONE,
	.stop_bits = UART_CFG_STOP_BITS_1,
	.data_bits = UART_CFG_DATA_BITS_8,
	.flow_ctrl = UART_CFG_FLOW_CTRL_NONE
};


int uart_cfg()
{
	int err = uart_configure(uart, &amp;amp;uart0_cfg);

	if (err == -ENOSYS) 
	{
        printk(&amp;quot;uart configuration failed\r\n&amp;quot;);
		return -ENOSYS;
	}
}

void uart_cb(const struct device *dev, struct uart_event *evt, void *user_data)
{
	switch (evt-&amp;gt;type) 
	{	
		case UART_RX_RDY:
			memset(host_data, &amp;#39;\0&amp;#39;, sizeof(host_data));
			
			memcpy(host_data, rx_buf, strlen(rx_buf));
			
			length = strlen(host_data);
			if((host_data[length] == &amp;#39;\n&amp;#39;) || (host_data[length - 1] == &amp;#39;\n&amp;#39;))
			{
				uart_rx_disable(uart);
				data_from_host = 1;
			}
			
			break;
		
		case UART_RX_DISABLED:
			memset(rx_buf, &amp;#39;\0&amp;#39;, sizeof(rx_buf));
			uart_rx_enable(uart ,rx_buf, sizeof(rx_buf), 150);
			break;
			
		default:
			break;
	}
}


int uart_init(void)
{
	if (!device_is_ready(uart)) 
	{
		printk(&amp;quot;UART device not ready\r\n&amp;quot;);
		return 1;
	}

	int err = uart_callback_set(uart, uart_cb, NULL);
	if (err) 
	{
        printk(&amp;quot;UART failed to set callback\r\n&amp;quot;);
		return err;
	}

	uart_rx_enable(uart ,rx_buf, sizeof(rx_buf), 150);
}

void send_through_uart(uint8_t *data)
{
	uart_tx(uart, data, strlen(data), 50);
	k_msleep(strlen(data));
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;prj.confg&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#
# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
CONFIG_IS_SECURE_BOOTLOADER=y
# CONFIG_MULTITHREADING=n
# CONFIG_GPIO=n
CONFIG_ARM_MPU=n
CONFIG_PM=n
CONFIG_TICKLESS_KERNEL=n
CONFIG_ERRNO=n
CONFIG_FPROTECT=y
CONFIG_SECURE_BOOT_CRYPTO=y
CONFIG_SECURE_BOOT_DEBUG=y
CONFIG_SECURE_BOOT_VALIDATION=y
CONFIG_SECURE_BOOT_STORAGE=y
CONFIG_BL_ROT_VERIFY_EXT_API_ENABLED=y
CONFIG_BL_SHA256_EXT_API_ENABLED=y
CONFIG_BL_SECP256R1_EXT_API_ENABLED=y
CONFIG_BL_VALIDATE_FW_EXT_API_ENABLED=y
CONFIG_EXT_API_PROVIDE_EXT_API_ENABLED=y
CONFIG_NRFX_NVMC=y
CONFIG_MAIN_STACK_SIZE=2048
CONFIG_TIMEOUT_64BIT=n

# Disable asserts because of false positive when writing to OTP.
CONFIG_ASSERT=n

# Avoid triggering IRQs from the RTC
# CONFIG_NRF_RTC_TIMER=n

# thej
CONFIG_UART_ASYNC_API=y
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able use UART in bootloader example code</title><link>https://devzone.nordicsemi.com/thread/461598?ContentTypeID=1</link><pubDate>Fri, 22 Dec 2023 14:32:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1be9af4d-2df7-41e5-80a9-317439764f5c</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not so sure why you receive the error. But it look to me that the LFCLK is not initialized.&amp;nbsp;The problem here is that the bootloader run very early in the booting process.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you try enabling&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_NRF_RTC_TIMER&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;As I mentioned earlier, it&amp;#39;s recommended that you don&amp;#39;t modify the immutable bootloader and write your own secondary bootloader instead. You can do UART and other task in the secondary bootloader. It&amp;#39;s safer because you have a chance to update this bootloader when you can&amp;#39;t do it with the immutable bootloader.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I will be on holiday until 2nd January 2024. There will be a delay on the response.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I wish you a merry Xmas and a happy new year.&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able use UART in bootloader example code</title><link>https://devzone.nordicsemi.com/thread/461517?ContentTypeID=1</link><pubDate>Fri, 22 Dec 2023 05:31:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:887a778c-80f3-415d-988f-757bbc7ffc9f</guid><dc:creator>Theja</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Despite the fact that I have an external LFCLK, I tried &amp;quot;CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y&amp;quot; The same error persists, and there isn&amp;#39;t much information about it on the internet.&lt;/p&gt;
&lt;p&gt;Is this due to CLOCK or something else because I&amp;#39;m using the same board for a BLE application and it&amp;#39;s working fine?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able use UART in bootloader example code</title><link>https://devzone.nordicsemi.com/thread/461467?ContentTypeID=1</link><pubDate>Thu, 21 Dec 2023 14:49:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:22fb0f58-1cd1-4920-9a6b-0261a5e7735a</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi again,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Did you try to search for the error :&lt;span&gt;undefined reference to `sys_clock_elapsed&amp;quot; ?&amp;nbsp;&lt;br /&gt;If you search you can find this:&amp;nbsp;&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/85416/initialization-problem"&gt;Initialization problem&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Could be that you need to add&amp;nbsp;CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y if you don&amp;#39;t have external LFCLK.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Please be aware that&amp;nbsp;an immutable bootloader is not able to be updated. So that&amp;#39;s the reason usually the bootloader has very little feature. If you want to have UART DFU, it&amp;#39;s suggested to use a secondary bootloader to handle the task. In this case you can use MCUBoot.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The bootloader should have only minimum feature so that it&amp;#39;s robust and have less chance to have a bug or vulnerability&amp;nbsp;that require a patch.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able use UART in bootloader example code</title><link>https://devzone.nordicsemi.com/thread/461451?ContentTypeID=1</link><pubDate>Thu, 21 Dec 2023 14:12:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4aceee29-a5ab-46b5-9df1-d8854e184366</guid><dc:creator>Theja</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote userid="2121" url="~/f/nordic-q-a/106853/not-able-use-uart-in-bootloader-example-code/461447"]Could you explain a little bit more about what you want to achieve ?[/quote]
&lt;p&gt;I&amp;#39;m trying to write my own bootloader using the bootloader sample code. I want to use UART there.&lt;/p&gt;
[quote userid="2121" url="~/f/nordic-q-a/106853/not-able-use-uart-in-bootloader-example-code/461447"]Where would your bootloader be located and how would it be executed ?&amp;nbsp;[/quote]
&lt;p&gt;It uses the sample code present in&amp;nbsp; this location &amp;quot;&lt;strong&gt;nrf/sample/bootloader&lt;/strong&gt;&amp;quot; and runs like a normal application.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able use UART in bootloader example code</title><link>https://devzone.nordicsemi.com/thread/461447?ContentTypeID=1</link><pubDate>Thu, 21 Dec 2023 13:49:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3e8de14e-db58-4888-984d-26c836122ae3</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Thejakumar,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you explain a little bit more about what you want to achieve ?&lt;/p&gt;
&lt;p&gt;You mentioned a custom bootloader, is that you plan that you replace MCUBoot with your own code ? Or you simply want to modify the MCUBoot ?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Where would your bootloader be located and how would it be executed ?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>