Wen-ting Lo
/
STM32F303RE_LPG
Basic
LPG_FlashIAP/LPG_FlashIAP.cpp@3:cb954c31709f, 2019-04-23 (annotated)
- Committer:
- lwtroach
- Date:
- Tue Apr 23 05:02:48 2019 +0000
- Revision:
- 3:cb954c31709f
- Parent:
- 2:e90526c0bcbe
Still Flash readable
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lwtroach | 2:e90526c0bcbe | 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 | 2:e90526c0bcbe | 10 | |
lwtroach | 2:e90526c0bcbe | 11 | void LPG_FlashIAP_WriteToFlash(char* buffer, uint32_t addr) |
lwtroach | 2:e90526c0bcbe | 12 | { |
lwtroach | 3:cb954c31709f | 13 | /* 目前無法erase成功,手動erase後可以寫入 */ |
lwtroach | 3:cb954c31709f | 14 | int sector = flash.get_sector_size(addr); |
lwtroach | 3:cb954c31709f | 15 | int page = flash.get_page_size(); |
lwtroach | 3:cb954c31709f | 16 | |
lwtroach | 3:cb954c31709f | 17 | flash.erase(addr,page); |
lwtroach | 2:e90526c0bcbe | 18 | flash.program(buffer,addr,sector); |
lwtroach | 2:e90526c0bcbe | 19 | flash.deinit(); |
lwtroach | 2:e90526c0bcbe | 20 | } |
lwtroach | 2:e90526c0bcbe | 21 | |
lwtroach | 3:cb954c31709f | 22 | void LPG_FlashIAP_ReadFromFlash(char* buffer,uint32_t addr) |
lwtroach | 2:e90526c0bcbe | 23 | { |
lwtroach | 3:cb954c31709f | 24 | flash.read(buffer,addr,sizeof(uint32_t)); |
lwtroach | 2:e90526c0bcbe | 25 | } |