<?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>TWIM usage in non secure application core</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/69641/twim-usage-in-non-secure-application-core</link><description>Hi, 
 We are currently porting our code to the newest nRf5340 chip. 
 Everything goes fine when the target is secure (not ending with &amp;quot;ns&amp;quot; and not defining &amp;quot;CONFIG_TRUSTED_EXECUTION_NONSECURE&amp;quot;. 
 However, when changing the target to be &amp;quot;nonsecure&amp;quot;, the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 18 Dec 2020 14:56:38 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/69641/twim-usage-in-non-secure-application-core" /><item><title>RE: TWIM usage in non secure application core</title><link>https://devzone.nordicsemi.com/thread/285875?ContentTypeID=1</link><pubDate>Fri, 18 Dec 2020 14:56:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d9f5f2f-355f-42cd-9380-ac737617583b</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hi again!&lt;br /&gt;&lt;br /&gt;That was unfortunate. I think this is tied to the peripheral not being present for nRF5340 in version v1.4.0 of the SDK yet. Could you try the master branch? I&amp;#39;m leaving on holiday and will be back in about a week. If the issue is pressing I suggest opening a new case.&lt;br /&gt;&lt;br /&gt;Happy holidays and best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWIM usage in non secure application core</title><link>https://devzone.nordicsemi.com/thread/285861?ContentTypeID=1</link><pubDate>Fri, 18 Dec 2020 14:16:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:424ca18e-aee7-45fc-a4b8-96d7d88c9564</guid><dc:creator>GiulianoFranchetto</dc:creator><description>&lt;p&gt;Hi !&amp;nbsp;&lt;/p&gt;
&lt;p&gt;After updating spm.c + adding the following to the KConfig:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;config SPM_NRF_QSPI_NS
	bool &amp;quot;QSPI is Non-Secure&amp;quot;
	default y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t have a crash anymore.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;However, the flash is not found :(&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;qspi_nor: flash id error. Extected: [194 40 23], got: [0 0 0]&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWIM usage in non secure application core</title><link>https://devzone.nordicsemi.com/thread/285849?ContentTypeID=1</link><pubDate>Fri, 18 Dec 2020 13:56:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1014e8b4-8d6a-4ea1-83e5-3c2806165ff3</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hi again!&lt;br /&gt;&lt;br /&gt;Great that the TWI-issue is solved. As for QSPI, could you try the following SPM.c?&amp;nbsp;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2019 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
 */

#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;sys/printk.h&amp;gt;
#include &amp;lt;sys/util.h&amp;gt;
#include &amp;lt;linker/linker-defs.h&amp;gt;
#include &amp;lt;device.h&amp;gt;
#include &amp;lt;drivers/gpio.h&amp;gt;
#include &amp;lt;hal/nrf_spu.h&amp;gt;
#include &amp;lt;arch/arm/aarch32/irq.h&amp;gt;
#include &amp;quot;spm_internal.h&amp;quot;

#if !defined(CONFIG_ARM_SECURE_FIRMWARE)
#error &amp;quot;Module requires compiling for Secure ARM Firmware&amp;quot;
#endif

/* Include required APIs for TrustZone-M */
#include &amp;lt;arm_cmse.h&amp;gt;
#include &amp;lt;cortex_m/tz.h&amp;gt;

#include &amp;lt;nrfx.h&amp;gt;

#if USE_PARTITION_MANAGER
#include &amp;lt;pm_config.h&amp;gt;
#define NON_SECURE_APP_ADDRESS PM_APP_ADDRESS
#define NON_SECURE_RAM_OFFSET PM_SRAM_SECURE_SIZE
#else
#include &amp;lt;storage/flash_map.h&amp;gt;
#define NON_SECURE_APP_ADDRESS FLASH_AREA_ID(image_0_nonsecure)
/* This reflects the configuration in DTS. */
#define NON_SECURE_RAM_OFFSET 0x10000
#endif /* USE_PARTITION_MANAGER */

#define NON_SECURE_FLASH_REGION_INDEX \
	((NON_SECURE_APP_ADDRESS) / (FLASH_SECURE_ATTRIBUTION_REGION_SIZE))
#define NON_SECURE_RAM_REGION_INDEX \
	((NON_SECURE_RAM_OFFSET) / (RAM_SECURE_ATTRIBUTION_REGION_SIZE))

/*
 *  * The security configuration for depends on where the non secure app
 *  * is placed. All flash regions before the region which contains the
 *  * non secure app is configured as Secure.
 *
 *                FLASH
 *  1 MB  |---------------------|
 *        |                     |
 *        |                     |
 *        |                     |
 *        |                     |
 *        |                     |
 *        |     Non-Secure      |
 *        |       Flash         |
 *        |                     |
 *  X kB  |---------------------|
 *        |                     |
 *        |     Secure          |
 *        |      Flash          |
 *  0 kB  |---------------------|
 *
 *  * The SRAM configuration is given by the partition manager.
 *  * To see the current configuration, run the &amp;#39;pm_report&amp;#39; target.
 *  * E.g. &amp;#39;ninja pm_report, in your build folder. All partitions
 *  * within the &amp;#39;secure_ram&amp;#39; span is configured as secure by the SPM.
 *
 */

extern irq_target_state_t irq_target_state_set(unsigned int irq,
	irq_target_state_t irq_target_state);
extern int irq_target_state_is_secure(unsigned int irq);

/* printk wrapper, to turn off logs when booting silently */
#define PRINT(...)                                                             \
	do {                                                                   \
		if (!IS_ENABLED(CONFIG_SPM_BOOT_SILENTLY)) {                   \
			printk(__VA_ARGS__);                                   \
		}                                                              \
	} while (0)

/* Local convenience macro to extract the peripheral
 * ID from the base address.
 */
#define NRFX_PERIPHERAL_ID_GET(base_addr) \
	(uint8_t)((uint32_t)(base_addr) &amp;gt;&amp;gt; 12)

#ifdef CONFIG_SPM_BOOT_SILENTLY
#define PERIPH(name, reg, config)                                              \
	{                                                                      \
		.id = NRFX_PERIPHERAL_ID_GET(reg), IS_ENABLED(config)          \
	}
#else
#define PERIPH(name, reg, config)                                              \
	{                                                                      \
		name, .id = NRFX_PERIPHERAL_ID_GET(reg), IS_ENABLED(config)    \
	}
#endif

/* Check if configuration exceeds the number of
 * DPPI Channels available on device.
 */
#if (CONFIG_SPM_NRF_DPPIC_PERM_MASK &amp;gt;= (1 &amp;lt;&amp;lt; DPPI_CH_NUM))
#error &amp;quot;SPM_NRF_DPPIC_PERM_MASK exceeds number of available DPPI channels&amp;quot;
#endif

#if defined(CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS)

static void spm_config_nsc_flash(void)
{
	/* Configure a single region in Secure Flash as Non-Secure Callable
	 * (NSC) area.
	 *
	 * Area to configure is dynamically decided with help from linker code.
	 *
	 * Note: Any Secure Entry functions, exposing secure services to the
	 * Non-Secure firmware, shall be located inside this NSC area.
	 *
	 * If the start address of the NSC area is hard-coded, it must follow
	 * the HW restrictions: The size must be a power of 2 between 32 and
	 * 4096, and the end address must fall on a SPU region boundary.
	 */
	uint32_t nsc_size = FLASH_NSC_SIZE_FROM_ADDR(__sg_start);

	__ASSERT((uint32_t)__sg_size &amp;lt;= nsc_size,
		&amp;quot;The Non-Secure Callable region is overflowed by %d byte(s).\n&amp;quot;,
		(uint32_t)__sg_size - nsc_size);

	nrf_spu_flashnsc_set(NRF_SPU, 0, FLASH_NSC_SIZE_REG(nsc_size),
			FLASH_NSC_REGION_FROM_ADDR(__sg_start), false);

	PRINT(&amp;quot;Non-secure callable region 0 placed in flash region %d with size %d.\n&amp;quot;,
		NRF_SPU-&amp;gt;FLASHNSC[0].REGION, NRF_SPU-&amp;gt;FLASHNSC[0].SIZE &amp;lt;&amp;lt; 5);
}
#endif /* CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS */


static void config_regions(bool ram, size_t start, size_t end, uint32_t perm)
{
	const size_t region_size = ram ? RAM_SECURE_ATTRIBUTION_REGION_SIZE
					: FLASH_SECURE_ATTRIBUTION_REGION_SIZE;

	for (size_t i = start; i &amp;lt; end; i++) {
		if (ram) {
			NRF_SPU-&amp;gt;RAMREGION[i].PERM = perm;
		} else {
			NRF_SPU-&amp;gt;FLASHREGION[i].PERM = perm;
		}
	}

	PRINT(&amp;quot;%02u %02u 0x%05x 0x%05x \t&amp;quot;, start, end - 1,
				region_size * start, region_size * end);
	PRINT(&amp;quot;%s&amp;quot;, perm &amp;amp; (ram ? SRAM_SECURE : FLASH_SECURE) ? &amp;quot;Secure\t\t&amp;quot; :
								&amp;quot;Non-Secure\t&amp;quot;);
	PRINT(&amp;quot;%c&amp;quot;, perm &amp;amp; (ram ? SRAM_READ : FLASH_READ)  ? &amp;#39;r&amp;#39; : &amp;#39;-&amp;#39;);
	PRINT(&amp;quot;%c&amp;quot;, perm &amp;amp; (ram ? SRAM_WRITE : FLASH_WRITE) ? &amp;#39;w&amp;#39; : &amp;#39;-&amp;#39;);
	PRINT(&amp;quot;%c&amp;quot;, perm &amp;amp; (ram ? SRAM_EXEC : FLASH_EXEC)  ? &amp;#39;x&amp;#39; : &amp;#39;-&amp;#39;);
	PRINT(&amp;quot;%c&amp;quot;, perm &amp;amp; (ram ? SRAM_LOCK : FLASH_LOCK)  ? &amp;#39;l&amp;#39; : &amp;#39;-&amp;#39;);
	PRINT(&amp;quot;\n&amp;quot;);
}


static void spm_config_flash(void)
{
	/* Regions of flash up to and including SPM are configured as Secure.
	 * The rest of flash is configured as Non-Secure.
	 */
	const uint32_t secure_flash_perm = FLASH_READ | FLASH_WRITE | FLASH_EXEC
			| FLASH_LOCK | FLASH_SECURE;
	const uint32_t nonsecure_flash_perm = FLASH_READ | FLASH_WRITE | FLASH_EXEC
			| FLASH_LOCK | FLASH_NONSEC;

	PRINT(&amp;quot;Flash regions\t\tDomain\t\tPermissions\n&amp;quot;);

	config_regions(false, 0, NON_SECURE_FLASH_REGION_INDEX,
			secure_flash_perm);
	config_regions(false, NON_SECURE_FLASH_REGION_INDEX,
			NUM_FLASH_SECURE_ATTRIBUTION_REGIONS,
			nonsecure_flash_perm);
	PRINT(&amp;quot;\n&amp;quot;);

#if defined(CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS)
	spm_config_nsc_flash();
	PRINT(&amp;quot;\n&amp;quot;);

#if defined(CONFIG_SPM_SECURE_SERVICES)
	int err = spm_secure_services_init();

	if (err != 0) {
		PRINT(&amp;quot;Could not initialize secure services (err %d).\n&amp;quot;, err);
	}
#endif
#endif /* CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS */
}

static void spm_config_sram(void)
{
	/* Lower 64 kB of SRAM is allocated to the Secure firmware image.
	 * The rest of SRAM is allocated to Non-Secure firmware image.
	 */

	const uint32_t secure_ram_perm = SRAM_READ | SRAM_WRITE | SRAM_EXEC
		| SRAM_LOCK | SRAM_SECURE;
	const uint32_t nonsecure_ram_perm = SRAM_READ | SRAM_WRITE | SRAM_EXEC
		| SRAM_LOCK | SRAM_NONSEC;

	PRINT(&amp;quot;SRAM region\t\tDomain\t\tPermissions\n&amp;quot;);

	/* Configuration for Secure RAM Regions (0 - 64 kB) */
	config_regions(true, 0, NON_SECURE_RAM_REGION_INDEX,
			secure_ram_perm);
	/* Configuration for Non-Secure RAM Regions (64 kb - end) */
	config_regions(true, NON_SECURE_RAM_REGION_INDEX,
			NUM_RAM_SECURE_ATTRIBUTION_REGIONS,
			nonsecure_ram_perm);
	PRINT(&amp;quot;\n&amp;quot;);
}

static bool usel_or_split(uint8_t id)
{
	const uint32_t perm = NRF_SPU-&amp;gt;PERIPHID[id].PERM;

	/* NRF_GPIOTE1_NS needs special handling as its
	 * peripheral ID for non-secure han incorrect properties
	 * in the NRF_SPM-&amp;gt;PERIPHID[id].perm register.
	 */
	if (id == NRFX_PERIPHERAL_ID_GET(NRF_GPIOTE1_NS)) {
		return true;
	}

	bool present = (perm &amp;amp; SPU_PERIPHID_PERM_PRESENT_Msk) ==
		       SPU_PERIPHID_PERM_PRESENT_Msk;

	/* User-selectable attribution */
	bool usel = (perm &amp;amp; SPU_PERIPHID_PERM_SECUREMAPPING_Msk) ==
		    SPU_PERIPHID_PERM_SECUREMAPPING_UserSelectable;

	/* Split attribution */
	bool split = (perm &amp;amp; SPU_PERIPHID_PERM_SECUREMAPPING_Msk) ==
		     SPU_PERIPHID_PERM_SECUREMAPPING_Split;

	return present &amp;amp;&amp;amp; (usel || split);
}

static int spm_config_peripheral(uint8_t id, bool dma_present)
{
	/* Set a peripheral to Non-Secure state, if
	 * - it is present
	 * - has UserSelectable/Split attribution.
	 *
	 * Assign DMA capabilities and lock down the attribution.
	 *
	 * Note: the function assumes that the peripheral ID matches
	 * the IRQ line.
	 */
	NVIC_DisableIRQ(id);

	if (usel_or_split(id)) {
		NRF_SPU-&amp;gt;PERIPHID[id].PERM = PERIPH_PRESENT | PERIPH_NONSEC |
			(dma_present ? PERIPH_DMA_NOSEP : 0) |
			PERIPH_LOCK;
	}

	/* Even for non-present peripherals we force IRQs to be routed
	 * to Non-Secure state.
	 */
	irq_target_state_set(id, IRQ_TARGET_STATE_NON_SECURE);
	return 0;
}

static void spm_dppi_configure(uint32_t mask)
{
	NRF_SPU-&amp;gt;DPPI[0].PERM = mask;
}

static void spm_config_peripherals(void)
{
	struct periph_cfg {
#ifndef CONFIG_SPM_BOOT_SILENTLY
		char *name;
#endif
		uint8_t id;
		uint8_t nonsecure;
	};

	/* - All user peripherals are allocated to the Non-Secure domain.
	 * - All GPIOs are allocated to the Non-Secure domain.
	 */
	static const struct periph_cfg periph[] = {
#ifdef NRF_P0
		PERIPH(&amp;quot;NRF_P0&amp;quot;, NRF_P0, CONFIG_SPM_NRF_P0_NS),
#endif
#ifdef NRF_P1
		PERIPH(&amp;quot;NRF_P1&amp;quot;, NRF_P1, CONFIG_SPM_NRF_P1_NS),
#endif
#ifdef NRF_QSPI
		PERIPH(&amp;quot;NRF_QSPI&amp;quot;, NRF_QSPI, CONFIG_SPM_NRF_QSPI_NS),
#endif
#ifdef NRF_CLOCK
		PERIPH(&amp;quot;NRF_CLOCK&amp;quot;, NRF_CLOCK, CONFIG_SPM_NRF_CLOCK_NS),
#endif
#ifdef NRF_RTC0
		PERIPH(&amp;quot;NRF_RTC0&amp;quot;, NRF_RTC0, CONFIG_SPM_NRF_RTC0_NS),
#endif
#ifdef NRF_RTC1
		PERIPH(&amp;quot;NRF_RTC1&amp;quot;, NRF_RTC1, CONFIG_SPM_NRF_RTC1_NS),
#endif
#ifdef NRF_NFCT
		PERIPH(&amp;quot;NRF_NFCT&amp;quot;, NRF_NFCT, CONFIG_SPM_NRF_NFCT_NS),
#endif
#ifdef NRF_NVMC
		PERIPH(&amp;quot;NRF_NVMC&amp;quot;, NRF_NVMC, CONFIG_SPM_NRF_NVMC_NS),
#endif
#ifdef NRF_UARTE1
		PERIPH(&amp;quot;NRF_UARTE1&amp;quot;, NRF_UARTE1, CONFIG_SPM_NRF_UARTE1_NS),
#endif
#ifdef NRF_UARTE2
		PERIPH(&amp;quot;NRF_UARTE2&amp;quot;, NRF_UARTE2, CONFIG_SPM_NRF_UARTE2_NS),
#endif
#ifdef NRF_TWIM2
		PERIPH(&amp;quot;NRF_TWIM2&amp;quot;, NRF_TWIM2, CONFIG_SPM_NRF_TWIM2_NS),
#endif
#ifdef NRF_SPIM3
		PERIPH(&amp;quot;NRF_SPIM3&amp;quot;, NRF_SPIM3, CONFIG_SPM_NRF_SPIM3_NS),
#endif
#ifdef NRF_TIMER0
		PERIPH(&amp;quot;NRF_TIMER0&amp;quot;, NRF_TIMER0, CONFIG_SPM_NRF_TIMER0_NS),
#endif
#ifdef NRF_TIMER1
		PERIPH(&amp;quot;NRF_TIMER1&amp;quot;, NRF_TIMER1, CONFIG_SPM_NRF_TIMER1_NS),
#endif
#ifdef NRF_TIMER2
		PERIPH(&amp;quot;NRF_TIMER2&amp;quot;, NRF_TIMER2, CONFIG_SPM_NRF_TIMER2_NS),
#endif
#ifdef NRF_SAADC
		PERIPH(&amp;quot;NRF_SAADC&amp;quot;, NRF_SAADC, CONFIG_SPM_NRF_SAADC_NS),
#endif
#ifdef NRF_PWM0
		PERIPH(&amp;quot;NRF_PWM0&amp;quot;, NRF_PWM0, CONFIG_SPM_NRF_PWM0_NS),
#endif
#ifdef NRF_PWM1
		PERIPH(&amp;quot;NRF_PWM1&amp;quot;, NRF_PWM1, CONFIG_SPM_NRF_PWM1_NS),
#endif
#ifdef NRF_PWM2
		PERIPH(&amp;quot;NRF_PWM2&amp;quot;, NRF_PWM2, CONFIG_SPM_NRF_PWM2_NS),
#endif
#ifdef NRF_PWM3
		PERIPH(&amp;quot;NRF_PWM3&amp;quot;, NRF_PWM3, CONFIG_SPM_NRF_PWM3_NS),
#endif
#ifdef NRF_WDT
		PERIPH(&amp;quot;NRF_WDT&amp;quot;, NRF_WDT, CONFIG_SPM_NRF_WDT_NS),
#endif
		/* There is no DTS node for the peripherals below,
		 * so address them using nrfx macros directly.
		 */
		PERIPH(&amp;quot;NRF_IPC&amp;quot;, NRF_IPC_S, CONFIG_SPM_NRF_IPC_NS),
		PERIPH(&amp;quot;NRF_VMC&amp;quot;, NRF_VMC_S, CONFIG_SPM_NRF_VMC_NS),
		PERIPH(&amp;quot;NRF_FPU&amp;quot;, NRF_FPU_S, CONFIG_SPM_NRF_FPU_NS),
		PERIPH(&amp;quot;NRF_EGU1&amp;quot;, NRF_EGU1_S, CONFIG_SPM_NRF_EGU1_NS),
		PERIPH(&amp;quot;NRF_EGU2&amp;quot;, NRF_EGU2_S, CONFIG_SPM_NRF_EGU2_NS),
		PERIPH(&amp;quot;NRF_DPPIC&amp;quot;, NRF_DPPIC_S, CONFIG_SPM_NRF_DPPIC_NS),

		PERIPH(&amp;quot;NRF_GPIOTE1&amp;quot;, NRF_GPIOTE1_NS,
				      CONFIG_SPM_NRF_GPIOTE1_NS),
		PERIPH(&amp;quot;NRF_REGULATORS&amp;quot;, NRF_REGULATORS_S,
				      CONFIG_SPM_NRF_REGULATORS_NS),
	};

	if (IS_ENABLED(CONFIG_SPM_NRF_DPPIC_NS)) {
		spm_dppi_configure(CONFIG_SPM_NRF_DPPIC_PERM_MASK);
	}

	PRINT(&amp;quot;Peripheral\t\tDomain\t\tStatus\n&amp;quot;);

	if (IS_ENABLED(CONFIG_SPM_NRF_P0_NS)) {
		/* Configure GPIO pins to be Non-Secure */
		NRF_SPU-&amp;gt;GPIOPORT[0].PERM = 0;
		//DEV_MOD
		NRF_SPU-&amp;gt;GPIOPORT[1].PERM = 0;
	}

	for (size_t i = 0; i &amp;lt; ARRAY_SIZE(periph); i++) {
		int err;

#ifndef CONFIG_SPM_BOOT_SILENTLY
		PRINT(&amp;quot;%02u %-21s%s&amp;quot;, i, periph[i].name,
		      periph[i].nonsecure ? &amp;quot;Non-Secure&amp;quot; : &amp;quot;Secure\t&amp;quot;);
#endif

		if (!periph[i].nonsecure) {
			//DEV_MOD
			if(periph[i].id == NRFX_PERIPHERAL_ID_GET(NRF_QSPI)) {
				PRINT(&amp;quot;\tFORCED\n&amp;quot;);
			}
			else {
				PRINT(&amp;quot;\tSKIP\n&amp;quot;);
				continue;
			}
		}

		err = spm_config_peripheral(periph[i].id, false);
		if (err) {
			PRINT(&amp;quot;\tERROR\n&amp;quot;);
		} else {
			PRINT(&amp;quot;\tOK\n&amp;quot;);
		}
	}
	PRINT(&amp;quot;\n&amp;quot;);
}


static void spm_configure_ns(const tz_nonsecure_setup_conf_t
	*spm_ns_conf)
{
	/* Configure core register block for Non-Secure state. */
	tz_nonsecure_state_setup(spm_ns_conf);
	/* Prioritize Secure exceptions over Non-Secure */
	tz_nonsecure_exception_prio_config(1);
	/* Set non-banked exceptions to target Non-Secure */
	tz_nbanked_exception_target_state_set(0);
	/* Configure if Non-Secure firmware should be allowed to issue System
	 * reset. If not it could be enabled through a secure service.
	 */
	tz_nonsecure_system_reset_req_block(
		IS_ENABLED(CONFIG_SPM_BLOCK_NON_SECURE_RESET)
	);
	/* Allow SPU to have precedence over (non-existing) ARMv8-M SAU. */
	tz_sau_configure(0, 1);

#if defined(CONFIG_ARMV7_M_ARMV8_M_FP) &amp;amp;&amp;amp; defined(CONFIG_SPM_NRF_FPU_NS)
	/* Allow Non-Secure firmware to use the FPU */
	tz_nonsecure_fpu_access_enable();
#endif /* CONFIG_ARMV7_M_ARMV8_M_FP */
}

void spm_jump(void)
{
	/* Extract initial MSP of the Non-Secure firmware image.
	 * The assumption is that the MSP is located at VTOR_NS[0].
	 */
	uint32_t *vtor_ns = (uint32_t *)NON_SECURE_APP_ADDRESS;

	PRINT(&amp;quot;SPM: NS image at 0x%x\n&amp;quot;, (uint32_t)vtor_ns);
	PRINT(&amp;quot;SPM: NS MSP at 0x%x\n&amp;quot;, vtor_ns[0]);
	PRINT(&amp;quot;SPM: NS reset vector at 0x%x\n&amp;quot;, vtor_ns[1]);

	/* Configure Non-Secure stack */
	tz_nonsecure_setup_conf_t spm_ns_conf = {
		.vtor_ns = (uint32_t)vtor_ns,
		.msp_ns = vtor_ns[0],
		.psp_ns = 0,
		.control_ns.npriv = 0, /* Privileged mode*/
		.control_ns.spsel = 0 /* Use MSP in Thread mode */
	};

	spm_configure_ns(&amp;amp;spm_ns_conf);

	/* Generate function pointer for Non-Secure function call. */
	TZ_NONSECURE_FUNC_PTR_DECLARE(reset_ns);
	reset_ns = TZ_NONSECURE_FUNC_PTR_CREATE(vtor_ns[1]);

	if (TZ_NONSECURE_FUNC_PTR_IS_NS(reset_ns)) {
		PRINT(&amp;quot;SPM: prepare to jump to Non-Secure image.\n&amp;quot;);

		/* Note: Move UARTE0 before jumping, if it is
		 * to be used on the Non-Secure domain.
		 */

		/* Configure UARTE0 as non-secure */
		spm_config_peripheral(
			NRFX_PERIPHERAL_ID_GET(NRF_UARTE0), 0);

		__DSB();
		__ISB();

		/* Jump to Non-Secure firmware */
		reset_ns();

		CODE_UNREACHABLE;

	} else {
		PRINT(&amp;quot;SPM: wrong pointer type: 0x%x\n&amp;quot;,
		      (uint32_t)reset_ns);
	}
}

void spm_config(void)
{
	spm_config_flash();
	spm_config_sram();
	spm_config_peripherals();
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Note that official support for QSPI on the nRF5340 as of now only exists on the master branch of NCS, but I believe the non-secure issue is still present there as well so I&amp;#39;ve taken this up with the developers.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;PS: The Holiday season is upon us, which will leave the Nordic support team understaffed until January 4th, 2021. This means that delayed replies will occur during this time. Sorry about the inconvenience and happy Holidays!&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWIM usage in non secure application core</title><link>https://devzone.nordicsemi.com/thread/285695?ContentTypeID=1</link><pubDate>Thu, 17 Dec 2020 16:15:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8b5d0fea-d5a4-44f0-8198-dbf5fe750228</guid><dc:creator>GiulianoFranchetto</dc:creator><description>&lt;p&gt;Apparently, this is not related to TWIM issue, but QSPI.&lt;/p&gt;
&lt;p&gt;A crash is happenig here:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;nrf_qspi_pins_set(NRF_QSPI, p_config);
    000184CA   LDR          R3, [PC, #0xBC]            
    000184CC   STR.W        LR, [R3, #0x524]
p_reg-&amp;gt;PSEL.CSN = NRF_QSPI_PIN_VAL(p_pins-&amp;gt;csn_pin);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve tried to add in smp.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#ifdef NRF_QSPI
		PERIPH(&amp;quot;NRF_QSPI&amp;quot;, NRF_QSPI, CONFIG_SPM_NRF_QSPI_NS),
#endif&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;but no luck&amp;nbsp;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f61e.svg" title="Disappointed"&gt;&amp;#x1f61e;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;When I disable QSPI, the crash disapears, and the TWI is indeed working &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt; So P1 not being accessible from not secure was indeed the issue.&lt;/p&gt;
&lt;p&gt;But apparently, this issue is also the same with QSPI. Correct?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWIM usage in non secure application core</title><link>https://devzone.nordicsemi.com/thread/285691?ContentTypeID=1</link><pubDate>Thu, 17 Dec 2020 15:56:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:feea2a82-d38f-4f7d-b11d-8a3461153dc4</guid><dc:creator>GiulianoFranchetto</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I just tried it. I now have a crash on startup:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;[00:00:00.002,685]&amp;#160;&amp;lt;err&amp;gt;&amp;#160;os:&amp;#160;*****&amp;#160;BUS&amp;#160;FAULT&amp;#160;*****
[00:00:00.002,685]&amp;#160;&amp;lt;err&amp;gt;&amp;#160;os:&amp;#160;&amp;#160;&amp;#160;Precise&amp;#160;data&amp;#160;bus&amp;#160;error
[00:00:00.002,685]&amp;#160;&amp;lt;err&amp;gt;&amp;#160;os:&amp;#160;&amp;#160;&amp;#160;BFAR&amp;#160;Address:&amp;#160;0x4002b524
[00:00:00.002,685]&amp;#160;&amp;lt;err&amp;gt;&amp;#160;os:&amp;#160;r0/a1:&amp;#160;&amp;#160;0x2000f370&amp;#160;&amp;#160;r1/a2:&amp;#160;&amp;#160;0x0001f82f&amp;#160;&amp;#160;r2/a3:&amp;#160;&amp;#160;0x200083b8
[00:00:00.002,685]&amp;#160;&amp;lt;err&amp;gt;&amp;#160;os:&amp;#160;r3/a4:&amp;#160;&amp;#160;0x4002b000&amp;#160;r12/ip:&amp;#160;&amp;#160;0x00000012&amp;#160;r14/lr:&amp;#160;&amp;#160;0x0000001
[00:00:00.002,716]&amp;#160;&amp;lt;err&amp;gt;&amp;#160;os:&amp;#160;&amp;#160;xpsr:&amp;#160;&amp;#160;0x81000000
[00:00:00.002,716]&amp;#160;&amp;lt;err&amp;gt;&amp;#160;os:&amp;#160;Faulting&amp;#160;instruction&amp;#160;address&amp;#160;(r15/pc):&amp;#160;0x000184ec
[00:00:00.002,716]&amp;#160;&amp;lt;err&amp;gt;&amp;#160;os:&amp;#160;&amp;gt;&amp;gt;&amp;gt;&amp;#160;ZEPHYR&amp;#160;FATAL&amp;#160;ERROR&amp;#160;0:&amp;#160;CPU&amp;#160;exception&amp;#160;on&amp;#160;CPU&amp;#160;0
[00:00:00.002,716]&amp;#160;&amp;lt;err&amp;gt;&amp;#160;os:&amp;#160;Current&amp;#160;thread:&amp;#160;0x200091b8&amp;#160;(unknown)
[00:00:00.657,623]&amp;#160;&amp;lt;err&amp;gt;&amp;#160;fatal_error:&amp;#160;Resetting&amp;#160;system[0m&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWIM usage in non secure application core</title><link>https://devzone.nordicsemi.com/thread/285680?ContentTypeID=1</link><pubDate>Thu, 17 Dec 2020 15:16:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c9470b96-0bcd-40bd-8bdb-91e15ceeb4a2</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hi again!&lt;br /&gt;&lt;br /&gt;I had another look at your device tree file. The P1.x pins of the nRF5340 are considered secure by default by the secure partition manager, this includes pin 34. Could you try to replace&lt;strong&gt; &lt;/strong&gt;the code of&lt;strong&gt;&amp;nbsp;&amp;lt;ncs_root&amp;gt;\nrf\subsys\spm\spm.c&lt;/strong&gt;&amp;nbsp;with the following:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*
 * Copyright (c) 2019 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
 */

#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;sys/printk.h&amp;gt;
#include &amp;lt;sys/util.h&amp;gt;
#include &amp;lt;linker/linker-defs.h&amp;gt;
#include &amp;lt;device.h&amp;gt;
#include &amp;lt;drivers/gpio.h&amp;gt;
#include &amp;lt;hal/nrf_spu.h&amp;gt;
#include &amp;lt;arch/arm/aarch32/irq.h&amp;gt;
#include &amp;quot;spm_internal.h&amp;quot;

#if !defined(CONFIG_ARM_SECURE_FIRMWARE)
#error &amp;quot;Module requires compiling for Secure ARM Firmware&amp;quot;
#endif

/* Include required APIs for TrustZone-M */
#include &amp;lt;arm_cmse.h&amp;gt;
#include &amp;lt;cortex_m/tz.h&amp;gt;

#include &amp;lt;nrfx.h&amp;gt;

#if USE_PARTITION_MANAGER
#include &amp;lt;pm_config.h&amp;gt;
#define NON_SECURE_APP_ADDRESS PM_APP_ADDRESS
#define NON_SECURE_RAM_OFFSET PM_SRAM_SECURE_SIZE
#else
#include &amp;lt;storage/flash_map.h&amp;gt;
#define NON_SECURE_APP_ADDRESS FLASH_AREA_ID(image_0_nonsecure)
/* This reflects the configuration in DTS. */
#define NON_SECURE_RAM_OFFSET 0x10000
#endif /* USE_PARTITION_MANAGER */

#define NON_SECURE_FLASH_REGION_INDEX \
	((NON_SECURE_APP_ADDRESS) / (FLASH_SECURE_ATTRIBUTION_REGION_SIZE))
#define NON_SECURE_RAM_REGION_INDEX \
	((NON_SECURE_RAM_OFFSET) / (RAM_SECURE_ATTRIBUTION_REGION_SIZE))

/*
 *  * The security configuration for depends on where the non secure app
 *  * is placed. All flash regions before the region which contains the
 *  * non secure app is configured as Secure.
 *
 *                FLASH
 *  1 MB  |---------------------|
 *        |                     |
 *        |                     |
 *        |                     |
 *        |                     |
 *        |                     |
 *        |     Non-Secure      |
 *        |       Flash         |
 *        |                     |
 *  X kB  |---------------------|
 *        |                     |
 *        |     Secure          |
 *        |      Flash          |
 *  0 kB  |---------------------|
 *
 *  * The SRAM configuration is given by the partition manager.
 *  * To see the current configuration, run the &amp;#39;pm_report&amp;#39; target.
 *  * E.g. &amp;#39;ninja pm_report, in your build folder. All partitions
 *  * within the &amp;#39;secure_ram&amp;#39; span is configured as secure by the SPM.
 *
 */

extern irq_target_state_t irq_target_state_set(unsigned int irq,
	irq_target_state_t irq_target_state);
extern int irq_target_state_is_secure(unsigned int irq);

/* printk wrapper, to turn off logs when booting silently */
#define PRINT(...)                                                             \
	do {                                                                   \
		if (!IS_ENABLED(CONFIG_SPM_BOOT_SILENTLY)) {                   \
			printk(__VA_ARGS__);                                   \
		}                                                              \
	} while (0)

/* Local convenience macro to extract the peripheral
 * ID from the base address.
 */
#define NRFX_PERIPHERAL_ID_GET(base_addr) \
	(uint8_t)((uint32_t)(base_addr) &amp;gt;&amp;gt; 12)

#ifdef CONFIG_SPM_BOOT_SILENTLY
#define PERIPH(name, reg, config)                                              \
	{                                                                      \
		.id = NRFX_PERIPHERAL_ID_GET(reg), IS_ENABLED(config)          \
	}
#else
#define PERIPH(name, reg, config)                                              \
	{                                                                      \
		name, .id = NRFX_PERIPHERAL_ID_GET(reg), IS_ENABLED(config)    \
	}
#endif

/* Check if configuration exceeds the number of
 * DPPI Channels available on device.
 */
#if (CONFIG_SPM_NRF_DPPIC_PERM_MASK &amp;gt;= (1 &amp;lt;&amp;lt; DPPI_CH_NUM))
#error &amp;quot;SPM_NRF_DPPIC_PERM_MASK exceeds number of available DPPI channels&amp;quot;
#endif

#if defined(CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS)

static void spm_config_nsc_flash(void)
{
	/* Configure a single region in Secure Flash as Non-Secure Callable
	 * (NSC) area.
	 *
	 * Area to configure is dynamically decided with help from linker code.
	 *
	 * Note: Any Secure Entry functions, exposing secure services to the
	 * Non-Secure firmware, shall be located inside this NSC area.
	 *
	 * If the start address of the NSC area is hard-coded, it must follow
	 * the HW restrictions: The size must be a power of 2 between 32 and
	 * 4096, and the end address must fall on a SPU region boundary.
	 */
	uint32_t nsc_size = FLASH_NSC_SIZE_FROM_ADDR(__sg_start);

	__ASSERT((uint32_t)__sg_size &amp;lt;= nsc_size,
		&amp;quot;The Non-Secure Callable region is overflowed by %d byte(s).\n&amp;quot;,
		(uint32_t)__sg_size - nsc_size);

	nrf_spu_flashnsc_set(NRF_SPU, 0, FLASH_NSC_SIZE_REG(nsc_size),
			FLASH_NSC_REGION_FROM_ADDR(__sg_start), false);

	PRINT(&amp;quot;Non-secure callable region 0 placed in flash region %d with size %d.\n&amp;quot;,
		NRF_SPU-&amp;gt;FLASHNSC[0].REGION, NRF_SPU-&amp;gt;FLASHNSC[0].SIZE &amp;lt;&amp;lt; 5);
}
#endif /* CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS */


static void config_regions(bool ram, size_t start, size_t end, uint32_t perm)
{
	const size_t region_size = ram ? RAM_SECURE_ATTRIBUTION_REGION_SIZE
					: FLASH_SECURE_ATTRIBUTION_REGION_SIZE;

	for (size_t i = start; i &amp;lt; end; i++) {
		if (ram) {
			NRF_SPU-&amp;gt;RAMREGION[i].PERM = perm;
		} else {
			NRF_SPU-&amp;gt;FLASHREGION[i].PERM = perm;
		}
	}

	PRINT(&amp;quot;%02u %02u 0x%05x 0x%05x \t&amp;quot;, start, end - 1,
				region_size * start, region_size * end);
	PRINT(&amp;quot;%s&amp;quot;, perm &amp;amp; (ram ? SRAM_SECURE : FLASH_SECURE) ? &amp;quot;Secure\t\t&amp;quot; :
								&amp;quot;Non-Secure\t&amp;quot;);
	PRINT(&amp;quot;%c&amp;quot;, perm &amp;amp; (ram ? SRAM_READ : FLASH_READ)  ? &amp;#39;r&amp;#39; : &amp;#39;-&amp;#39;);
	PRINT(&amp;quot;%c&amp;quot;, perm &amp;amp; (ram ? SRAM_WRITE : FLASH_WRITE) ? &amp;#39;w&amp;#39; : &amp;#39;-&amp;#39;);
	PRINT(&amp;quot;%c&amp;quot;, perm &amp;amp; (ram ? SRAM_EXEC : FLASH_EXEC)  ? &amp;#39;x&amp;#39; : &amp;#39;-&amp;#39;);
	PRINT(&amp;quot;%c&amp;quot;, perm &amp;amp; (ram ? SRAM_LOCK : FLASH_LOCK)  ? &amp;#39;l&amp;#39; : &amp;#39;-&amp;#39;);
	PRINT(&amp;quot;\n&amp;quot;);
}


static void spm_config_flash(void)
{
	/* Regions of flash up to and including SPM are configured as Secure.
	 * The rest of flash is configured as Non-Secure.
	 */
	const uint32_t secure_flash_perm = FLASH_READ | FLASH_WRITE | FLASH_EXEC
			| FLASH_LOCK | FLASH_SECURE;
	const uint32_t nonsecure_flash_perm = FLASH_READ | FLASH_WRITE | FLASH_EXEC
			| FLASH_LOCK | FLASH_NONSEC;

	PRINT(&amp;quot;Flash regions\t\tDomain\t\tPermissions\n&amp;quot;);

	config_regions(false, 0, NON_SECURE_FLASH_REGION_INDEX,
			secure_flash_perm);
	config_regions(false, NON_SECURE_FLASH_REGION_INDEX,
			NUM_FLASH_SECURE_ATTRIBUTION_REGIONS,
			nonsecure_flash_perm);
	PRINT(&amp;quot;\n&amp;quot;);

#if defined(CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS)
	spm_config_nsc_flash();
	PRINT(&amp;quot;\n&amp;quot;);

#if defined(CONFIG_SPM_SECURE_SERVICES)
	int err = spm_secure_services_init();

	if (err != 0) {
		PRINT(&amp;quot;Could not initialize secure services (err %d).\n&amp;quot;, err);
	}
#endif
#endif /* CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS */
}

static void spm_config_sram(void)
{
	/* Lower 64 kB of SRAM is allocated to the Secure firmware image.
	 * The rest of SRAM is allocated to Non-Secure firmware image.
	 */

	const uint32_t secure_ram_perm = SRAM_READ | SRAM_WRITE | SRAM_EXEC
		| SRAM_LOCK | SRAM_SECURE;
	const uint32_t nonsecure_ram_perm = SRAM_READ | SRAM_WRITE | SRAM_EXEC
		| SRAM_LOCK | SRAM_NONSEC;

	PRINT(&amp;quot;SRAM region\t\tDomain\t\tPermissions\n&amp;quot;);

	/* Configuration for Secure RAM Regions (0 - 64 kB) */
	config_regions(true, 0, NON_SECURE_RAM_REGION_INDEX,
			secure_ram_perm);
	/* Configuration for Non-Secure RAM Regions (64 kb - end) */
	config_regions(true, NON_SECURE_RAM_REGION_INDEX,
			NUM_RAM_SECURE_ATTRIBUTION_REGIONS,
			nonsecure_ram_perm);
	PRINT(&amp;quot;\n&amp;quot;);
}

static bool usel_or_split(uint8_t id)
{
	const uint32_t perm = NRF_SPU-&amp;gt;PERIPHID[id].PERM;

	/* NRF_GPIOTE1_NS needs special handling as its
	 * peripheral ID for non-secure han incorrect properties
	 * in the NRF_SPM-&amp;gt;PERIPHID[id].perm register.
	 */
	if (id == NRFX_PERIPHERAL_ID_GET(NRF_GPIOTE1_NS)) {
		return true;
	}

	bool present = (perm &amp;amp; SPU_PERIPHID_PERM_PRESENT_Msk) ==
		       SPU_PERIPHID_PERM_PRESENT_Msk;

	/* User-selectable attribution */
	bool usel = (perm &amp;amp; SPU_PERIPHID_PERM_SECUREMAPPING_Msk) ==
		    SPU_PERIPHID_PERM_SECUREMAPPING_UserSelectable;

	/* Split attribution */
	bool split = (perm &amp;amp; SPU_PERIPHID_PERM_SECUREMAPPING_Msk) ==
		     SPU_PERIPHID_PERM_SECUREMAPPING_Split;

	return present &amp;amp;&amp;amp; (usel || split);
}

static int spm_config_peripheral(uint8_t id, bool dma_present)
{
	/* Set a peripheral to Non-Secure state, if
	 * - it is present
	 * - has UserSelectable/Split attribution.
	 *
	 * Assign DMA capabilities and lock down the attribution.
	 *
	 * Note: the function assumes that the peripheral ID matches
	 * the IRQ line.
	 */
	NVIC_DisableIRQ(id);

	if (usel_or_split(id)) {
		NRF_SPU-&amp;gt;PERIPHID[id].PERM = PERIPH_PRESENT | PERIPH_NONSEC |
			(dma_present ? PERIPH_DMA_NOSEP : 0) |
			PERIPH_LOCK;
	}

	/* Even for non-present peripherals we force IRQs to be routed
	 * to Non-Secure state.
	 */
	irq_target_state_set(id, IRQ_TARGET_STATE_NON_SECURE);
	return 0;
}

static void spm_dppi_configure(uint32_t mask)
{
	NRF_SPU-&amp;gt;DPPI[0].PERM = mask;
}

static void spm_config_peripherals(void)
{
	struct periph_cfg {
#ifndef CONFIG_SPM_BOOT_SILENTLY
		char *name;
#endif
		uint8_t id;
		uint8_t nonsecure;
	};

	/* - All user peripherals are allocated to the Non-Secure domain.
	 * - All GPIOs are allocated to the Non-Secure domain.
	 */
	static const struct periph_cfg periph[] = {
#ifdef NRF_P0
		PERIPH(&amp;quot;NRF_P0&amp;quot;, NRF_P0, CONFIG_SPM_NRF_P0_NS),
#endif
#ifdef NRF_CLOCK
		PERIPH(&amp;quot;NRF_CLOCK&amp;quot;, NRF_CLOCK, CONFIG_SPM_NRF_CLOCK_NS),
#endif
#ifdef NRF_RTC0
		PERIPH(&amp;quot;NRF_RTC0&amp;quot;, NRF_RTC0, CONFIG_SPM_NRF_RTC0_NS),
#endif
#ifdef NRF_RTC1
		PERIPH(&amp;quot;NRF_RTC1&amp;quot;, NRF_RTC1, CONFIG_SPM_NRF_RTC1_NS),
#endif
#ifdef NRF_NFCT
		PERIPH(&amp;quot;NRF_NFCT&amp;quot;, NRF_NFCT, CONFIG_SPM_NRF_NFCT_NS),
#endif
#ifdef NRF_NVMC
		PERIPH(&amp;quot;NRF_NVMC&amp;quot;, NRF_NVMC, CONFIG_SPM_NRF_NVMC_NS),
#endif
#ifdef NRF_UARTE1
		PERIPH(&amp;quot;NRF_UARTE1&amp;quot;, NRF_UARTE1, CONFIG_SPM_NRF_UARTE1_NS),
#endif
#ifdef NRF_UARTE2
		PERIPH(&amp;quot;NRF_UARTE2&amp;quot;, NRF_UARTE2, CONFIG_SPM_NRF_UARTE2_NS),
#endif
#ifdef NRF_TWIM2
		PERIPH(&amp;quot;NRF_TWIM2&amp;quot;, NRF_TWIM2, CONFIG_SPM_NRF_TWIM2_NS),
#endif
#ifdef NRF_SPIM3
		PERIPH(&amp;quot;NRF_SPIM3&amp;quot;, NRF_SPIM3, CONFIG_SPM_NRF_SPIM3_NS),
#endif
#ifdef NRF_TIMER0
		PERIPH(&amp;quot;NRF_TIMER0&amp;quot;, NRF_TIMER0, CONFIG_SPM_NRF_TIMER0_NS),
#endif
#ifdef NRF_TIMER1
		PERIPH(&amp;quot;NRF_TIMER1&amp;quot;, NRF_TIMER1, CONFIG_SPM_NRF_TIMER1_NS),
#endif
#ifdef NRF_TIMER2
		PERIPH(&amp;quot;NRF_TIMER2&amp;quot;, NRF_TIMER2, CONFIG_SPM_NRF_TIMER2_NS),
#endif
#ifdef NRF_SAADC
		PERIPH(&amp;quot;NRF_SAADC&amp;quot;, NRF_SAADC, CONFIG_SPM_NRF_SAADC_NS),
#endif
#ifdef NRF_PWM0
		PERIPH(&amp;quot;NRF_PWM0&amp;quot;, NRF_PWM0, CONFIG_SPM_NRF_PWM0_NS),
#endif
#ifdef NRF_PWM1
		PERIPH(&amp;quot;NRF_PWM1&amp;quot;, NRF_PWM1, CONFIG_SPM_NRF_PWM1_NS),
#endif
#ifdef NRF_PWM2
		PERIPH(&amp;quot;NRF_PWM2&amp;quot;, NRF_PWM2, CONFIG_SPM_NRF_PWM2_NS),
#endif
#ifdef NRF_PWM3
		PERIPH(&amp;quot;NRF_PWM3&amp;quot;, NRF_PWM3, CONFIG_SPM_NRF_PWM3_NS),
#endif
#ifdef NRF_WDT
		PERIPH(&amp;quot;NRF_WDT&amp;quot;, NRF_WDT, CONFIG_SPM_NRF_WDT_NS),
#endif
		/* There is no DTS node for the peripherals below,
		 * so address them using nrfx macros directly.
		 */
		PERIPH(&amp;quot;NRF_IPC&amp;quot;, NRF_IPC_S, CONFIG_SPM_NRF_IPC_NS),
		PERIPH(&amp;quot;NRF_VMC&amp;quot;, NRF_VMC_S, CONFIG_SPM_NRF_VMC_NS),
		PERIPH(&amp;quot;NRF_FPU&amp;quot;, NRF_FPU_S, CONFIG_SPM_NRF_FPU_NS),
		PERIPH(&amp;quot;NRF_EGU1&amp;quot;, NRF_EGU1_S, CONFIG_SPM_NRF_EGU1_NS),
		PERIPH(&amp;quot;NRF_EGU2&amp;quot;, NRF_EGU2_S, CONFIG_SPM_NRF_EGU2_NS),
		PERIPH(&amp;quot;NRF_DPPIC&amp;quot;, NRF_DPPIC_S, CONFIG_SPM_NRF_DPPIC_NS),

		PERIPH(&amp;quot;NRF_GPIOTE1&amp;quot;, NRF_GPIOTE1_NS,
				      CONFIG_SPM_NRF_GPIOTE1_NS),
		PERIPH(&amp;quot;NRF_REGULATORS&amp;quot;, NRF_REGULATORS_S,
				      CONFIG_SPM_NRF_REGULATORS_NS),
	};

	if (IS_ENABLED(CONFIG_SPM_NRF_DPPIC_NS)) {
		spm_dppi_configure(CONFIG_SPM_NRF_DPPIC_PERM_MASK);
	}

	PRINT(&amp;quot;Peripheral\t\tDomain\t\tStatus\n&amp;quot;);

	if (IS_ENABLED(CONFIG_SPM_NRF_P0_NS)) {
		/* Configure GPIO pins to be Non-Secure */
		NRF_SPU-&amp;gt;GPIOPORT[0].PERM = 0;
		NRF_SPU-&amp;gt;GPIOPORT[1].PERM = 0;
	}

	for (size_t i = 0; i &amp;lt; ARRAY_SIZE(periph); i++) {
		int err;

#ifndef CONFIG_SPM_BOOT_SILENTLY
		PRINT(&amp;quot;%02u %-21s%s&amp;quot;, i, periph[i].name,
		      periph[i].nonsecure ? &amp;quot;Non-Secure&amp;quot; : &amp;quot;Secure\t&amp;quot;);
#endif

		if (!periph[i].nonsecure) {
			PRINT(&amp;quot;\tSKIP\n&amp;quot;);
			continue;
		}

		err = spm_config_peripheral(periph[i].id, false);
		if (err) {
			PRINT(&amp;quot;\tERROR\n&amp;quot;);
		} else {
			PRINT(&amp;quot;\tOK\n&amp;quot;);
		}
	}
	PRINT(&amp;quot;\n&amp;quot;);
}


static void spm_configure_ns(const tz_nonsecure_setup_conf_t
	*spm_ns_conf)
{
	/* Configure core register block for Non-Secure state. */
	tz_nonsecure_state_setup(spm_ns_conf);
	/* Prioritize Secure exceptions over Non-Secure */
	tz_nonsecure_exception_prio_config(1);
	/* Set non-banked exceptions to target Non-Secure */
	tz_nbanked_exception_target_state_set(0);
	/* Configure if Non-Secure firmware should be allowed to issue System
	 * reset. If not it could be enabled through a secure service.
	 */
	tz_nonsecure_system_reset_req_block(
		IS_ENABLED(CONFIG_SPM_BLOCK_NON_SECURE_RESET)
	);
	/* Allow SPU to have precedence over (non-existing) ARMv8-M SAU. */
	tz_sau_configure(0, 1);

#if defined(CONFIG_ARMV7_M_ARMV8_M_FP) &amp;amp;&amp;amp; defined(CONFIG_SPM_NRF_FPU_NS)
	/* Allow Non-Secure firmware to use the FPU */
	tz_nonsecure_fpu_access_enable();
#endif /* CONFIG_ARMV7_M_ARMV8_M_FP */
}

void spm_jump(void)
{
	/* Extract initial MSP of the Non-Secure firmware image.
	 * The assumption is that the MSP is located at VTOR_NS[0].
	 */
	uint32_t *vtor_ns = (uint32_t *)NON_SECURE_APP_ADDRESS;

	PRINT(&amp;quot;SPM: NS image at 0x%x\n&amp;quot;, (uint32_t)vtor_ns);
	PRINT(&amp;quot;SPM: NS MSP at 0x%x\n&amp;quot;, vtor_ns[0]);
	PRINT(&amp;quot;SPM: NS reset vector at 0x%x\n&amp;quot;, vtor_ns[1]);

	/* Configure Non-Secure stack */
	tz_nonsecure_setup_conf_t spm_ns_conf = {
		.vtor_ns = (uint32_t)vtor_ns,
		.msp_ns = vtor_ns[0],
		.psp_ns = 0,
		.control_ns.npriv = 0, /* Privileged mode*/
		.control_ns.spsel = 0 /* Use MSP in Thread mode */
	};

	spm_configure_ns(&amp;amp;spm_ns_conf);

	/* Generate function pointer for Non-Secure function call. */
	TZ_NONSECURE_FUNC_PTR_DECLARE(reset_ns);
	reset_ns = TZ_NONSECURE_FUNC_PTR_CREATE(vtor_ns[1]);

	if (TZ_NONSECURE_FUNC_PTR_IS_NS(reset_ns)) {
		PRINT(&amp;quot;SPM: prepare to jump to Non-Secure image.\n&amp;quot;);

		/* Note: Move UARTE0 before jumping, if it is
		 * to be used on the Non-Secure domain.
		 */

		/* Configure UARTE0 as non-secure */
		spm_config_peripheral(
			NRFX_PERIPHERAL_ID_GET(NRF_UARTE0), 0);

		__DSB();
		__ISB();

		/* Jump to Non-Secure firmware */
		reset_ns();

		CODE_UNREACHABLE;

	} else {
		PRINT(&amp;quot;SPM: wrong pointer type: 0x%x\n&amp;quot;,
		      (uint32_t)reset_ns);
	}
}

void spm_config(void)
{
	spm_config_flash();
	spm_config_sram();
	spm_config_peripherals();
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This enables P1.x pins for non-secure use, which should fix the problem.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWIM usage in non secure application core</title><link>https://devzone.nordicsemi.com/thread/285658?ContentTypeID=1</link><pubDate>Thu, 17 Dec 2020 14:02:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0fc1bbb0-33b1-4eee-b16a-e7169a9c36ec</guid><dc:creator>GiulianoFranchetto</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;We are using our own custom board.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The i2c device is found without problem (device_get_binding() is not NULL).&lt;/p&gt;
&lt;p&gt;The issue here is not that the bus is not referenced, but is said to be &amp;quot;busy&amp;quot;.&lt;/p&gt;
&lt;p&gt;My guts tell me that the I2C periph. is not properly configured once entering the NS domain, and one (or both) SDA/SCL line is not well configured.&lt;/p&gt;
&lt;p&gt;Once again, this issue is not present if the program is built on the secure target&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWIM usage in non secure application core</title><link>https://devzone.nordicsemi.com/thread/285650?ContentTypeID=1</link><pubDate>Thu, 17 Dec 2020 13:41:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6dbccd01-2eec-4fa6-9497-e9f9d0a6d782</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hi!&lt;br /&gt;&lt;br /&gt;Just to confirm: you&amp;#39;re using the nRF5340DK v.0.11? It should be sufficient to rename your overlay file to&amp;nbsp;&lt;strong&gt;nrf5340dk_nrf5340_cpuappns.overlay&lt;/strong&gt;. In addition you must make sure&amp;nbsp;to add the _NS postfix (like this&amp;nbsp;NRF_TWIM2_NS) when referencing the device directly.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>