<?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>NRF53 QSPI XIP mode: unable to uninitialized qspi</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/94010/nrf53-qspi-xip-mode-unable-to-uninitialized-qspi</link><description>We are using QSPI XIP mode to access data in external flash for our project. We are trying put QSPI peripheral in standby mode. 
 However, we can&amp;#39;t uninitialized QSPI peripheral by calling nrfx_qspi_uninit() even though XIP mode is disabled and no data</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 28 Nov 2022 15:03:52 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/94010/nrf53-qspi-xip-mode-unable-to-uninitialized-qspi" /><item><title>RE: NRF53 QSPI XIP mode: unable to uninitialized qspi</title><link>https://devzone.nordicsemi.com/thread/397928?ContentTypeID=1</link><pubDate>Mon, 28 Nov 2022 15:03:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fe19aa4a-9d50-4a03-acee-9a410c1c8028</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks to point out the difference in the log. I am able to reproduce the issue now.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This behavior is caused by&amp;nbsp;&lt;/span&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/errata_nRF5340_Rev1/ERR/nRF5340/Rev1/latest/anomaly_340_43.html#anomaly_340_43" rel="nofollow noopener noreferrer" target="_blank"&gt;anomaly 43&lt;/a&gt;&lt;span&gt;&amp;nbsp;which is not yet handled in the nrfx_qspi driver - the mentioned&amp;nbsp;&lt;/span&gt;&lt;tt&gt;nrf_qspi_cinstr_long_transfer_is_ongoing&lt;/tt&gt;&lt;span&gt;&amp;nbsp;function is accessing the&amp;nbsp;&lt;/span&gt;&lt;tt&gt;NRF_QSPI-&amp;gt;CINSTRCONF&lt;/tt&gt;&lt;span&gt;&amp;nbsp;register, which is at offset 0x634, so it triggers the anomaly.&lt;/span&gt;&lt;br /&gt;&lt;span&gt;Currently, the workaround described in the errata pointed out above needs to be applied in the application, so&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;nrf_qspi_task_trigger(NRF_QSPI, NRF_QSPI_TASK_ACTIVATE);&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;needs to be called before&amp;nbsp;&lt;tt&gt;nrfx_qspi_uninit()&lt;/tt&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;-Amanda H.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF53 QSPI XIP mode: unable to uninitialized qspi</title><link>https://devzone.nordicsemi.com/thread/397807?ContentTypeID=1</link><pubDate>Mon, 28 Nov 2022 09:26:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d78b1b3c-1207-4fd3-8d8b-5aca7613b6f7</guid><dc:creator>keat_sigma</dc:creator><description>&lt;p&gt;Hi Amanda, &lt;/p&gt;
&lt;p&gt;Do you have any update for this case?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF53 QSPI XIP mode: unable to uninitialized qspi</title><link>https://devzone.nordicsemi.com/thread/396535?ContentTypeID=1</link><pubDate>Mon, 21 Nov 2022 02:09:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03b2789e-bd19-4633-b251-ab6c013911de</guid><dc:creator>keat_sigma</dc:creator><description>&lt;p&gt;Hi Amanda,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve tried your modified code. My log is as followed&lt;/p&gt;
&lt;p&gt;:&lt;pre class="ui-code" data-mode="text"&gt;*** Booting Zephyr OS build v3.1.99-ncs1  ***
Address of main function 0x4f9
Address of function_in_ext_flash 0x10000001
Address of var_ext_sram_data 0x200000a0 (10)
Address of function_in_sram 0x20000001
Address of var_sram_data 0x200000a4 (10)
Hello World! nrf5340dk_nrf5340_cpuapp&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;it&amp;#39;s still unable to run this instruction: printk(&amp;quot;qspi_ext_mem_uninit successfully\n&amp;quot;); And, I noticed that, the output log of &amp;quot;Address of function_in_ext_flash&amp;quot; is different.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Address of function_in_ext_flash 0x10000001 (mine)&lt;/p&gt;
&lt;p&gt;Address of function_in_ext_flash 0x42d (yours)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF53 QSPI XIP mode: unable to uninitialized qspi</title><link>https://devzone.nordicsemi.com/thread/396480?ContentTypeID=1</link><pubDate>Fri, 18 Nov 2022 17:15:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:929a3a11-6fc0-4e2b-92a1-19ec1ea22d8a</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I modify the code as&lt;br /&gt;main.c&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2018 Intel Corporation.
 * Copyright (c) 2022 Carlo Caione &amp;lt;ccaione@baylibre.com&amp;gt;
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/sys/printk.h&amp;gt;

/*
 * This function will allow execute from sram region.  This is needed only for
 * this sample because by default all soc will disable the execute from SRAM.
 * An application that requires that the code be executed from SRAM will have
 * to configure the region appropriately in arm_mpu_regions.c.
 */
#ifdef CONFIG_ARM_MPU
#include &amp;lt;zephyr/arch/arm/aarch32/cortex_m/cmsis.h&amp;gt;
void disable_mpu_rasr_xn(void)
{
	uint32_t index;

	/*
	 * Kept the max index as 8(irrespective of soc) because the sram would
	 * most likely be set at index 2.
	 */
	for (index = 0U; index &amp;lt; 8; index++) {
		MPU-&amp;gt;RNR = index;
#if defined(CONFIG_ARMV8_M_BASELINE) || defined(CONFIG_ARMV8_M_MAINLINE)
		if (MPU-&amp;gt;RBAR &amp;amp; MPU_RBAR_XN_Msk) {
			MPU-&amp;gt;RBAR ^= MPU_RBAR_XN_Msk;
		}
#else
		if (MPU-&amp;gt;RASR &amp;amp; MPU_RASR_XN_Msk) {
			MPU-&amp;gt;RASR ^= MPU_RASR_XN_Msk;
		}
#endif /* CONFIG_ARMV8_M_BASELINE || CONFIG_ARMV8_M_MAINLINE */
	}
}
#endif /* CONFIG_ARM_MPU */

extern void function_in_ext_flash(void);
extern void function_in_sram(void);

void main(void)
{
#ifdef CONFIG_ARM_MPU
	disable_mpu_rasr_xn();
#endif	/* CONFIG_ARM_MPU */

    //qspi_ext_mem_init();

	printk(&amp;quot;Address of %s function %p\n&amp;quot;, __func__, &amp;amp;main);

	function_in_ext_flash();
	function_in_sram();

	printk(&amp;quot;Hello World! %s\n&amp;quot;, CONFIG_BOARD);
	qspi_ext_mem_uninit();
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;ext_mem_init.c&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2022 Nordic Semiconductor ASA.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;errno.h&amp;gt;
#include &amp;lt;zephyr/init.h&amp;gt;
#include &amp;lt;zephyr/drivers/pinctrl.h&amp;gt;
#include &amp;lt;nrfx_qspi.h&amp;gt;
#include &amp;lt;hal/nrf_clock.h&amp;gt;

#define QSPI_STD_CMD_WRSR  0x01
#define QSPI_STD_CMD_RSTEN 0x66
#define QSPI_STD_CMD_RST   0x99

#define QSPI_NODE DT_NODELABEL(qspi)

static int qspi_ext_mem_init(const struct device *dev)
{
	ARG_UNUSED(dev);

	static const nrfx_qspi_config_t qspi_config = {
		.prot_if = {
			.readoc    = NRF_QSPI_READOC_READ4IO,
			.writeoc   = NRF_QSPI_WRITEOC_PP4IO,
			.addrmode  = NRF_QSPI_ADDRMODE_24BIT,
		},
		.phy_if = {
			/* Frequency = PCLK192M / 2 * (sck_freq + 1) -&amp;gt; 32 MHz.
			 * 33 MHz is the maximum for WRSR, even in the High
			 * Performance mode.
			 */
			.sck_freq  = 2,
			.sck_delay = 0x05,
			.spi_mode  = NRF_QSPI_MODE_0,
		},
		.skip_gpio_cfg = true,
		.skip_psel_cfg = true,
	};
	static const nrf_qspi_phy_conf_t qspi_phy_48mhz = {
		/* After sending WRSR, use 48 MHz (96 MHz cannot be used,
		 * as 80 MHz is the maximum for the MX25R6435F chip).
		 */
		.sck_freq  = 1,
		.sck_delay = 0x05,
		.spi_mode  = NRF_QSPI_MODE_0,
	};
	nrf_qspi_cinstr_conf_t cinstr_cfg = {
		.opcode    = QSPI_STD_CMD_RSTEN,
		.length    = NRF_QSPI_CINSTR_LEN_1B,
		.io2_level = true,
		.io3_level = true,
		.wipwait   = true,
	};
	static const uint8_t flash_chip_cfg[] = {
		/* QE (Quad Enable) bit = 1 */
		BIT(6),
		0x00,
		/* L/H Switch bit = 1 -&amp;gt; High Performance mode */
		BIT(1),
	};
	nrfx_err_t err;
	int ret;

	PINCTRL_DT_DEFINE(QSPI_NODE);

	ret = pinctrl_apply_state(PINCTRL_DT_DEV_CONFIG_GET(QSPI_NODE),
				  PINCTRL_STATE_DEFAULT);
	if (ret &amp;lt; 0) {
		return ret;
	}

	err = nrfx_qspi_init(&amp;amp;qspi_config, NULL, NULL);
	if (err != NRFX_SUCCESS) {
		return -EIO;
	}

	nrf_clock_hfclk192m_div_set(NRF_CLOCK, NRF_CLOCK_HFCLK_DIV_1);

	/* Send reset enable */
	nrfx_qspi_cinstr_xfer(&amp;amp;cinstr_cfg, NULL, NULL);

	/* Send reset command */
	cinstr_cfg.opcode = QSPI_STD_CMD_RST;
	nrfx_qspi_cinstr_xfer(&amp;amp;cinstr_cfg, NULL, NULL);

	/* Switch to Quad I/O and High Performance mode */
	cinstr_cfg.opcode = QSPI_STD_CMD_WRSR;
	cinstr_cfg.wren   = true;
	cinstr_cfg.length = NRF_QSPI_CINSTR_LEN_4B;
	nrfx_qspi_cinstr_xfer(&amp;amp;cinstr_cfg, &amp;amp;flash_chip_cfg, NULL);

	nrf_qspi_ifconfig1_set(NRF_QSPI, &amp;amp;qspi_phy_48mhz);

	/* Enable XiP */
	nrf_qspi_xip_set(NRF_QSPI, true);

	return 0;
}

int qspi_ext_mem_uninit(void)
{
	nrf_qspi_xip_set(NRF_QSPI, false);
	nrfx_qspi_uninit();
	printk(&amp;quot;qspi_ext_mem_uninit successfully\n&amp;quot;);
	return 0;
}

SYS_INIT(qspi_ext_mem_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_OBJECTS);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Get the log as&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** Booting Zephyr OS build v3.1.99-ncs1-1  ***
Address of main function 0x485
Address of function_in_ext_flash 0x42d
Address of var_ext_sram_data 0x20000000 (10)
Address of function_in_sram 0x4c1
Address of var_sram_data 0x20000004 (10)
Hello World! nrf5340dk_nrf5340_cpuapp
qspi_ext_mem_uninit successfully&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Amanda H.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>