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.

Reading SPI Flash ID in U-boot

HI,

I have written a small code in u-boot level to read the ID of the SPI Flash of 8148EVM but it is always returning FF.

Kindly help me to read the SPI Flash ID in u-boot.

here is my code.

static int uu_spi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{

        struct spi_slave *slave;
        char  *cp = 0;
        uchar tmp;
        int   j;
        int   rcode = 0;
        unsigned int    bus;
        unsigned int    cs;
        unsigned int    mode;
        int             bitlen;

        bus = 0;
        cs = 0;
        mode = 0;
        dout[0] = OPCODE_RDID;

        slave = spi_setup_slave(bus, cs,1000000, mode);
        if (!slave) {
                printf("Invalid device %d:%d\n", bus, cs);
                return 1;
        }
        spi_claim_bus(slave);

        if(spi_xfer(slave, 1*8, dout,din,
                                SPI_XFER_BEGIN | SPI_XFER_END) != 0) {
                printf("Error during SPI transaction\n");
                rcode = 1;
        }
        else
        {
                printf("SPI Flash id = %d  %d  %d  %d  %d \n",din[0],din[1],din[2],din[3],din[4]);
        }
        spi_release_bus(slave);
        spi_free_slave(slave);
        return 0;
}

all the bytes are coming as FF.

Regards,

Vimal

  • Vimal,

    The first thing we can check is whether you are enabling the SPI Flash on the DM8148 EVM BaseBoard. SW2.2 should be ON (1) to enable the SPI Flash.

    Could you verify you have enabled (SW2.2 = 1) the SPI Flash on the DM814x EVM?

    Regards,
    Pavel

  • hi pavel,

    yes it is enabled.

    Regards,

    vimal

  • Vimal,

    Vimal Gupta said:
      mode = 0;

    Can you try with mode = 3

    Vimal Gupta said:
      slave = spi_setup_slave(bus, cs,1000000, mode);

    Can you try with max speed of 75000000:

    spi_setup_slave(bus,cs,75000000,3);

    Vimal Gupta said:
    spi_claim_bus(slave);

    You should add error check:

     rcode = spi_claim_bus(slave);
        if (rcode) {
            printf("SF: Failed to claim SPI bus: %d\n", rcode);
            goto err_claim_bus;
        }

    err_claim_bus:
        spi_free_slave(slave);
        return NULL;

    Let me know the result.

    Regards,
    Pavel

  • Hi Pavel,

    I have tested it after integrating your suggestion and the result is as below:

    VIMAL id = 255  0  0  0  0

    Regards,

    Vimal

  • Vimal,

    Vimal Gupta said:
    VIMAL id = 255  0  0  0  0

    This does not look to be correct. On my DM814x/AM387x EVM, the ID code is:

    SF: Got idcode ef 30 16 00 00

    This is how I get this id. On a clean u-boot, I just modify:

    ti-ezsdk_dm814x-evm_5_05_02_00/board-support/u-boot-2010.06-psp04.04.00.01/drivers/mtd/spi/spi_flash.c

    struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
            unsigned int max_hz, unsigned int spi_mode)
    {
        struct spi_slave *spi;
        struct spi_flash *flash;
        int ret;
        u8 idcode[5];
       
        spi = spi_setup_slave(bus, cs, max_hz, spi_mode);
        if (!spi) {
            debug("SF: Failed to set up slave\n");
            return NULL;
        }

        ret = spi_claim_bus(spi);
        if (ret) {
            debug("SF: Failed to claim SPI bus: %d\n", ret);
            goto err_claim_bus;
        }
       
        /* Read the ID codes */
        ret = spi_flash_cmd(spi, CMD_READ_ID, &idcode, sizeof(idcode));
        if (ret)
            goto err_read_id;

        /*debug("SF: Got idcode %02x %02x %02x %02x %02x\n", idcode[0],
                idcode[1], idcode[2], idcode[3], idcode[4]);*/
        printf("SF: Got idcode %02x %02x %02x %02x %02x\n", idcode[0],
                idcode[1], idcode[2], idcode[3], idcode[4]);

        switch (idcode[0]) {

    .....

    With this new u-boot, when I probe the SPI, I have the ID code:

    TI8148_EVM#sf probe 0:0
    SF: Got idcode ef 30 16 00 00
    4096 KiB W25X32 at 0:0 is now current device

    Can you try the same at your side. What is the result?

    Best regards,
    Pavel

  • Hi pavel,

    while i am running sf probe command it is giving me "Unknown command ' sf' where as in the help it is showing the sf command.

    I am compiling the u-boot with following command.

    make ARCH=arm ti8148_evm_min_sd

    and make ARCH=arm ti8148_evm_config

    do i need to compile it with some other option.

    thanks,

    vimal

  • Vimal,

    Vimal Gupta said:
    I am compiling the u-boot with following command.

    Vimal Gupta said:
    ti8148_evm_min_sd

    Are you booting from MMC/SD card? If yes, then these are the correct commands:

    u-boot-2010.06-psp04.04.00.01$ make distclean
    u-boot-2010.06-psp04.04.00.01$ make ti8148_evm_min_sd
    u-boot-2010.06-psp04.04.00.01$ make u-boot.ti

    This set of commands will generate you (in the current u-boot folder) the 1st stage bootloader for SD boot -> u-boot.min.sd file, which should be renamed to MLO and placed in the /media/BOOT/ partition of the SD card

    Then you should generated the 2nd stage bootloader (u-boot.bin) and place it to the /media/BOOT/ partition of the SD card.

    u-boot-2010.06-psp04.04.00.01$ make distclean
    u-boot-2010.06-psp04.04.00.01$ make ti8148_evm_config_sd
    u-boot-2010.06-psp04.04.00.01$ make u-boot.ti

    Refer to the below wiki page for more info:

    http://processors.wiki.ti.com/index.php/TI81XX_PSP_UBOOT_User_Guide#Building_U-Boot

    Vimal Gupta said:

    make ARCH=arm ti8148_evm_min_sd

    and make ARCH=arm ti8148_evm_config


    Make sure that you set your CROSS_COMPILE to .../CodeSourcery/arm-2009q1/bin/arm-none-linux-gnueabi-

    Regards,
    Pavel

  • Hi Pavel,

    I compiled as per your suggestion but still i am getting the same error "Unknown command" for 'sf probe' command.

    whats the problem.

    Regards,

    Vimal

  • Vimal,

    Can you provide me full log of your console output (boot up + "sf probe")?

    Regards,
    Pavel