Read protection self reset
I'm trying to set read protection on STM32F412 to level 1 via JLink during initial flashing. I'm issuing next commands:
J-Link>w4 0x40023C08 0x08192A3B
Writing 08192A3B -> 40023C08
J-Link>w4 0x40023C08 0x4C5D6E7F
Writing 4C5D6E7F -> 40023C08
J-Link>mem32 0x40023C14 1
40023C14 = 0FFFAAEC
J-Link>w4 0x40023C14 0x0fff55ED
Writing 0FFF55ED -> 40023C14
J-Link>mem32 0x40023C14 1
40023C14 = 0FFF55ED
J-Link>r
Reset delay: 0 ms
Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.
Reset: Halt core after reset via DEMCR.VC_CORERESET.
Reset: Reset device via AIRCR.SYSRESETREQ.
J-Link>mem32 0x40023C14 1
40023C14 = 0FFFAAED But AFTER rest and BEFORE any user code can run it self-resets from 0x55 - LEVEL1 to AA - LEVEL0.
A few hours before this happened I was able to lock it from bootloader with next code:
FLASH_OBProgramInitTypeDef flash;
HAL_FLASH_OB_Unlock();
flash.RDPLevel = OB_RDP_LEVEL_1;
flash.WRPState = OB_WRPSTATE_ENABLE;
flash.WRPSector = OB_WRP_SECTOR_All;
HAL_FLASHEx_OBProgram(&flash);
HAL_FLASH_OB_Lock();After issuing this code I was not able connect to MCU via JLink. Next I run code to switch from Level 1 to Level 0:
FLASH_OBProgramInitTypeDef flash;
HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();
flash.RDPLevel = OB_RDP_LEVEL_0;
flash.WRPState = OB_WRPSTATE_DISABLE;
HAL_FLASHEx_OBProgram(&flash);After this I was able to connect to MCU via JLink BUT no flash erase was performed.
And now I can't set read protection nor with JLink nor with user code.
Am I doing something wrong or MCU just broke?
