<?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>Init/deinit openthread stack causes a failed assert</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/75709/init-deinit-openthread-stack-causes-a-failed-assert</link><description>Hello, 
 for our application i need to periodically enable and disable the openthread stack on the nRF52840 chip. 
 For testing purposes i&amp;#39;ve modified the Thread CLI example so that the main loop keeps doing the following: 
 
 Wait for a timer to expire</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 17 Nov 2021 09:30:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/75709/init-deinit-openthread-stack-causes-a-failed-assert" /><item><title>RE: Init/deinit openthread stack causes a failed assert</title><link>https://devzone.nordicsemi.com/thread/339366?ContentTypeID=1</link><pubDate>Wed, 17 Nov 2021 09:30:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c573f6ea-2ad0-45da-8e37-1b1adcb5f4b8</guid><dc:creator>Marjeris Romero</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I am so sorry for not getting back to you on this one, it looks like I forgot to reply. I don&amp;#39;t see anything it your code snippets that seem unormal to me. Are you still struggling with this? Could you give me an update on how it&amp;#39;s going with your project?&lt;/p&gt;
&lt;p&gt;Again I am so sorry I didn&amp;#39;t see this ticket wasn&amp;#39;t reply to before now...&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marjeris&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Init/deinit openthread stack causes a failed assert</title><link>https://devzone.nordicsemi.com/thread/312655?ContentTypeID=1</link><pubDate>Mon, 31 May 2021 13:15:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:41dc00f7-bb0c-4083-b971-570f108759ff</guid><dc:creator>MarcoLG</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;sure, i&amp;#39;ll try to share you the relevant parts. However, this is not my application code, but simply a modified Thread CLI example that i did in order to reproduce the problem.&lt;/p&gt;
&lt;p&gt;The main function creates a timer, &amp;quot;connect_timer_id&amp;quot;, used to decide when to connect. In the main loop, this is the code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    while(true) 
    {
        if (connect_timer_expired)
        {
            connect_timer_expired = 0;
            if (thread_state == STATE_DISCONNECTED)
            {
                thread_state = STATE_CONNECTING;
                thread_network_up();
            }
            else if (thread_state == STATE_CONNECTED)
            {
                thread_state = STATE_DISCONNECTED;
                thread_network_down();
                err = app_timer_start(connect_timer_id, APP_TIMER_TICKS(7000), (uint32_t *)0x1);
                APP_ERROR_CHECK(err);
            }
        }
        
        if (thread_instance_initialized) {
            thread_process();
        }
        
        NRF_LOG_PROCESS();
    }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;connect_timer_expired is set in interrupt context upon timer expiration.&lt;/p&gt;
&lt;p&gt;The thread_network_up() function configures the thread network parameters and starts a radio scan using otLinkActiveScan. Once the scan finds the configured thread network, the system enables the remaining thread stack by calling thread_interface_enable(), defined as:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void thread_interface_enable(bool enabled)
{
    otError error;
    /* Start the Thread network interface (CLI cmd &amp;gt; ifconfig up) */
    otInstance *instance = thread_ot_instance_get();

    error = otIp6SetEnabled(instance, enabled);
    APP_ERROR_CHECK(error);

    /* Start the Thread stack (CLI cmd &amp;gt; thread start) */
    error = otThreadSetEnabled(instance, enabled);
    APP_ERROR_CHECK(error);
    
    NRF_LOG_INFO(&amp;quot;Thread interface %s&amp;quot;, enabled ? &amp;quot;enabled&amp;quot; : &amp;quot;disabled&amp;quot;);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Once the device is connected to the thread network, the timer is started again to schedule a disconnection. This is part of the thread_state_changed_callback function:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void thread_state_changed_callback(uint32_t flags, void * p_context)
{
    otDeviceRole role = otThreadGetDeviceRole(p_context);
    NRF_LOG_INFO(&amp;quot;State changed! Flags: 0x%08x Current role: %d\r\n&amp;quot;,
                 flags, role);
    
    [...]
    if (role &amp;gt;= OT_DEVICE_ROLE_CHILD)
    {
        thread_state = STATE_CONNECTED;
        uint32_t err = app_timer_start(connect_timer_id, APP_TIMER_TICKS(1500), (uint32_t *)0x1);
        APP_ERROR_CHECK(err);    
    }
    
    [...]
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Basically this is it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Init/deinit openthread stack causes a failed assert</title><link>https://devzone.nordicsemi.com/thread/312629?ContentTypeID=1</link><pubDate>Mon, 31 May 2021 12:03:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d3bfef3c-8705-4a36-bb6d-13b49426bc2d</guid><dc:creator>Marjeris Romero</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Yes, it looks like something isn&amp;#39;t finished from the previous operation. Could you perhaps share your code with us to review and see what you are doing?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marjeris&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>