This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Endless loop when NUS RX for FDS

Hello,
I'm hoping that I missed something in the code and not something that might be inherent with nus and fds.
Combining SDK 15.3 template, uart and fds examples, with some additional code from Vidar in this case,
I can get write, delete, erase and fds stats working fine, as the functions nicely execute one after the other.
Flash a DK32 with the attached SES code, press reset on the DK a couple of times, and results are displayed as follows.

<00> info> app: void fds_record_write_1(void)
<00> info> app: Event: FDS_EVT_WRITE received (NRF_SUCCESS)
<00> info> app: FDS_EVT_WRITE DONE
<00> info> app: rec_id var1 var2 var3 var4
<00> info> app: 1 AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD
<00> info> app: Record written.
00>
<00> info> app: void fds_file_delete_1(void)
<00> info> app: Event: FDS_EVT_DEL_FILE received (NRF_SUCCESS)
<00> info> app: FDS_EVT_DEL_FILE here
<00> info> app: FDS_EVT_DEL_FILE DONE
<00> info> app: File deleted.
00>
<00> info> app: void fds_file_erase_1(void)
<00> info> app: Event: FDS_EVT_GC received (NRF_SUCCESS)
<00> info> app: FDS_EVT_GC DONE
<00> info> app: File erased.
00>
<00> info> app: void fds_flash_usage_1(void)
<00> info> app: Found 0 valid records.
<00> info> app: Found 0 dirty records (ready to be garbage collected).
<00> info> app: Found 3 pages available.
<00> info> app: Found 4 words used.
<00> info> app: Found 1022 largest contig.
<00> info> app: Found 0 freeable words.
<00> info> app: Found 0 freeable words (bytes).
<00> info> app: Stat displayed.
00>

When trying to write a record using nus rx, I'm getting an endless loop at "while (!fds_record_write_flag);".

This is done by using nRF Connect, with DK connected, click UART RX characteristic, tab to Unsigned, enter '1', and Write.
[enter: 1 (write record), 2 (file delete), 3 (erase), 4 (record delete), 5 (stat) ]

File delete seems to work fine when called by nus if no valid records exist.
But if there are valid records, file delete gets into a loop.
Write, erase, and record delete are always in a loop. Stat works fine in all cases.

I tried switching from bool to unint8_t for the while flags, changed void and static on the functions, changed while loop structures,
and also tried using nRF Connect for android, and sdk 17.0.2, but same endless loop results as 15.3 and ios.

All good when functions are run from main(), but not so good when called from nus rx.

thank-you,

Parents
  • Do I understand it correct that fds_record_write_1() works as intended when called from main(), but not when called from nus_data_handler()? In that case it sounds like a interrupt priority issue, where fds_evt_handler() is not able to preempt nus_data_handler(). Maybe you can just use flags to pass data from nus_data_handler() to main(), then call fds_record_write_1() from main().

    Kenneth

  • fds_record_write_1() works as intended when called from main(), but not when called from nus_data_handler(),
    and same for delete and error all good in main, butnot from nus_data_handler.

    I added nus_file_delete_flag to nus_data_handler for fds_record_write_1.
    After writing "1" to nus rx in nrf connect, the nus_file_delete_flag stays in nus_data_handler without reaching main().
    Is this what you were describing?
    If so, I'm not understanding how main() can pick up a nus event.

  • It looks to me that your nus data handler is triggered from a softdevice event, the fds data handler is triggered by a softdevice event, in your case you are waiting for an event from the next softdevice event (fds) in your current softdevice event (nus). So this won't work. You need to call fds_record_write_1() from main context if you want to wait for the nus_file_delete_flag.

    Kenneth

Reply
  • It looks to me that your nus data handler is triggered from a softdevice event, the fds data handler is triggered by a softdevice event, in your case you are waiting for an event from the next softdevice event (fds) in your current softdevice event (nus). So this won't work. You need to call fds_record_write_1() from main context if you want to wait for the nus_file_delete_flag.

    Kenneth

Children
No Data
Related