<?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>SPIM place transfer buffer in data RAM region</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/57204/spim-place-transfer-buffer-in-data-ram-region</link><description>Hello, 
 
 I am interfacing a nRF52 based module with external flash memory. 
 When I try to program/read a single byte, I get the &amp;quot; NRF_ERROR_INVALID_ADDR&amp;quot; error. 
 This relates to placing the transfer buffer in the data RAM region as mentioned in the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 05 Feb 2020 13:01:09 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/57204/spim-place-transfer-buffer-in-data-ram-region" /><item><title>RE: SPIM place transfer buffer in data RAM region</title><link>https://devzone.nordicsemi.com/thread/232842?ContentTypeID=1</link><pubDate>Wed, 05 Feb 2020 13:01:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:19fdf117-fba9-4280-a7c2-7091d0ed9d0a</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I see you have already got feedback on the&amp;nbsp;new issue on the &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/57395/cannot-write-read-a-byte-from-external-flash-via-spi"&gt;other thread&lt;/a&gt;, so I suggest we close this.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPIM place transfer buffer in data RAM region</title><link>https://devzone.nordicsemi.com/thread/232685?ContentTypeID=1</link><pubDate>Tue, 04 Feb 2020 22:19:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6e110cac-73a5-4c88-84b5-5930d7958c63</guid><dc:creator>RO</dc:creator><description>&lt;p&gt;Thanks, that removed the alert sign.&lt;/p&gt;
&lt;p&gt;And I don&amp;#39;t seem to get the invalid address error.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But I still can&amp;#39;t read the byte. I still see &amp;quot;00&amp;quot; in the debug window.&lt;/p&gt;
&lt;p&gt;I also created a new ticket:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/57395/cannot-write-read-a-byte-from-external-flash-via-spi"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/57395/cannot-write-read-a-byte-from-external-flash-via-spi&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Any idea what I am doing wrong?&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPIM place transfer buffer in data RAM region</title><link>https://devzone.nordicsemi.com/thread/232341?ContentTypeID=1</link><pubDate>Mon, 03 Feb 2020 13:29:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:05e66895-392f-47d5-bef4-4087093d6164</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="ro269"]When I build the code on SES I get a yellow alert sign on the at_program line in main.c .[/quote]
&lt;p&gt;The yellow alert sign indicates a compiler warning. What does it say?&amp;nbsp;Is it in&amp;nbsp;at_program()&amp;nbsp;NRF_ERROR_INVALID_ADDR is returned from the call to&amp;nbsp;nrf_drv_spi_transfer()?&lt;/p&gt;
&lt;p&gt;Looking at your code, I see an easy to do a mistake, which I assume triggers the warning. read_buf is a variable, but you pass it as a pointer. You should have used &lt;strong&gt;&amp;amp;&lt;/strong&gt;read_buf to the call to at_read. Since you are using an uninitialized variable as a pointer, this will point to whatever happened to be in RAM, so this is most likely the issue.&lt;/p&gt;
&lt;p&gt;(It is a good idea to always take warnings serious as that will save you a lot of time in the long run.)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPIM place transfer buffer in data RAM region</title><link>https://devzone.nordicsemi.com/thread/232156?ContentTypeID=1</link><pubDate>Fri, 31 Jan 2020 17:58:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ce9cb6b-82e1-4579-8180-58bf7023a4a1</guid><dc:creator>RO</dc:creator><description>&lt;p&gt;I am using a BMD 349 module based on nRF52840.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am interfacing with&amp;nbsp;&lt;span&gt;AT25SF041 flash memory.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I am using SDK 14.2.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I am using SPIM instance 0.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I have attached the relevant parts of the code:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Below is slash_mem.c&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;quot;flash_mem.h&amp;quot;
#include &amp;quot;nrf_drv_spi.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;

static const nrf_drv_spi_t m_spi_at = NRF_DRV_SPI_INSTANCE(0);

static uint32_t spi_config(void)
{
    uint32_t err_code;
    nrf_drv_spi_config_t config = NRF_DRV_SPI_DEFAULT_CONFIG;
    config.frequency = NRF_DRV_SPI_FREQ_1M;
    config.mode      = NRF_DRV_SPI_MODE_3;
    config.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;
    config.mosi_pin  = AT_PIN_MOSI;
    config.miso_pin  = AT_PIN_MISO;
    config.sck_pin   = AT_PIN_SCK;
    config.ss_pin    = AT_PIN_CS; 
    err_code = nrf_drv_spi_init(&amp;amp;m_spi_at, &amp;amp;config, NULL, NULL);
    if (err_code != NRF_SUCCESS)
    {
        // Initialization failed. Take recovery action.
    }   
    nrf_gpio_cfg_output(AT_PIN_CS);
    nrf_gpio_pin_set(AT_PIN_CS);
    return err_code;
}


uint32_t at_init(void)
{
    return spi_config();
}

void at_read_rems(uint8_t * manufacturer_id, uint8_t * device_id)
{
    uint8_t spi_tx_cmd[] = {0x9F};
    uint8_t spi_rx_response[3];
    nrf_gpio_pin_clear(AT_PIN_CS);
    nrf_drv_spi_transfer(&amp;amp;m_spi_at, spi_tx_cmd, sizeof(spi_tx_cmd), spi_rx_response, sizeof(spi_rx_response));
    nrf_gpio_pin_set(AT_PIN_CS);
    *manufacturer_id = spi_rx_response[1]; 
    *device_id = spi_rx_response[2];
}


void at_write_enable(void)
{
    static uint8_t spi_tx_cmd[] = {CMD_WREN};
    nrf_gpio_pin_clear(AT_PIN_CS);
    nrf_drv_spi_transfer(&amp;amp;m_spi_at, spi_tx_cmd, sizeof(spi_tx_cmd), 0, 0);
    nrf_gpio_pin_set(AT_PIN_CS);
}

void at_program(uint32_t address, uint8_t * data_ptr, uint32_t data_length)
{
    uint8_t spi_tx_cmd[] = {CMD_PROGRAM, (address &amp;gt;&amp;gt; 16) &amp;amp; 0xFF, (address &amp;gt;&amp;gt; 8) &amp;amp; 0xFF, (address &amp;gt;&amp;gt; 0) &amp;amp; 0xFF};
    nrf_gpio_pin_clear(AT_PIN_CS);
    nrf_drv_spi_transfer(&amp;amp;m_spi_at, spi_tx_cmd, sizeof(spi_tx_cmd),NULL, NULL);
    while(data_length &amp;gt; 255)
    {
        nrf_drv_spi_transfer(&amp;amp;m_spi_at, data_ptr, 255, NULL, NULL);
        data_ptr += 255;
        data_length -= 255;
    }
    nrf_drv_spi_transfer(&amp;amp;m_spi_at, data_ptr, data_length, NULL, NULL);
    nrf_gpio_pin_set(AT_PIN_CS);
}


void at_read(uint32_t address, uint8_t * data_ptr, uint32_t data_length)
{
    uint8_t spi_tx_cmd[] = {CMD_READ, (address &amp;gt;&amp;gt; 16) &amp;amp; 0xFF, (address &amp;gt;&amp;gt; 8) &amp;amp; 0xFF, (address &amp;gt;&amp;gt; 0) &amp;amp; 0xFF};
    nrf_gpio_pin_clear(AT_PIN_CS);
    nrf_drv_spi_transfer(&amp;amp;m_spi_at, spi_tx_cmd, sizeof(spi_tx_cmd), NULL, NULL);
    while(data_length &amp;gt; 255)
    {
        nrf_drv_spi_transfer(&amp;amp;m_spi_at, 0, 0, data_ptr, 255);
        data_ptr += 255;
        data_length -= 255;
    }
    nrf_drv_spi_transfer(&amp;amp;m_spi_at, NULL, NULL , data_ptr, data_length);
    nrf_gpio_pin_set(AT_PIN_CS);
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Below is part of main.c&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;
int main(void)
{

    uint8_t status_register, man_id, dev_id;
    uint8_t data_buf = 0x23;
    uint8_t read_buf;
    at_init();
    at_write_enable();

    uint32_t address = 0x01A8FF;
            //for(int i = 0; i &amp;lt; READ_WRITE_LENGTH; i++) data_buf[i] = i;
            at_program(address, data_buf, 1);
            
        //at_read(address, read_buf, 1);
       //NRF_LOG_INFO(&amp;quot;Reading address %.8x: &amp;quot;, address);
       //NRF_LOG_INFO(&amp;quot;%.2X-&amp;quot; ,(int)read_buf);
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;When I build the code on SES I get a yellow alert sign on the at_program line in main.c .&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The nrf_drv_spi_transfer function in at_program() gives the&amp;nbsp;&amp;nbsp;NRF_ERROR_INVALID_ADDR error.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Please help,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;thanks&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPIM place transfer buffer in data RAM region</title><link>https://devzone.nordicsemi.com/thread/232083?ContentTypeID=1</link><pubDate>Fri, 31 Jan 2020 12:26:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:514e7c9f-23ce-4ba9-a744-da5674a9c933</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;If you have a normal buffer (static or not) which is not constant, it will&amp;nbsp;be in the data RAM region. You can refer to &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/memory.html?cp=4_2_0_7#memory"&gt;Memory&lt;/a&gt;&amp;nbsp;for details.&lt;/p&gt;
&lt;p&gt;If this does not help, can you specify which function returns&amp;nbsp;NRF_ERROR_INVALID_ADDR, which chip you use, which SPIM instance you use and which SDK you use?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>