hii @Alice_Yang , i just try to write the code this console
consider, i have to stored the VERSION and Temperature on the IAP FLASH Memory, and i displayed theVERSION and Temperature value with 1.8 inch TFT DISPLAY.
uint32_t DEMO_IAP_FLASH_SECTOR = 63;//sector number
uint32_t PAGE_SIZE_BYTES = 64;
#define SECTOR_SIZE_BYTES (1024)
static uint32_t s_IapFlashAddress = 64512;//=>1008(page_num)*64(page size)
static uint32_t s_IapFlashAddress1 = 64576;//=>1009(page_num)*64(page size)
int main()
{
TFT_Init();
home_screen();
while(1)
{
}
}
void home_screen()
{
static uint32_t s_PageBuf=78;
static uint32_t s_PageBuf1=190;
Erace(DEMO_IAP_FLASH_SECTOR);
Writing_Data _one(s_PageBuf);
Writing_data_two(s_PageBuf1);
//read part
uint32_t *read_ptr = (uint32_t *)(s_IapFlashAddress);
uint32_t Version_value = *read_ptr;
uint32_t *read_ptr1 = (uint32_t *)(s_IapFlashAddress1);
uint32_t Temp_value = *read_ptr;
print_tft(145, 2,Version_value , YELLOW_COLOR, BLUE_COLOR);
print_tft(145, 20,Temp_value , YELLOW_COLOR, BLUE_COLOR);
}
void Write_data_one(uint32_t s_PageBuf)
{
IAP_FLASH_WRITE(DEMO_IAP_FLASH_SECTOR,s_IapFlashAddress,s_PageBuf,PAGE_SIZE_BYTES);
}
void Write_data_two(uint32_t s_PageBuf1)
{
IAP_FLASH_WRITE(DEMO_IAP_FLASH_SECTOR,s_IapFlashAddress1,s_PageBuf1,PAGE_SIZE_BYTES);
}
void IAP_FLASH_WRITE(uint32_t DEMO_IAP_FLASH_SECTOR,uint32_t FlashAddress,uint32_t s_PageBuf,uint32_t PAGE_SIZE_BYTES)
{
// IAP_PrepareSectorForWriteone(DEMO_IAP_FLASH_SECTOR, DEMO_IAP_FLASH_SECTOR);
// IAP_EraseSectorone(DEMO_IAP_FLASH_SECTOR, DEMO_IAP_FLASH_SECTOR, SystemCoreClock);
IAP_PrepareSectorForWriteone(DEMO_IAP_FLASH_SECTOR, DEMO_IAP_FLASH_SECTOR);
IAP_CopyRamToFlashone(FlashAddress, &s_PageBuf,PAGE_SIZE_BYTES, SystemCoreClock);
}
void Erace(uint32_t DEMO_IAP_FLASH_SECTOR)
{
IAP_PrepareSectorForWriteone(DEMO_IAP_FLASH_SECTOR, DEMO_IAP_FLASH_SECTOR);
IAP_EraseSectorone(DEMO_IAP_FLASH_SECTOR, DEMO_IAP_FLASH_SECTOR, SystemCoreClock);
}
void IAP_PrepareSectorForWriteone(uint32_t startSector, uint32_t endSector)
{
uint32_t command[5] = {0x00U};
uint32_t result[5] = {0x00U};
command[0] = (uint32_t)kIapCmd_IAP_PrepareSectorforWrite;//50u
command[1] = startSector;
command[2] = endSector;
iap_entry(command, result);
}
void IAP_EraseSectorone(uint32_t startSector, uint32_t endSector, uint32_t systemCoreClock)
{
uint32_t command[5] = {0x00U};
uint32_t result[5] = {0x00U};
command[0] = (uint32_t)kIapCmd_IAP_EraseSector;//52u
command[1] = startSector;
command[2] = endSector;
// command[3] = systemCoreClock / HZ_TO_KHZ_DIV;
iap_entry(command, result);
}
void IAP_CopyRamToFlashone(uint32_t dstAddr, uint32_t *srcAddr, uint32_t numOfBytes, uint32_t systemCoreClock)
{
uint32_t command[5] = {0x00U};
uint32_t result[5] = {0x00U};
command[0] = (uint32_t)kIapCmd_IAP_CopyRamToFlash;//51u
command[1] = dstAddr;
command[2] = (uint32_t)srcAddr;
command[3] = numOfBytes;
// command[4] = systemCoreClock / HZ_TO_KHZ_DIV;
iap_entry(command, result);
}
Whenever I write the above program, the FLASH MEMORY writes and reads the data properly.
However, whenever I hide the #Erace(DEMO_IAP_FLASH_SECTOR); function, the first data is not read properly, but the second data is read well. Why?
explain these below two function if i hide why first data should not printed.
IAP_PrepareSectorForWriteone(DEMO_IAP_FLASH_SECTOR, DEMO_IAP_FLASH_SECTOR);
IAP_EraseSectorone(DEMO_IAP_FLASH_SECTOR, DEMO_IAP_FLASH_SECTOR, SystemCoreClock);