2015-06-11 04:25 AM
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 .2015-06-11 04:41 AM
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.
JW2015-06-11 05:37 AM
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.2015-06-11 06:12 AM
2015-06-11 06:19 AM
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.2015-06-11 06:24 AM
thank you
From: clive1Posted: Thursday, June 11, 2015 3:19 PMSubject: 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.2015-06-11 07:43 AM
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.2015-06-11 08:00 AM
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);
2015-06-12 12:37 AM
thank you clive ...
i have done in another way but ur idea is useful :)2015-06-12 06:22 AM
Don't delete posts, it damages the integrity of the thread, and it pisses me off.