读写OTP区域,按照中文手册先写00到BLOCK0的LOCK位,再写BLOCK
读LOCK位发现已经成功清0,但是读BLOCK发现没能成功写入,读到全F,追踪代码 写入OTP数据后 FLASH->SR 的FLASH_FLAG_WRPERRbit为1 ,即写保护
请教下:
1,为何写保护? 查看手册,写保护原因以下
[mw_shl_code=c,true]If a program operation is requested, the WRPERR bit is set when:
? A write operation is performed on system memory or on the reserved part of the user
specific sector.
? A write operation is performed to the user configuration sector
? A write operation is performed on a sector write protected by option bit.
? A write operation is requested on an OTP area which is already locked
? The Flash memory is read protected and an intrusion is detected.[/mw_shl_code]
第一/二/三条不符合, 第四条我已经清0。第五条不太明白,但是我可以写LOCK位,不能写OTP BLOCK,似乎也不像是这原因。
2,应当如何正确操作
代码如下
[mw_shl_code=c,true]#define OTP_BLOCK_BASE 0x1FFF7800
#define OTP_LOCK_BASE 0x1FFF7A00
STMFLASH_Write(OTP_LOCK_BASE,0x00000000,1);
STMFLASH_Write(OTP_BLOCK_BASE,0x1a2b3f4d,1);// 没写成功
STMFLASH_Read(OTP_LOCK_BASE,(u32*)datatemp,1);//读到0 之前读是0xffffffff说明成功了
STMFLASH_Read(OTP_BLOCK_BASE,(u32*)datatemp,1);//一直是0xffffffff SR的写保护有问题
[/mw_shl_code]
移植的原子大神的代码,大家帮忙看看哈
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>