cancel
Showing results for 
Search instead for 
Did you mean: 

flash readback protection

stenasc
Senior
Posted on November 12, 2013 at 17:36

Hi Forum,

I need to implement is flash readback protection. I have a couple of questions....

1...Can I enable this on the STM32f051in software or does it have to be set in the programming tools? I'm using Keil uVision. It would be preferable if I could set this in software as we will be shipping a lot of these units and if we only had to program the binary, it would make production easier and it would stop any units getting out without protection.

2...Once Flash Readback protection is enabled, can I still use the uVision bugger. Is the board bricked as far as using the debugger on it again, or can I reflash again.

3...How can I verify if protection is enabled. Will uVision display this?

Apologies for these questions, but I want to make sure that this stage is correct before we go to production.

Bob Carter

7 REPLIES 7
Posted on November 12, 2013 at 18:39

The debugger will be useless, purposefully so. You can run stuff from RAM if that helps. You can mass erase the part, either from your own app, or via the System Loader and USART. (Speaking from an F1/F2/F4 perspective, I'm not using the F0).

Your own code should be able read, and output FLASH content if you choose. ie if you coded your own monitor/diagnostic app. ROP is designed to limit exfiltration via SWD/JTAG or Serial/System Loader.

You shouldn't even need external tools, put code paths in your own application to test the ROP state, and if not set, set it and reset. ie First boot after programming it locks down the device. If you're using the System Loader to program you could use that too.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
stenasc
Senior
Posted on November 13, 2013 at 11:06

Hi Clive,

Thanks for that. There is a utility s/w that we can use to program the option bytes (works through jtag and fine for development purposes), but for bulk programming this is no use. We need to set these option bytes in s/w, so when board boots, these are already set. Is there some source example available that I can add to the project? I had a quick read of the docs, but we are under severe pressure to meet our production slot so any examples would be great.

Many Thanks

Bob

Posted on November 14, 2013 at 02:21

STM32F0xx_StdPeriph_Lib_V1.1.0\Project\STM32F0xx_StdPeriph_Examples\FLASH\Write_Protection\main.c

STM32F0xx_AN4065_FW_V1.0.0\Project\STM32F0xx_IAP\src\flash_if.c This is a blind stab at what the F0 would need, perhaps you can donate some gear

void SetRDP(void)
{
FLASH_Status FLASHStatus = FLASH_COMPLETE;
/* Unlock the Flash Program Erase controller */
FLASH_Unlock();
FLASH_OB_Unlock();
/* Clear all FLASH flags */
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR | FLASH_FLAG_BSY);
if (!FLASH_OB_GetRDP())
{
FLASH_Status = FLASH_OB_RDPConfig(OB_RDP_Level_1); // Locks Chip (Lvl 2 Toasts)
if (FLASH_Status == FLASH_COMPLETE)
{
/* Generate System Reset to load the new option byte values */
FLASH_OB_Launch();
}
} // 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..
stenasc
Senior
Posted on November 14, 2013 at 10:38

Cheers Clive. Check email.

stenasc
Senior
Posted on November 18, 2013 at 01:19

Hi Clive,

It had to happen!! Your code worked...very well indeed !! Yep everyone, Clive does know his stuff. Now I cannot reprogram the board. Is there anyway of getting back to being able to program the unit again? I'm using ULink2 and uVision4?

Bob

Posted on November 18, 2013 at 02:14

There are two techniques I've used, one is via the System Loader (USART1) and issuing the commands to Mass Erase, or change the RDP/ROP, the other is to implement similar to nuke the part via a specific internal command sequence.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jpeacock2399
Associate II
Posted on November 18, 2013 at 15:45

If you accidently set the read protection level to 2 then you can't recover.  JTAG and bootloader are disabled.  If you can't get the JTAG to connect that's the problem.

  Jack Peacock