cancel
Showing results for 
Search instead for 
Did you mean: 

How to properly unlock a STM32F4xx device...

jeanpierre
Associate II
Posted on December 02, 2014 at 19:30

Hello ST gurus!

May I inquire on the right sequence of steps to unlock a device (level 1 lock) to unlocked (level 0)?

The STM library reveals the following sequence is required to lock:

FLASH_OB_Unlock();                        // Take the STM32F4xx from unlocked (level 0) to reversible lock (level 1)

FLASH_OB_RDPConfig(OB_RDP_Level_1);

FLASH_OB_Launch();

I assume the following code would unlock but it doesn't work!

FLASH_OB_Unlock();                        // Take the STM32F4xx from reversible lock (level 1) to unlocked (level 0) -> Does not work!

FLASH_OB_RDPConfig(OB_RDP_Level_0);

FLASH_OB_Launch();

When I run the unlock code below, the chip crashes (understandable as its Flash & memory is wiped) and the chip becomes invisible via JTAG.

The only way to revert the STM32 back to level 0 is by booting the device in DFU mode by shorting boot pins and lanuching the DFUSE utility to unprotect the device.

Can unlocking be done in code?  If DFUSE can do it I assume there is a magic sequence that can unlock a device by code running in Flash?

Thank you!!

   Jean-Pierre

#locking-unlocking-protection
11 REPLIES 11
Posted on December 03, 2014 at 02:01

Really tricky stuff!  Is there a sample app that shows how to correctly lock & unlock.

Yes, unfortunately such things tend not to fall out of trees, people have either invested a lot of resources to build/understand them, or wear darker hats and move in different circles. I suspect it would take several hours to knock out something serviceable.

sourcer32@gmail.com
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Danish1
Lead II
Posted on December 03, 2014 at 11:01

Your Q1: Will it run differently in Flash or RAM?

Pay attention at the back there! Flash gets erased during the process. So if you try to run it from FLASH then most-likely it will never complete cleanly e.g. it might miss off the FLASH_OB_Lock() and instead head off into the hills leaving your stm32 in an unknown state.

Q2: Is my code similar to Clives?

Yes largely. I log some diagnostic information but that's mainly so I know how far it's completed.

And also between the Unlock and the RDPConfig I do:

    FLASH_OB_WRPConfig(OB_WRP_Sector_All, DISABLE);

Hope this helps,

Danish