STM32H75x - How to erase properly with removal of secure area?
I have some code that removes a "secure area" on STM32H75x by so called "regression" from RDP level 1 to level 0, which causes full erase.
(Actually this code is based on example very kindly provided by ST support)
void EraseAll(void)
{
uint32_t flashUserOpt;
printf("Launching erase all process. Requires RDPL1 already set\n");
__HAL_FLASH_CLEAR_FLAG_BANK1(FLASH_FLAG_ALL_ERRORS_BANK1);
HAL_FLASH_OB_Unlock();
FLASH->OPTSR_PRG = 0x13BEAAF0; /* RDP level 0 */
FLASH->PRAR_PRG1 = 0x80000FFF; /* No PCROP */
FLASH->SCAR_PRG1 = 0x80000FFF; /* No secure area */
FLASH->WPSN_PRG1 = 0x000000FF; /* No WRP */
OBLaunchWithCheck();
HAL_FLASH_OB_Lock();
}
void OBLaunchWithCheck(void)
{
HAL_StatusTypeDef error;
if ((error=HAL_FLASH_OB_Launch()) != HAL_OK)
{
printf("HAL_FLASH_OB_Launch failed. HAL_ERROR: %d Error code : %8.8x ...\r\n", error, pFlash.ErrorCode);
printf("Flash->SR1: 0x%8.8x\r\n", FLASH->SR1);
}
}The erase usually (*) works, but after a power cycle ST-LINK utility cannot access the chip, says "remove protection".
In this state, the option bytes dialog shows SECURITY bit set.
I then clear the SECURITY bit, save option bytes, then ST-LINK utility regains full access to the chip, can read and program etc.
My question is, can this reset of SECURITY bit be skipped?
In the snippet above, line 9, the value written into FLASH_OPTSR_PRG has SECURITY bit (21) set.
Should it be so or it is error?
Already bricked all my stock of cheap H75x boards, waiting for a new order.
So sorry, I cannot try and test it by myself, until more boards arrive.
@Jocelyn RICARD
By the way - my test boards have H750 revision Y. Has anything relevant changed/improved in revision V?
Thanks in advance,
-- Pavel A.
(*) When the board becomes bricked, the ST-LINK utility detects the chip correctly - but cannot read neither flash nor option bytes; then it disconnects and cannot connect again without a power cycle. It looks like secure area and/or RDP1 still are active, but the code in the secure area has been erased (no signs of this code running).
