Skip to content

Commit

Permalink
add Clear method
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyLadanov committed May 25, 2024
1 parent 565ca87 commit 24d62af
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Components/NVS_Lib/Inc/NVS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class NVS

uint32_t GetAvaliableSpaceInBlocks(void);

void Clear(void);

private:

uint32_t GetPageFreeSpace(void);
Expand Down
14 changes: 14 additions & 0 deletions Components/NVS_Lib/Src/NVS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ void NVS::Init(FlashDesc_t *flash_desc, uint32_t len)
{

int32_t LastNumTemp = -1;

WriteNumber = 0;

if (flash_desc)
{
Expand Down Expand Up @@ -405,4 +407,16 @@ uint32_t NVS::GetAvaliableSpaceInBytes(void)
uint32_t NVS::GetAvaliableSpaceInBlocks(void)
{
return GetAvaliableSpaceInBytes() / NVS_Cell::MEMORY_CELL_SIZE;
}



void NVS::Clear(void)
{
for (uint32_t i = 0; i < FlashDescriptorsSize; i++)
{
FlashInterface.PageErase(FlashDescriptors[i].MemPtr, FlashDescriptors[i].Sector, FlashDescriptors[i].Size);
}

Init(FlashDescriptors, FlashDescriptorsSize);
}
2 changes: 2 additions & 0 deletions Core/Src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ int main(void)
Check(CheckStorage);
printf("\r\n\r\n");

// CheckStorage.Clear();
// Check(CheckStorage);
printf("End");
return 0;
}

0 comments on commit 24d62af

Please sign in to comment.