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

2019-07-21 02:00发布

内部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)处现象,说明已经全部写入了。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。