This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

6678 emif16 16位访问的问题



您好,

6678 emif16 接16位的FLASH,对于DSP端程序来说,对FLASH操作的偏移地址是不是应该作乘2的操作?

谢谢?

  • 不过多少位,软件都是一样的。

    但不同位宽时,硬件连线不一样。在16位宽的情况下,管脚和逻辑字节地址的对应关系如下:

    EMIFA23->A1

    EMIFA0->A2

    EMIFA1->A3

    EMIFA2->A4

    ......

    注意16位宽时,逻辑字节地址A0不存在。

  • Brighton Feng ,

    您好,我看    【开发例程共享】Keystone1 软件开发包 K1_STK_1010.zip中的EMIF例程,里面有关于nor flash部分是16位访问,其中的程序 对flash读写命令其偏移地址作了乘2的操作,读写数据时,地址增量为+2,等价于偏移地址作了乘2的操作。而实事上这样读写flash才没有问题?

    谢谢!

  • 没明白你的意思,能把相关代码贴出来吗?

  • 您好,

    以下是 例程的部分相关代码

    #define FLASH_BUS_WIDTH_1_BYTE 1
    #define FLASH_BUS_WIDTH_2_BYTES 2

    static void NOR_flashWriteCmd (NOR_InfoHandle hNorInfo, Uint32 blkAddr, Uint32 offset, Uint32 cmd)
    {
    Uint32 addr= blkAddr + offset*hNorInfo->busWidth;
    if (FLASH_BUS_WIDTH_1_BYTE==hNorInfo->busWidth)
    *(Uint8 *)addr = (Uint8)cmd;
    else /*FLASH_BUS_WIDTH_2_BYTES*/
    *(Uint16 *)addr = (Uint16)cmd;
    }

    // NOR_WriteBytes
    Uint32 NOR_writeBytes( NOR_InfoHandle hNorInfo, Uint32 writeAddress, Uint32 numBytes, Uint32 readAddress)
    {
    Int32 i;
    Uint32 retval = E_PASS;

    if(FLASH_BUS_WIDTH_2_BYTES == hNorInfo->busWidth)
    {
    if (writeAddress & 0x00000001)
    {
    puts("address is not aligned to 2-byte boundary");
    return E_FAIL;
    }

    if (numBytes & 0x00000001)
    {
    puts("number of bytes is not even");
    return E_FAIL;
    }
    }

    while (numBytes > 0)
    {
    if( (numBytes < hNorInfo->bufferSize) || (writeAddress & (hNorInfo->bufferSize-1) ))
    {
    if ((*Flash_Write)(hNorInfo, writeAddress, NOR_flashReadData(hNorInfo,readAddress,0) ) != E_PASS)
    {
    puts("Normal write failed.");
    retval = E_FAIL;
    }
    else
    {
    numBytes -= hNorInfo->busWidth;
    writeAddress += hNorInfo->busWidth;
    readAddress += hNorInfo->busWidth;
    }
    }
    else
    {
    // Try to use buffered writes
    if((*Flash_BufferWrite)(hNorInfo, writeAddress, (volatile Uint8 *)readAddress, hNorInfo->bufferSize) == E_PASS)
    {
    numBytes -= hNorInfo->bufferSize;
    writeAddress += hNorInfo->bufferSize;
    readAddress += hNorInfo->bufferSize;
    }
    else
    {
    puts("Buffered write failed. Trying normal write");
    // Try normal writes as a backup
    for(i = 0; i<hNorInfo->bufferSize; i+= hNorInfo->busWidth)
    {
    if ((*Flash_Write)(hNorInfo, writeAddress, NOR_flashReadData(hNorInfo,readAddress,0) ) != E_PASS)
    {
    puts("Normal write also failed");
    retval = E_FAIL;
    break;
    }
    else
    {
    numBytes -= hNorInfo->busWidth;
    writeAddress += hNorInfo->busWidth;
    readAddress += hNorInfo->busWidth;
    }
    }
    }
    }

    // Output status info on the write operation
    if (retval == E_PASS)
    {
    /*print progress*/
    if ( (0==(writeAddress & 0xFFFFF)) || (numBytes == 0) )
    {
    printf("NOR Write OK through 0x%x\n", writeAddress);
    }
    }
    else
    {
    puts( "NOR Write Failed...Aborting!");
    return E_FAIL;
    }
    }

    return retval;
    }

    谢谢!

  • 哦,你列出的这些代码的意思是16-bit NOR FLASH的最小寻址单位是2 bytes。也就是访问16-bit NOR FLASH时,地址最低bit始终应该为0.

    命令字的的偏移地址也是以2 bytes为单位,所以命令字的写地址=起始地址+偏移地址*2.

    而我们一般说的DSP核访问数据的地址是以byte为单位的,不需要乘2,但要保证是2的整数倍,即最低bit为0.