Wen-ting Lo / Mbed OS STM32F303RE_LPG

Dependencies:   MQTT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LPG_FlashIAP.cpp Source File

LPG_FlashIAP.cpp

00001 #include "LPG_FlashIAP.h"
00002 
00003 FlashIAP flash;
00004 
00005 void LPG_FlashIAP_InitIAP()
00006 {
00007     flash.init();
00008 }
00009 
00010 void LPG_FlashIAP_DeInitIAP()
00011 {
00012     flash.deinit();
00013 }
00014 
00015 void LPG_FlashIAP_WriteToFlash(char* buffer, uint32_t addr,RawSerial DebugPort)
00016 {
00017     /* 目前erase成功,但寫入不會在同一位址上會連續 */
00018     int sector = flash.get_sector_size(addr);
00019     int eraseResult = flash.erase(addr,sector);
00020     //DebugPort.printf("eraseResult : %s\r\n",((eraseResult==0)?"Sucess":"Fail"));
00021     DebugPort.puts("eraseResult:");
00022     DebugPort.puts(((eraseResult==0)?"Sucess":"Fail"));
00023     DebugPort.puts("\r\n");
00024     int programResult = flash.program(buffer,addr,sizeof(char)*7);
00025     //DebugPort.printf("programResult : %s\r\n",((programResult==0)?"Sucess":"Fail"));
00026     DebugPort.puts("programResult:");
00027     DebugPort.puts(((programResult==0)?"Sucess":"Fail"));
00028     DebugPort.puts("\r\n");
00029     //flash.deinit();
00030 }
00031 
00032 void LPG_FlashIAP_ReadFromFlash(char* buffer,uint32_t addr)
00033 {
00034     flash.read(buffer,addr,sizeof(uint32_t));
00035 }