<?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>Unable to return from fds_gc(), stuck in infinite loop.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/45789/unable-to-return-from-fds_gc-stuck-in-infinite-loop</link><description>There is a bug in fds.c file, Please go through the below code snippet. 
 
 I do not return from fds_gc(), execution stays there for infinite. 
 
 More information: 
 1) #define FDS_VIRTUAL_PAGES 30 
 2) #define FDS_VIRTUAL_PAGE_SIZE (1024) 
 3) Initialization</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 09 Sep 2020 13:55:38 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/45789/unable-to-return-from-fds_gc-stuck-in-infinite-loop" /><item><title>RE: Unable to return from fds_gc(), stuck in infinite loop.</title><link>https://devzone.nordicsemi.com/thread/268783?ContentTypeID=1</link><pubDate>Wed, 09 Sep 2020 13:55:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:88ac3839-8fe3-4905-ab00-601e9a0b70d0</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;For this case in specific it have been pending code to recreate it as requested here:&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/45789/unable-to-return-from-fds_gc-stuck-in-infinite-loop/189211"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/45789/unable-to-return-from-fds_gc-stuck-in-infinite-loop/189211&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;So I&amp;nbsp;do not know if the issue is solved since I have not received code that can recreate it. That said, there have been FDS fixes in general that affect garbage collection since SDKv15.2, from the release notes:&lt;/p&gt;
&lt;p&gt;SDK16 release notes:&lt;/p&gt;
&lt;p&gt;- FDS: fixed two bugs where a power loss at very specific times during garbage&lt;br /&gt; collection could corrupt the file system, making FDS unable to initialize and return&lt;br /&gt; FDS_ERR_NO_PAGES on initialization.&lt;br /&gt;- FDS: fixed a bug that prevented using the last word of a flash page to save a record.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;SDK17 release notes:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;- Fixed a bug where FDS garbage collection ran on more pages than necessary,&lt;br /&gt; causing unnecessary flash wear.&lt;/p&gt;
&lt;p&gt;So it may have been fixed indirectly in recent SDK releases.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to return from fds_gc(), stuck in infinite loop.</title><link>https://devzone.nordicsemi.com/thread/268780?ContentTypeID=1</link><pubDate>Wed, 09 Sep 2020 13:40:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:56f930f8-fe2a-46da-bc6f-d4aa248460b2</guid><dc:creator>GT</dc:creator><description>&lt;p&gt;Well I am asking about the status of this ticket. There is no confirmed answer for this one.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to return from fds_gc(), stuck in infinite loop.</title><link>https://devzone.nordicsemi.com/thread/268764?ContentTypeID=1</link><pubDate>Wed, 09 Sep 2020 13:13:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf81d4d8-c5c5-4932-b29b-82e78cae3def</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;I suggest to start a new case, and preferably state SDK+SD version and provide an example we may run here to recreate it?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to return from fds_gc(), stuck in infinite loop.</title><link>https://devzone.nordicsemi.com/thread/268722?ContentTypeID=1</link><pubDate>Wed, 09 Sep 2020 11:18:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eea2ff25-552f-4e0c-afd2-ae0d0248c866</guid><dc:creator>GT</dc:creator><description>&lt;p&gt;Hi Nordic team,&lt;/p&gt;
&lt;p&gt;Is there any root cause for this issue? Is this confirmed as a bug in SDK?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;GT&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to return from fds_gc(), stuck in infinite loop.</title><link>https://devzone.nordicsemi.com/thread/226008?ContentTypeID=1</link><pubDate>Wed, 18 Dec 2019 06:18:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cdb7fa48-cd34-4c70-be90-98a34c56bf5d</guid><dc:creator>Bevin</dc:creator><description>&lt;p&gt;Hi Kenneth&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I also met the issue that fds_gc() would be stuck in SDK 15.3.0_59ac345.&lt;/p&gt;
&lt;p&gt;Would it be possible for you to tell me if this problem&amp;nbsp;has been solved or not?&lt;/p&gt;
&lt;p&gt;Look forward to hearing from you soon.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Sincerely&lt;/p&gt;
&lt;p&gt;Bevin&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to return from fds_gc(), stuck in infinite loop.</title><link>https://devzone.nordicsemi.com/thread/210179?ContentTypeID=1</link><pubDate>Tue, 17 Sep 2019 14:49:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:46720f42-33fa-41f5-accc-403106bf8bf5</guid><dc:creator>mathiasvanbelle</dc:creator><description>&lt;p&gt;i see the same problem. How do i fixes this?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to return from fds_gc(), stuck in infinite loop.</title><link>https://devzone.nordicsemi.com/thread/189211?ContentTypeID=1</link><pubDate>Mon, 27 May 2019 07:38:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:88e3ef82-bbef-4362-aa1d-bce1e5d918a1</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Can you provide an example we may run here to recreate it?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to return from fds_gc(), stuck in infinite loop.</title><link>https://devzone.nordicsemi.com/thread/188500?ContentTypeID=1</link><pubDate>Wed, 22 May 2019 09:54:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ab3c4a7-2c82-4f51-8b8f-330985a10fd7</guid><dc:creator>ThierryC</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I experienced a similar issue as Jagadeep Ram. It&amp;#39;s not when I call fds_gc() on my case, but I got stuck on the same loop, where queue_has_next() return true, but FDS_OP in NONE and never get out of the loop !&lt;br /&gt;&lt;br /&gt;About Kenneth suggestion to check fs_sys_event_handler(), I don&amp;#39;t understand it. Is this function still called in SDK 15.2 ? I was thinking it was part of fstorage module.&lt;/p&gt;
&lt;p&gt;On SDK15, on_operation_failure() is called inside nrf_fstorage_sd module and never hit on my case.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to return from fds_gc(), stuck in infinite loop.</title><link>https://devzone.nordicsemi.com/thread/181566?ContentTypeID=1</link><pubDate>Thu, 11 Apr 2019 11:48:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7891f04f-7053-4e63-911f-9999023b81d6</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Terje is currently out travelling.&lt;/p&gt;
&lt;p&gt;I was wondering if you experience&amp;nbsp;on_operation_failure() occurs here, this will be triggered by&amp;nbsp;NRF_EVT_FLASH_OPERATION_ERROR in&amp;nbsp;fs_sys_event_handler().&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to return from fds_gc(), stuck in infinite loop.</title><link>https://devzone.nordicsemi.com/thread/180926?ContentTypeID=1</link><pubDate>Tue, 09 Apr 2019 08:03:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bcaea93e-71a7-408e-a800-b91ee2c6c66e</guid><dc:creator>Jagadeep Ram</dc:creator><description>&lt;p&gt;I missed an important information.&lt;/p&gt;
&lt;p&gt;The event handler is not called with&amp;nbsp;FDS_EVT_GC event after called fds_gc().&amp;nbsp; Please find the updated event handler function and code using FDS functions.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void fds_evt_handler(const fds_evt_t* p_evt)
{
    switch (p_evt-&amp;gt;id)
    {
        case FDS_EVT_INIT:
        {
            if (p_evt-&amp;gt;result == FDS_SUCCESS)
            {
                m_fds_initialized = 1;
                NRF_LOG_INFO(&amp;quot;Event: Init&amp;quot;);
            }
            break;
        }
        case FDS_EVT_WRITE:
        {
            if (p_evt-&amp;gt;result == FDS_SUCCESS)
            {
                write_done = 1;
                NRF_LOG_INFO(&amp;quot;Event: Write&amp;quot;);
            }
            break;
        }
        case FDS_EVT_DEL_RECORD:
        {
            if (p_evt-&amp;gt;result == FDS_SUCCESS)
            {
                erase_done = 1;
                NRF_LOG_INFO(&amp;quot;Event: Delete&amp;quot;);
            }
            break;
        }
        case FDS_EVT_UPDATE:
        {
            if (p_evt-&amp;gt;result == FDS_SUCCESS)
            {
                update_done = 1;
                NRF_LOG_INFO(&amp;quot;Event: Update&amp;quot;);
            }
            break;
        }
        case FDS_EVT_GC:
            if (p_evt-&amp;gt;result == FDS_SUCCESS)
            {
                gc_done = 1;
                NRF_LOG_INFO(&amp;quot;Event: Garbage Collection&amp;quot;);
            }
            break;
        default:
            break;
    }
}

static void wait_for_fds_ready(void)
{
    while (!m_fds_initialized)
    {
        __WFE();
    }
}

static void wait_for_write_done(void)
{
    while (!write_done)
    {
        __WFE();
    }
    write_done = 0;
}

static void wait_for_update_done(void)
{
    while (!update_done)
    {
        __WFE();
    }
    update_done = 0;
}

static void wait_for_gc_done(void)
{
    while (!gc_done)
    {
        __WFE();
    }
    gc_done = 0;
}

void write_event()
{
   ret_code = fds_record_find(record_id-&amp;gt;file_id, record_id-&amp;gt;key, &amp;amp;desc, &amp;amp;tok);
    /* Write only when file is not found */
    if (ret_code == FDS_ERR_NOT_FOUND)
    {
        ret_code = fds_record_write(&amp;amp;desc, record_id);
        if (ret_code == FDS_SUCCESS)
        {
            wait_for_write_done();
        }
        else if (ret_code == FDS_ERR_NO_SPACE_IN_FLASH)
        {
            ret_code = fds_gc();
            wait_for_gc_done();
            ERROR_CHECK_HIGH(ret_code);
            ret_code = fds_record_write(&amp;amp;desc, record_id);
            wait_for_write_done();
        }
    }
    else if (ret_code == FDS_SUCCESS)
    {
        /* Write the updated record to flash. */
        ret_code = fds_record_update(&amp;amp;desc, record_id);
        if (ret_code == FDS_SUCCESS)
        {
            wait_for_update_done();
        }
        else if (ret_code == FDS_ERR_NO_SPACE_IN_FLASH)
        {
            ret_code = fds_gc();
            wait_for_gc_done();
            ERROR_CHECK_HIGH(ret_code);
            ret_code = fds_record_update(&amp;amp;desc, record_id);
            wait_for_update_done();
        }
        else
        {
            ERROR_CHECK_HIGH(ret_code);
        }
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to return from fds_gc(), stuck in infinite loop.</title><link>https://devzone.nordicsemi.com/thread/180923?ContentTypeID=1</link><pubDate>Tue, 09 Apr 2019 07:54:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0b4e0bad-eed6-4969-9d25-06f0292d6feb</guid><dc:creator>Jagadeep Ram</dc:creator><description>&lt;p&gt;Hi Terje.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll explain what I&amp;#39;m trying to and what I have found during debug session.&lt;/p&gt;
&lt;p&gt;A) What I want to do?&lt;/p&gt;
&lt;p&gt;I want to store information in the FLASH storage during certain events take place. A single event record is 16 bytes and wants to store at least&amp;nbsp;500 events (8000 bytes in total). I have assigned&amp;nbsp;&lt;span&gt;FDS_VIRTUAL_PAGE_SIZE (1024) and&amp;nbsp;FDS_VIRTUAL_PAGES 12, way more than needed.&amp;nbsp; The product life is for 5 years and wanted to test the FLASH endurance (maximum events stored/updated), as the datasheet mention 10,0000 cycles.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;B) What I have done?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp; 1)&amp;nbsp; Created a file to store all events.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp; 2)&amp;nbsp; An event is stored as a record in the file.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp; 3)&amp;nbsp; Successfully created and stored 500 records using fds_record_write().&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp; 4) Update the existing records from the beginning for further records using&amp;nbsp;fds_record_update(). The goal is to set up a ring buffer of 500 records.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp; 5) An&amp;nbsp;fds_record_update()&amp;nbsp;&lt;/span&gt;&lt;span&gt;invalidates the current and creates a new record.&amp;nbsp; The allocated buffer&amp;nbsp;is utilized completely after around 2000 events and the update function returned FDS_ERR_NO_SPACE_IN_FLASH. As per the instruction,&amp;nbsp;fds_gc() should be used to free the invalidated records and continue with the update function.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;6) While calling the fds_gc() function, doesn&amp;#39;t return back to my layer and keeps calling queue_process() function infinitely.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;7) It is estimated that at least&amp;nbsp;5000 events should be stored (in circular fashion) during the product lifetime and hence it is important to fix this bug.&amp;nbsp;I found the issue while unit testing the event logging module.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void fds_evt_handler(const fds_evt_t* p_evt)
{
    switch (p_evt-&amp;gt;id)
    {
        case FDS_EVT_INIT:
        {
            if (p_evt-&amp;gt;result == FDS_SUCCESS)
            {
                m_fds_initialized = 1;
                NRF_LOG_INFO(&amp;quot;Event: Init&amp;quot;);
            }
            break;
        }
        case FDS_EVT_WRITE:
        {
            if (p_evt-&amp;gt;result == FDS_SUCCESS)
            {
                write_done = 1;
                NRF_LOG_INFO(&amp;quot;Event: Write&amp;quot;);
            }
            break;
        }
        case FDS_EVT_DEL_RECORD:
        {
            if (p_evt-&amp;gt;result == FDS_SUCCESS)
            {
                erase_done = 1;
                NRF_LOG_INFO(&amp;quot;Event: Delete&amp;quot;);
            }
            break;
        }
        case FDS_EVT_UPDATE:
        {
            if (p_evt-&amp;gt;result == FDS_SUCCESS)
            {
                update_done = 1;
                NRF_LOG_INFO(&amp;quot;Event: Update&amp;quot;);
            }
            break;
        }
        case FDS_EVT_GC:
            if (p_evt-&amp;gt;result == FDS_SUCCESS)
            {
                NRF_LOG_INFO(&amp;quot;Event: Garbage Collection&amp;quot;);
            }
            break;
        default:
            break;
    }
}

static void wait_for_fds_ready(void)
{
    while (!m_fds_initialized)
    {
        __WFE();
    }
}

static void wait_for_write_done(void)
{
    while (!write_done)
    {
        __WFE();
    }
    write_done = 0;
}

static void wait_for_update_done(void)
{
    while (!update_done)
    {
        __WFE();
    }
    update_done = 0;
}

void write_event()
{
   ret_code = fds_record_find(record_id-&amp;gt;file_id, record_id-&amp;gt;key, &amp;amp;desc, &amp;amp;tok);
    /* Write only when file is not found */
    if (ret_code == FDS_ERR_NOT_FOUND)
    {
        ret_code = fds_record_write(&amp;amp;desc, record_id);
        wait_for_write_done();
        if (ret_code == FDS_ERR_NO_SPACE_IN_FLASH)
        {
            ret_code = fds_gc();
            ERROR_CHECK_HIGH(ret_code);
            ret_code = fds_record_write(&amp;amp;desc, record_id);
            wait_for_write_done();
        }
    }
    else if (ret_code == FDS_SUCCESS)
    {
        /* Write the updated record to flash. */
        ret_code = fds_record_update(&amp;amp;desc, record_id);
        if (ret_code == FDS_SUCCESS)
        {
            wait_for_update_done();
        }
        else if (ret_code == FDS_ERR_NO_SPACE_IN_FLASH)
        {
            ret_code = fds_gc();
            ERROR_CHECK_HIGH(ret_code);
            ret_code = fds_record_update(&amp;amp;desc, record_id);
            wait_for_update_done();
        }
        else
        {
            ERROR_CHECK_HIGH(ret_code);
        }
    }
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I placed a breakpoint at fds_gc() function and could see that it revolves within itself. The variable result is having value FDS_ERR_INTERNAL inside&amp;nbsp;the function&amp;nbsp;queue_process().&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void queue_process(ret_code_t result)
{
    static fds_op_t              * m_p_cur_op;  // Current fds operation.
    static nrf_atfifo_item_get_t   m_iget_ctx;  // Queue context for the current operation.

    while (true)
    {
        if (m_p_cur_op == NULL)
        {
            // Load the next from the queue if no operation is being executed.
            m_p_cur_op = queue_load(&amp;amp;m_iget_ctx);
        }

        /* We can reach here in three ways:
         * from queue_start(): something was just queued
         * from the fstorage event handler: an operation is being executed
         * looping: we only loop if there are operations still in the queue
         *
         * In all these three cases, m_p_cur_op != NULL.
         */
        ASSERT(m_p_cur_op != NULL);

        switch (m_p_cur_op-&amp;gt;op_code)
        {
            case FDS_OP_INIT:
                result = init_execute(result, m_p_cur_op);
                break;

            case FDS_OP_WRITE:
            case FDS_OP_UPDATE:
                result = write_execute(result, m_p_cur_op);
                break;

            case FDS_OP_DEL_RECORD:
            case FDS_OP_DEL_FILE:
                result = delete_execute(result, m_p_cur_op);
                break;

            case FDS_OP_GC:
                result = gc_execute(result);
                break;

            default:
                result = FDS_ERR_INTERNAL;
                break;
        }

        if (result == FDS_OP_EXECUTING)
        {
            // The operation has not completed yet. Wait for the next system event.
            break;
        }

        // The operation has completed (either successfully or with an error).
        // - send an event to the user
        // - free the operation buffer
        // - execute any other queued operations

        fds_evt_t evt =
        {
            // The operation might have failed for one of the following reasons:
            // FDS_ERR_BUSY              - flash subsystem can&amp;#39;t accept the operation
            // FDS_ERR_OPERATION_TIMEOUT - flash subsystem timed out
            // FDS_ERR_CRC_CHECK_FAILED  - a CRC check failed
            // FDS_ERR_NOT_FOUND         - no record found (delete/update)
            .result = (result == FDS_OP_COMPLETED) ? FDS_SUCCESS : result,
        };

        event_prepare(m_p_cur_op, &amp;amp;evt);
        event_send(&amp;amp;evt);

        // Zero the pointer to the current operation so that this function
        // will fetch a new one from the queue next time it is run.
        m_p_cur_op = NULL;

        // The result of the operation must be reset upon re-entering the loop to ensure
        // the next operation won&amp;#39;t be affected by eventual errors in previous operations.
        result = NRF_SUCCESS;

        // Free the queue element used by the current operation.
        queue_free(&amp;amp;m_iget_ctx);

        if (!queue_has_next())
        {
            // No more elements left. Nothing to do.
            break;
        }
    }
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The code is stuck in this while loop. The&amp;nbsp;following exit point conditions are not True and hence its not possible to escape the loop.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;1)&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt; if (result == FDS_OP_EXECUTING)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // The operation has not completed yet. Wait for the next system event.&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;break;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;2)&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;if (!queue_has_next())&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;{&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// No more elements left. Nothing to do.&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;break;&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Let me know if you want more information. I&amp;#39;m open for a call or video session to share more code.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;/Jagadeep&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to return from fds_gc(), stuck in infinite loop.</title><link>https://devzone.nordicsemi.com/thread/180669?ContentTypeID=1</link><pubDate>Mon, 08 Apr 2019 08:51:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c61819f6-59c5-48ef-80eb-c889c0cd2271</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;All FDS functions that writes to or erases flash are asynchronous, and &lt;a href="https://www.nordicsemi.com/DocLib/Content/SDK_Doc/nRF5_SDK/v15-3-0/group__fds#ga90285f376c435c64b352023e725b7ebb"&gt;fds_gc()&lt;/a&gt; is no exception. This means on the call to fds_gc() the actual garbage collection gets queued. You will get an FDS_EVT_GC event at a later point, when the garbage collection has run. This means that yes, the code snippet that you listed initially does not work. In the case where garbage collection is needed, what happens in that code is that garbage collection gets queued, then before garbage collection is finished there is a new attempt to write for which you should expect another ret_code of FDS_ERR_NO_SPACE_IN_FLASH.&lt;/p&gt;
&lt;p&gt;Have you done a debug session in order to confirm where you get stuck?&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to return from fds_gc(), stuck in infinite loop.</title><link>https://devzone.nordicsemi.com/thread/180447?ContentTypeID=1</link><pubDate>Fri, 05 Apr 2019 08:45:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2af5c387-8515-49c5-b858-907f1e43dee1</guid><dc:creator>Jagadeep Ram</dc:creator><description>&lt;p&gt;Hi all,&lt;/p&gt;
&lt;p&gt;During the fds_gc() function call, I see the following code execute in the function&amp;nbsp;queue_process().&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; result = FDS_ERR_INTERNAL;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;        switch (m_p_cur_op-&amp;gt;op_code)
        {
            case FDS_OP_INIT:
                result = init_execute(result, m_p_cur_op);
                break;

            case FDS_OP_WRITE:
            case FDS_OP_UPDATE:
                result = write_execute(result, m_p_cur_op);
                break;

            case FDS_OP_DEL_RECORD:
            case FDS_OP_DEL_FILE:
                result = delete_execute(result, m_p_cur_op);
                break;

            case FDS_OP_GC:
                result = gc_execute(result);
                break;

            default:
                result = FDS_ERR_INTERNAL;
                break;
        }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Due to this, the while loop executes infinitely.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please someone guide me on how to use the&amp;nbsp;garbage collection function and solve my problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>