Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(BLE): WSF-NVM Storage Full Error Handling #975

Merged
merged 27 commits into from
Apr 10, 2024
Merged

Conversation

EricB-ADI
Copy link
Contributor

@EricB-ADI EricB-ADI commented Apr 2, 2024

Description

  • WsfNvm no longer asserts on storage full. Returns a FALSE and leaves it up to user what to do next.
  • Added API to de-fragment NVM. Previously once marked as unused all NVM needed to be wiped to use the space again.

@EricB-ADI EricB-ADI added WIP work in progress MAX32655 Related to the MAX32655 (ME17) MAX32665 Related to the MAX32665 (ME14) MAX32690 Related to the MAX32690 (ME18) BLE Related to Bluetooth labels Apr 2, 2024
@github-actions github-actions bot removed MAX32665 Related to the MAX32665 (ME14) MAX32690 Related to the MAX32690 (ME18) labels Apr 2, 2024
@EricB-ADI
Copy link
Contributor Author

/clang-format-run

@github-actions github-actions bot added MAX78000 Related to the MAX78000 (AI85) and removed MAX32655 Related to the MAX32655 (ME17) labels Apr 4, 2024
@github-actions github-actions bot added the MAX32655 Related to the MAX32655 (ME17) label Apr 4, 2024
@EricB-ADI EricB-ADI requested a review from Jake-Carter April 4, 2024 18:50
@github-actions github-actions bot removed the MAX32655 Related to the MAX32655 (ME17) label Apr 4, 2024
@EricB-ADI EricB-ADI requested a review from yc-adi April 4, 2024 19:13
Copy link
Contributor

@Jake-Carter Jake-Carter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @EricB-ADI, looks good. Minor requests below


/*If the entry is valid copy it into the defragmentation buffer, if its reserved we can defrag it*/
if (header.id != WSF_NVM_RESERVED_FILECODE) {
PalFlashRead(&copyBuf[copyOffset], fileSize, currentOffset);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am getting a HardFault on the memcpy call inside this call.

I have defined PAL_NVM_SIZE to be 0x2000. I also fixed the bug in this comment.

I filled up the DB, and now when this code executes, wsfNvmCb.availAddr's value is 0x2010, which is past the bounds of the DB. So the header actually has invalid data. header.len is 0x2000242c, which ultimately causes the HardFault in memcpy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you see where the address gets set to the out of bounds state? Once again the wsfHaveEnoughSpace function is intended to block against this condition. If it isn't, I need to fix that. A workaround that I don't like is just getting the min between the available address and the total size

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's being set in WsfNvmInit on a subsequent boot, after the failed write due to insufficient space.

@@ -232,7 +287,11 @@ bool_t WsfNvmWriteData(uint64_t id, const uint8_t *pData, uint16_t len, WsfNvmCo
}

WSF_ASSERT(!((id == WSF_NVM_RESERVED_FILECODE) || (id == WSF_NVM_UNUSED_FILECODE)));
WSF_ASSERT((wsfNvmCb.availAddr - WSF_NVM_START_ADDR) <= wsfNvmCb.totalSize);

if (!wsfNvmHaveEnoughSpace(len)) {
Copy link

@sullivanmj sullivanmj Apr 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be checking for wsfNvmHaveEnoughSpace(len+sizeof(header))? I am still seeing a HardFault, even with the additional fixes from today (which look great to me). I'm trying to figure out if it's a problem with my test setup or not. Noticed this while I was investigating.

@@ -63,6 +65,9 @@ typedef struct {
uint32_t dataCrc; /*!< CRC of subsequent data. */
} WsfNvmHeader_t;

#define WSF_NVM_HEADER_SIZE sizeof(WsfNvmHeader_t)
#define WSF_NVM_FILE_SIZE(header_len) (WSF_NVM_HEADER_SIZE + (header_len))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the cause of my HardFault is that the offset for reading chunks while defragging is calculated using this, without an alignment bump, whereas WsfNvmWriteData is writing files witha n alignment adjustment. See

storageAddr += WSF_NVM_WORD_ALIGN(header.len) + sizeof(header);

When I made this change, I was able to get past that HardFault.

Presumably this macro should be doing the same thing (and maybe the write function should also use this macro?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to add, I also had to change this line

to account for that alignment offset as well, in order to fix the HardFault

@EricB-ADI
Copy link
Contributor Author

Hardfaults are gone and non word aligned de fragmentation is fixed

@EricB-ADI EricB-ADI requested a review from Jake-Carter April 9, 2024 15:14
Copy link
Contributor

@Jake-Carter Jake-Carter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sullivanmj if you can run a final test and give us confirmation your issue and findings have been resolved we'll merge it

@EricB-ADI in the meantime a very minor macro request below

bool_t WsfNvmDefragment(uint8_t *copyBuf, uint32_t size)
{
#if WSF_ASSERT_ENABLED == 1
WSF_ASSERT(copyBuf && size >= wsfNvmCb.totalSize);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I would suggest checking for WSF_ASSERT_ENABLED inside the WSF_ASSERT macro. It cleans up the code and is much easier to maintain

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jake-Carter Yes, with the changes provided by @EricB-ADI, the original issue can now be resolved on my end by detecting that the writing of pairing keys failed due to insufficient space, defragging, and then re-attempting to store the keys, which succeeds.

Thanks!

@EricB-ADI EricB-ADI requested a review from Jake-Carter April 10, 2024 14:20
@EricB-ADI
Copy link
Contributor Author

/clang-format-run

@EricB-ADI EricB-ADI removed the MAX78000 Related to the MAX78000 (AI85) label Apr 10, 2024
@Jake-Carter Jake-Carter merged commit 1644294 into main Apr 10, 2024
7 checks passed
@Jake-Carter Jake-Carter deleted the feat/wsf-nvm branch April 10, 2024 16:53
EricB-ADI pushed a commit that referenced this pull request Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BLE Related to Bluetooth WIP work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants