cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to enable BOOT_LOCK through Hex file in STM32G4

nagaparimi
Associate II

Hi,

I am using STM32G431 MCU and PB8-BOOT0 pin is used as UART3 RX, with STM32 cube programmer i am able to change option bytes, but for my production, i need single hex file included with option bytes, 

I tried with below method

 

In .s File added below lines to 

 

	SECTION optionbytes :CONST (1)
;-------------------------------------------------
                
        //Check BOOTLOCK
        // SEC_SIZE1, Reserved, BOOT_LOCK, Reserved
        DC8	0x80, 0xFF, 0xFF, 0xFF 
        DC8	0x7F, 0x00, 0x00, 0x00       
            
        END

In .icf file added below lines

define symbol OPTSTART  = 0x1FFF7828;
define symbol OPTEND    = 0x1FFF782F;
place at address mem: OPTSTART { ro section optionbytes};

 

BOOT_LOCK option bytes values are appended in hex file as below in 0x1FFF7828 location

nagaparimi_1-1709552051957.png

nagaparimi_2-1709552313440.png

 

But I am seeing no change in option bytes, tried with other option bytes like BOR level, i am seeing the change for BOR, why BOOT_LOCK is not changing.

 

Thank you.

 

 

 

 

6 REPLIES 6
TDK
Guru

The 0x7F000000 value you're putting in doesn't match the table you've provided or what's in the reference manual. If you want BOOT_LOCK=1, and SEC_SIZE1=0, then you should write 0xFF01FF00 for the 32-bit option byte or 0x00FE00FFFF01FF00 for the 64-bit register.

 

TDK_0-1709558240315.png

 

If you feel a post has answered your question, please click "Accept as Solution".
nagaparimi
Associate II

Hi TDK,

Thanks for your response, 

In my question, value is 0xFFFFFF80, were BOOT_LOCK is 1 and SECSIZE1 is 0x80

for 64 bit value is 0x0000007FFFFFFF80, 

Anyway, i tried as you suggested and below is the stm32 cube programmer snapshot

nagaparimi_0-1709560874495.png

but no luck, am i missing something..?

I didn't mention it before since you said other option bytes were "working", but how are you setting OPTSTRT to actually program the option bytes? The registers in RAM are just the interface, they don't control the values stored in FLASH, at least not directly. Presumably this scheme might work if OPTSTRT is set last, or set by some other mechanism.

If you feel a post has answered your question, please click "Accept as Solution".
nagaparimi
Associate II

below changes are to modify BOR value to "2" and it worked without OPTSTRT

nagaparimi_1-1709563397624.png

 

nagaparimi_0-1709563376120.png

nagaparimi_2-1709563432296.png

BOR_LEV changed from 0 to 2

 

 

 

TDK
Guru

Okay, could be two things going on here, but the more important point is that option bytes do need to be written with OPTSTRT in order to write them to nonvolatile memory, otherwise they will be reset when the chip gets reset. STM32CubeProgrammer is just reading from the registers and doesn't know if they've been written correctly or not.

If you feel a post has answered your question, please click "Accept as Solution".

I repowered MCU and read, BOR_LEV value didn't reset, it remains as 2