<?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>Problem running LESC on nRF5 SDK with App Scheduler running</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/112876/problem-running-lesc-on-nrf5-sdk-with-app-scheduler-running</link><description>Hi there, 
 I have a project developed in SES, using nRF5 SDK v15.3.0 with only Just Works security without using LESC running on nRF52840. It has been running fine for 2 years. Recently, I have upgraded it to nRF5 SDK v17.1.0. Everything works fine.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 15 Jul 2024 06:57:36 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/112876/problem-running-lesc-on-nrf5-sdk-with-app-scheduler-running" /><item><title>RE: Problem running LESC on nRF5 SDK with App Scheduler running</title><link>https://devzone.nordicsemi.com/thread/493811?ContentTypeID=1</link><pubDate>Mon, 15 Jul 2024 06:57:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:438e9c91-bfa8-49bf-b136-412349327ee6</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi Sunny.&lt;/p&gt;
&lt;p&gt;Good to hear. If you want, I can take a look at your FDS code to see if I can spot any potential problems with the implementation. Just let me know.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem running LESC on nRF5 SDK with App Scheduler running</title><link>https://devzone.nordicsemi.com/thread/493785?ContentTypeID=1</link><pubDate>Mon, 15 Jul 2024 02:20:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df7fc579-a3da-4f59-bcb3-8567dd4f1f29</guid><dc:creator>Sunny Lo</dc:creator><description>&lt;p&gt;&lt;span&gt;Hi Vidar,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Oh yes.&amp;nbsp; The demo is running ok now.&amp;nbsp; Thanks.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I still see problems with my code in the section running the fds storage.&amp;nbsp; I will spend time looking at it.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Sunny&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem running LESC on nRF5 SDK with App Scheduler running</title><link>https://devzone.nordicsemi.com/thread/493593?ContentTypeID=1</link><pubDate>Fri, 12 Jul 2024 08:58:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df00412c-e4f8-43cc-822b-20706c1a6290</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;APP_ERROR_HANDLER() calls the error handler function regardless of what the error code is. You probably meant to use&amp;nbsp;APP_ERROR_CHECK().&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem running LESC on nRF5 SDK with App Scheduler running</title><link>https://devzone.nordicsemi.com/thread/493587?ContentTypeID=1</link><pubDate>Fri, 12 Jul 2024 08:37:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9a3b2b83-bcaa-4a8c-9b60-6aa8fa5e5ab1</guid><dc:creator>Sunny Lo</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
&lt;p&gt;Yes, you are right.&amp;nbsp; I missed the APP_SCHED_INIT macro.&amp;nbsp; Now I added it back.&amp;nbsp; The timer use scheduler works.&amp;nbsp; But something strange happens if I add the app_sched_execute() in the idle_state_handle().&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As long as I add the macro APP_ERROR_HANDLER(err_code) after the&amp;nbsp;app_sched_event_put(...), an error pops up.&amp;nbsp; If I remove this macro, everything works fine.&amp;nbsp; Do you see anything wrong with my code?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Commented out &lt;span&gt;APP_ERROR_HANDLER(err_code)&lt;/span&gt;&lt;span&gt;, no error.&amp;nbsp; Program runs fine.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&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/Screenshot-2024_2D00_07_2D00_12-151447.png" alt=" " /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;With APP_ERROR_HANDLER(err_code), program halt even though the error code is &amp;quot;ERROR 0 [NRF_SUCCESS]&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&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/Screenshot-2024_2D00_07_2D00_12-150423.png" alt=" " /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&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/Screenshot-2024_2D00_07_2D00_12-150330.png" alt=" " /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem running LESC on nRF5 SDK with App Scheduler running</title><link>https://devzone.nordicsemi.com/thread/493364?ContentTypeID=1</link><pubDate>Thu, 11 Jul 2024 10:16:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fb8c00ef-cf4f-449e-b9f9-7d8644899509</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi Sunny,&lt;/p&gt;
&lt;p&gt;It seems like you may have forgotten to initialize the scheduler with APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE); in main()?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem running LESC on nRF5 SDK with App Scheduler running</title><link>https://devzone.nordicsemi.com/thread/493332?ContentTypeID=1</link><pubDate>Thu, 11 Jul 2024 08:49:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:921bfb60-48ff-4a5a-9351-1335452241fe</guid><dc:creator>Sunny Lo</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
&lt;p&gt;Thank you for your reply.&lt;/p&gt;
&lt;p&gt;You are right that the modified code from glucose example was not a hard fault.&amp;nbsp; Instead it is ERROR 4 [NRF_ERROR_NO_MEM].&amp;nbsp; Sorry about that.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;However, I don&amp;#39;t understand why this error happens.&amp;nbsp; What I&amp;nbsp;have changed to the glucose example was to add a 1 second counter from the app timer.&amp;nbsp; When it reaches 30 times (roughly 30 seconds), it puts the event check_if_put_bmr_to_sleep_seh into the scheduler queue.&amp;nbsp; In fact, it only happens once and the&amp;nbsp;&lt;span&gt;NRF_ERROR_NO_MEM error shows up.&amp;nbsp; I don&amp;#39;t understand why putting 1 single event into the scheduler event queue&amp;nbsp;cause this NRF_ERROR_NO_MEM error.&amp;nbsp; I have probably overlook something.&amp;nbsp; Can you please educate me on it?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/* 
   Added timestamp to the log
*/
static uint64_t   m_clock_cnt;

uint32_t get_rtc_counter(void)
{
    return NRF_RTC1-&amp;gt;COUNTER;
}

/**@brief Function for initializing the nrf log module.
 */
static void log_init(void)
{
    ret_code_t err_code = NRF_LOG_INIT(get_rtc_counter);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();
}
......

static void timers_init(void)
{
    ret_code_t err_code;

    // Initialize timer module.
    err_code = app_timer_init();
    APP_ERROR_CHECK(err_code);

    // Create timers.
    err_code = app_timer_create(&amp;amp;m_battery_timer_id,
                                APP_TIMER_MODE_REPEATED,
                                battery_level_meas_timeout_handler);
    APP_ERROR_CHECK(err_code);

    // Timer to emulate clock
    err_code = app_timer_create(&amp;amp;clock_em_tid, APP_TIMER_MODE_REPEATED, clock_em_eh);   
    APP_ERROR_CHECK(err_code);                                                                        

}


static void application_timers_start(void)
{
    ret_code_t err_code;

    // Start application timers.
    err_code = app_timer_start(m_battery_timer_id, BATTERY_LEVEL_MEAS_INTERVAL, NULL);
    APP_ERROR_CHECK(err_code);

    // Start clock emulation timer
    err_code = app_timer_start(clock_em_tid, APP_TIMER_TICKS(1000), NULL);
    m_clock_cnt = 0; 
    APP_ERROR_CHECK(err_code);
}

void check_if_put_bmr_to_sleep_seh(void *p_ev_data, uint16_t ev_size) {
    NRF_LOG_INFO(&amp;quot;Reached 30 seconds! Reset clock counter to ZERO!&amp;quot;);
}

/**@brief Function to check if bmr should be put to sleep
 *
 * @details if m_clock_cnt &amp;gt;= 30; reset m_clock_cnt = 0; 
*/
void check_if_put_bmr_to_sleep() {
    ret_code_t  err_code;
    if (m_clock_cnt &amp;gt;= 30) {
        m_clock_cnt = 0;

        NRF_LOG_INFO(&amp;quot;Put function in Scheduler!&amp;quot;);
        err_code = app_sched_event_put(0,0,check_if_put_bmr_to_sleep_seh);
        APP_ERROR_CHECK(err_code);
    }
}

/**@brief Function for the 1 second clock emulation.
 *
 * @details Run every 1 second
 */
void clock_em_eh(void *p_context) {
    UNUSED_PARAMETER(p_context);
    m_clock_cnt++;
    check_if_put_bmr_to_sleep();

}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/Screenshot-2024_2D00_07_2D00_11-164337.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BTW, I use the original Glucose Application main.c without making any changes.&amp;nbsp; Then I change the following&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; #define APP_TIMER_CONFIG_USE_SCHEDULER 1&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; #define NRF_LOG_BACKEND_RTT_ENABLED 1&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; #define NRF_LOG_BACKEND_UART_ENABLED 0&lt;/p&gt;
&lt;p&gt;in sdk_config.h&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Then the error&amp;nbsp;ERROR 9 [NRF_ERROR_INVALID_LENGTH] shows up.&amp;nbsp; I think I must be missing something here.&amp;nbsp; Please help.&lt;/p&gt;
&lt;p&gt;Thank you.&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/Screenshot-2024_2D00_07_2D00_11-173038.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Best Regards&lt;/p&gt;
&lt;p&gt;Sunny&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem running LESC on nRF5 SDK with App Scheduler running</title><link>https://devzone.nordicsemi.com/thread/493299?ContentTypeID=1</link><pubDate>Thu, 11 Jul 2024 07:21:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e15aaad9-7363-48f2-bde1-ad942cf500e2</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;The issues you are seeing does not appear to be related to LESC. I&amp;#39;m not aware of any known issues with using LESC and the app scheduler together either.&lt;/p&gt;
[quote user=""]3. After I started debugging in SES, I got the DH_key and had completed the connection.&amp;nbsp; However, once the &amp;quot;app_sched_event_put(0,0,check_if_put_bmr_to_sleep_seh)&amp;quot; was executed the hardfault error (timer_expire) came out.&amp;nbsp;[/quote]
&lt;p&gt;The first screenshot you posted was showing a hardfault, but this one is not. The error handler is invoked because a runtime error check failed in the timer_expire() function. Perhaps you have exhausted the scheduler queue due to long-running tasks. If that&amp;#39;s the case, it&amp;#39;s likely failing here:&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/pastedimage1720682250013v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;You will get a more detailed crash log if you debug your project using the &amp;#39;Debug&amp;#39; build configuration instead of &amp;#39;Release&amp;#39;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>