2025-03-04 2:40 AM
Hi,
I have a problem with FLASH. Key point of mine application program is a moment that saves 128B setting struct with magic-key pair (0xA55A and 0x5AA5) in the being and the end of a setting string. After power cycle, I do browse strings (+ integrity) and select the entry with the highest "index value". I'm using 2 pages (39-40), erase page mechanism, i.e. method similar to the EEPROM emulation SW, but much more space efficient. Naturally I'm using BLE and HW semaphore mechanism towards CPU2. Otherwise the CPU2 was failing over by breaking a BLE connection, as expected though. I'm using a flash_driver.c from ST example.
Problem I do have is that after power-up/reset, the first 8B of entry during programing fails. Each next attempt is succesfull although. The same with erease operation. I traced down the issue to the point of returing error (160) during HAL_Erase operation. I even noticed that in the function FLASH_WaitForLastOperation there is a walkaround implemented, but doesn't seems to work.
If there something I should focus on and will accelerate mine issue sorting, please let me know.
Thank
Marcin
}
}
/* Check FLASH operation error flags */
error = FLASH->SR;
/* Check FLASH End of Operation flag */
if ((error & FLASH_FLAG_EOP) != 0U)
{
/* Clear FLASH End of Operation pending bit */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
}
/* Workaround for BZ 70309 :
- OPTVERR is always set at power-up due to failure of engi bytes checking
- FLASH_WaitForLastOperation() is called at the beginning of erase or program
operations, so the bit will be clear when performing first operation */
if ((error & FLASH_FLAG_OPTVERR) != 0U)
{
/* Clear FLASH OPTVERR bit */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
/* Clear OPTVERR bit in "error" variable to not treat it as error */
error &= ~FLASH_FLAG_OPTVERR;
}
/* Now update error variable to only error value */
error &= FLASH_FLAG_SR_ERRORS;
/* clear error flags */
__HAL_FLASH_CLEAR_FLAG(error);