cancel
Showing results for 
Search instead for 
Did you mean: 

OTP(One time programmable)

arunl4g
Associate II
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 .
9 REPLIES 9
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
Posted on June 11, 2015 at 14:37

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

 

thank in advance.

This was for the F2, but is directly applicable.

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32F2xx%20OTP%20issue&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=943

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
arunl4g
Associate II
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 ?...

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 Up vote any posts that you find helpful, it shows what's working..
arunl4g
Associate II
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.
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 Up vote any posts that you find helpful, it shows what's working..
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 Up vote any posts that you find helpful, it shows what's working..
arunl4g
Associate II
Posted on June 12, 2015 at 09:37

thank you clive ...

i have done in another way but ur idea is useful 🙂

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 Up vote any posts that you find helpful, it shows what's working..