nrf_sdh_evts_poll hangs when trying to write/erase flash after SDH is enabled

Dear Support, 

I was working on refactoring the project and changed a majority of cmake files to improve the architecture of the project but when I finished I found out that something has been broken. After initial investigation I figured out that nrf_fstorage_write/nrf_fstorage_erase works only before SDH enable request is sent. If the function is called after that the firmware reboots by WDT with no assertions from SD or SDK's code. 

When I disabled WDT and tried to debug the project using J-Link it turned out that it hangs in nrf_sdh_evts_poll that's used to wait for completion of an operation. I also tried to put delays but operations are not getting completed. Although it returns SUCCESS on the first call, it fails on following calls.

    bool complete = false;
    if (NRF_SUCCESS != nrf_fstorage_erase(&fdb, addr, erase_pages, &complete)) {
        return 0;
    }
    while (!complete) nrf_sdh_evts_poll();

    return size;

There were no significant changes in the code that could cause such a behavior. Also, I compared compilation and linking flags before and after my changes - they look the same. 

As I mentioned, the code was working before and there are no mistakes in sdk_config file. I tried many approaches to debug the issue but they were unfruitful. 

Since I ran out idea, could you please advise possible reasons for the issue? 

I'm using: nRF5 SDK 17.1.0 with nRF52833 and S113. 

Thank you, 

Ramil.

Parents Reply Children
  • It's not interrupt context. As I mentioned, it was working well before I did some work on the cmake architecture. Likely, the issue should be related to compilation or linking. 

    I'll also put some details of my latest debugging session: 

    1. If I do not wait in loop endlessly calling nrf_sdh_evts_poll it puts 4 operations in the queue and then starts returning NO_MEM return code which is expected since the queue length is 4. 

    2. There are no events in SDH_SOC_OBSERVER's handler in nrf_fstorage_sd too.

    Unfortunately, I stuck here because there is no way to move forward. 

  • Turned out that the stack observer which is registered in nrf_sdh_soc.c has not been linked. That's why events were getting missed.

    I will try to find out why. 

  • Unlikely, anyone else will come across the issue but just in case I will put some explanation here what's happened. It's more about cmake rather than nRF5 SDK. 

    In our cmake infrastructure nrf_sdh_soc.c was a part of a library that's called let's say nrf5_sdh_lib. Before the changes I applied the library was linking directly to the application executable but after that I included it into another library that's supposed to be linked to the final executable. But since nrf_sdh_soc.c doesn't have any external references it was omitted with the included sections (although attribute "used" has been applied). 

    I'm not expert in cmake and the best what I found is linking the library directly to the executable. 

Related