<?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>nrf5340 qspi flash dma</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/87497/nrf5340-qspi-flash-dma</link><description>Dear nordic engineers: 
 The only example I can find about flash is under zephyr/samples/drivers/spi_flash. However, the flash writing is pretty slow, and the MCU is halting while waiting for writing result. 
 If dma buffer is available, I can send the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 23 May 2022 08:59:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/87497/nrf5340-qspi-flash-dma" /><item><title>RE: nrf5340 qspi flash dma</title><link>https://devzone.nordicsemi.com/thread/368946?ContentTypeID=1</link><pubDate>Mon, 23 May 2022 08:59:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f2aac50b-4637-4d81-8666-cdeabdf99234</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
[quote user="szhaulai"]Hi Thanks for the answer, I got it to work with your suggestion, putting put fifo out of interrupt handler. One final question to this thread about flash driver, is it needed to erase before writing a new dataset into flash?&amp;nbsp;[/quote]
&lt;p&gt;If you use the low level flash driver then you normally need to erase a page before you can write anything to it, that is correct. Since flash only allows you to clear bits when writing and not set bits any word that is not already 0xFFFFFFFF (all ones) can not be written to without first erasing the page.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you use a higher level driver, like&amp;nbsp;NVS, then the page erase is handled for you by the driver, and you don&amp;#39;t need to know about the intricacies of working with flash memory.&amp;nbsp;&lt;/p&gt;
[quote user="szhaulai"]Some other question, is there example on using other zephyr fifo api, like k_fifo_alloc_put(). I get error on zephyr CPU and don&amp;#39;t know how to debug. I have tried to run in debug mode, but zephyr doesn&amp;#39;t report any error or halting.[/quote]
&lt;p&gt;Are you saying that the k_fifo_alloc_put() call doesn&amp;#39;t return any error codes, but still the application will crash?&lt;/p&gt;
[quote user="szhaulai"]I feel frustrated when it comes to zephyr, the document is not very clear. Is there forum for zephyr like the one you have hosted very well on the nordic site?&amp;nbsp;[/quote]
&lt;p&gt;Zephyr is hosted on Github, which means you can raise issues or ask questions through Github directly:&lt;br /&gt;&lt;a href="https://github.com/zephyrproject-rtos/zephyr/issues"&gt;https://github.com/zephyrproject-rtos/zephyr/issues&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We are also happy to help with Zephyr related questions here on the Devzone &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;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf5340 qspi flash dma</title><link>https://devzone.nordicsemi.com/thread/368865?ContentTypeID=1</link><pubDate>Fri, 20 May 2022 15:44:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:17d40470-53dd-4b56-8ec9-42eb635c1f20</guid><dc:creator>szhaulai</dc:creator><description>&lt;p&gt;Hi Thanks for the answer, I got it to work with your suggestion, putting put fifo out of interrupt handler. One final question to this thread about flash driver, is it needed to erase before writing a new dataset into flash?&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Some other question, is there example on using other zephyr fifo api, like k_fifo_alloc_put(). I get error on zephyr CPU and don&amp;#39;t know how to debug. I have tried to run in debug mode, but zephyr doesn&amp;#39;t report any error or halting. I feel frustrated when it comes to zephyr, the document is not very clear. Is there forum for zephyr like the one you have hosted very well on the nordic site?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf5340 qspi flash dma</title><link>https://devzone.nordicsemi.com/thread/368294?ContentTypeID=1</link><pubDate>Wed, 18 May 2022 11:02:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ff770c3-cbff-4ae5-a81c-fcf8ba56cb90</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Maybe yo could try just to print something to the log if mem_ptr != 0 ?&lt;/p&gt;
&lt;p&gt;You should&amp;nbsp;skip the remaining code in the timer event handler if this occurs, to avoid writing to the flash_write_fifo if the malloc fails.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Also, unless you don&amp;#39;t use k_malloc anywhere else it is not safe to call this function from an interrupt handler. It is best to only use this method from a thread or a work item (or even better to use statically defined memory structures, rather than dynamic memory allocation).&lt;/p&gt;
[quote user="szhaulai"]question 1. if I have a thread that needs a long time to process (assume extreme case 100ms), is it a &amp;quot;o.k&amp;quot; practice to have a sleep period less than the process time (assume 1ms).&amp;nbsp;[/quote]
&lt;p&gt;If the thread has a positive priority number it can be interrupted by other, more important threads as long as they have a higher interrupt priority (lower number).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As an example, if you give your time consuming but less critical thread a priority of 5, you can put other more time critical threads at priority 4 or below, and they will be able to interrupt the slow running thread when they have some work to do.&amp;nbsp;&lt;/p&gt;
[quote user="szhaulai"]question 2: assume I have many threads that do multiple signal processings, writing to flash. How do I know which thread will be run during the sleep. Should I plan&amp;nbsp;a specific time for the main thread to sleep and activate a specific thread to run during the sleep time of main thread?[/quote]
&lt;p&gt;You don&amp;#39;t really know when the different threads are going to run, this is all controlled by the scheduler.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you feel that you need to know this information then it sounds like you need a better way to synchronize the different activities in your program.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As an example, if you have multiple processes that need to access the flash at different times you can use a FIFO to allow the different threads to schedule flash operations, and execute the operations (read the FIFO) from a single thread so that you avoid conflicts.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf5340 qspi flash dma</title><link>https://devzone.nordicsemi.com/thread/367981?ContentTypeID=1</link><pubDate>Mon, 16 May 2022 08:17:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a45117a6-ebc7-4bbf-a419-c9466a4cf0a7</guid><dc:creator>szhaulai</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks for the reply. I&amp;#39;ve been able to let the thread run by making k_msleep. But I still have a bunch of question about thread, which will be deviate from my origin question about flash writing time.&amp;nbsp; Please suggest if I should raise a new ticket.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The setback I have experienced is the thread is somehow locked. In the code, it uses&amp;nbsp;__ASSERT_NO_MSG, I have no idea how to debug with the message. I tried to take&amp;nbsp;&lt;span&gt;__ASSERT_NO_MSG&lt;/span&gt;&amp;nbsp;away and get some zephyr message about faulting during interrupt handling but I&amp;nbsp; have no idea how to debug it.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/0827.main.c"&gt;devzone.nordicsemi.com/.../0827.main.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Please give me some indication how I can debug thread and interrupt. I&amp;#39;ve tried with breakpoint but it doesn&amp;#39;t seems to help, the thread just suddenly halted.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Another question I have about thread is about the sleep time that you suggested.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;question 1. if I have a thread that needs a long time to process (assume extreme case 100ms), is it a &amp;quot;o.k&amp;quot; practice to have a sleep period less than the process time (assume 1ms).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;question 2: assume I have many threads that do multiple signal processings, writing to flash. How do I know which thread will be run during the sleep. Should I plan&amp;nbsp;a specific time for the main thread to sleep and activate a specific thread to run during the sleep time of main thread?&lt;/p&gt;
&lt;p&gt;I hope there are example that can explain this better.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks for help&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf5340 qspi flash dma</title><link>https://devzone.nordicsemi.com/thread/367331?ContentTypeID=1</link><pubDate>Wed, 11 May 2022 08:25:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:699d045b-9a5e-44cf-9cc3-ccb5fc26c728</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;There is no need to run k_thread_start(..) manually. It will start automatically as long as you use the K_THREAD_DEFINE(..) macro.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I think the problem here is that you have a while(1){} loop in your main function. This will&amp;nbsp;make the main thread run 100%, potentially blocking other threads from running.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you try either removing the loop (with Zephyr it is fine to exit the main() function), or adding a delay function inside the while(1) loop to allow other threads to run?&lt;/p&gt;
&lt;p&gt;Just changing the loop like this should be sufficient:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;while(1) {&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&amp;nbsp; k_msleep(1000);&lt;/em&gt;&lt;br /&gt;&lt;em&gt;}&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf5340 qspi flash dma</title><link>https://devzone.nordicsemi.com/thread/367085?ContentTypeID=1</link><pubDate>Tue, 10 May 2022 08:13:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:253066ff-9806-4527-ab12-dd4fa3a8af95</guid><dc:creator>szhaulai</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I tried to implement the thread but experience some set back. I couldn&amp;#39;t start the thread. Would you please check my file and let me know where I do wrong. Thanks for help!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I use a timer to create a counter and save the number to a fifo. Then I tried to use a thread that handling the flash, in which, I plan to get the data from fifo and write to flash for every 128 samples. However, the tread is never started.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/3386.main.c"&gt;devzone.nordicsemi.com/.../3386.main.c&lt;/a&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/0243.prj.conf"&gt;devzone.nordicsemi.com/.../0243.prj.conf&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf5340 qspi flash dma</title><link>https://devzone.nordicsemi.com/thread/366439?ContentTypeID=1</link><pubDate>Thu, 05 May 2022 11:40:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:85cf6e67-959d-42e8-b39e-0e4ba77e5c01</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Making your own threads in Zephyr is very easy, and there is also a sample available &lt;a href="https://github.com/nrfconnect/sdk-zephyr/tree/main/samples/basic/threads"&gt;here&lt;/a&gt; showing you how you can do it.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Essentially you can create a new thread with a single line of code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;// The thread function should be void(void)
void thread_func(void)
{

}

// Make a thread with priority 5 and stacksize 512
#define MY_THREAD_PRIORITY 5
#define MY_THREAD_STACKSIZE 512
K_THREAD_DEFINE(blink0_id, MY_THREAD_STACKSIZE, thread_func, NULL, NULL, NULL, MY_THREAD_PRIORITY, 0, 0);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If you exit the thread function the thread will be disabled, so normally you would have an infinite loop in the thread function to make it run forever.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In order for the thread not to occupy the CPU all the time you can use a sleep function, like k_msleep(), or yield the thread by calling k_yield(), whenever you don&amp;#39;t have anything to do in the thread.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf5340 qspi flash dma</title><link>https://devzone.nordicsemi.com/thread/366119?ContentTypeID=1</link><pubDate>Wed, 04 May 2022 08:21:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:68cd8c0c-69fd-4d46-a033-2cc25e0706cf</guid><dc:creator>szhaulai</dc:creator><description>&lt;p&gt;Thanks for reply, can you give example on how to use different thread? I am testing with external memory chip mx25R6435 on nRF5340DK.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf5340 qspi flash dma</title><link>https://devzone.nordicsemi.com/thread/366116?ContentTypeID=1</link><pubDate>Wed, 04 May 2022 08:15:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6e2bb953-ee11-4cf0-97dc-e243f3252a3a</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Normally the higher level flash driver will use the Nordic SPI drivers under the hood, and these drivers will utilize the EasyDMA controller by default.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In the nRF5340 there is no option to disable EasyDMA in the SPI master peripheral, and DMA will always be used.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Have you tried to run the flash writing from a different thread to see if it will still block the system?&lt;br /&gt;Even if the flash API is a blocking API, as long as DMA is used under the hood other threads should still be able to run.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Are you testing this using the external memory chip on the nRF5340DK?&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>