Skip to main content
fabien
Associate
October 15, 2014
Question

Programming user option bytes

  • October 15, 2014
  • 5 replies
  • 1298 views
Posted on October 15, 2014 at 14:52

Hello,

I would like to know if it is possible to change the value of the register FLASH_OPTCR by mapping a variable on it and to set the value in constant ? I think this is not possible because we need to respect a predefined sequence to unlock the register but I can always ask for the question :) Example of what I want :

const u32 u32_FlashOptcr @ 0x40023C14 = 0xFFFFFFFF;

Thanks, Fabien.
    This topic has been closed for replies.

    5 replies

    chen
    Associate II
    October 15, 2014
    Posted on October 15, 2014 at 15:12

    Hi

    ''I would like to know if it is possible to change the value of the register FLASH_OPTCR by mapping a variable on it and to set the value in constant ? I think this is not possible because we need to respect a predefined sequence to unlock the register''

    You are correct - you cannot just load it with a single constant value.

    There are APIs for doing this in the peripheral library :

    stm32f4xx_flash.c

    FLASH_OB_Unlock()

    FLASH_OB_WRPConfig()

    FLASH_OB_Lock()

    fabien
    fabienAuthor
    Associate
    October 15, 2014
    Posted on October 15, 2014 at 15:22

    Thanks for the response.

    I know about the APIs, but the purpose of my idea was to protect the flash by just flashing a software, and to not make other manipulation with other sofwtare like ''STM32 ST-LINK Utility'' to change the option bytes.

    chen
    Associate II
    October 15, 2014
    Posted on October 15, 2014 at 15:35

    ''the purpose of my idea was to protect the flash by just flashing a software, and to not make other manipulation with other sofwtare like ''STM32 ST-LINK Utility'' to change the option bytes.''

    I do not understand - maybe it is your english.

    The ST-Link will automatically un-lock any write protected sectors and re-lock them afterwards.

    So the ST-Link can over-ride the write protect bits anyway!

    Tesla DeLorean
    Guru
    October 15, 2014
    Posted on October 15, 2014 at 16:48

    The options and flash can be programmed by user code, you don't have to use ST-LINK Utilities, or external tools/interfaces, to achieve this.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    fabien
    fabienAuthor
    Associate
    October 15, 2014
    Posted on October 15, 2014 at 16:55

    Sorry for my english :(

    I just see the ''Automatic Mode'' in st-link utility and I think it will do the job :)

    I will try to use the st-link utility with command line to unlock flash, program and relock the flash.

    Thanks.