Wen-ting Lo
/
STM32F303RE_LPG
Basic
Revision 9:4731ae675a01, committed 2019-04-24
- Comitter:
- lwtroach
- Date:
- Wed Apr 24 06:13:22 2019 +0000
- Branch:
- Flash_Exam
- Parent:
- 8:92f9f1fb11e2
- Commit message:
- 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.
Changed in this revision
--- a/LPG_FlashIAP/LPG_FlashIAP.cpp Wed Apr 24 05:10:36 2019 +0000 +++ b/LPG_FlashIAP/LPG_FlashIAP.cpp Wed Apr 24 06:13:22 2019 +0000 @@ -7,16 +7,26 @@ flash.init(); } +void LPG_FlashIAP_DeInitIAP() +{ + flash.deinit(); +} void LPG_FlashIAP_WriteToFlash(char* buffer, uint32_t addr,RawSerial DebugPort) { - /* 目前無法erase成功,手動erase後可以寫入 */ + /* 目前erase成功,但寫入不會在同一位址上會連續 */ int sector = flash.get_sector_size(addr); int eraseResult = flash.erase(addr,sector); - DebugPort.printf("eraseResult : %s\r\n",((eraseResult==0)?"Sucess":"Fail")); - int programResult = flash.program(buffer,addr,sector); - DebugPort.printf("programResult : %s\r\n",((programResult==0)?"Sucess":"Fail")); - flash.deinit(); + //DebugPort.printf("eraseResult : %s\r\n",((eraseResult==0)?"Sucess":"Fail")); + DebugPort.puts("eraseResult:"); + DebugPort.puts(((eraseResult==0)?"Sucess":"Fail")); + DebugPort.puts("\r\n"); + int programResult = flash.program(buffer,addr,sizeof(char)*7); + //DebugPort.printf("programResult : %s\r\n",((programResult==0)?"Sucess":"Fail")); + DebugPort.puts("programResult:"); + DebugPort.puts(((programResult==0)?"Sucess":"Fail")); + DebugPort.puts("\r\n"); + //flash.deinit(); } void LPG_FlashIAP_ReadFromFlash(char* buffer,uint32_t addr)
--- a/LPG_FlashIAP/LPG_FlashIAP.h Wed Apr 24 05:10:36 2019 +0000 +++ b/LPG_FlashIAP/LPG_FlashIAP.h Wed Apr 24 06:13:22 2019 +0000 @@ -2,6 +2,7 @@ #include <FlashIAP.h> void LPG_FlashIAP_InitIAP(void); +void LPG_FlashIAP_DeInitIAP(void); void LPG_FlashIAP_ReadFromFlash(char* buffer,uint32_t addr); void LPG_FlashIAP_WriteToFlash(char* buffer, uint32_t addr,RawSerial DebugPort);
--- a/main.cpp Wed Apr 24 05:10:36 2019 +0000 +++ b/main.cpp Wed Apr 24 06:13:22 2019 +0000 @@ -67,19 +67,32 @@ int count = 0; int index = 0; char buMat[100] = {0}; - char* buf = "TEST_1"; + + //LPG_FlashIAP_InitIAP(); while (true) { + char* buf; + if(index==0) buf = "TEST_0"; + else if(index==1) buf = "TEST_1"; + else if(index==2) buf = "TEST_2"; + else if(index==3) buf = "TEST_3"; + else if(index==4) buf = "TEST_4"; + else index = -1; + DebugPort.puts(buf); + DebugPort.puts("\r\n"); LPG_FlashIAP_InitIAP(); + LPG_FlashIAP_WriteToFlash(&buf[0],0x0807C000,DebugPort); + LPG_FlashIAP_DeInitIAP(); // Blink LED and wait 0.5 seconds Led_1 = !Led_1; Led_2 = !Led_2; Led_3 = !Led_3; wait_ms(2000); //ATCmdPort.puts("ATI\r\n"); - LPG_FlashIAP_WriteToFlash(&buf[0],0x0807C000,DebugPort); + //LPG_FlashIAP_WriteToFlash(&buf[0],0x0807C000,DebugPort); /*LPG_FlashIAP_ReadFromFlash(&buMat[0],0x0800BF00); DebugPort.puts(buMat); DebugPort.puts("\r\n");*/ + index++; if ((0 == count) || (PRINT_AFTER_N_LOOPS == count)) { // Following the main thread wait, report on the current system status sys_state.report_state();