diff --git a/libraries/Desktop/support/DataFlash.cpp b/libraries/Desktop/support/DataFlash.cpp index 798b8e9e1b..6cc7786f01 100644 --- a/libraries/Desktop/support/DataFlash.cpp +++ b/libraries/Desktop/support/DataFlash.cpp @@ -16,7 +16,7 @@ static int flash_fd; static uint8_t buffer[2][DF_PAGE_SIZE]; -#define OVERWRITE_DATA 0 // 0: When reach the end page stop, 1: Start overwritten from page 1 +#define OVERWRITE_DATA 1 // 0: When reach the end page stop, 1: Start overwritten from page 1 // Constructors //////////////////////////////////////////////////////////////// DataFlash_Class::DataFlash_Class() @@ -120,7 +120,7 @@ void DataFlash_Class::ChipErase () void DataFlash_Class::StartWrite(int16_t PageAdr) { df_BufferNum = 1; - df_BufferIdx = 0; + df_BufferIdx = 4; df_PageAdr = PageAdr; df_Stop_Write = 0; @@ -137,12 +137,12 @@ void DataFlash_Class::FinishWrite(void) df_PageAdr++; if (OVERWRITE_DATA==1) { - if (df_PageAdr>=4096) // If we reach the end of the memory, start from the begining + if (df_PageAdr>=DF_LAST_PAGE) // If we reach the end of the memory, start from the begining df_PageAdr = 1; } else { - if (df_PageAdr>=4096) // If we reach the end of the memory, stop here + if (df_PageAdr>=DF_LAST_PAGE) // If we reach the end of the memory, stop here df_Stop_Write=1; } @@ -167,17 +167,17 @@ void DataFlash_Class::WriteByte(byte data) df_BufferIdx++; if (df_BufferIdx >= df_PageSize) // End of buffer? { - df_BufferIdx=0; + df_BufferIdx=4; BufferToPage(df_BufferNum,df_PageAdr,0); // Write Buffer to memory, NO WAIT df_PageAdr++; if (OVERWRITE_DATA==1) { - if (df_PageAdr>=4096) // If we reach the end of the memory, start from the begining + if (df_PageAdr>=DF_LAST_PAGE) // If we reach the end of the memory, start from the begining df_PageAdr = 1; } else { - if (df_PageAdr>=4096) // If we reach the end of the memory, stop here + if (df_PageAdr>=DF_LAST_PAGE) // If we reach the end of the memory, stop here df_Stop_Write=1; } @@ -218,7 +218,7 @@ int16_t DataFlash_Class::GetPage() void DataFlash_Class::StartRead(int16_t PageAdr) { df_Read_BufferNum=1; - df_Read_BufferIdx=0; + df_Read_BufferIdx=4; df_Read_PageAdr=PageAdr; WaitReady(); PageToBuffer(df_Read_BufferNum,df_Read_PageAdr); // Write Memory page to buffer @@ -234,10 +234,10 @@ byte DataFlash_Class::ReadByte() df_Read_BufferIdx++; if (df_Read_BufferIdx >= df_PageSize) // End of buffer? { - df_Read_BufferIdx=0; + df_Read_BufferIdx=4; PageToBuffer(df_Read_BufferNum,df_Read_PageAdr); // Write memory page to Buffer df_Read_PageAdr++; - if (df_Read_PageAdr>=4096) // If we reach the end of the memory, start from the begining + if (df_Read_PageAdr>=DF_LAST_PAGE) // If we reach the end of the memory, start from the begining { df_Read_PageAdr = 0; df_Read_END = true;