Basic

Dependencies:   MQTT

Committer:
lwtroach
Date:
Wed Apr 24 06:13:22 2019 +0000
Branch:
Flash_Exam
Revision:
9:4731ae675a01
Parent:
7:e556528beeba
When programming the data into flash, the size to API of IAP must be the correct size of data itself, or the algorithm will save the next data after it.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lwtroach 7:e556528beeba 1 #include "LPG_FlashIAP.h"
lwtroach 2:e90526c0bcbe 2
lwtroach 2:e90526c0bcbe 3 FlashIAP flash;
lwtroach 2:e90526c0bcbe 4
lwtroach 2:e90526c0bcbe 5 void LPG_FlashIAP_InitIAP()
lwtroach 2:e90526c0bcbe 6 {
lwtroach 2:e90526c0bcbe 7 flash.init();
lwtroach 2:e90526c0bcbe 8 }
lwtroach 2:e90526c0bcbe 9
lwtroach 9:4731ae675a01 10 void LPG_FlashIAP_DeInitIAP()
lwtroach 9:4731ae675a01 11 {
lwtroach 9:4731ae675a01 12 flash.deinit();
lwtroach 9:4731ae675a01 13 }
lwtroach 2:e90526c0bcbe 14
lwtroach 7:e556528beeba 15 void LPG_FlashIAP_WriteToFlash(char* buffer, uint32_t addr,RawSerial DebugPort)
lwtroach 2:e90526c0bcbe 16 {
lwtroach 9:4731ae675a01 17 /* 目前erase成功,但寫入不會在同一位址上會連續 */
lwtroach 3:cb954c31709f 18 int sector = flash.get_sector_size(addr);
lwtroach 7:e556528beeba 19 int eraseResult = flash.erase(addr,sector);
lwtroach 9:4731ae675a01 20 //DebugPort.printf("eraseResult : %s\r\n",((eraseResult==0)?"Sucess":"Fail"));
lwtroach 9:4731ae675a01 21 DebugPort.puts("eraseResult:");
lwtroach 9:4731ae675a01 22 DebugPort.puts(((eraseResult==0)?"Sucess":"Fail"));
lwtroach 9:4731ae675a01 23 DebugPort.puts("\r\n");
lwtroach 9:4731ae675a01 24 int programResult = flash.program(buffer,addr,sizeof(char)*7);
lwtroach 9:4731ae675a01 25 //DebugPort.printf("programResult : %s\r\n",((programResult==0)?"Sucess":"Fail"));
lwtroach 9:4731ae675a01 26 DebugPort.puts("programResult:");
lwtroach 9:4731ae675a01 27 DebugPort.puts(((programResult==0)?"Sucess":"Fail"));
lwtroach 9:4731ae675a01 28 DebugPort.puts("\r\n");
lwtroach 9:4731ae675a01 29 //flash.deinit();
lwtroach 2:e90526c0bcbe 30 }
lwtroach 2:e90526c0bcbe 31
lwtroach 3:cb954c31709f 32 void LPG_FlashIAP_ReadFromFlash(char* buffer,uint32_t addr)
lwtroach 2:e90526c0bcbe 33 {
lwtroach 3:cb954c31709f 34 flash.read(buffer,addr,sizeof(uint32_t));
lwtroach 2:e90526c0bcbe 35 }