<?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>nRF54 SPI Asynchronous Slave - Done never raised</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/113927/nrf54-spi-asynchronous-slave---done-never-raised</link><description>Hello ! I&amp;#39;m currently working on a SPI slave implementation for the nRF54L15. 
 I already read the spi-master-slave example. 
 The idea atm is basic and as follow : 
 My slave needs to listen if the master sent anything. If not, nothing happens. If he</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 23 Aug 2024 04:47:28 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/113927/nrf54-spi-asynchronous-slave---done-never-raised" /><item><title>RE: nRF54 SPI Asynchronous Slave - Done never raised</title><link>https://devzone.nordicsemi.com/thread/499466?ContentTypeID=1</link><pubDate>Fri, 23 Aug 2024 04:47:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d7937afe-04e4-4387-925b-300e723ce2f6</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hugo,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Sorry for late response, I was away for few days. It looks like the event does not come at all. If you are certain that the SPI activity was complete and you see valid activity on the SPI pins and still the event is not generated, then it smells like a bug in the driver or library. Can you please help me reproduce it at my end by giving a simplistic project.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF54 SPI Asynchronous Slave - Done never raised</title><link>https://devzone.nordicsemi.com/thread/498892?ContentTypeID=1</link><pubDate>Mon, 19 Aug 2024 14:37:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b5199f77-0491-489e-ae48-85861f7b93db</guid><dc:creator>Hugo P.</dc:creator><description>&lt;p&gt;I introduced the EVENT as follow :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static struct k_poll_event async_rx_evt = K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL, K_POLL_MODE_NOTIFY_ONLY, &amp;amp;spi_rx_done_sig);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And modified the periodical function with :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;int8_t drv_nrf_msg_check_u8(){
	LOG_INF(&amp;quot;CHECKING RECEPTION&amp;quot;);
	rx_raised = k_poll(&amp;amp;async_rx_evt, 1, K_MSEC(200));
	if(rx_raised == -EAGAIN){
		LOG_INF(&amp;quot;Waiting period timed out.&amp;quot;);
	}
	/* Reinitializing for next call */
	async_rx_evt.signal-&amp;gt;signaled = 0U;
	async_rx_evt.state = K_POLL_STATE_NOT_READY;
    return(rx_raised);
} &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The log here is :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1724078189474v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;So yeah basically it seems that the event never happens. I may be doing something wrong with the usage of spi_read_signal.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF54 SPI Asynchronous Slave - Done never raised</title><link>https://devzone.nordicsemi.com/thread/498835?ContentTypeID=1</link><pubDate>Mon, 19 Aug 2024 12:31:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:657619c6-3342-4af4-8eb0-9a2cc46fbac4</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;I think there seems to be some kind of deadlock in the way you are using signal, not very obvious though.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The common way to use this signal is to correlate it with a &lt;a href="https://docs.zephyrproject.org/apidoc/latest/group__poll__apis.html#ga8e3889f2bac281a6e65e31068e58047e"&gt;K_POLL_EVENT_INITIALIZER&lt;/a&gt;&amp;nbsp;and do a k_poll on that event rather done checking that signal from some other thread.&lt;/p&gt;
&lt;p&gt;There are samples for this provided in zephyr for example in &lt;a href="https://github.com/zephyrproject-rtos/zephyr/blob/main/tests/drivers/spi/spi_controller_peripheral/src/main.c#L228"&gt;zephyr\tests\drivers\spi\spi_controller_peripheral\src\main.c&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As you can see, The async_evt that is associated with the signal here is more reliable poll candidate and you can reset the signal right after the polling is complete.&lt;/p&gt;
&lt;p&gt;Can you give it a try and see if this helps else we need to dive into the whole signal usage of the spi driver to understand why you are seeing that deadlock when using only signals and not the poll_evts.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF54 SPI Asynchronous Slave - Done never raised</title><link>https://devzone.nordicsemi.com/thread/498809?ContentTypeID=1</link><pubDate>Mon, 19 Aug 2024 11:29:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bda5c031-614e-4151-a031-36fc090dd02a</guid><dc:creator>Hugo P.</dc:creator><description>&lt;p&gt;Hello !&lt;br /&gt;Sorry for the late answer, it was a public holiday in France.&lt;/p&gt;
&lt;p&gt;I modified a bit my code but the problem remains the same.&lt;br /&gt;My SPI thread is the following :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void thread_spi_listening(void){
    while(1){
		LOG_INF(&amp;quot;SPI THREAD!&amp;quot;);
		svc_nrf_listening_rx_v();
		k_msleep(SLEEPTIME);		
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The listening function basically calls the RX function if this is the first occurrence, and then wait for a done signal to be raised.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void svc_nrf_listening_rx_v(){
    if(true == first){
        LOG_INF(&amp;quot;FIRST ITERATION, POLLING RX&amp;quot;);
        first = false;
        drv_spi_slave_rx_v(spi_buffer_u8, spi_buffer_len_u8);
    }else{
        rx_raised = drv_nrf_msg_check_u8();
        if(rx_raised != 0){
            //We received a msg.
            //TODO handling msg decryption
            LOG_HEXDUMP_INF(spi_buffer_u8, sizeof(spi_buffer_u8),&amp;quot;MSG RECEIVED !&amp;quot;);
            drv_nrf_reset_rx_v();
            drv_spi_slave_rx_v(spi_buffer_u8, spi_buffer_len_u8);
        }
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If we received something, I want to print it. Then I reset the signal and try another RX.&lt;/p&gt;
&lt;p&gt;Here is the signal initialisation :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static struct k_poll_signal spi_rx_done_sig = K_POLL_SIGNAL_INITIALIZER(spi_rx_done_sig);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And the RX function :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void drv_spi_slave_rx_v(uint8_t* rx_buffer_pt, uint8_t rx_buffer_size_u8){
    if(NULL != rx_buffer_pt){
	    struct spi_buf rx_buf = {
		    .buf = rx_buffer_pt,
		    .len = rx_buffer_size_u8
	    };
	    struct spi_buf_set s_rx = {
		    .buffers = &amp;amp;rx_buf,
		    .count = 1
	    };
		LOG_INF(&amp;quot;READING RX...&amp;quot;);
        int8_t error = spi_read_signal(nrf_spi_slave, &amp;amp;spi_slave_cfg,&amp;amp;s_rx,&amp;amp;spi_rx_done_sig);
            if(error &amp;lt; 0){
                LOG_ERR(&amp;quot;TRANSCEIVING ERROR !&amp;quot;);
            }
    }else{
        LOG_ERR(&amp;quot;POINTER ISSUE&amp;quot;);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;When I execute this code, I have the following logs :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1724066842254v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;So my problem here isn&amp;#39;t a paused thread but the k_poll_signal_check that never returns true.&lt;/p&gt;
&lt;p&gt;The documentation about&amp;nbsp;spi_read_signal is not really detailed. But I assume that the k_poll_signal should be raised whenever a transaction is done ?&lt;br /&gt;PS : I have a master connected that pushes messages periodically.&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF54 SPI Asynchronous Slave - Done never raised</title><link>https://devzone.nordicsemi.com/thread/498421?ContentTypeID=1</link><pubDate>Thu, 15 Aug 2024 10:06:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0eec412a-c1fc-438a-ad61-6ef3827bf0b6</guid><dc:creator>Susheel Nuguru</dc:creator><description>[quote user=""]It seems to be a problem with a semaphore never released.[/quote]
&lt;p&gt;You have come very far in debugging this. Can you point to the exact semaphore that is not getting released? It seems to be a deadlock issue. Probably you are transmitting and polling for something in the same context? I need to understand more after you tell me which semaphore is not getting released.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>