Skip to main content
arunl4g
Associate III
June 11, 2015
Question

OTP(One time programmable)

  • June 11, 2015
  • 9 replies
  • 1185 views
Posted on June 11, 2015 at 13:25

i am using stm32f4 discivery board .i would like to write a block of data to OTP. 

Can anyone tell me how to proceed. or does anyone put some  sample code for that. 

thank in advance .
    This topic has been closed for replies.

    9 replies

    waclawek.jan
    Super User
    June 11, 2015
    Posted on June 11, 2015 at 13:41

    You write to it in the same way as to other parts of FLASH, except you can't erase it i.e. you can only change bits from 1 to 0; plus it's lockable.

    JW
    Tesla DeLorean
    Guru
    June 11, 2015
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    arunl4g
    arunl4gAuthor
    Associate III
    June 11, 2015
    Posted on June 11, 2015 at 15:12

    thank you clive. 

    i want to write a structure of data inside OTP. so how can i write that ?...

    Tesla DeLorean
    Guru
    June 11, 2015
    Posted on June 11, 2015 at 15:19

    i want to write a structure of data inside OTP. so how can i write that ?...

    One word at a time? Iterate on the program word.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    arunl4g
    arunl4gAuthor
    Associate III
    June 11, 2015
    Posted on June 11, 2015 at 15:24

    thank you 

    From: clive1

    Posted: Thursday, June 11, 2015 3:19 PM

    Subject: OTP(One time programmable)

    i want to write a structure of data inside OTP. so how can i write that ?...

    One word at a time? Iterate on the program word.
    Tesla DeLorean
    Guru
    June 11, 2015
    Posted on June 11, 2015 at 16:43

    can't i write the whole structure? is it able to write only one word at a time?

    Cast it to a word pointer, and write the whole structure one 32-bit word at a time in a loop, at the point I have the single write now. Code your routine like your fwrite()'ing it to a file.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Tesla DeLorean
    Guru
    June 11, 2015
    Posted on June 11, 2015 at 17:00

    FLASH_Status WriteOTPBlock(size_t Size, void *Buffer)
    {
    uint32_t Addr = 0x1FFF7800; // Base of OTP
    uint32_t *p = (uint32_t *)Buffer;
    size_t i = (Size + sizeof(uint32_t) - 1) / sizeof(uint32_t);
    FLASH_Status Status;
    FLASH_Unlock();
    /* Clear pending flags (if any), observed post flashing */
    FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
    FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR| FLASH_FLAG_PGSERR);
    /* Wait for last operation to be completed */
    Status = FLASH_WaitForLastOperation();
    while(i-- && (Status == FLASH_COMPLETE))
    {
    Status = FLASH_ProgramWord(Addr, *p++); // Write OTP
    Addr += sizeof(uint32_t);
    }
    FLASH_Lock();
    return(Status); // sourcer32@gmail.com
    }
    WriteOTPBlock(sizeof(InstrumentState), IS);

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    arunl4g
    arunl4gAuthor
    Associate III
    June 12, 2015
    Posted on June 12, 2015 at 09:37

    thank you clive ...

    i have done in another way but ur idea is useful :)

    Tesla DeLorean
    Guru
    June 12, 2015
    Posted on June 12, 2015 at 15:22

    Don't delete posts, it damages the integrity of the thread, and it pisses me off.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..