<?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 SPI init hangs after event loop starts</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/71598/nrf52840-spi-init-hangs-after-event-loop-starts</link><description>Hi, 
 My project uses nRF52840 with SD 140, SDK 17.0.2 and SES. My hardware has SD Card SPI and LCD SPI sharing bus pins, using CS pins to switch devices. Because of this each device needs to be uninitialized before starting comms with the other. Essentially</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 19 Feb 2021 09:49:12 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/71598/nrf52840-spi-init-hangs-after-event-loop-starts" /><item><title>RE: nRF52840 SPI init hangs after event loop starts</title><link>https://devzone.nordicsemi.com/thread/295284?ContentTypeID=1</link><pubDate>Fri, 19 Feb 2021 09:49:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a238fae-f022-47cc-86d4-b37b799f0c29</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote user="poolshark021"]My RTT log window gets &amp;lt;DEBUG&amp;gt;, &amp;lt;INFO&amp;gt;, etc messages during normal operation, just not until my while loop executes and NRF_LOG_PROCESS() is called.[/quote]
&lt;p&gt;Thats great, thank you for clarifying.&lt;br /&gt;NRF_LOG_PROCESS must be called when using the DEFERRED logging option - this allows you to control when log processing will happen, so that it minimally affects the performance of the application during development. For example, if you are doing a time-critical task, and a lot of logging, it would be unfortunate to use in-place processing.&lt;br /&gt;You can read more about &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v17.0.2%2Flib_nrf_log.html&amp;amp;anchor=nrf_log_config"&gt;the logger module library here&lt;/a&gt;.&lt;/p&gt;
[quote user="poolshark021"]I ended up using a bunch of breakpoints and code stepping to figure out the hard fault was because I was adding too big of an array to the stack.&amp;nbsp; I never once&amp;nbsp;hit the hardfault breakpoint and never got any info displayed about it.[/quote]
&lt;p&gt;It sounds to me like your hardfault handler is not enabled / implemented properly.&lt;br /&gt;Please &lt;a href="https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/an-introduction-to-error-handling-in-nrf5-projects"&gt;have a look at this blogpost about error handling with the nRF5 SDK&lt;/a&gt;.&lt;br /&gt;If this does not remedy your issue, please open a new ticket forum, since this is diverging from the original topic.&lt;/p&gt;
[quote user="poolshark021"]My original problem is now solved, however I would like to see the hardfault handler working for future use.&amp;nbsp; Do I need to do anything else besides add the correct handler file and enable it in sdk_config.h?&amp;nbsp;&amp;nbsp;[/quote]
&lt;p&gt;I am happy to hear that your original problem is now solved! &lt;br /&gt;For future reference I would&amp;nbsp;ask that you open a new ticket for this new issue, since it is diverging from the original topic in this ticket - this will keep the forums tidy, and easier to navigate for other users. :)&lt;br /&gt;&lt;br /&gt;Please do not hesitate to open a new ticket if you should encounter any other issues or questions during your development!&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SPI init hangs after event loop starts</title><link>https://devzone.nordicsemi.com/thread/294715?ContentTypeID=1</link><pubDate>Tue, 16 Feb 2021 19:32:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5b5d21d8-3ea5-4af0-94a9-6a0e69814cbf</guid><dc:creator>poolshark021</dc:creator><description>&lt;p&gt;My RTT log window gets &amp;lt;DEBUG&amp;gt;, &amp;lt;INFO&amp;gt;, etc messages during normal operation, just not until my while loop executes and NRF_LOG_PROCESS() is called.&amp;nbsp; However when I had a hard fault I would not get any info on the logger screen at all.&amp;nbsp; I tried to implement the hardfault_handler by adding hardfault_handler_gcc.c to my project and enabling it in sdk_config.h, but nothing changed.&lt;/p&gt;
&lt;p&gt;I ended up using a bunch of breakpoints and code stepping to figure out the hard fault was because I was adding too big of an array to the stack.&amp;nbsp; I never once&amp;nbsp;hit the hardfault breakpoint and never got any info displayed about it.&lt;/p&gt;
&lt;p&gt;My original problem is now solved, however I would like to see the hardfault handler working for future use.&amp;nbsp; Do I need to do anything else besides add the correct handler file and enable it in sdk_config.h?&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SPI init hangs after event loop starts</title><link>https://devzone.nordicsemi.com/thread/294607?ContentTypeID=1</link><pubDate>Tue, 16 Feb 2021 11:53:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ec498fe3-b16a-4670-873e-9b4ead35a1fe</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user="poolshark021"]I think I solved my interrupt issue with info from this topic:[/quote]
&lt;p&gt;I am happy to hear that you have resolved your issue!&lt;/p&gt;
[quote user="poolshark021"]I decided to only use the event handler to set a flag and then let the interrupt return.&amp;nbsp; Then I circle back and handle the flag and data transfer afterwards.&amp;nbsp;[/quote]
&lt;p&gt;This is a good way of implementing this, especially if it is not paramount that the flag event is processed immediately(since the main context has the lowest priority). Good choice!&lt;/p&gt;
[quote user="poolshark021"]I have DEBUG and DEBUG_NRF defined.&amp;nbsp; No info is displayed in the log (using RTT backend).[/quote]
&lt;p&gt;By this, do you mean that you are not seeing anything at all written out to your RTT backend, or only that you are not seeing any error messages despite having DEBUG defined?&lt;/p&gt;
[quote user="poolshark021"]I am currently stepping through code leading to the hard faults.&amp;nbsp; If I can pinpoint where its happening I will update this thread[/quote]
&lt;p&gt;Be advised that you can not step through the code when the SoftDevice is active, as this will halt the CPU - causing the SoftDevice to miss its timing-critical tasks, and thus crash. If you are debugging a peripheral I recommend disabling the BLE parts of the application before stepping through the code.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SPI init hangs after event loop starts</title><link>https://devzone.nordicsemi.com/thread/294438?ContentTypeID=1</link><pubDate>Mon, 15 Feb 2021 15:41:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ccee40ce-d378-472c-b186-333ada573e8f</guid><dc:creator>poolshark021</dc:creator><description>&lt;p&gt;I think I solved my interrupt issue with info from this topic:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/49732/spi-sd_app_evt_wait-and-nested-interrupts"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/49732/spi-sd_app_evt_wait-and-nested-interrupts&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I decided to only use the event handler to set a flag and then let the interrupt return.&amp;nbsp; Then I circle back and handle the flag and data transfer afterwards.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m still getting hard faults but it&amp;#39;s not related to the interrupt issue.&amp;nbsp; I&amp;#39;m hitting V7M Exception breakpoints for ExceptionEntryReturnFault and HardFault.&amp;nbsp; I have the hardfault handler enabled but I don&amp;#39;t ever see it getting used.&amp;nbsp; I have DEBUG and DEBUG_NRF defined.&amp;nbsp; No info is displayed in the log (using RTT backend).&lt;/p&gt;
&lt;p&gt;I am currently stepping through code leading to the hard faults.&amp;nbsp; If I can pinpoint where its happening I will update this thread&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SPI init hangs after event loop starts</title><link>https://devzone.nordicsemi.com/thread/294312?ContentTypeID=1</link><pubDate>Mon, 15 Feb 2021 08:15:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:29e4ca9c-a7fe-45c4-8713-207d1fec700a</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello poolshark021,&lt;/p&gt;
[quote user=""]EDIT: It appears I might have an interrupt issue?&amp;nbsp; But if I set NRFX_SPIM and SPI_ENABLED irq priority to 3 or 5 I get hard fault when event handler routine is called[/quote]
&lt;p&gt;Could you elaborate what you mean when you say hard fault?&lt;br /&gt;Is the device resetting of itself, or is anything written to the log?&lt;br /&gt;Please ensure that you have DEBUG defined in your preprocessor defines like shown in the included image, to make sure a debug output is printed when an error occurs.&lt;br /&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/5621.enabling_5F00_debug_5F00_SES.PNG" /&gt;&lt;/p&gt;
[quote user=""]This all works fine when called from my main() function.&amp;nbsp; I can display as many bmp images in a row as I desire.&amp;nbsp; The problem occurs once the event loop has started.&amp;nbsp; &amp;nbsp;Both the SD card and LCD will not initialize from an event handler function.&amp;nbsp; The SD card&amp;nbsp;hangs at&amp;nbsp;m_drives[drv].config.wait_func(); in diskio_blkdev.c&amp;nbsp;or the LCD hangs at&amp;nbsp;while(!m_spi_xfer_done)&amp;nbsp; after calling nrfx_spim_xfer();[/quote]
&lt;p&gt;Yes, this definitely sounds like a interrupt priority issue.&lt;br /&gt;What is the priority you are using for the interrupt handler which you would like to initialize the SPI instances from, and what is the priority of the SPI instances?&lt;br /&gt;The best illustration of this issue is how the LCD hangs on !m_spi_xfer_done - this is a flag which should be set as part of the SPI event handler ( on a TX / RX complete event ), but if the waiting occurs in an interrupt with a equal or higher priority than the SPI interrupt, the SPI interrupt will never get to process - because it is waiting for the interrupt that contains the SPI init to finish - and that interrupt will never finish, because it is waiting for the SPI event handler to toggle the flag.&lt;br /&gt;This is likely the cause of the deadlock you are seeing - its quite a common issue when working with different priority interrupts that depend on each other.&lt;br /&gt;&lt;br /&gt;The reason why everything works in you main context is because it has the lower priority, which means it will be interrupted by any interrupt regardless of priority level. Thus, whenever a interrupt (such as the SPI RX / TX complete event ) occurs, it is immediately processed. You can read &lt;a href="https://infocenter.nordicsemi.com/topic/sds_s112/SDS/s1xx/processor_avail_interrupt_latency/exception_mgmt_sd.html"&gt;more about the different interrupt priorities here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I think we will be able to resolve this issue as soon as we know what priority the different interrupts have in your application.&lt;br /&gt;&lt;br /&gt;Looking forward to resolving this issue together!&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>