<?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>Facing HardFault issue while  using SPI peripheral in any callback function in nrf Connect SDK 2.4.0</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/102073/facing-hardfault-issue-while-using-spi-peripheral-in-any-callback-function-in-nrf-connect-sdk-2-4-0</link><description>Hi, I want to implement a flow for callback/interrupt driven code. In the whole process I have to read and write data over SPI. Here I am using nrf52840 as SPI Master and ESP32 dev kit as Slave. When I try to communicate normally in a while in main.c</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 16 Oct 2023 09:39:55 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/102073/facing-hardfault-issue-while-using-spi-peripheral-in-any-callback-function-in-nrf-connect-sdk-2-4-0" /><item><title>RE: Facing HardFault issue while  using SPI peripheral in any callback function in nrf Connect SDK 2.4.0</title><link>https://devzone.nordicsemi.com/thread/450498?ContentTypeID=1</link><pubDate>Mon, 16 Oct 2023 09:39:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5e9a4ef1-ea28-4a0b-87d2-54d0911e2b54</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello Owain,&lt;/p&gt;
[quote user="OwainJangor"]I refactored&amp;nbsp; code to do the meaty stuff in a thread; all ISR now does is signal the thread to run. This has allowed turning asserts back on; all seems to be working well at the moment.[/quote]
&lt;p&gt;Thank you for the update - I am happy to hear that you have aligned your code with the best practice for this and that you are no longer having an issue with this! :)&amp;nbsp;&lt;/p&gt;
[quote user="OwainJangor"]Main processor is STM, ble processor is Nordic; but it is interesting what you mention about the easyDMA.[/quote]
&lt;p&gt;Aha, I understand. I dont have any personal experience with STM and so I cant speak to their features or capabilities, but in general I can say that the easyDMA indeed is a very useful feature when working with asynchronous memory processes in Nordic devices, at least.&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: Facing HardFault issue while  using SPI peripheral in any callback function in nrf Connect SDK 2.4.0</title><link>https://devzone.nordicsemi.com/thread/450342?ContentTypeID=1</link><pubDate>Fri, 13 Oct 2023 14:32:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6f2f26a-3c76-4770-9c52-7224023b4b1a</guid><dc:creator>OwainJangor</dc:creator><description>&lt;p&gt;Hi Karl,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I refactored&amp;nbsp; code to do the meaty stuff in a thread; all ISR now does is signal the thread to run. This has allowed turning asserts back on; all seems to be working well at the moment.&lt;br /&gt;&lt;br /&gt;Main processor is STM, ble processor is Nordic; but it is interesting what you mention about the easyDMA.&lt;br /&gt;&lt;br /&gt;Regards,&lt;br /&gt;Owain&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Facing HardFault issue while  using SPI peripheral in any callback function in nrf Connect SDK 2.4.0</title><link>https://devzone.nordicsemi.com/thread/450217?ContentTypeID=1</link><pubDate>Fri, 13 Oct 2023 07:52:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d8233b69-0679-4386-ace6-513f2477a6ad</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user="OwainJangor"]Is what I have said correct and what is best practise here?[/quote]
&lt;p&gt;You are correct that you should not make blocking calls as part of your ISR.&lt;br /&gt;&lt;br /&gt;The general advise here is that you should avoid computationally extensive work or blocking calls in your ISRs - instead, your ISRs should signal for the extensive work to be done as part of a lower priority workthread or similar, to avoid blocking all lower priority interrupts for the duration of the execution.&lt;br /&gt;This especially goes for blocking calls which you can not be exactly certain when will complete, like reception of data from another device.&lt;br /&gt;&lt;br /&gt;Something I should also note is that I have seen customers coming from projects with non-Nordic devices that are unaware of &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/easydma.html"&gt;the easyDMA feature of the nrF52 and nRF53 series devices&lt;/a&gt;&amp;nbsp;which lets you receive data through the serial interfaces without having the CPU actively receiving it - this of course also means that you do not&amp;nbsp;&lt;em&gt;need&lt;/em&gt; to use blocking calls to receive your serial data. This also goes for transmission of serial data.&lt;/p&gt;
[quote user="OwainJangor"]Did anything happen n discord?[/quote]
&lt;p&gt;The Zephyr Discord is open to join, and so if Sarvesh does not come back with a reply here you could join the server yourself and look for the thread on this matter :)&amp;nbsp;&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: Facing HardFault issue while  using SPI peripheral in any callback function in nrf Connect SDK 2.4.0</title><link>https://devzone.nordicsemi.com/thread/449419?ContentTypeID=1</link><pubDate>Mon, 09 Oct 2023 22:42:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c7b341ea-c62e-46f1-98cd-f4a0347429da</guid><dc:creator>OwainJangor</dc:creator><description>&lt;p&gt;I too have just been stung by this one.&lt;/p&gt;
&lt;p&gt;I know for other RTOSs&amp;#39; that one is not allowed to make blocking calls in ISR&amp;#39;s; this is normal; I just am not sure for this Zephyr OS case.&lt;br /&gt;&lt;br /&gt;If the meat of the interrupt processing is being done from a worker thread; then I assume you can make blocking calls? This is the way the original driver for the SPI peripheral I am working with worked. GPIO Interrupt fired; ISR disabled further interrupt and posted job to workqueue where SPI transceive (which make a blocking call) is called.&lt;br /&gt;&lt;br /&gt;But driver I have has been hacked and now the SPI transceive is being called directly from the ISR. In fact the GPIO interrupt fires and the our SPI handler is called directly from interrupt context.&lt;br /&gt;&lt;br /&gt;As part of a merge of my code to this branch; the branch picked up CONFIG_ASSERT=y from my branch; hence the issue being revealed to me.&lt;br /&gt;&lt;br /&gt;Is what I have said correct and what is best practise here?&lt;br /&gt;&lt;br /&gt;I can see 2 design possibilities here....&lt;br /&gt;&lt;br /&gt;1) ISR processes the peripheral to &amp;quot;clear down&amp;quot; interrupt and posts the result to a worker thread for further processing.&lt;br /&gt;&lt;br /&gt;2) As in original driver ISR just disables peripheral interrupt and posts a job to the worker thread. All processing to be done at task/thread level.&lt;br /&gt;&lt;br /&gt;If ISR is to do any real work it needs to do SPI transactions to access peripheral registers; and we hit this assert.&lt;br /&gt;&lt;br /&gt;Could you advise? Did anything happen n discord?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Facing HardFault issue while  using SPI peripheral in any callback function in nrf Connect SDK 2.4.0</title><link>https://devzone.nordicsemi.com/thread/437675?ContentTypeID=1</link><pubDate>Fri, 21 Jul 2023 12:55:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7b9100b9-04fc-4885-a713-5edf975a7148</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote user="Sarvesh"]Thanks Karl [/quote]
&lt;p&gt;No problem at all, I am happy to help! :)&amp;nbsp;&lt;/p&gt;
[quote user="Sarvesh"]Actually disabling the ASSERT is not a best practice to follow.&amp;nbsp;[/quote]
&lt;p&gt;I agree with this, especially so since you might be missing other important asserts during your development as well.&lt;/p&gt;
[quote user="Sarvesh"]It would be great if you can give some input or get [/quote]
&lt;p&gt;I would recommend that you go into the Zephyr Discord directly to ask their input on this - this way you can faster get the help you need with this.&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: Facing HardFault issue while  using SPI peripheral in any callback function in nrf Connect SDK 2.4.0</title><link>https://devzone.nordicsemi.com/thread/437616?ContentTypeID=1</link><pubDate>Fri, 21 Jul 2023 09:05:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d87300a4-7b00-4101-9fb5-ab8f7bdca5c5</guid><dc:creator>Sarvesh</dc:creator><description>&lt;p&gt;Thanks Karl , It would be great if you can give some input or get . Actually disabling the ASSERT is not a best practice to follow.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Facing HardFault issue while  using SPI peripheral in any callback function in nrf Connect SDK 2.4.0</title><link>https://devzone.nordicsemi.com/thread/437601?ContentTypeID=1</link><pubDate>Fri, 21 Jul 2023 08:35:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fe1d8da2-fb70-4b2c-83ea-95792241b546</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Thank you for clarifying, the assertion here happens due to the &lt;a href="https://github.com/zephyrproject-rtos/zephyr/blob/b69cd3cbc101cae3558a4730fa320e25a43b1543/drivers/spi/spi_context.h#L101C2-L101C36"&gt;SPI attempting to wait indefinitely for the semaphor in the ISR context&lt;/a&gt;, which is not allowed.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&amp;quot;The kernel does allow an ISR to take a semaphore, however the ISR must not attempt to wait if the semaphore is unavailable&amp;quot; this SPI driver cannot work.&amp;quot;&lt;br /&gt;&lt;br /&gt;&lt;/em&gt;Since this is an issue with the Zephyr&amp;#39;s SPI context I would raise the question in the Zephyr Discord, to ask what the best practice for working around this would be.&lt;br /&gt;The quickest and simplest solution to this issue would probably be to modify the&amp;nbsp;K_FOREVER to K_NO_WAIT, but I would not generally recommend making changes to the drivers and infrastructure directly without having consulted the Zephyr community first.&lt;em&gt;&lt;br /&gt;&lt;br /&gt;&lt;/em&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Facing HardFault issue while  using SPI peripheral in any callback function in nrf Connect SDK 2.4.0</title><link>https://devzone.nordicsemi.com/thread/437585?ContentTypeID=1</link><pubDate>Fri, 21 Jul 2023 07:48:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9aaa057d-0502-4363-be58-77f0ff19c715</guid><dc:creator>Sarvesh</dc:creator><description>&lt;p&gt;Sure I have enabled the assertion - this is the assert I am getting when hardfault&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;00&amp;gt; ASSERTION FAIL [((arch_is_in_isr() == 0) || ((timeout).ticks == (((k_timeout_t) {0})).ticks))] @ WEST_TOPDIR/zephyr/kernel/sem.c:121&lt;br /&gt;00&amp;gt; &lt;br /&gt;00&amp;gt; [00:00:00.772,216] &amp;lt;err&amp;gt; os: r0/a1: 0x00000004 r1/a2: 0x00000079 r2/a3: 0x00000004&lt;br /&gt;00&amp;gt; [00:00:00.772,247] &amp;lt;err&amp;gt; os: r3/a4: 0x00000079 r12/ip: 0x20003064 r14/lr: 0x0002ce89&lt;br /&gt;00&amp;gt; [00:00:00.772,247] &amp;lt;err&amp;gt; os: xpsr: 0x41000021&lt;br /&gt;00&amp;gt; [00:00:00.772,277] &amp;lt;err&amp;gt; os: Faulting instruction address (r15/pc): 0x00033d24&lt;br /&gt;00&amp;gt; [00:00:00.772,308] &amp;lt;err&amp;gt; os: &amp;gt;&amp;gt;&amp;gt; ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0&lt;br /&gt;00&amp;gt; [00:00:00.772,338] &amp;lt;err&amp;gt; os: Fault during interrupt handling&lt;br /&gt;00&amp;gt; &lt;br /&gt;00&amp;gt; [00:00:00.772,399] &amp;lt;err&amp;gt; os: Current thread: 0x20002df8 (idle)&lt;br /&gt;00&amp;gt; [00:00:01.100,646] &amp;lt;err&amp;gt; fatal_error: Resetting system&lt;br /&gt;00&amp;gt; *** Booting Zephyr OS build v3.3.99-ncs1 ***&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Facing HardFault issue while  using SPI peripheral in any callback function in nrf Connect SDK 2.4.0</title><link>https://devzone.nordicsemi.com/thread/437529?ContentTypeID=1</link><pubDate>Thu, 20 Jul 2023 15:34:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0461f2cd-ccc0-4d8c-bd30-487f7054221b</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;br /&gt;&lt;br /&gt;I am glad to read that this is not an issue for you anymore, but I am still curious which ASSERT it was that triggered?&lt;br /&gt;In general that asserts are added as guardrails for you to hit during development, so that the condition will not be an issue in release. I would therefore suggest that we take a closer look at the specific assert that triggered in this case, so that we can ensure that it is not something that will come back to cause trouble for you later in the development.&lt;br /&gt;In general it is not recommended to perform calls that could be blocking (or otherwise lengthy) as part of an event handler.&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: Facing HardFault issue while  using SPI peripheral in any callback function in nrf Connect SDK 2.4.0</title><link>https://devzone.nordicsemi.com/thread/437474?ContentTypeID=1</link><pubDate>Thu, 20 Jul 2023 12:43:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f75dafe-a5df-4e01-b943-288c86fe38d2</guid><dc:creator>Sarvesh</dc:creator><description>&lt;p&gt;Hi , Thanks for help but I have resolved the issue , I just have to disable the&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_ASSERT&lt;/span&gt;&lt;span&gt;=n&lt;/span&gt;&lt;/div&gt;
&amp;nbsp;in the prj.conf file of project&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;We can close this now&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>