<?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>question about SPI availability on nrf5340 with secure and non secure modes</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/77673/question-about-spi-availability-on-nrf5340-with-secure-and-non-secure-modes</link><description>1. Your documents mention only SPI3 and SPI4 are available in non- secure mode.. which means spi-0,1,2 should not be available in non-secure mode.. But if i use nrfx drivers, I am able to use spi-2 in secure and non secure mode.. so does nrfx drivers</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 24 Mar 2022 13:26:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/77673/question-about-spi-availability-on-nrf5340-with-secure-and-non-secure-modes" /><item><title>RE: question about SPI availability on nrf5340 with secure and non secure modes</title><link>https://devzone.nordicsemi.com/thread/359821?ContentTypeID=1</link><pubDate>Thu, 24 Mar 2022 13:26:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0405a289-2cde-4882-8950-b15777ab524b</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hi again!&lt;br /&gt;&lt;br /&gt;I&amp;#39;m finally back with an answer here. As SPI, UART and TWI all shares the same base address setting instance non-secure will render all the other instances non-secure as well. For example, TWI2 is configured as non-secure by SPM by default. Thus, SPIM2 will be non-secure as well!&lt;br /&gt;&lt;br /&gt;Thank you for your patience.&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: question about SPI availability on nrf5340 with secure and non secure modes</title><link>https://devzone.nordicsemi.com/thread/326010?ContentTypeID=1</link><pubDate>Fri, 20 Aug 2021 15:06:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9acd65b1-c58b-4878-98bc-06b85df6f27f</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hello again!&lt;br /&gt;&lt;br /&gt;I haven&amp;#39;t gotten any response to my inquiry yet, likely due to most of our developers being away on summer holidays. I&amp;#39;ll ping them and see if I get anything back!&lt;br /&gt;&lt;br /&gt;Thank you for your patience.&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: question about SPI availability on nrf5340 with secure and non secure modes</title><link>https://devzone.nordicsemi.com/thread/325203?ContentTypeID=1</link><pubDate>Tue, 17 Aug 2021 01:17:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:67a60ea5-549b-42ec-82ba-5063ba4a8411</guid><dc:creator>sshenoy105</dc:creator><description>&lt;p&gt;any update on &amp;quot;&amp;nbsp;&lt;span&gt;I actually managed to do the same myself while testing here, so I have reached out to the developers to get some more insight on what might be going on. Will report back here if I get any feasible answers.&amp;quot;..&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: question about SPI availability on nrf5340 with secure and non secure modes</title><link>https://devzone.nordicsemi.com/thread/321833?ContentTypeID=1</link><pubDate>Mon, 26 Jul 2021 13:05:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:208dd988-adc0-4e6a-bb09-d62af778fbee</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hello again!&lt;br /&gt;&lt;br /&gt;Good to hear that this answered some of your questions and thank you for the description! I actually managed to do the same myself while testing here, so I have reached out to the developers to get some more insight on what might be going on. Will report back here if I get any feasible answers.&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: question about SPI availability on nrf5340 with secure and non secure modes</title><link>https://devzone.nordicsemi.com/thread/321209?ContentTypeID=1</link><pubDate>Thu, 22 Jul 2021 01:09:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:67648f0c-9ed7-412f-9e75-3e30b753864e</guid><dc:creator>sshenoy105</dc:creator><description>&lt;p&gt;Thank you.. this really helps..&amp;nbsp;&lt;br /&gt;&lt;strong&gt;2. All peripherals are available to secure applications. :&amp;nbsp;&lt;/strong&gt;I could have guessed that but needed to hear from you guys and thank you.. that makes perfect sense now&lt;br /&gt;&lt;strong&gt;3.&lt;/strong&gt; Understood .. that kinda aligns with what I have read on devzone but always great to get it confirmed&amp;nbsp;.. Thank you&lt;br /&gt;&lt;strong&gt;4.&lt;/strong&gt; Got it.. and I already knew about not using overlapping peripherals (as you could see from my use case where I will be using&amp;nbsp;&lt;span&gt;uart0, i2c1, spi2, i2c3 and spi4 and qspi&amp;nbsp;)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1.&lt;/strong&gt;&amp;nbsp;I wish i could just send an example project/code for you to test but it is part of my current project and will take time to isolate it.&lt;br /&gt;&lt;/span&gt;But here is essentially what I did&lt;br /&gt;&lt;br /&gt;using a custom board (but haven;t ported to my own device tree yet and just using nrf5340dk name)&lt;br /&gt;here&amp;#39;s my nrf5340dk_nrf5340_cpuappns.overlay&lt;/p&gt;
&lt;p&gt;// UART debug port&lt;br /&gt;&amp;amp;uart0 {&lt;br /&gt; status = &amp;quot;okay&amp;quot;;&lt;br /&gt; tx-pin = &amp;lt; 0x19 &amp;gt;;&lt;br /&gt; rx-pin = &amp;lt; 0x1a &amp;gt;;&lt;br /&gt;};&lt;/p&gt;
&lt;p&gt;&amp;amp;i2c1 {&lt;br /&gt; status = &amp;quot;okay&amp;quot;;&lt;br /&gt; compatible = &amp;quot;nordic,nrf-twim&amp;quot;;&lt;br /&gt; sda-pin = &amp;lt;4&amp;gt;;&lt;br /&gt; scl-pin = &amp;lt;5&amp;gt;;&lt;br /&gt; clock-frequency = &amp;lt;I2C_BITRATE_STANDARD&amp;gt;; &lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;and here&amp;#39;s&amp;nbsp;nrf5340dk_nrf5340_cpuapp.overlay&lt;/p&gt;
&lt;p&gt;// UART debug port&lt;br /&gt;&amp;amp;uart0 {&lt;br /&gt; status = &amp;quot;okay&amp;quot;;&lt;br /&gt; tx-pin = &amp;lt; 0x19 &amp;gt;;&lt;br /&gt; rx-pin = &amp;lt; 0x1a &amp;gt;;&lt;br /&gt;};&lt;/p&gt;
&lt;p&gt;&amp;amp;i2c1 {&lt;br /&gt; status = &amp;quot;okay&amp;quot;;&lt;br /&gt; compatible = &amp;quot;nordic,nrf-twim&amp;quot;;&lt;br /&gt; sda-pin = &amp;lt;4&amp;gt;;&lt;br /&gt; scl-pin = &amp;lt;5&amp;gt;;&lt;br /&gt; clock-frequency = &amp;lt;I2C_BITRATE_STANDARD&amp;gt;; &lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;here&amp;#39;s proj.conf (as definitions not necessarily needed by code i will past below)&lt;/p&gt;
&lt;p&gt;#&lt;br /&gt;# Copyright (c) 2019 Nordic Semiconductor ASA&lt;br /&gt;#&lt;br /&gt;# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic&lt;br /&gt;#&lt;br /&gt;# General config&lt;br /&gt;CONFIG_ASSERT=y&lt;/p&gt;
&lt;p&gt;# Logging&lt;br /&gt;CONFIG_UART_CONSOLE=y&lt;br /&gt;CONFIG_SERIAL=y&lt;/p&gt;
&lt;p&gt;# Stacks and heaps&lt;br /&gt;CONFIG_MAIN_STACK_SIZE=4096&lt;br /&gt;CONFIG_HEAP_MEM_POOL_SIZE=16384&lt;/p&gt;
&lt;p&gt;# I2C&lt;br /&gt;CONFIG_I2C=y&lt;br /&gt;CONFIG_I2C_NRFX=y&lt;br /&gt;CONFIG_I2C_1=y&lt;br /&gt;CONFIG_NRFX_TWIM1=y&lt;br /&gt;CONFIG_NRFX_TWIM3=y&lt;/p&gt;
&lt;p&gt;# Rebooot&lt;br /&gt;CONFIG_REBOOT=n&lt;/p&gt;
&lt;p&gt;#SPI&lt;br /&gt;CONFIG_SPI=n&lt;br /&gt;CONFIG_NRFX_SPIM=y&lt;br /&gt;CONFIG_NRFX_SPIM2=y&lt;br /&gt;CONFIG_NRFX_SPIM3=y&lt;br /&gt;CONFIG_NRFX_SPIM4=y&lt;/p&gt;
&lt;p&gt;# Use PWM&lt;br /&gt;CONFIG_PWM=y&lt;br /&gt;CONFIG_DEPRECATED_ZEPHYR_INT_TYPES=y&lt;br /&gt;CONFIG_ADC=y&lt;/p&gt;
&lt;p&gt;# Use GPIO&lt;br /&gt;CONFIG_GPIO=y&lt;br /&gt;&lt;br /&gt;I build secure version build with command&amp;nbsp; &lt;strong&gt;west build -b nrf5340dk_nrf5340_cpuapp -p&lt;br /&gt;&lt;/strong&gt;and non secure version with command&amp;nbsp; &lt;strong&gt;west build -b nrf5340dk_nrf5340_cpuappns -p&lt;br /&gt;&lt;/strong&gt;and I am using &lt;strong&gt;NCS SDK 1.5.1&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;and here&amp;#39;s the code.. if SPI_2 was not available in non-secure build, i would expect this code to not run and&amp;nbsp; unable to access my SPI slave and read/write registers.. But I cna do that wiht secure and non-secure build and using SPI_2.. hence my confusion.. My guess is I have missed something very obvious as this is NOT supposed tow work the way i see it working&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define SPI_INSTANCE 2
static const nrfx_spim_t spim2 = NRFX_SPIM_INSTANCE(SPI_INSTANCE);

#define SPIM2_XXXXXX_CS_PIN (45)
#define SPIM2_SCK_PIN (40)
#define SPIM2_MISO_PIN (42)
#define SPIM2_MOSI_PIN (41)

#define SPIM2_DEFAULT_CONFIG(_pin_sck, _pin_mosi, _pin_miso, _pin_ss)   \
{                                                                           \
    .sck_pin        = _pin_sck,                                             \
    .mosi_pin       = _pin_mosi,                                            \
    .miso_pin       = _pin_miso,                                            \
    .ss_pin         = _pin_ss,                                              \
    .ss_active_high = false,                                                \
    .irq_priority   = NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY,                \
    .orc            = 0xFF,                                                 \
    .frequency      = NRF_SPIM_FREQ_4M,                                     \
    .mode           = NRF_SPIM_MODE_0,                                      \
    .bit_order      = NRF_SPIM_BIT_ORDER_MSB_FIRST,                         \
    .miso_pull      = NRF_GPIO_PIN_NOPULL,                                  \
    NRFX_SPIM_DEFAULT_EXTENDED_CONFIG                                       \
}


static nrfx_spim_config_t spim2_config = SPIM2_DEFAULT_CONFIG(SPIM2_SCK_PIN, SPIM2_MOSI_PIN, SPIM2_MISO_PIN, SPIM2_XXXXXX_CS_PIN);
static uint8_t m_tx_buf[] = {0x28, 0x00, 0x00, 0x00};

static uint8_t m_rx_buf[sizeof(m_tx_buf)];
static const uint8_t m_length = sizeof(m_tx_buf);
static uint8_t m_got_lis2dw12_ID = 0;

static volatile bool spim2_xfer_done; /**&amp;lt; Flag used to indicate that SPIM instance completed the transfer. */


static void manual_spim2_isr_setup()
{
	IRQ_DIRECT_CONNECT(SPIM2_SPIS2_TWIM2_TWIS2_UARTE2_IRQn, 0,
			   nrfx_spim_2_irq_handler, 0);
	irq_enable(SPIM2_SPIS2_TWIM2_TWIS2_UARTE2_IRQn);

}

void spim2_event_handler(nrfx_spim_evt_t const *p_event, void *p_context)
{

    if (p_event-&amp;gt;type == NRFX_SPIM_EVENT_DONE)
    {
        spim2_xfer_done = true;
    }
    for(int i = 0; i &amp;lt; sizeof(m_rx_buf); i++)
    {
		printk(&amp;quot;%x &amp;quot;, m_rx_buf[i]);
    }
    printk(&amp;quot;\n&amp;quot;);
}

void main(void) {
    nrfx_spim_xfer_desc_t spim2_xfer_desc = NRFX_SPIM_XFER_TRX(m_tx_buf, m_length, m_rx_buf, m_length);
    printk(&amp;quot;\n\n SPI based XXX read Id test&amp;quot;);
    nrfx_err_t err_code;

          printk(&amp;quot;\n\n Read from register 0xc1\n&amp;quot;);
         memset(m_rx_buf, 0, m_length);
          spim2_xfer_done = false;

          //prepare write values
          m_tx_buf[0] = 0xc1;
          m_tx_buf[1] = 0x00;
          m_tx_buf[2] = 0x00;
          m_tx_buf[3] = 0x00;

          err_code = nrfx_spim_xfer(&amp;amp;spim2, &amp;amp;spim2_xfer_desc, 0);

          if (err_code == NRFX_ERROR_BUSY) {
            printk(&amp;quot;SPI busy\n&amp;quot;);
          } else if (err_code != NRFX_SUCCESS) {
            printk(&amp;quot;Error code = %d\n&amp;quot;, err_code);
          }

          while (!spim2_xfer_done) {
            __WFE();
          }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: question about SPI availability on nrf5340 with secure and non secure modes</title><link>https://devzone.nordicsemi.com/thread/321067?ContentTypeID=1</link><pubDate>Wed, 21 Jul 2021 09:38:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e0c7711-7188-4239-b405-ae5c455a10c1</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hello!&lt;br /&gt;&lt;br /&gt;First some clarification here: as explained in both the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/ug_nrf9160.html#application-mcu"&gt;nRF9160&lt;/a&gt;&amp;nbsp;and &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/ug_nrf5340.html#application-core"&gt;nRF5340&lt;/a&gt; documentation the ARM TrustZone enables the MCU to be divided into secure and non-secure domains, but a secure application will always be running at the bottom. By default the secure partition has access to all peripherals, including SPI and access is granted to the non-secure partition by using the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/include/spm.html#secure-partition-manager-spm"&gt;Secure&amp;nbsp;Partition Manager (SPM)&lt;/a&gt;. With this in mind, here&amp;#39;s answers to your question:&lt;br /&gt;1. nRFX should not override SPM. Could you explain how you tested this?&lt;br /&gt;2. All peripherals are available to secure applications.&amp;nbsp;&lt;br /&gt;3. All non-secure applications are &amp;quot;mixed&amp;quot; as in as they run on top of a secure partition. The usage of peripherals you suggest should be possible regardless, but as you touched on in your first question some peripherals aren&amp;#39;t handled by SPM currently and will thus not be available in non-secure applications. This can be fixed after the summer holidays, but it&amp;#39;s quite trivial to add new peripherals yourself by copy pasting and renaming existing peripherals in the SPM library (&lt;strong&gt;&amp;lt;ncs_root&amp;gt;\n&lt;/strong&gt;&lt;strong&gt;rf\subsys\spm&lt;/strong&gt;).&lt;br /&gt;4. In secure mode all SPI ports are available. As mentioned above some peripherals are not yet configured by SPM to be available in non-secure application. The most important thing to remember when using several peripherals is to not have overlapping instances (e.g. UART&lt;strong&gt;0&lt;/strong&gt; and I2C&lt;strong&gt;0&lt;/strong&gt; cannot be enabled at the same time).&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>