<?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][zephyr] SPI Access in GPIOTE interrupt causes a kernel panic</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/113193/nrf52840-zephyr-spi-access-in-gpiote-interrupt-causes-a-kernel-panic</link><description>Hello, 
 Although I already used the nrf52840 on previous projects (nrfxlib), I&amp;#39;m a newbie using nRF Connect and ZephyrOS (I previously used RTOS). 
 
 I&amp;#39;m integrating a driver which uses a GPIO interrupt to trigger read of SPI bus. The driver isn&amp;#39;t RTOS</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 16 Jul 2025 08:16:50 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/113193/nrf52840-zephyr-spi-access-in-gpiote-interrupt-causes-a-kernel-panic" /><item><title>RE: [nrf52840][zephyr] SPI Access in GPIOTE interrupt causes a kernel panic</title><link>https://devzone.nordicsemi.com/thread/542612?ContentTypeID=1</link><pubDate>Wed, 16 Jul 2025 08:16:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2b99599-5f39-4a36-92b2-a29b7aed92c7</guid><dc:creator>0xGael</dc:creator><description>&lt;p&gt;I reply to myself to close the issue :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I solved the issue by reworking my driver to be RTOS compatible:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;* when the driver needs to wait for an interrupt on a pin, in the pin interrupt callback I call an API from my driver to handle the interrupt&lt;/p&gt;
&lt;p&gt;* in the previous API I do the minimal work :&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;* disable pin interrupt (to avoid being retriggered)&lt;/p&gt;
&lt;div style="background-color:#002b36;color:#839496;font-family:Consolas, &amp;#39;Courier New&amp;#39;, monospace;font-size:14px;font-weight:normal;line-height:19px;white-space:pre;"&gt;
&lt;div&gt;&lt;code&gt;&lt;span style="color:#268bd2;"&gt;gpio_pin_interrupt_configure_dt()&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;* then I raise an RTOS event to notify a task which will handle others driver&amp;#39;s actions:&lt;/p&gt;
&lt;div style="background-color:#002b36;color:#839496;font-family:Consolas, &amp;#39;Courier New&amp;#39;, monospace;font-size:14px;font-weight:normal;line-height:19px;white-space:pre;"&gt;
&lt;div&gt;&lt;span style="color:#268bd2;"&gt;k_event_post&lt;/span&gt;()&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;* In the driver context, when driver needs to wait for the pin interrupt :&lt;/p&gt;
&lt;p&gt;&amp;nbsp; * it clears the event mask to&amp;nbsp; wait for :&amp;nbsp;&lt;/p&gt;
&lt;div style="background-color:#002b36;color:#839496;font-family:Consolas, &amp;#39;Courier New&amp;#39;, monospace;font-size:14px;font-weight:normal;line-height:19px;white-space:pre;"&gt;
&lt;div&gt;&lt;span style="color:#268bd2;"&gt;k_event_clear()&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;* then it waits for the event :&lt;/p&gt;
&lt;div style="background-color:#002b36;color:#839496;font-family:Consolas, &amp;#39;Courier New&amp;#39;, monospace;font-size:14px;font-weight:normal;line-height:19px;white-space:pre;"&gt;
&lt;div&gt;&lt;span style="color:#268bd2;"&gt;k_event_wait&lt;/span&gt;()&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;* When the event is raised (because the pin has interrupted), I call a function to handle the remaining actions (read SPI bus) :&amp;nbsp;&lt;/p&gt;
&lt;div style="background-color:#002b36;color:#839496;font-family:Consolas, &amp;#39;Courier New&amp;#39;, monospace;font-size:14px;font-weight:normal;line-height:19px;white-space:pre;"&gt;
&lt;div&gt;&lt;span style="color:#268bd2;"&gt;spi_transceive&lt;/span&gt;()&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [nrf52840][zephyr] SPI Access in GPIOTE interrupt causes a kernel panic</title><link>https://devzone.nordicsemi.com/thread/495822?ContentTypeID=1</link><pubDate>Fri, 26 Jul 2024 12:58:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1b434ec6-f1ad-4fc9-a923-cc6ec628ad5f</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;Thanks for the context!&lt;/p&gt;
&lt;p&gt;I found this &lt;a href="https://github.com/zephyrproject-rtos/zephyr/issues/70915"&gt;https://github.com/zephyrproject-rtos/zephyr/issues/70915&lt;/a&gt; and this &lt;a href="https://github.com/zephyrproject-rtos/zephyr/issues/59116"&gt;https://github.com/zephyrproject-rtos/zephyr/issues/59116&lt;/a&gt; which could maybe be related to a similar issue?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [nrf52840][zephyr] SPI Access in GPIOTE interrupt causes a kernel panic</title><link>https://devzone.nordicsemi.com/thread/494852?ContentTypeID=1</link><pubDate>Fri, 19 Jul 2024 15:10:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d70c2194-8d8f-4499-a203-554309e75eee</guid><dc:creator>0xGael</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Are you writing the driver as part of your project, or as part of Zephyr?&lt;br /&gt;Are your writing a driver for an external sensor?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;No. I&amp;#39;m integrating a driver (for an external sensor) into an application I&amp;#39;m writing. I don&amp;#39;t try to integrate the driver in Zephyr.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The code of &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.6.99-ncs2/drivers/sensor/tdk/icm42605/icm42605_trigger.c"&gt;icm42605_trigger.&lt;/a&gt; is a good example for my case to asynchronize the processing of my gpio interrupt (in another thread), without modifying the code of the driver I&amp;#39;m integrating.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;But I still don&amp;#39;t understand why I have the crash in my initial implementation&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [nrf52840][zephyr] SPI Access in GPIOTE interrupt causes a kernel panic</title><link>https://devzone.nordicsemi.com/thread/494822?ContentTypeID=1</link><pubDate>Fri, 19 Jul 2024 13:08:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1d482bc-15c2-4703-a431-011ec1299855</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;Ah, you are talking about integrating a driver. (I missed that in my first read of the ticket)&lt;/p&gt;
&lt;p&gt;Workqueue threads may not be the right solution, as you say.&lt;/p&gt;
&lt;p&gt;Here are some questions for me to understand this a bit better:&lt;/p&gt;
&lt;p&gt;Are you writing the driver as part of your project, or as part of Zephyr?&lt;br /&gt;Are your writing a driver for an external sensor?&lt;/p&gt;
&lt;p&gt;Maybe have a look at other Zephyr drivers for sensor, such as &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.6.99-ncs2/drivers/sensor/tdk/icm42688/icm42688_spi.c"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v3.6.99-ncs2/drivers/sensor/tdk/icm42688/icm42688_spi.c&lt;/a&gt;&lt;br /&gt;or &lt;br /&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.6.99-ncs2/drivers/sensor/tdk/icm42605/icm42605_trigger.c"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v3.6.99-ncs2/drivers/sensor/tdk/icm42605/icm42605_trigger.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Does these help?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [nrf52840][zephyr] SPI Access in GPIOTE interrupt causes a kernel panic</title><link>https://devzone.nordicsemi.com/thread/494621?ContentTypeID=1</link><pubDate>Thu, 18 Jul 2024 14:33:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08e8168c-1c79-4a3f-9af3-47f58ce29765</guid><dc:creator>0xGael</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span style="margin:0;padding:0;text-align:left;"&gt;Are you working with interrupts from a ISR?&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This is one of my point. The Zephyr API hides many thing so it&amp;#39;s not easy to understand which peripheral and features are really used.&lt;/p&gt;
&lt;p&gt;I defined my spi device as &lt;code&gt;&lt;em&gt;compatible = &amp;quot;nordic,nrf-spim&amp;quot;&lt;/em&gt;&lt;/code&gt;; in the overlay, so it uses easyDMA, so I suppose it uses interrupts.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span style="margin:0;padding:0;text-align:left;"&gt;Instead I recommend using a &lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/kernel/services/threads/workqueue.html"&gt;Workqueue thread&lt;/a&gt;?&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;What do you mean ? You mean use the workqueue thread instead of semaphore ?&lt;/p&gt;
&lt;p&gt;I would like as much as possible to don&amp;#39;t change the driver code. So I&amp;#39;d like to understand why I have the lock issue instead of changing the driver&amp;#39;s code&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;PS : I started to read &amp;quot;nRF Connect SDK Intermediate&amp;quot;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [nrf52840][zephyr] SPI Access in GPIOTE interrupt causes a kernel panic</title><link>https://devzone.nordicsemi.com/thread/494537?ContentTypeID=1</link><pubDate>Thu, 18 Jul 2024 11:07:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e3608fe-cc7d-436b-bacb-8c7dfa4739fb</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]Although I already used the nrf52840 on previous projects (nrfxlib), I&amp;#39;m a newbie using nRF Connect and ZephyrOS (I previously used RTOS).[/quote]
&lt;p&gt;&lt;span style="margin:0;padding:0;text-align:left;"&gt;I recommend the &lt;a href="https://academy.nordicsemi.com/" rel="noopener noreferrer" target="_blank"&gt;Nordic Developer Academy&lt;/a&gt; as an excellent place to start learning the nRF Connect SDK. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="margin:0;padding:0;text-align:left;"&gt;For the issue:&lt;br /&gt;Are you working with interrupts from a ISR?&lt;br /&gt;Instead I recommend using a &lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/kernel/services/threads/workqueue.html"&gt;Workqueue thread&lt;/a&gt;? As its docs say:&lt;br /&gt;&amp;quot;. A workqueue is typically used by an ISR or a high-priority thread to offload non-urgent processing to a lower-priority thread so it does not impact time-sensitive processing.&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="margin:0;padding:0;text-align:left;"&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>