shujianhongye_feng 2016-05-04 03:42 采纳率: 0%
浏览 6856

stm32的flash擦除不正常

先贴代码:
U32 Flashadd;
U8 FLASH_Sector;
FLASH_Status status = FLASH_COMPLETE;
Flashadd=addr-0x8000000;

if(Flashadd<0x10000) FLASH_Sector=(U8)(Flashadd>>14);
else if(Flashadd<=0x1ffff) FLASH_Sector=4;
else if(Flashadd<=0x1fffff) FLASH_Sector=(U8) (5+((Flashadd-0x20000)>>17));
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_PGSERR | FLASH_FLAG_PGPERR |   FLASH_FLAG_PGAERR | FLASH_FLAG_WRPERR |    FLASH_FLAG_OPERR | FLASH_FLAG_EOP); 
    FLASH_OB_WRPConfig(FLASH_Sector, DISABLE);
FLASH_OB_Unlock();

/* Check the parameters /
assert_param(IS_FLASH_SECTOR(FLASH_Sector));
/
Wait for last operation to be completed /
status = FLASH_WaitForLastOperation(ERASE_TIMEOUT);
FLASH_Sector=FLASH_Sector<<3;
if(status == FLASH_COMPLETE)
{
/
if the previous operation is completed, proceed to erase the sector */
FLASH->CR &= SECTOR_MASK;
FLASH->CR |= FLASH_CR_SER | FLASH_Sector;
FLASH->CR |= FLASH_CR_STRT;

/* Wait for last operation to be completed */
status = FLASH_WaitForLastOperation(ERASE_TIMEOUT);

/* if the erase operation is completed, disable the SER Bit */
FLASH->CR &= (~FLASH_CR_SER);
FLASH->CR &= SECTOR_MASK; 

}
FLASH_Lock();
/* Return the Erase Status */
return status;
运行这个函数的,我在线调试时会出现Could not stop Cortex-M device.
将改程序中的FLASH->CR |= FLASH_CR_STRT;语句屏蔽,就能进入调试,但是擦除flash不正常,不知道为什么,有哪位大虾指点迷津,小弟在此道谢。

  • 写回答

1条回答

  • m0_49335453 2020-07-17 23:27
    关注

    要配置flash_acr寄存器disable才能正常写入

    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试