<?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>nRF52840 QSPI XIP read function，qspi can&amp;#39;t reinit</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/72942/nrf52840-qspi-xip-read-function-qspi-can-t-reinit</link><description>We used qspi xip read function. If I uninit qspi and then init qspi again，the mcu halted。 
 
 Is there a problem with my use? What can i do now。</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 19 Mar 2021 09:12:07 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/72942/nrf52840-qspi-xip-read-function-qspi-can-t-reinit" /><item><title>RE: nRF52840 QSPI XIP read function，qspi can't reinit</title><link>https://devzone.nordicsemi.com/thread/300843?ContentTypeID=1</link><pubDate>Fri, 19 Mar 2021 09:12:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:615ef349-f2ca-4240-9bd0-2107745c81b0</guid><dc:creator>bh.niu</dc:creator><description>&lt;div&gt;I tried your code,then it&amp;#39;s ok.&lt;/div&gt;
&lt;div&gt;I find the&amp;nbsp;nrf_drv_qspi_init must config without callback&amp;nbsp;handler.&lt;/div&gt;
&lt;div&gt;nrf_drv_qspi_init(&amp;amp;config, NULL, NULL);//It&amp;#39;s ok&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;nrf_drv_qspi_init(p_qspi_cfg, qspi_handler, &lt;span&gt;NULL&lt;/span&gt;);//It&amp;#39;s will stop at&amp;nbsp;&lt;span&gt;while&lt;/span&gt;&lt;span&gt;(NRF_QSPI-&amp;gt;&lt;/span&gt;&lt;span&gt;EVENTS_READY&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;==&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;) {};&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp;To make sure the words are aligned, I read the data like this：&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*************************************************************************   
**	function name:	qspi_read 
**	input para:		
**                  
**	input para:		 	
**	return:					                                         
**************************************************************************/
void qspi_read(u8_t *p_data, u32_t addr, u16_t len)
{
    u16_t i;

    for(i=0; i&amp;lt;len; i += 4)
    {
        u32_t tmp_data = *(__IO uint32_t*)(0x12000000 + addr + i);
        if((i+4)&amp;gt;len)
        {
            if((len%4) &amp;gt;= 1)
            {
                p_data[i] = (u8_t)(tmp_data);
            }

            if((len%4) &amp;gt;= 2)
            {
                p_data[i+1] = (u8_t)(tmp_data &amp;gt;&amp;gt; 8);
            }      

            if((len%4) &amp;gt;= 3)
            {
                p_data[i+2] = (u8_t)(tmp_data &amp;gt;&amp;gt; 16);
            }                 
        }
        else
        {
            p_data[i]   = (u8_t)(tmp_data);
            p_data[i+1] = (u8_t)(tmp_data &amp;gt;&amp;gt; 8);
            p_data[i+2] = (u8_t)(tmp_data &amp;gt;&amp;gt; 16);
            p_data[i+3] = (u8_t)(tmp_data &amp;gt;&amp;gt; 24);                
        }
    }   
}&lt;/pre&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 QSPI XIP read function，qspi can't reinit</title><link>https://devzone.nordicsemi.com/thread/300814?ContentTypeID=1</link><pubDate>Fri, 19 Mar 2021 07:09:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7ef3b77b-4c17-4e55-8aef-2007aaa6238b</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;First off, please make sure that all memory access by the QSPI peripheral to external memory devices are word-aligned, as you can only write/read in full words (usually 32 bits). What SDK version are you using?&lt;/p&gt;
&lt;p&gt;There was a bug in SDK v15.3 that would result in the CPU hanging without access to the SWD interface, which would be caused by either reading/writing from a specific register or calling the uninit function to reconfigure the QSPI.&lt;/p&gt;
&lt;p&gt;The workaround is to trigger the ACTIVATE task of the QSPI peripheral before calling the uninit function as such:&lt;/p&gt;
&lt;div&gt;&lt;span&gt;NRF_QSPI-&amp;gt;&lt;/span&gt;&lt;span&gt;EVENTS_READY&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;NRF_QSPI-&amp;gt;&lt;/span&gt;&lt;span&gt;TASKS_ACTIVATE&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;while&lt;/span&gt;&lt;span&gt;(NRF_QSPI-&amp;gt;&lt;/span&gt;&lt;span&gt;EVENTS_READY&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;==&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;) {};&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;Both &amp;quot;done&amp;quot; and &amp;quot;end&amp;quot; is printed. I&amp;#39;ve included the code with the workaround implemented.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**
 * Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA &amp;quot;AS IS&amp;quot; AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
/** @file
 * @defgroup qspi_example_main main.c
 * @{
 * @ingroup qspi_example
 *
 * @brief QSPI Example Application main file.
 *
 * This file contains the source code for a sample application using QSPI.
 */

#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;quot;nrf_drv_qspi.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;app_util_platform.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;

#include &amp;quot;crc32.h&amp;quot;

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;
#include &amp;quot;sdk_config.h&amp;quot;

#include &amp;quot;nrf_delay.h&amp;quot;


#define QSPI_STD_CMD_WRSR   0x01
#define QSPI_STD_CMD_RSTEN  0x66
#define QSPI_STD_CMD_RST    0x99


#define QSPI_FLASH_DPM_ENTER_DURATION                   3                              //Duration required to enter DPM, in units of 16us
#define QSPI_FLASH_DPM_EXIT_DURATION                    3                              //Duration required to exit DPM, in units of 16us

static void configure_memory()
{
    uint8_t temporary = 0x40;
    uint32_t err_code;
    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,
        .wren      = true
    };

    // Send reset enable
    err_code = nrf_drv_qspi_cinstr_xfer(&amp;amp;cinstr_cfg, NULL, NULL);
    APP_ERROR_CHECK(err_code);

    // Send reset command
    cinstr_cfg.opcode = QSPI_STD_CMD_RST;
    err_code = nrf_drv_qspi_cinstr_xfer(&amp;amp;cinstr_cfg, NULL, NULL);
    APP_ERROR_CHECK(err_code);

    // Switch to qspi mode
    cinstr_cfg.opcode = QSPI_STD_CMD_WRSR;
    cinstr_cfg.length = NRF_QSPI_CINSTR_LEN_2B;
    err_code = nrf_drv_qspi_cinstr_xfer(&amp;amp;cinstr_cfg, &amp;amp;temporary, NULL);
    APP_ERROR_CHECK(err_code);
}

uint32_t GenerateCRC(void *data, uint32_t nSize)
{
    NRF_LOG_INFO(&amp;quot;crc of %lx size %d&amp;quot;, data, nSize);

    uint32_t i = 0;
    uint32_t nSeg = 32;
    uint32_t nCRC = 0;
    while (i &amp;lt; nSize)
    {
        if ((i + nSeg) &amp;gt; nSize)
        {
            nSeg = nSize - i;
        }

        nCRC = crc32_compute((const uint8_t*)(data + i), nSeg, &amp;amp;nCRC);
        i += nSeg;
    }

    return nCRC;
}

int main(void)
{
    uint32_t err_code;

    err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();

    NRF_LOG_INFO(&amp;quot;&amp;quot;
                 &amp;quot;QSPI write and read example using 24bit addressing mode&amp;quot;);

    nrf_drv_qspi_config_t config = NRF_DRV_QSPI_DEFAULT_CONFIG;



    //This delay is to allow for nrfjprog to erase the device after a reboot, otherwise it locks out SWD access, DO NOT REMOVE!
    nrf_delay_ms(2000);



    //Setup QSPI to allow for DPM but with it turned off, set XIP offset to 0x0
    config.phy_if.dpmen = false;
    config.xip_offset = 0x0;
    config.prot_if.dpmconfig = true;
    NRF_QSPI-&amp;gt;DPMDUR = (QSPI_FLASH_DPM_EXIT_DURATION &amp;lt;&amp;lt; QSPI_DPMDUR_EXIT_Pos) | QSPI_FLASH_DPM_ENTER_DURATION;
    err_code = nrf_drv_qspi_init(&amp;amp;config, NULL, NULL);
    APP_ERROR_CHECK(err_code);
    NRF_LOG_INFO(&amp;quot;QSPI example started.&amp;quot;);
    configure_memory();

    uint8_t pBuf[64];
    nrf_drv_qspi_read(pBuf, 64, 0x0);

    uint32_t mycrc = GenerateCRC((uint32_t*)0x12000000, 0x1000);
    NRF_LOG_INFO(&amp;quot;Got: %lx&amp;quot;, mycrc);
    
    //Workaround
    NRF_QSPI-&amp;gt;EVENTS_READY = 0;
    NRF_QSPI-&amp;gt;TASKS_ACTIVATE = 1;
    while(NRF_QSPI-&amp;gt;EVENTS_READY == 0) {};
 


    //This is what causes the issue
    uint32_t nConfig = NRF_QSPI-&amp;gt;IFCONFIG1;
    nConfig |= 1U &amp;lt;&amp;lt; QSPI_IFCONFIG1_DPMEN_Pos;
    NRF_QSPI-&amp;gt;IFCONFIG1 = nConfig;



    //This never executes
    NRF_LOG_INFO(&amp;quot;done&amp;quot;);

    nrf_drv_qspi_uninit();

    NRF_LOG_INFO(&amp;quot;end&amp;quot;);

    for (;;)
    {
    }
}

/** @} */&lt;/pre&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Simon&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 QSPI XIP read function，qspi can't reinit</title><link>https://devzone.nordicsemi.com/thread/300637?ContentTypeID=1</link><pubDate>Thu, 18 Mar 2021 10:33:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1f6f1252-7abd-454e-acc6-76d16c900b74</guid><dc:creator>bh.niu</dc:creator><description>&lt;p&gt;&lt;span&gt;Thank you&amp;nbsp; for reply.&amp;nbsp;I tried the way you said, but it still doesn&amp;#39;t work。&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;The reason of MCU &lt;span&gt;halted&lt;/span&gt; is because of this code：&lt;br /&gt;u8_t tmp = *(__IO uint8_t*)(0x12000000);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;After the &lt;span&gt;MCU&amp;nbsp;halted&lt;/span&gt;, if&amp;nbsp;I stop debugging, Keil will pop up such a prompt.&lt;br /&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1616063515128v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 QSPI XIP read function，qspi can't reinit</title><link>https://devzone.nordicsemi.com/thread/300622?ContentTypeID=1</link><pubDate>Thu, 18 Mar 2021 10:12:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:97de721e-cd77-40c5-aad0-252222b8bb96</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;How does your nrf_drv_qspi_uninit() function look? Please be aware of &lt;a href="https://infocenter.nordicsemi.com/topic/errata_nRF52840_Rev2/ERR/nRF52840/Rev2/latest/anomaly_840_122.html"&gt;erratum 122&lt;/a&gt; present in nRF52840, so the uninitialization should look something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    *(volatile uint32_t *)0x40029010ul = 1ul;
    *(volatile uint32_t *)0x40029054ul = 1ul;
    nrf_drv_qspi_uninit();&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If the problem persists, can you try to explain&amp;nbsp;&lt;strong&gt;how&amp;nbsp;&lt;/strong&gt;the MCU is halted exactly?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>