OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 5964|回复: 1

求助一下,内部flash读出全为0

[复制链接]

13

主题

57

帖子

0

精华

初级会员

Rank: 2

积分
193
金钱
193
注册时间
2014-9-11
在线时间
15 小时
发表于 2015-8-10 15:28:35 | 显示全部楼层 |阅读模式
5金钱
内部flash读出的数据全部为0,应该是写入进去了。各位帮忙看一下
#define FLASH_USER_START_ADDR   ADDR_FLASH_SECTOR_3   /* Start @ of user Flash area */
#define FLASH_USER_END_ADDR        0x0800C190 /* End @ of user Flash area */

__IO uint32_t data32 = 10;

void FLASH_Read(aCm *Buf)
{
tPriint32 *Ptr=(tPriint32*)Buf;
Address = FLASH_USER_START_ADDR;

while (Address < FLASH_USER_END_ADDR)
{
data32 = *(__IO uint32_t*)Address;
Address = Address + 4;
  }  
}

void FLASH_Eraser()
{
/* Clear pending flags (if any) */  
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | 
             FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR); 

/* Get the number of the start and end sectors */
StartSector = GetSector(FLASH_USER_START_ADDR);
EndSector = GetSector(FLASH_USER_END_ADDR);

for (SectorCounter = StartSector; SectorCounter < EndSector; SectorCounter += 8)
{
/* Device voltage range supposed to be [2.7V to 3.6V], the operation will
  be done by word */ 
if (FLASH_EraseSector(SectorCounter, VoltageRange_3) != FLASH_COMPLETE)

 /* Error occurred while sector erase. 
    User can add here some code to deal with this error  */
       while (1);
}
}
}


void FLASH_Write(aCm *Buf)
{
tPriint32 Value=20;
// float * Ptr=(float*)Buf;

FLASH_Unlock();
FLASH_Eraser();
Address = FLASH_USER_START_ADDR;


while (Address < FLASH_USER_END_ADDR)
{

if (FLASH_ProgramWord(Address,Value) == FLASH_COMPLETE)
{
Address = Address + 4;
}
else
{
while (1);
}
}
FLASH_Lock(); 
}



/**
  * @brief  Gets the sector of a given address
  * @param  None
  * @retval The sector of a given address
  */
uint32_t GetSector(uint32_t Address)
{
  uint32_t sector = 0;
  
  if((Address < ADDR_FLASH_SECTOR_1) && (Address >= ADDR_FLASH_SECTOR_0))
  {
    sector = FLASH_Sector_0;  
  }
  else if((Address < ADDR_FLASH_SECTOR_2) && (Address >= ADDR_FLASH_SECTOR_1))
  {
    sector = FLASH_Sector_1;  
  }
  else if((Address < ADDR_FLASH_SECTOR_3) && (Address >= ADDR_FLASH_SECTOR_2))
  {
    sector = FLASH_Sector_2;  
  }
  else if((Address < ADDR_FLASH_SECTOR_4) && (Address >= ADDR_FLASH_SECTOR_3))
  {
    sector = FLASH_Sector_3;  
  }
  else if((Address < ADDR_FLASH_SECTOR_5) && (Address >= ADDR_FLASH_SECTOR_4))
  {
    sector = FLASH_Sector_4;  
  }
  else if((Address < ADDR_FLASH_SECTOR_6) && (Address >= ADDR_FLASH_SECTOR_5))
  {
    sector = FLASH_Sector_5;  
  }
  else if((Address < ADDR_FLASH_SECTOR_7) && (Address >= ADDR_FLASH_SECTOR_6))
  {
    sector = FLASH_Sector_6;  
  }
  else if((Address < ADDR_FLASH_SECTOR_8) && (Address >= ADDR_FLASH_SECTOR_7))
  {
    sector = FLASH_Sector_7;  
  }
  else if((Address < ADDR_FLASH_SECTOR_9) && (Address >= ADDR_FLASH_SECTOR_8))
  {
    sector = FLASH_Sector_8;  
  }
  else if((Address < ADDR_FLASH_SECTOR_10) && (Address >= ADDR_FLASH_SECTOR_9))
  {
    sector = FLASH_Sector_9;  
  }
  else if((Address < ADDR_FLASH_SECTOR_11) && (Address >= ADDR_FLASH_SECTOR_10))
  {
    sector = FLASH_Sector_10;  
  }
  else/*(Address < FLASH_END_ADDR) && (Address >= ADDR_FLASH_SECTOR_11))*/
  {
    sector = FLASH_Sector_11;  
  }

  return sector;
}

基本就是官方例程修改的,我也比较原子哥的例程了,应该不会出现读出为零的问题啊,写入时没有出现停在while(1)处现象,说明已经全部写入了。

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165371
金钱
165371
注册时间
2010-12-1
在线时间
2110 小时
发表于 2015-8-10 22:33:44 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-2-25 03:35

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表