我使用的MCU为STM32F103ZET6,NOR FLASH 为M29W128FH。
我现在将从SD卡读取的数据连续写入NOR FLASH中,但是写入失败(只能成功写入一次)。奇怪的是我单独写入是成功的。
不知大家有没有遇到类似问题,请多多指教!
这是电路图。
以下是程序:
[mw_shl_code=c,true]void NOR_WriteFont16(void)
{
FRESULT f_result;
u16 dataflash=0x0000;
// NOR_Status Status;
static uint32_t WriteAddr=0x00000000;
NOR_ReturnToReadMode();
NOR_ReadBuffer(&dataflash, 0x020000, 0x01);
// while(!USART_GetFlagStatus(USART2, USART_FLAG_TXE));
// USART_SendData(USART2, dataflash);
//如果不存在,读取SD卡中的字库
if(dataflash !=0xFFAF)
{
NOR_EraseBlock(0x000000);
NOR_EraseBlock(0x008000);
NOR_EraseBlock(0x010000);
NOR_EraseBlock(0x018000);
//挂载SD卡
fr = f_mount(&fs0, "0:/", 1);
RA8875_DispAscii(0, 240, "FATFS Init OK!",WHITE,BLUE);
f_result = f_open(&f0, "sys/HZK16.bin", FA_OPEN_EXISTING | FA_READ); //在SD卡里搜索HZK16.bin
if(f_result == FR_OK)
{
do
{
f_read(&f0, TempBuffer, 256, &br);
NOR_WriteBuffer(TempBuffer, WriteAddr, br);
WriteAddr = WriteAddr+br;
}
while(br==256);
//写入字库存在标志
dataflash= 0xAFAF;
NOR_EraseBlock(0x020000);
NOR_WriteBuffer(&dataflash, 0x020000, 0x01);
RA8875_DispAscii(0, 330, "HZK16 writes OK!",WHITE,BLUE);
}
else
{
RA8875_DispAscii(0, 330, "Cannot find sys/HZK16.bin",WHITE,BLUE);
}
f_close(&f0);
}
else
{
RA8875_DispAscii(0, 300, "Font lib exists on M29W128FH!",WHITE,BLUE);
}
}[/mw_shl_code]
|