<?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>SPI TXD write from flash vector in ISR fail</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/107111/spi-txd-write-from-flash-vector-in-isr-fail</link><description>This two lines outside ISR works: 
 
 p_spi_instance-&amp;gt;p_nrf_spi-&amp;gt;TXD = ram_array [i++] ; 
 p_spi_instance-&amp;gt;p_nrf_spi-&amp;gt;TXD = flash_array [i++]; 
 
 This line inside ISR works: 
 
 p_spi_instance-&amp;gt;p_nrf_spi-&amp;gt;TXD = ram_array [i++]; 
 
 This line inside ISR</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 08 Jan 2024 14:51:19 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/107111/spi-txd-write-from-flash-vector-in-isr-fail" /><item><title>RE: SPI TXD write from flash vector in ISR fail</title><link>https://devzone.nordicsemi.com/thread/463186?ContentTypeID=1</link><pubDate>Mon, 08 Jan 2024 14:51:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94d5eae1-7de9-40a4-9929-75f62623fac0</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Pablo,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Can you please make a simple code to demonstrate the issue. It looks a bit complex in your&amp;nbsp;spi_master_send_recv_irq() that I don&amp;#39;t know where&amp;nbsp;&lt;span&gt;flash_array is used in the code.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If you can make something very simple, (maybe&amp;nbsp;bare metal, without using library) just write one single byte after the first byte is sent it would be easier to&amp;nbsp;investigate.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI TXD write from flash vector in ISR fail</title><link>https://devzone.nordicsemi.com/thread/463038?ContentTypeID=1</link><pubDate>Sun, 07 Jan 2024 20:26:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03056db9-8959-4513-86c8-0701fc74a16e</guid><dc:creator>pslavkin</dc:creator><description>&lt;p&gt;Hey, tks for your answer, I&amp;#39;ve added more code related to the issue. Maybe it helps you to undertand what is happening.&lt;/p&gt;
&lt;p&gt;Tks. Pablo&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI TXD write from flash vector in ISR fail</title><link>https://devzone.nordicsemi.com/thread/462944?ContentTypeID=1</link><pubDate>Fri, 05 Jan 2024 15:09:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c155a782-1d84-40d9-823b-9cdfa9868f08</guid><dc:creator>pslavkin</dc:creator><description>&lt;p&gt;&lt;span style="font-size:150%;"&gt;Hi Hung:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;"&gt;&amp;nbsp;this is the first byte sended outside the ISR when invoke the transfer:&lt;/span&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;span style="font-size:150%;"&gt;&lt;code&gt;&lt;span style="color:rgba(0, 0, 255, 1);"&gt;&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static __INLINE void spi_master_send_initial_bytes(spi_master_instance_t * const p_spi_instance)
{
APP_ERROR_CHECK_BOOL(p_spi_instance != NULL);

p_spi_instance-&amp;gt;p_nrf_spi-&amp;gt;TXD = ((p_spi_instance-&amp;gt;p_tx_buffer != NULL) &amp;amp;&amp;amp;
(p_spi_instance-&amp;gt;tx_index &amp;lt; p_spi_instance-&amp;gt;tx_length)) ?
p_spi_instance-&amp;gt;p_tx_buffer[p_spi_instance-&amp;gt;tx_index] :
SPI_DEFAULT_TX_BYTE;
(p_spi_instance-&amp;gt;tx_index)++;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;span style="font-size:150%;"&gt;&lt;code&gt;&lt;span style="color:rgba(0, 0, 255, 1);"&gt;&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;"&gt;&lt;span&gt;And this is the ISR (part of) that jumps after the first byte gets out of the register:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:rgba(0, 0, 255, 1);font-size:150%;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static __INLINE void spi_master_send_recv_irq(spi_master_instance_t * const p_spi_instance)
{

uint8_t rx_byte;

p_spi_instance-&amp;gt;bytes_count++;
rx_byte = p_spi_instance-&amp;gt;p_nrf_spi-&amp;gt;RXD;

if ((p_spi_instance-&amp;gt;p_rx_buffer != NULL) &amp;amp;&amp;amp;
(p_spi_instance-&amp;gt;rx_index &amp;lt; p_spi_instance-&amp;gt;rx_length))
{
p_spi_instance-&amp;gt;p_rx_buffer[p_spi_instance-&amp;gt;rx_index++] = rx_byte;
}

if ((p_spi_instance-&amp;gt;tx_index &amp;lt; p_spi_instance-&amp;gt;max_length) &amp;amp;&amp;amp; (!(p_spi_instance-&amp;gt;abort_flag)))

{
 p_spi_instance-&amp;gt;p_nrf_spi-&amp;gt;TXD = ((p_spi_instance-&amp;gt;p_tx_buffer != NULL) &amp;amp;&amp;amp; (p_spi_instance-&amp;gt;tx_index &amp;lt; p_spi_instance-&amp;gt;tx_length)) ? p_spi_instance-&amp;gt;p_tx_buffer[p_spi_instance-&amp;gt;tx_index] :
SPI_DEFAULT_TX_BYTE);

 (p_spi_instance-&amp;gt;tx_index)++;
}

return;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:rgba(0, 0, 255, 1);font-size:150%;"&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Array definitions is like:&lt;/p&gt;
&lt;p&gt;char ram_array[100]={&amp;quot;hello world&amp;quot;};&lt;/p&gt;
&lt;p&gt;char* flash_array=&amp;quot;hello world&amp;quot;;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The first byte works fine with two arrays as the ps_spi_instance-&amp;gt;p_tx_buffer&lt;/li&gt;
&lt;li&gt;The following bytes works fine if I use ram_array but not from flash_array.&lt;/li&gt;
&lt;li&gt;Nothing hang, everything works except that the data sended is corrupted/garbage when I use flash_array&lt;/li&gt;
&lt;li&gt;If I debug with jtag, step by step, everything works like a charm on any array as input&lt;/li&gt;
&lt;li&gt;if I copy the p_tx_buffer[i] to a global ram memory before transfer to TXD, it works like a charm on any array as input&lt;/li&gt;
&lt;li&gt;if I copy the p_tx_buffer[i] to a local ram memory before transfer to TXD it doesn&amp;#39;t work when using flash_array. But if I add a small delay between copy to local and transfer local to TXD it begins to work&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;My suspicious is that reading from flash and transfer to the TXD register takes time that is not in consideration, but from ram no&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t know the version of the SDK, but the copyright header said&lt;/p&gt;
&lt;p&gt;/**&lt;br /&gt; * Copyright (c) 2014 - 2017, Nordic Semiconductor ASA&lt;br /&gt; * &lt;br /&gt; * All rights reserved.&lt;span&gt;&lt;span style="font-size:150%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span style="font-size:150%;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI TXD write from flash vector in ISR fail</title><link>https://devzone.nordicsemi.com/thread/462920?ContentTypeID=1</link><pubDate>Fri, 05 Jan 2024 14:12:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4d618fc7-4f50-4e81-b004-35b644690a7d</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;Error is in code not shown.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI TXD write from flash vector in ISR fail</title><link>https://devzone.nordicsemi.com/thread/462918?ContentTypeID=1</link><pubDate>Fri, 05 Jan 2024 14:03:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:50ae1615-edbe-4e73-ac22-822e2fd1c68c</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Pabloo,&amp;nbsp;&lt;br /&gt;Could you give some more information about your SDK ? Which SDK you use and which version ?&amp;nbsp;&lt;br /&gt;Please also show us how you define&amp;nbsp;flash_array and&amp;nbsp;ram_array.&lt;/p&gt;
&lt;p&gt;I assume you have the same problem if you access the TXD address directly instead of using&amp;nbsp;p_spi_instance-&amp;gt;p_nrf_spi-&amp;gt;TXD.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When you mentioned &amp;quot;does not work&amp;quot; what exactly you meant ? The value was not correct or the application hang or there were no SPI output ?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>