打印
[STM8]

IAR for STM8, FLASH_EraseBlock在release模式卡死

[复制链接]
601|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
laocuo1142|  楼主 | 2021-1-5 14:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
使用STM8AF52xx,配置了#define RAM_EXECUTION  (1)
在debug模式下(low optimization)使用FLASH_EraseBlock可以正常擦除。
在release模式下(medium 或 high optimization)使用FLASH_EraseBlock卡死。
  • IN_RAM(void FLASH_EraseBlock(uint16_t BlockNum, FLASH_MemType_TypeDef FLASH_MemType))
  • {
  •   uint32_t startaddress = 0;
  • #if defined(STM8S105) || defined(STM8S005) || defined(STM8S103) || defined(STM8S003) || \
  •     defined(STM8S001) || defined(STM8S903) || defined (STM8AF626x) || defined (STM8AF622x)
  •     uint32_t PointerAttr  *pwFlash;
  • #elif defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined (STM8AF62Ax) || defined (STM8AF52Ax)
  •   uint8_t PointerAttr  *pwFlash;
  • #endif
  •   /* Check parameters */
  •   assert_param(IS_MEMORY_TYPE_OK(FLASH_MemType));
  •   if(FLASH_MemType == FLASH_MEMTYPE_PROG)
  •   {
  •     assert_param(IS_FLASH_PROG_BLOCK_NUMBER_OK(BlockNum));
  •     startaddress = FLASH_PROG_START_PHYSICAL_ADDRESS;
  •   }
  •   else
  •   {
  •     assert_param(IS_FLASH_DATA_BLOCK_NUMBER_OK(BlockNum));
  •     startaddress = FLASH_DATA_START_PHYSICAL_ADDRESS;
  •   }
  •   /* Point to the first block address */
  • #if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined (STM8AF62Ax) || defined (STM8AF52Ax)
  •   pwFlash = (PointerAttr uint8_t *)(MemoryAddressCast)(startaddress + ((uint32_t)BlockNum * FLASH_BLOCK_SIZE));
  • #elif defined(STM8S105) || defined(STM8S005) || defined(STM8S103) || defined(STM8S003) || \
  •       defined(STM8S001) || defined (STM8S903) || defined (STM8AF626x) || defined (STM8AF622x)
  •     pwFlash = (PointerAttr uint32_t *)(MemoryAddressCast)(startaddress + ((uint32_t)BlockNum * FLASH_BLOCK_SIZE));
  • #endif        /* STM8S208, STM8S207 */
  •   /* Enable erase block mode */
  •   FLASH->CR2 |= FLASH_CR2_ERASE;
  •   FLASH->NCR2 &= (uint8_t)(~FLASH_NCR2_NERASE);
  • #if defined(STM8S105) || defined(STM8S005) || defined(STM8S103) || defined(STM8S003) ||  \
  •     defined(STM8S001) || defined(STM8S903) || defined (STM8AF626x) || defined (STM8AF622x)
  •     *pwFlash = (uint32_t)0;
  • #elif defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined (STM8AF62Ax) || \
  •   defined (STM8AF52Ax)
  •     *pwFlash = (uint8_t)0;
  •   *(pwFlash + 1) = (uint8_t)0;
  •   *(pwFlash + 2) = (uint8_t)0;
  •   *(pwFlash + 3) = (uint8_t)0;   
  • #endif
  • }

[color=rgb(51, 102, 153) !important]复制代码

在release模式下,对程序区FLASH_ProgramWord可以写入没有问题

有人碰到过吗?

使用特权

评论回复
沙发
观海| | 2021-2-2 12:54 | 只看该作者
卡在什么位置了啊

使用特权

评论回复
板凳
guanjiaer| | 2021-2-2 12:57 | 只看该作者
量一下电压  过低的话也不行

使用特权

评论回复
地板
heimaojingzhang| | 2021-2-2 12:59 | 只看该作者
难道在debug模式就不卡死吗

使用特权

评论回复
5
keaibukelian| | 2021-2-2 13:01 | 只看该作者
单步调试看看结果吧

使用特权

评论回复
6
labasi| | 2021-2-2 13:02 | 只看该作者
这两种模式有什么区别吗

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1167

主题

5098

帖子

12

粉丝