endian problem when use XIP ?



  • when put the spi3 in xip mode,follow code as:

    u8_test_ptr = (uint8_t *)SPI3_BASE_ADDR;
    w25qxx_enable_xip_mode();
    print_uint8_array(u8_test_ptr+off ,0x10,8);
    uint8_t test[0x10];
    memcpy(test,u8_test_ptr+off ,0x10);
    print_uint8_array(test ,0x10,8);

    got result:
    data @ 0x54100048
    df,b8,be,b8,ca,6f,58,6d,
    86,5e,60,96,9b,8d,87,8f,

    data @ 0x80022480
    b8,be,b8,df,6d,58,6f,ca,
    96,60,5e,86,8f,87,8d,9b,

    so endian changed when use copy???



  • @loboris thanks!



  • @yan211 said in endian problem when use XIP ?:

    b8,be,b8,df,

    Yes, XIP reads 32-bit values as big endian.

    The application binary flashed with kflash has also changed endianess, kflash automatically changes it (you can check it by 'normal' flash read from address 0). This is because the K210 ROM trransfers the data at boot from Flash to SRAM in XIP mode.
    So if you write the data to the flash with with flash sector/page write to be read in XIP mode, you must change endianess of every 32-bit value to big-endian...
    If you flash the data with kflash it will be read in XIP mode corectlly.

    The similar problem exists if you flash the data with kflash to be read from application in 'normal' SPI flash mode (for example the prebuilt file system). You must change endianess of every 32-bit value to big-endian before flashing.