IJK 发表于 2013-5-6 10:46
感觉是 FLASH编程 的步骤没有做完
写FLASH的代码
void STMFLASH_Write(u32 WriteAddr,u8 *pBuffer,u16 NumToWrite)
{
u16 byteN = 0;
if(( WriteAddr > STM32_FLASH_BASE ) && (WriteAddr < ( STM32_FLASH_BASE + 1024*STM32_FLASH_SIZE )))
{
FLASH_Unlock();
FLASH_ErasePage(WriteAddr);
while(NumToWrite)
{
Flash_Temp16.un_temp8[0] = *( pBuffer + byteN );
Flash_Temp16.un_temp8[1] = *( pBuffer + byteN + 1 );
FLASH_ProgramHalfWord(( WriteAddr + byteN ), Flash_Temp16.un_temp16 );
if( 1 == NumToWrite )
{
break;
}
else//
{
byteN += 2;
NumToWrite -= 2;
}
}
FLASH_Lock();//
}
}
读FLASH的代码
void FlashReadStr( u32 flash_add, u16 len, u8* data )
{
u16 byteN = 0;
if(( flash_add > STM32_FLASH_BASE ) && (flash_add < (STM32_FLASH_BASE+1024*STM32_FLASH_SIZE))
&& ( NULL != data ))
{
while( len )
{
Flash_Temp16.un_temp16 = *(vu16*)(flash_add+byteN);
if( 1==len )
{
*(data+byteN) = Flash_Temp16.un_temp8[0];
break;
}
else
{
*(data+byteN) = Flash_Temp16.un_temp8[0];
*(data+byteN+1) = Flash_Temp16.un_temp8[1];
byteN += 2;
len -= 2;
}
}
}
}
|