请香帮主和damiaa 帮助看看
STM32F103ZET6+K9F1G08 NAND Flash
已经将FSMC_NAND_WriteSmallPage,FSMC_NAND_ReadSmallPage 改写,并证实读写正确
初始化时使能了ECC,并设为2048Bytes.
int main(void)
{
u32 eccxor;
volatile u32 ecc1 = 0xf0;
volatile u32 ecc2= 0x0f;
#ifdef DEBUG
debug();
#endif
u32 i;
/* System Clocks Configuration */
RCC_Configuration();
/* NVIC Configuration */
NVIC_Configuration();
/* PB.12,13,14 config to drive LD2 and LD3,LD4 ******************************/
/* Enable GPIOB clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
/* Configure PB.12,13,14 as Output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
LED2OFF();
LED3OFF();
LED4OFF();
/* Enable the FSMC Clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
/* FSMC Initialization */
FSMC_NAND_Init();
/* NAND read ID command */
FSMC_NAND_ReadID(&NAND_ID);
/* Verify the NAND ID */
if((NAND_ID.Maker_ID == NAND_ST_MakerID) && (NAND_ID.Device_ID == NAND_ST_DeviceID))
{
/* NAND memory address to write to */
WriteReadAddr.Zone = 0x00;
WriteReadAddr.Block = 0x00;
WriteReadAddr.Page = 0x00;
/* Erase the NAND first Block */
status = FSMC_NAND_EraseBlock(WriteReadAddr);
/* Write data to FSMC NAND memory */
/* Fill the buffer to send */
Fill_Buffer(TxBuffer, BUFFER_SIZE , 0x66);
status = FSMC_NAND_WriteSmallPage(TxBuffer, WriteReadAddr, PageNumber);
/* 通过地址 0xa0000074查看生成ECC值为0x0f0f*/
ecc1 = FSMC_GetECC(FSMC_Bank2_NAND);
/* ecc1 值等于0x0f0f*/
FSMC_NANDECCCmd(FSMC_Bank2_NAND,DISABLE);
/* 通过地址 0xa0000074查看生成ECC值被清零*/
FSMC_NANDECCCmd(FSMC_Bank2_NAND,ENABLE);
/* Read back the written data */
status = FSMC_NAND_ReadSmallPage (RxBuffer, WriteReadAddr, PageNumber);
/*RxBuffer已经得到正确的值*/
* 通过地址 0xa0000074查看生成ECC值还是零*/
ecc2 = FSMC_GetECC(FSMC_Bank2_NAND);
FSMC_NANDECCCmd(FSMC_Bank2_NAND,DISABLE);
eccxor = ecc1 ^ ecc2;
if(eccxor==0)LED4ON();
}
else
{
/* Turn on LD3 */
LED3ON();
}
while(1)
{
}
}
问题就在于,ECC使用一次后,无论如何就一直为零了。
查阅了damiaa 的帖子https://bbs.21ic.com/viewthread.php?tid=132297&highlight=ecc
说是 前面加了volatile 才开始变, 我在程序开始就定义了 volatile u32 ecc1 = 0xf0;
volatile u32 ecc2= 0x0f; 没有作用呀!并且通过地址直接观察,ECC就是一直是0呀。
似乎ECC被DISABLE后再ENABLE也没有作用了。请解决了此问题的大侠指点一二,谢了先 |