55 explicit StmNvs(
const char* namespace_name =
"default",
70 size_t* actual_size =
nullptr)
noexcept override;
72 hf_nvs_err_t SetBlob(
const char* key,
const void* data,
size_t data_size)
noexcept override;
74 size_t* actual_size =
nullptr)
noexcept override;
78 bool KeyExists(
const char* key)
noexcept override;
128 const void* data,
size_t data_size)
noexcept;
131 bool IsValidKey(
const char* key)
const noexcept;
Abstract base class for Non-Volatile Storage implementations in the HardFOC system.
hf_nvs_err_t
Definition BaseNvs.h:76
uint32_t hf_u32_t
Platform-agnostic 32-bit unsigned integer type.
Definition HardwareTypes.h:52
uint8_t hf_u8_t
Platform-agnostic 8-bit unsigned integer type.
Definition HardwareTypes.h:40
uint16_t hf_u16_t
Platform-agnostic 16-bit unsigned integer type.
Definition HardwareTypes.h:46
STM32 platform-specific type definitions for hardware abstraction.
Abstract base class for non-volatile storage operations.
Definition BaseNvs.h:147
STM32 NVS — flash-backed key-value store with wear leveling.
Definition StmNvs.h:48
hf_nvs_err_t SetString(const char *key, const char *value) noexcept override
Store a string value.
Definition StmNvs.cpp:121
EntryType
NVS entry types.
Definition StmNvs.h:98
size_t entry_count_
Current entry count.
Definition StmNvs.h:145
hf_nvs_err_t GetU32(const char *key, hf_u32_t &value) noexcept override
Retrieve a 32-bit unsigned integer value.
Definition StmNvs.cpp:107
hf_stm32_nvs_config_t flash_config_
Flash region config.
Definition StmNvs.h:142
size_t GetEntryCount() const noexcept
Get number of stored entries.
Definition StmNvs.h:91
int FindCacheEntry(const char *key) const noexcept
Find entry in RAM cache by key.
Definition StmNvs.cpp:240
hf_nvs_err_t Commit() noexcept override
Commit any pending writes to non-volatile storage.
Definition StmNvs.cpp:198
hf_nvs_err_t SetBlob(const char *key, const void *data, size_t data_size) noexcept override
Store binary data (blob).
Definition StmNvs.cpp:155
StmNvs(const char *namespace_name="default", const hf_stm32_nvs_config_t &flash_config=hf_stm32_nvs_config_t()) noexcept
Construct with namespace and flash configuration.
Definition StmNvs.cpp:37
struct __attribute__((packed)) EntryHeader
Entry header stored in flash (packed)
Definition StmNvs.h:106
size_t GetMaxKeyLength() const noexcept override
Get maximum key length supported.
Definition StmNvs.cpp:224
hf_nvs_err_t EraseKey(const char *key) noexcept override
Remove a key from storage.
Definition StmNvs.cpp:186
hf_nvs_err_t GetBlob(const char *key, void *buffer, size_t buffer_size, size_t *actual_size=nullptr) noexcept override
Retrieve binary data (blob).
Definition StmNvs.cpp:167
bool KeyExists(const char *key) noexcept override
Check if a key exists in storage.
Definition StmNvs.cpp:203
const char * GetDescription() const noexcept override
Get description of this storage implementation.
Definition StmNvs.cpp:220
size_t GetMaxValueSize() const noexcept override
Get maximum value size supported.
Definition StmNvs.cpp:228
hf_nvs_err_t SetU32(const char *key, hf_u32_t value) noexcept override
Store a 32-bit unsigned integer value.
Definition StmNvs.cpp:96
hf_nvs_err_t Deinitialize() noexcept override
Deinitialize the storage system and close the namespace.
Definition StmNvs.cpp:82
const hf_stm32_nvs_config_t & GetFlashConfig() const noexcept
Get the flash configuration.
Definition StmNvs.h:88
hf_nvs_err_t Initialize() noexcept override
Initialize the storage system and open the namespace.
Definition StmNvs.cpp:59
size_t GetFreeSpace() const noexcept
Get available free space in current sector (bytes)
Definition StmNvs.cpp:232
hf_nvs_err_t GetSize(const char *key, size_t &size) noexcept override
Get the size of a stored value.
Definition StmNvs.cpp:209
static hf_u32_t ComputeCrc32(const void *data, size_t length) noexcept
Simple CRC32 for entry validation.
Definition StmNvs.cpp:401
hf_nvs_err_t GetString(const char *key, char *buffer, size_t buffer_size, size_t *actual_size=nullptr) noexcept override
Retrieve a string value.
Definition StmNvs.cpp:135
static constexpr size_t kMaxEntries
Max cached entries.
Definition StmNvs.h:143
bool IsValidKey(const char *key) const noexcept
Validate a key string.
Definition StmNvs.cpp:270
hf_nvs_err_t LoadFromFlash() noexcept
Read entries from flash into RAM cache.
Definition StmNvs.cpp:348
hf_u32_t write_offset_
Current write position in flash.
Definition StmNvs.h:146
~StmNvs() noexcept override
Definition StmNvs.cpp:51
hf_nvs_err_t FlushToFlash() noexcept
Write all dirty entries to flash.
Definition StmNvs.cpp:276
int AddOrUpdateCache(const char *key, EntryType type, const void *data, size_t data_size) noexcept
Add or update entry in RAM cache.
Definition StmNvs.cpp:249
CacheEntry cache_[kMaxEntries]
RAM cache.
Definition StmNvs.h:144
RAM cache entry.
Definition StmNvs.h:114
bool dirty
Needs flash write.
Definition StmNvs.h:119
hf_u16_t data_length
Actual data length.
Definition StmNvs.h:118
char key[64]
Key string.
Definition StmNvs.h:115
hf_u8_t data[256]
Value data.
Definition StmNvs.h:117
EntryType type
Value type.
Definition StmNvs.h:116
bool erased
Marked for deletion.
Definition StmNvs.h:120
Flash-based NVS configuration for STM32.
Definition StmTypes.h:457