cancel
Showing results for 
Search instead for 
Did you mean: 

Programming STM32 Option bytes : When and where ?

jerome2
Associate II
Posted on March 06, 2013 at 15:00

Dear All

I'm using IAR EWARM to compile my bootloader and application.

I'm developing on STM32L151 64K version.

My bootloader is located in pages 0-63, sectors 0-3, I would like to protect this area against flash write, just to be sure my bootloader will never been written spuriously.

I understand I have to write the WRP byte of option bytes to enable this protection.

What I do not understand is where and when I should write these option bytes ?

1) Should these option bytes should be included into the hex or bin file ? So I'm sure the protection will be active once the chip burned with the hex or bin file ?

If so, how can I configure IAR to setup these option bytes ?

2) In my bootloader code ? Should I programmatically write the option bytes in my bootloader code ? I tried, but it seems as soon as the option byte is written, the chip resets and then an infinite loop occurs.

3) ?

I agree I'm missing the basics about the options bytes programming, any help would be greatly appreciated !

Thanks

Jerome

#iar-ewarm #option-bytes #stm32-flash-bootloader
7 REPLIES 7
Posted on March 06, 2013 at 18:04

Assuming you don't use IAR as your production program Option 2 is quite appealing.

Option 3 would probably be to use the built in System Loader and a production app which pushes firmware and options at the device/product in a test fixture via the serial port.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jerome2
Associate II
Posted on March 07, 2013 at 08:53

Thanks for your reply Clive.

Anybody else on this forum using a flash protection for a boot loader !? 

jerome2
Associate II
Posted on March 08, 2013 at 17:49

Nobody here programming Option bytes on STM32 ?

Any answer would be greatly appreciated !

flyer31
Senior
Posted on March 12, 2013 at 07:48

Hi Jerome,

I also would be interested very much to do this during the ''normal chip programming'', typically using the STLINK Utility and including the option bytes settings in the checksum calcuation.

Unfortunately I think this is not possible. I use the Keil environment. There it is possible to include the option byte programming during the flash programming, but as I see it the option bytes are not included in the checksum - this is quite dangerous.

Best from my point of view would be to include the option bytes into the BIN or HEX file, so then they would be included in the checksum calculation, but this somehow does not seem to work.

According to the ST-LINK utility software (see UM0892 from stm, chapter 4.1.4), the option byte programming should be possible through command line parameters in this utility software, but again without checksum control, so a bit not so save. (I did not test this yet, but at least it is well described there ...).

Writing a bootloader only to program the option bytes seems to be a bit too much for me (also a bit dangerous, I do not like the idea that the chip starts re-programming itself without very special supervision).

Posted on March 12, 2013 at 14:31

The checksummed firmware checks the options are set correctly, I'm not sure how that isn't safe, and if the firmware itself is busted there's no guarantee it'll function at all, let alone correctly.

The only time the reset code needs to program the options is when they are unprogrammed, and that can occur in a fraction of a second whilst still in the test fixture.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
flyer31
Senior
Posted on March 18, 2013 at 19:24

Thank you for this recommendation - I think it is a good idea to program the option byte from within the application.

Is there some application note available with a proposed C code how to program the option byte in the Flash memory? I looked at the example flash\write_protection. There the Option byte is modified, but as I understand it only the Option byte RAM copy at address 0x40023C14.

As I understand the instructions in the ''Flash programming manual PM0081'', instead I should reprogram the option byte in Flash at adress 0x1FFFC000 and 0x1FFFC008. Is there any example code available, how to get this done in a safe way?

flyer31
Senior
Posted on March 18, 2013 at 19:31

... sorry, I think I got this now - it seems to work through the function FLASH_OB_Launch - thus just by setting the bit FLASH_OPTCR_OPTSTRT, as described in the ''Flash programming manual PM0081''.

... Just I would also like to program the OTP bytes. Is there an easy way to program the OTP bytes? (Or any application note / example program available for this?)

PS: Sorry, I found the procedure in the Flash/program example. As I understand, it is just FLASH_Unlock, FLASH_ProgramWord, FLASH_Lock, so quite easy.