stm32 - Flash is corrupting after a couple of immediate resets -
i want store device id inside flash permanently. using internal flash of stm32. can write&read flash in stm32. after writing value flash, , switch off , can read without problem. problem coming couple of different scenario such : when resetting mcu immidieatly after first reset, data inside flash becoming 0. other scenario data disappearing after while (not tested , can not entire conditions) idea flash problem ?
ide : keil mdk uvision 4
write function:
void eeprom_write(uint32_t data) { /* porgram flash bank1 ********************************************************/ flash_unlockbank1(); /* unlock flash bank1 program erase controller */ nbrofpage = (bank1_write_end_addr - bank1_write_start_addr) / flash_page_size; /* define number of page erased */ flash_clearflag(flash_flag_eop | flash_flag_pgerr | flash_flag_wrprterr); /* clear pending flags */ for(erasecounter = 0; (erasecounter < nbrofpage) && (flashstatus == flash_complete); erasecounter++) /* erase flash pages */ { flashstatus = flash_erasepage(bank1_write_start_addr + (flash_page_size * erasecounter)); } address = bank1_write_start_addr; /* program flash bank1 */ while((address < bank1_write_end_addr) && (flashstatus == flash_complete)) { flashstatus = flash_programword(address, data); address = address + 4; } flash_lockbank1(); address = bank1_write_start_addr; /* check corectness of written data */ while((address < bank1_write_end_addr) && (memoryprogramstatus != failed)) { if((*(__io uint32_t*) address) != data) { memoryprogramstatus = failed; } address += 4; } }
read function
uint32_t eeprom_read(void) { uint32_t readvalue; flash_unlockbank1(); address = bank1_write_start_addr; readvalue = (*(__io uint32_t*) address); flash_lockbank1(); return readvalue; }
fortunately, have solved issue explained here: after initialization of peripherals inside main function, calling eeprom_write() function based on conditions. once have restarted entire system, flash writing operation broken external switch on-off demand. therefore, have found couple of different solution instead of calling eeprom_write() @ beginning such calling function when low power interrupt comes. more details posted on blog : http://www.ozturkibrahim.com/tr/eeprom-emulation-on-stm32/
Comments
Post a Comment