有網友問到 : [ 請問LPC1114 Flash如何當eeprom來使用? 有範例程式可提供嗎? ]
上回在 這篇 LPC1114 Flash如何當eeprom來使用? (IAP) 的回答僅回答前面一個問號.
剛好最近工作上也用到,順道做個介紹與分享問題後面段的 有範例程式可提供嗎?.
這個實驗中,會將wrtie_data[ ] 中的資料寫入flash 0x00001000 起的flash中.
#define APP_START_ADDR 0x00001000UL
static uint8_t write_data[256] __attribute__ ((aligned(4)))={
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x00,
0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x00,0x01,
0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x00,0x01,0x02,
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x00,
0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x00,0x01,
0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x00,0x01,0x02,
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x00,
0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x00,0x01,
0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x00,0x01,0x02,
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x00,
0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x00,0x01,
0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x00,0x01,0x02,
};
這份範例程式是由 AN10995 修改.
在下圖1 ,程式圈起處會見到
u32IAP_EraseSectors(APP_START_SECTOR, APP_END_SECTOR)
這段程式執行後,IAP command 會將 這些sector 都清除 0xFF.
所以可以看到下面Memory 0x00001000起都變為 FFFFFFF....
圖1 |
接著 u32BootLoader_ProgramFlash(&write_data[0], 256 ) 會將 write_data中的 256 Bytes都寫入Flash中.
圖2 |
Memory中 0x000010000 起的資料都已經改變了.
範例就這麼簡單.
再強調
1. FLASH 清除的次數約為10000次.
2.清除必須以Sector為單位, LPC111x系列的Sector為4096 Bytes.
如果經常需要更新其資料,建議要多些機制來延長Flash壽命,
可參考
AN11008 Flash based non-volatile storage V1 (Jan 5, 2011) with software (Oct 5, 2010)
裡面有更多對於Flash programming以及上述兩個注意項目的更多說明.
參考範例請至此下載 Download
Hi 版主 謝謝您無私分享 但是 這個連結已經失去作用
回覆刪除=>>>>裡面有更多對於Flash programming以及上述兩個注意項目的更多說明.
可以重新連結嗎?謝謝
link跳過去後看一下 application note page 找看看
刪除