2025-03-06 3:21 AM
Hello,
So, i have created a small project in which the diagnostic information was saved in the internal flash of STM32F429ZET6 at the time of a crash. So, to test this project i have triggered usage-fault exception in an infinite loop by dividing a number via 0.
In the exception handler, i'm capturing and storing the diagnostic information in sector 0 of internal flash (I have modified the linker script to reserve this area, and configured sector 0 as non-executable area via MPU). The below is the logic i am using to store the diagnostic info.
FLASH_OBProgramInitTypeDef OBInit;
HAL_FLASH_OB_Unlock();
OBInit.OptionType = OPTIONBYTE_WRP;
OBInit.WRPSector = OB_WRP_SECTOR_0;
OBInit.WRPState = OB_WRPSTATE_DISABLE;
HAL_FLASHEx_OBProgram(&OBInit);
HAL_FLASH_OB_Launch();
HAL_FLASH_OB_Lock();
HAL_FLASH_Unlock();
HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, list_ad, p_gnl[i]);
HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, diag_ad, p_gnl[i])
HAL_FLASH_Lock();
HAL_FLASH_OB_Unlock();
OBInit.OptionType = OPTIONBYTE_WRP;
OBInit.WRPState = OB_WRPSTATE_ENABLE;
OBInit.WRPSector = OB_WRP_SECTOR_0;
HAL_FLASHEx_OBProgram(&OBInit);
HAL_FLASH_OB_Launch();
HAL_FLASH_OB_Lock();
And now, after i flash this code, i could not flash other code, this is the error i'm getting :
Error: failed to erase memory
Error: failed to erase memory
Encountered Error when opening C:\ST\STM32CubeIDE_1.17.0\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_2.2.0.202409170845\tools\bin\STM32_Programmer_CLI.exe
Error in STM32CubeProgrammer
Shutting down...
Exit.
Please help me fix this issue.
Thanks in advance.
2025-03-06 5:56 AM
Dont do stuff with flash in the first 1s of a program running or the debugger will have a hard time maintaining a connection.
Hold BOOT0 high during reset to boot in the bootloader and erase the chip to recover.