2020-05-05 08:58 AM
Hi,
I save my configuration structure to flash memory. It work. Data is stored in flash. But after unplug ang plug power memory page is writen by 0xFF.
int eepromSaveConfig() {
uint32_t error;
uint64_t *configPtr;
uint32_t address;
FLASH_EraseInitTypeDef erase;
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
erase.Banks = FLASH_BANK_1;
erase.NbPages = 1;
erase.Page = 127;
erase.TypeErase = FLASH_TYPEERASE_PAGES;
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
if (HAL_FLASHEx_Erase(&erase, &error) != HAL_OK){
logging("Eeprom save error -1", DEBUG);
return -1;
}
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
configPtr = (uint64_t*) &controllerConfig;
address = 0x0803F800;
for (uint16_t i = 0; i < (sizeof(ControllerCfg_t) - 8); i += 8) {
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, address,
*configPtr))
return -2;
address += 8;
configPtr++;
}
HAL_FLASH_Lock();
logging("Eeprom save OK", DEBUG);
eepromReadConfig();
return 1;
}
int eepromReadConfig(){
uint8_t *configPtr;
configPtr = (uint8_t*) 0x0803F800;
memcpy( &controllerConfig, configPtr, sizeof(ControllerCfg_t));
return 1;
}
What could be the reason for this?
2020-05-05 10:01 AM
> Data is stored in flash
Do you verify it, i.e. read back immediately after writing and compare/check?
JW
2020-05-05 10:08 AM
Yes. I read config/data after save and compare it. I also check this by scroll memory
2020-05-05 12:51 PM
Can you try a page in the lower end of memory?
I have no experience with the G4, but they have this switchable buswidth/banking, can't this be related?
JW
2020-05-19 03:06 AM
I thought that I solved problem. But It came back. Main cause was
inaccurate soldering one VCC pin. Indication to this it was fine working at other mcu. I noticed only this problem caused by incorrect connection.
Thank you Jan for involvement.