打印

stm32 flash 模拟eeprom 遇问题

[复制链接]
2841|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
mcuatmel|  楼主 | 2012-1-31 17:15 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
IC:STM32F103RCT6
想用片内flash存用户参数,在网上找了下,官方的没找到,在本论坛中找到一个优化的那个例程,在我的目标板上没能运行起来,不知是哪儿没改,也不知道该改哪儿,后来移到我现在的程序中,发现只要调用读函数EE_ReadVariable(VirtAddVarTab[0],&tempary[us16]),程序一点儿也不运行,直接进入void HardFaultException(void),如果注掉读调用,一切正常,不知问题出在哪里,请高手指点下!
沙发
mcuatmel|  楼主 | 2012-2-1 11:05 | 只看该作者
在主函中调用这个函数程序就会一点儿也不执行
uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data)
{
  uint16_t ValidPage = PAGE0;
  uint16_t AddressValue = 0x5555, ReadStatus = 1;
  uint32_t Address = 0x0803e800, PageStartAddress = 0x0803e800;

  /* Get active Page for read operation */
  ValidPage = EE_FindValidPage(READ_FROM_VALID_PAGE);

  /* Check if there is no valid page */
  if (ValidPage == NO_VALID_PAGE)
  {
    return  NO_VALID_PAGE;
  }

  /* Get the valid Page start Address */
  PageStartAddress = (uint32_t)(EEPROM_START_ADDRESS + (uint32_t)(ValidPage * PAGE_SIZE));

  /* Get the valid Page end Address */
  //Address = (uint32_t)((EEPROM_START_ADDRESS - 2) + (uint32_t)((1 + ValidPage) * PAGE_SIZE));
  Address=CurWrAddress-2;

  /* Check each active page address starting from end */
  while (Address > (PageStartAddress + 2))
  {
    /* Get the current location content to be compared with virtual address */
    AddressValue = (*(__IO uint16_t*)Address);

    /* Compare the read address with the virtual address */
    if (AddressValue == VirtAddress)
    {
      /* Get content of Address-2 which is variable value */
      *Data = (*(__IO uint16_t*)(Address - 2));

      /* In case variable value is read, reset ReadStatus flag */
      ReadStatus = 0;

      break;
    }
    else
    {
      /* Next address location */
      Address = Address - 4;
    }
  }

  /* Return ReadStatus value: (0: variable exist, 1: variable doesn't exist) */
  return ReadStatus;
}

使用特权

评论回复
板凳
airwill| | 2012-2-3 08:26 | 只看该作者
HardFaultException(void) 是个比较难处理的问题, 不妨先了解一下它
然后, 单步跟踪一下, 看看走到那条指令, 引发的这个异常.

第一直觉:  0x0803e800 这个 FLASH 地址, 是不是超出你的 cpu 的 FLASH 有效地址空间了?

使用特权

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

本版积分规则

512

主题

1456

帖子

2

粉丝