Non-Volatile Memory Version 3 (NVM3) Debugging and Error Handling#

This section provides strategies for identifying and resolving issues when working with the Non-Volatile Memory version 3 (NVM3) driver on SiWx917.
It covers debugging techniques, analysis tools, and error-handling methods to help ensure reliable memory management and data integrity.

Common Debugging Tips#

Debugging NVM3 involves systematically isolating and addressing issues related to flash memory interaction, data persistence, and system performance.
The following best practices outline effective tools and methods for troubleshooting.

Use NVM3 Error Handling#

Most NVM3 functions (such as, nvm3_readData() and nvm3_writeData()) return status codes that indicate success or failure. Always inspect these return values to diagnose potential issues.

  • The nvm3_open() function is different:
    It performs internal recovery attempts and reports success if a valid NVM3 instance is restored.
    Errors from nvm3_open() usually indicate serious issues, such as:

    • Insufficient flash space (due to bad pages)

    • Incorrect NVM3 region configuration

Leverage Simplicity Commander#

Use Simplicity Commander, a Silicon Labs command-line tool, to read and inspect NVM3 data stored in flash. It allows you to analyze stored application states at various points in runtime.

For more information about Simplicity Commander, see Simplicity Commander – NVM3 Commands.

Implement Logging and Tracing#

Enable debug logging to capture system activity during NVM3 operations.
Add diagnostic printouts around key operations such as:

  • nvm3_eraseAll()

  • nvm3_deleteObject()

  • nvm3_writeData()

These logs help verify that no unintended erase or delete operations occur.

Address Potential Data Corruption#

Although NVM3 automatically marks failing flash pages as bad and relocates data, applications should still handle errors gracefully.

  • If data changes unexpectedly across reboots, verify that NVM3 flash regions do not overlap with bootloader or OTA areas.

  • During validation, read back recently written objects before rebooting to confirm data persistence.

Optimize Memory Management#

Efficient configuration of memory allocation and caching improves performance and flash lifetime.

  • Right-size the storage region:
    Match NVM capacity to expected object count, size, and update frequency.

  • Optimize cache size:
    Ensure the cache accommodates both active and deleted objects for faster lookups.

  • Use low-memory callbacks:
    Register a callback with nvm3_registerCallback() to handle low-memory warnings (for example, trigger repacking automatically when space runs low).

Adopt a Structured Debugging Approach#

Follow a disciplined process for troubleshooting NVM3 issues:

  1. Reproduce the issue: Define the exact conditions that cause the failure.

  2. Isolate the source: Use debug logs and tools to narrow down the fault.

  3. Analyze the cause: Examine system state, configuration, and stack traces.

  4. Fix and verify: Apply fixes and re-test under similar conditions to validate stability.

By applying these structured debugging practices, you can significantly improve system robustness and NVM3 data reliability on SiWx917.

Note: If all pages in an NVM3 instance are marked as bad, the memory is considered full and corrupt, and the NVM3 driver will fail and return an error code.

Error Code Handling#

This section lists common NVM3 driver error codes and their corresponding recovery actions.

Error Code

Description

Recommended Recovery Action

SL_STATUS_OK

Operation completed successfully.

Continue normal operation.

SL_STATUS_INVALID_PARAMETER

Invalid configuration or parameter value.

Verify and correct input parameters.

SL_STATUS_NVM3_KEY_MISMATCH

Key validation failed.

Ensure the correct object key is used.

SL_STATUS_NVM3_INVALID_ADDR

Invalid NVM address detected.

Provide a valid, aligned NVM address.

SL_STATUS_NVM3_SIZE_ERROR

Object size mismatch with buffer size.

Adjust the buffer to match object size.

SL_STATUS_NVM3_READ_DATA_SIZE

Read length does not match stored object size.

Correct the requested read length.

SL_STATUS_NVM3_NO_VALID_PAGES

Initialization failed; no valid pages found.

Check NVM3 configuration and available flash pages.

Tip: Invalid flash alignment, page overlaps, or incorrect size parameters are common causes of NVM3 initialization failures.