<?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>Updating to nrfxlib 2.4.1 causes nrf_modem_ init() to timeout (errno 116)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/102281/updating-to-nrfxlib-2-4-1-causes-nrf_modem_-init-to-timeout-errno-116</link><description>Hi, I have been developing with the nRF9160 using Rust. We have a crate (nrfxlib-sys) that generates Rust bindings to the nrfxlib headers. Recently, we&amp;#39;ve been trying to update from version 2.1.0 to 2.4.1. We can successfully generate all the needed bindings</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 07 Aug 2023 14:26:47 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/102281/updating-to-nrfxlib-2-4-1-causes-nrf_modem_-init-to-timeout-errno-116" /><item><title>RE: Updating to nrfxlib 2.4.1 causes nrf_modem_ init() to timeout (errno 116)</title><link>https://devzone.nordicsemi.com/thread/440155?ContentTypeID=1</link><pubDate>Mon, 07 Aug 2023 14:26:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b7a03b08-fb9c-44db-b653-4de1f1140a22</guid><dc:creator>dkhayes117</dc:creator><description>&lt;p&gt;Marking this as solved.&amp;nbsp; It turns out that the&amp;nbsp;&lt;span&gt;&lt;code&gt;nrf_modem_os_sem_take()&lt;/code&gt; function has a timeout parameter that is in milliseconds.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Our match on timeout calls &lt;code&gt;nrf_modem_busy_wait()&lt;/code&gt; with a delay value of 1 and decrements the timeout value by 1 when an integer timeout value is passed in.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;It turns out that the busywait function takes microseconds, not milliseconds; therefore, the timeout would happen 1000 times sooner than expected!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Updating to nrfxlib 2.4.1 causes nrf_modem_ init() to timeout (errno 116)</title><link>https://devzone.nordicsemi.com/thread/439582?ContentTypeID=1</link><pubDate>Thu, 03 Aug 2023 01:01:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:764dd237-549a-4565-b814-d0cab42f59b7</guid><dc:creator>dkhayes117</dc:creator><description>&lt;p&gt;I made another discovery, I was fooled that it kept working by not refreshing my cargo.lock file after changes.&amp;nbsp; I&amp;#39;ve found the root of the problem, although I don&amp;#39;t understand the implication.&amp;nbsp; In our&amp;nbsp; &lt;code&gt;nrf_modem_os_sem_take()&lt;/code&gt; function we match the timeout parameter to whether it should return EAGAIN, busywait forever, or busywait for the timeout value.&amp;nbsp; increasing the delay when a timeout int is provided fixes the issue.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;pub extern &amp;quot;C&amp;quot; fn nrf_modem_os_sem_take(
    sem: *mut core::ffi::c_void,
    mut timeout: core::ffi::c_int,
) -&amp;gt; core::ffi::c_int {
    unsafe {
        if sem.is_null() {
            return -(nrfxlib_sys::NRF_EAGAIN as i32);
        }

        if nrfxlib_sys::nrf_modem_os_is_in_isr() {
            timeout = nrfxlib_sys::NRF_MODEM_OS_NO_WAIT as i32;
        }

        loop {
            if (*(sem as *mut Semaphore))
                .current_value
                .fetch_update(Ordering::SeqCst, Ordering::SeqCst, |val| {
                    if val &amp;gt; 0 {
                        Some(val - 1)
                    } else {
                        None
                    }
                })
                .is_ok()
            {
                return 0;
            }

            match timeout {
                0 =&amp;gt; return -(nrfxlib_sys::NRF_EAGAIN as i32),
                nrfxlib_sys::NRF_MODEM_OS_FOREVER =&amp;gt; {
                    nrf_modem_os_busywait(1);
                }
                _ =&amp;gt; {
                    timeout -= 1;
                    nrf_modem_os_busywait(2); // changing this from 1 to 2 fixes the timeout error
                }
            }
        }
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Updating to nrfxlib 2.4.1 causes nrf_modem_ init() to timeout (errno 116)</title><link>https://devzone.nordicsemi.com/thread/439555?ContentTypeID=1</link><pubDate>Wed, 02 Aug 2023 16:25:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c1894ea-329f-42ab-ba3c-a4be286b6f2c</guid><dc:creator>dkhayes117</dc:creator><description>&lt;p&gt;temporarily changing the &lt;code&gt;nrf_modem_os_busywait()&lt;/code&gt; function to take longer than needed fixed the modem init timeout error.&amp;nbsp; Later changing it back to the original delay, and it works just fine now!&amp;nbsp; Definitely something strange is going on, seeing as someone else had the same issue with the nrfconnect sdk.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/101722/nrf9160-modem-fails-to-init-on-some-units/437742"&gt;devzone.nordicsemi.com/.../437742&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Updating to nrfxlib 2.4.1 causes nrf_modem_ init() to timeout (errno 116)</title><link>https://devzone.nordicsemi.com/thread/438660?ContentTypeID=1</link><pubDate>Fri, 28 Jul 2023 03:16:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a5e31009-6495-4694-b91e-b892347ecb74</guid><dc:creator>dkhayes117</dc:creator><description>&lt;p&gt;Thanks for pointing that change out.&amp;nbsp; I updated our IPC handler function, but it still didn&amp;#39;t work, so I added RTT logging to every single FFI function we had defined and it started working!&amp;nbsp; &lt;/p&gt;
&lt;p&gt;It seems to have been some sort of timing issue.&amp;nbsp; Inside our nrf_modem_os_timedwait(), we can&amp;#39;t use K_FOREVER, so it loops over a nrf_modem_os_busywait() function that does nothing but uses assembly to create a delay.&amp;nbsp; The calculation was usec * 64, so I changed it to times 200 and removed the trace logging and it still worked.&amp;nbsp; I&amp;#39;m not sure why that would cause a timeout error, but this is progress &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f603.svg" title="Smiley"&gt;&amp;#x1f603;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;cortex_m::asm::delay((usec as u32) * 200);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Updating to nrfxlib 2.4.1 causes nrf_modem_ init() to timeout (errno 116)</title><link>https://devzone.nordicsemi.com/thread/438584?ContentTypeID=1</link><pubDate>Thu, 27 Jul 2023 15:08:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e5c9b38b-8152-43c5-81a0-f80f4666ad93</guid><dc:creator>Didrik Rokhaug</dc:creator><description>&lt;p&gt;It&amp;#39;s been very long since I last worked with Rust, so I was hoping I wouldn&amp;#39;t have to figure out how to set up the project.&lt;/p&gt;
&lt;p&gt;Looking at nrf-modem, do I understand it correctly that you have re-implemented the nrfx drivers used by the modem library, rather than using our implementation?&lt;/p&gt;
&lt;p&gt;With nrf_modem 2.4.0, the nrfx version it was using was also increased.&lt;/p&gt;
&lt;p&gt;Could you try to add &lt;a href="https://github.com/NordicSemiconductor/nrfx/blob/v2.11.0/drivers/src/nrfx_ipc.c#L157-L161"&gt;this&lt;/a&gt; part to the nrfx_ipc_irq_handler, and see if that solves your problem?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Updating to nrfxlib 2.4.1 causes nrf_modem_ init() to timeout (errno 116)</title><link>https://devzone.nordicsemi.com/thread/438511?ContentTypeID=1</link><pubDate>Thu, 27 Jul 2023 12:11:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32eb7509-529f-4155-a2e0-23262426b74e</guid><dc:creator>dkhayes117</dc:creator><description>&lt;p&gt;Thank you Didrik,&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/diondokter/nrf-modem/blob/update-nrfxlib/src/lib.rs#L89-L131"&gt;Here &lt;/a&gt;is the function that we use to init the modem.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/dkhayes117/golioth-rs/blob/rx_task/memory.x"&gt;Here&lt;/a&gt; is our memory.x definition for linking&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Those should be the only relevant pieces to this puzzle, I think.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Just in case, &lt;a href="https://github.com/diondokter/nrfxlib-sys"&gt;here &lt;/a&gt;is&amp;nbsp;the link to nrfxlib-sys being used to test the update to 2.4.1.&lt;/p&gt;
&lt;p&gt;also, I&amp;#39;m using mfw 1.3.5.&lt;/p&gt;
&lt;p&gt;-Daniel&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Updating to nrfxlib 2.4.1 causes nrf_modem_ init() to timeout (errno 116)</title><link>https://devzone.nordicsemi.com/thread/438453?ContentTypeID=1</link><pubDate>Thu, 27 Jul 2023 08:45:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f833918-168c-4b73-a39f-576d1a2bce9a</guid><dc:creator>Didrik Rokhaug</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The hardfault seems to come from an assert (unwrap()) checking the return value of nrf_modem_init(), so the hardfault should disappear when you are able to initialize the modem.&lt;/p&gt;
&lt;p&gt;Can you share your project (or enough of it to reproduce your problem), so I can look at how it is set up?&lt;/p&gt;
&lt;p&gt;We don&amp;#39;t officially support Rust, but I can at least try to have a look.&lt;/p&gt;
&lt;p&gt;Also, due to summer vacations, we are a bit short on staff, so responses might be slower than normal.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Didrik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>