Trouble programming flash with HAL_FLASH_Program
I have troubles writing succesfully to flash on a STM32G07 chip.
The application is similar to this:
uint64_t data;
HAL_FLASH_Unlock();
HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, addr, data);
HAL_FLASH_Lock();
I started getting hardfault in lock because of error in programming. I found out that this was related to timeout on the wait for operation to finish inside program function. So I added a check that program returning HAL_OK before calling lock . But this just moved the problem.
The behavious is very strange.
I can see that PGAERR and PGSERR in the FLASH SR register are being set.
My data is aligned at a 64-bit boundry I have added check that both data and the address i program to will have addr & 0x07 == 0.
I suspect some other interrupt could interefere in some way. But adding __disable_irq(); does not help.
Data is programmed like 25-50% of the times rest I simply get no data programmed.
