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

nrf9160 - NVS read/write error code 22

Hi, I'm working on an application (Zephyr) that uses nvs storage and it's been working just great for awhile (months) without any major issues. Today I noticed that when reading or writing using nvs_read or nvs_write, I am suddenly getting a return code of -22 which is for an invalid argument.

I've tried re-flashing the nrf9160 several times but no luck. I ended up trying out the nvs sample (ncs/zephyr/samples/subsys/nvs) and it's working just fine. I adjusted the read IDs in the sample code to match a few of the addresses I was using in my custom application and it it still appears to work just fine (verified being able to read/write the contents just fine). After finishing testing the sample code, I switched back to my custom app and those addresses I tested out started working again and the addresses I didn't test still had the same issue.

I've matched the sample application nvs initialization to be almost identical (I've increased the sector_count but that's that only notable difference). I found that once I went back to the sample app and adjusted the read and writes to the remaining IDs I was using and swapped back, everything was working just fine which is strange.

Technically the issue is 'resolved' now but now I'm not sure why it was even happening in the first place or why I needed to run the sample app to fix the issue. Since the issue seems to get resolved whenever I use the sample application, I'm lead to believe I'm doing something wrong or missing something in my custom app but I'm failing to see what it could be since everything matches (except the sector_count). The project configuration file has all of the same defines and everything had been working just fine before without a hitch.

Maybe unrelated but I had recently updated the nrf9160 modem firmware but I didn't think that would have affected this.

Any insight would be much appreciated.

Parents
  • Technically the issue is 'resolved' now but now I'm not sure why it was even happening in the first place or why I needed to run the sample app to fix the issue.

    Good to hear that it now works, I don't know why there initially was an issue no. Maybe do a full erase (e.g. nrfjprog --eraseall --coprocessor CP_APPLICATION) of the application and check that it is indeed resolved?

    Kenneth

Reply
  • Technically the issue is 'resolved' now but now I'm not sure why it was even happening in the first place or why I needed to run the sample app to fix the issue.

    Good to hear that it now works, I don't know why there initially was an issue no. Maybe do a full erase (e.g. nrfjprog --eraseall --coprocessor CP_APPLICATION) of the application and check that it is indeed resolved?

    Kenneth

Children
  • I can't verify if the full erase would resolve the issue since it seems to be fixed now.

    I am thinking it is related to the sector_count + size definitions since I was defining the sector_count = 7 and the sector_size is 4096 with the offset being at 0x000FA000 (limit being 0x000FF000). I was pointed down this path from this post and am guessing that the issue I was seeing was the address I was trying read/write from was on a sector that was out of the address range.

    This would cause an error which happened to be -22 and would explain why the sample application worked, it was only using 3 sectors and they would be within the allowed range and accessing the IDs that were out of the sector range, updated them to be within the right address space.

    Does this seem probable as to what was happening?

Related