我用的是stm32f103ze这款单片机,外挂一块S29AL008D70TAI02 flash,使用NOR_Status FSMC_NOR_WriteBuffer(u16 *pBuffer, u32 WriteAddr, u32 NumHalfwordToWrite)这个函数偶尔会写不进去(只能写进第一个字符),我调试的时候发现 NOR_Status FSMC_NOR_WriteBuffer(u16 *pBuffer, u32 WriteAddr, u32 NumHalfwordToWrite) { NOR_Status status = NOR_ONGOING; do { /* Transfer data to the memory */ status = FSMC_NOR_WriteHalfWord(WriteAddr, *pBuffer++); WriteAddr = WriteAddr + 2; NumHalfwordToWrite--; } while((status == NOR_SUCCESS) && (NumHalfwordToWrite != 0)); return (status); } 写进去第一个字符就返回了一个 NOR_ERROR 所以后面的字符都写不进去了。 下面的函数是我的同事改的 NOR_Status FSMC_NOR_GetStatus(u32 Timeout) { u16 val1 = 0x00, val2 = 0x00; NOR_Status status = NOR_ONGOING; //u32 timeout = Timeout; /* // Poll on NOR memory Ready/Busy signal ------------------------------------ while((GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_6) != RESET) && (timeout > 0)) { timeout--; } timeout = Timeout; while((GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_6) == RESET) && (timeout > 0)) { timeout--; } */ // Get the NOR memory operation status ------------------------------------- while((Timeout != 0x00) && (status != NOR_SUCCESS)) { Timeout--; //Read DQ6 and DQ5 //Read DQ6 and DQ2 val1 = *(vu16 *)(Bank1_NOR2_ADDR); val2 = *(vu16 *)(Bank1_NOR2_ADDR); // If DQ6 did not toggle between the two reads then return NOR_Success if((val1 & 0x0040) == (val2 & 0x0040)) { return NOR_SUCCESS; } //if((val1 & 0x0020) != 0x0020) if((val1 & 0x0004) != 0x0004) { status = NOR_ONGOING; } val1 = *(vu16 *)(Bank1_NOR2_ADDR); val2 = *(vu16 *)(Bank1_NOR2_ADDR); if((val1 & 0x0040) == (val2 & 0x0040)) { return NOR_SUCCESS; } @ //else if((val1 & 0x0020) == 0x0020) else if((val1 & 0x0004) == 0x0004) { return NOR_ERROR; } } if(Timeout == 0x00) { status = NOR_TIMEOUT; } // Return the operation status return (status); } 我想请教一下这一块@是不是有问题, 我把@ else if((val1 & 0x0020) == 0x0020) //else if((val1 & 0x0004) == 0x0004) 改成这样就正常了,但是让我担心的这个函数的其他的几个变量可能是有关联的,我怕影响产品的稳定性,我想请教一下这个函数该怎么改,非常感谢 |
RE:stm32f103ze 外挂nor flash 只能存储器第一个字符