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.

5505 failed to boot from reformatted SD; can't read FAT32 when booting from SD

Other Parts Discussed in Thread: CSD

Hi everyone,

I am having 2 problems booting my program from SD card in my custom board using VC5505.I hope you guys could help me out.

1. My program boot & executed well with a new, untouched SD card but if I copy the boot5505 bin file to some another cards (which had been formatted as FAT32 using Windows XP) then it fails to boot. The problem is similar when using the programmer.out to program to SD card. The programmer.out can write the bin file successfully to a new SD card but not a windows-formatted one.

2. I have another program which uses LCDC, MMC & ATA FAT. Everything works perfectly when I load & execute it using CCS 4.1. When I tried to boot it from SD, the LCDC works well (I can see the LCD was on) but not the MMC module. Could anyone tell me what's the differences running the code from CCS and booting using boot-loader? I guess CCS initialize something for us but I am not sure what it is.

Here is my initialization code I took from an EVM sample project:

void InitSystem(void)
{
    Uint16 i;
// PLL set up from RTC
    // bypass PLL
    CONFIG_MSW = 0x0;

#if (PLL_100M ==1)
    PLL_CNTL2 = 0x8000;
    PLL_CNTL4 = 0x0000;
    PLL_CNTL3 = 0x0806;
    PLL_CNTL1 = 0x82FA;
   
#elif (PLL_12M ==1)
    PLL_CNTL2 = 0x8000;
    PLL_CNTL4 = 0x0200;
    PLL_CNTL3 = 0x0806;
    PLL_CNTL1 = 0x82ED;
#elif (PLL_98M ==1)   
    PLL_CNTL2 = 0x8000;
    PLL_CNTL4 = 0x0000;
    PLL_CNTL3 = 0x0806;
    PLL_CNTL1 = 0x82ED;
   
#endif

    while ( (PLL_CNTL3 & 0x0008) == 0);
    // Switch to PLL clk
    CONFIG_MSW = 0x1;

// clock gating
// enable all clocks
    IDLE_PCGCR = 0;
    IDLE_PCGCR_MSW = 0xFF84;
   

// reset peripherals
    PER_RSTCOUNT = 0x02;
    PER_RESET = 0x00fb;   
    for (i=0; i< 200; i++);
   
}

Any help would be highly appreciated. Thank you very much!

Joe

 

  • Hi Joe,

     

    1. How did you make boot5505.bin file?

    2. Do you still have this problem? Is this different from your other post?

    http://e2e.ti.com/support/dsp/tms320c5000_power-efficient_dsps/f/109/p/52229/190633.aspx#190633

     

    Regards,

    Hyun

  • Hi Hyun,

    1. I use C55BootImage.exe to create the bin file. I got that tool from TI support & it works great!

    2.The problem in the other post is solved.

    This problem is temporarily solved too. I used polling in stead of DMA to push data to the LCD & it worked! I guess the problem is somehow the interrupt handler not being executed (when booting using bootloader)

    I got another problem with the ATA FS. I have a program loading data from a file in SD card & displaying on the LCD. It works well when debugging using CCS but when loaded & run by bootloader, it ruins the FAT32 table in the SD after a few tests. It's even worst that the ruined card cannot be formatted using Wins XP explorer. I solved that problem by using another FAT32 open source.

    I am still interested in using ATAFS & DMA for LCDC. It would be great if you could tell me when you have any newer version.

    Thanks a lot!

    Joe

  • Hi Joe,

     

    We'll release a next CSL within a month.

     

    Regards,

    Hyun

  • Hi Hyun,

    I just checked the website but I couldn't find any new version of CSL yet. Could you please tell me when you possibly upload it? I am looking forward to it.

    Thanks,

    Joe

  • Hi Joe,

     

    Sorry for the delay. We found the last minute bug and trying to fix it. We are planning to release the new CSL at the end of next week.

     

    Regards,

    Hyun

  • I have a question for JoeTran

     

    Which FAT32 open source did you use? And could you please help me by sending me interface functions for it . You know the ones which utilize mmc_read and mmc_write at low level.

     

    I tried using FullFAT and FatFS but I always get into problems with my code. It hangs somewhere in the MMC_Read or MMC_Write. My guess is that I'm not interfacing the FS with the CSL library correctly. Any helpl will be highly appreciated!!!

     

    Thank you...

  • Hi KungFu Master,

    I was using the source code from here:

    http://elm-chan.org/fsw/ff/00index_e.html

    Yes, you can use mmc_read & mmc_write with it. If it hangs somewhere in MMC_read/write then it's CSL's problem, not the FAT. CSL is being developed & not carefully tested yet so there are still a lot of bugs. I hope they will upload a newer version soon.

    HTH

    Joe

  • Thank you for the prompt answer.

    Did you use CSL functions to interface SD card with the FatFS? I would be very gratefull if you send me the low level drivers (mosty I'm interested in implementation for disk_read and disk_write).

    Cheers!

  • Hi,

    Yes, all source code is included in the new CSL.

    Regards,

    Hyun

  • Hi,

    This is how I implement the disk_read, disk_ioctl & disk_initialize function. Try to see if it works for you.

    DRESULT disk_read (
        BYTE drv,            /* Physical drive nmuber (0) */
        BYTE *buff,            /* Pointer to the data buffer to store read data */
        DWORD sector,        /* Start sector number (LBA) */
        BYTE count            /* Sector count (1..255) */
    )
    {
        int i;
        CSL_Status         result;

            result = MMC_read(mmcsdHandle, sector,
                          ((512)*(count)), (Uint16*)buff);

    //            ataErr = MMC_readNSectors(ataState.pAtaMediaState, (AtaUint16 *) buff, sector, count);
                i = 256 * count;
                do
                {
                    i--;
                    buff[(i<<1) + 1] = HIBYTE(buff[i]);
                    buff[i<<1] = LOWBYTE(buff[i]);
                } while (i);
               
                return result;
    }
    ---------


    DRESULT disk_ioctl (
        BYTE drv,        /* Physical drive nmuber (0) */
        BYTE ctrl,        /* Control code */
        void *buff        /* Buffer to send/receive data block */
    )
    {
        DRESULT res;
        BYTE n, csd[16], *ptr = buff;
        DWORD csize;


        if (drv) return RES_PARERR;
        if (Stat & STA_NOINIT) return RES_NOTRDY;

        res = RES_ERROR;
       
        switch (ctrl) {
            case CTRL_SYNC :    /* Flush dirty buffer if present */
                mmcStatus = MMC_stop(mmcsdHandle);
                break;

            case GET_SECTOR_COUNT :    /* Get number of sectors on the disk (WORD) */
            //    SD_getCardCsd (mmcsdHandle, &sdCardCsdObj);
                *(DWORD*)buff = 0x3AF000;
                res = RES_OK;
                break;

            case GET_SECTOR_SIZE :    /* Get sectors on the disk (WORD) */
                *(WORD*)buff = 512;
                res = RES_OK;
                break;

            case GET_BLOCK_SIZE :    /* Get erase block size in unit of sectors (DWORD) */
                *(DWORD*)buff = 0x2000;
                res = RES_OK;
                break;

            case MMC_GET_TYPE :        /* Get card type flags (1 byte) */
                *ptr = CardType;
                res = RES_OK;
                break;

            case MMC_GET_CSD :    /* Receive CSD as a data block (16 bytes) */

                break;

            case MMC_GET_CID :    /* Receive CID as a data block (16 bytes) */

                break;

            case MMC_GET_OCR :    /* Receive OCR as an R3 resp (4 bytes) */

                break;

            case MMC_GET_SDSTAT :    /* Receive SD statsu as a data block (64 bytes) */

                break;

            default:
                res = RES_PARERR;
        }

        return res;
    }

    -----------

    DSTATUS disk_initialize (
        BYTE drv        /* Physical drive nmuber (0) */
    )
    {

        Uint16       looper;
        Uint16         actCard;
        CSL_CardType cardType = CSL_CARD_NONE;
        Uint32       cardAddr;
        Uint16       clockDiv;
        Uint32       sectCount;

        sectCount = 0;

        /* Get the clock divider value for the current CPU frequency */
        clockDiv = computeClkRate();

        /* Initialize the CSL MMCSD module */
        mmcStatus = MMC_init();
        if(mmcStatus != CSL_SOK)
        {
            printf("API: MMC_init Failed\n");
            return(mmcStatus);
        }

        /* Open the MMCSD module in POLLED mode */
        mmcsdHandle = MMC_open(&pMmcsdContObj, CSL_MMCSD0_INST, CSL_MMCSD_OPMODE_POLLED, &mmcStatus);
        if(mmcStatus != CSL_SOK)
        {
            printf("API: MMC_open Failed\n");
            return(mmcStatus);
        }
        else
        {
            printf("API: MMC_open Successful\n");
        }

        /* Send CMD0 to the card */
        mmcStatus = MMC_sendGoIdle(mmcsdHandle);
        if(mmcStatus != CSL_SOK)
        {
            printf("API: MMC_sendGoIdle Failed\n");
            return(mmcStatus);
        }

        /* Check for the card */
        mmcStatus = MMC_selectCard(mmcsdHandle, &mmcCardObj);
        if(mmcStatus != CSL_SOK)
        {
            printf("API: MMC_selectCard Failed\n");
            return(mmcStatus);
        }

        /* Verify whether the SD card is detected or not */
        if(mmcCardObj.cardType == CSL_SD_CARD)
        {
            printf("SD card Detected!\n");
        }
        else
        {
            /* Check if No card is inserted */
            if(mmcCardObj.cardType == CSL_CARD_NONE)
            {
                printf("No Card Detected!\n");
            }
            else
            {
                printf("SD card is not Detected!\n");
            }

            printf("Please Insert SD card!!\n");
            return(CSL_ESYS_FAIL);
        }

        /* Set the init clock */
        mmcStatus = MMC_sendOpCond(mmcsdHandle, 70);
        if(mmcStatus != CSL_SOK)
        {
            printf("API: MMC_sendOpCond Failed\n");
            return(mmcStatus);
        }

        /* Set the Relative Card Address */
        mmcStatus = SD_sendRca(mmcsdHandle, &mmcCardObj, 0x0000);
        if(mmcStatus != CSL_SOK)
        {
            printf("API: SD_sendRca Failed\n");
            return(mmcStatus);
        }

        /* Send the card identification Data */
        mmcStatus = SD_sendAllCID(mmcsdHandle, &sdCardIdObj);
        if(mmcStatus != CSL_SOK)
        {
            printf("API: SD_sendAllCID Failed\n");
            return(mmcStatus);
        }

        /* Check if the card is high capacity card */
        if(mmcsdHandle->cardObj->sdHcDetected == TRUE)
        {
            printf("SD card is High Capacity Card\n");
            printf("Memory Access will use Block Addressing\n\n");

            /* For the SDHC card Block addressing will be used.
               Sector address will be same as sector number */
            cardAddr = sectCount;
        }
        else
        {
            printf("SD card is Standard Capacity Card\n");
            printf("Memory Access will use Byte Addressing\n\n");

            /* For the SD card Byte addressing will be used.
                 Sector address will be product of  sector number and sector size */
            cardAddr = (sectCount)*(CSL_MMCSD_BLOCK_LENGTH);
        }

        /*  the SD Card Specific Data */
        mmcStatus = SD_getCardCsd(mmcsdHandle, &sdCardCsdObj);
        if(mmcStatus != CSL_SOK)
        {
            printf("API: SD_getCardCsd Failed\n");
            return(mmcStatus);
        }

        /* Set the card type in internal data structures */
        mmcStatus = MMC_setCardType(&mmcCardObj, cardType);
        if(mmcStatus != CSL_SOK)
        {
            printf("API: MMC_setCardType Failed\n");
            return(mmcStatus);
        }

        /* Set the card pointer in internal data structures */
        mmcStatus = MMC_setCardPtr(mmcsdHandle, &mmcCardObj);
        if(mmcStatus != CSL_SOK)
        {
            printf("API: MMC_setCardPtr Failed\n");
            return(mmcStatus);
        }

        /* Get the number of cards */
        mmcStatus = MMC_getNumberOfCards(mmcsdHandle, &actCard);
        if(mmcStatus != CSL_SOK)
        {
            printf("API: MMC_getNumberOfCards Failed\n");
            return(mmcStatus);
        }

        /* Set clock for read-write access */
        mmcStatus = MMC_sendOpCond(mmcsdHandle, clockDiv);
        if(mmcStatus != CSL_SOK)
        {
            printf("API: MMC_sendOpCond Failed\n");
            return(mmcStatus);
        }

        /* Set Endian mode for read and write operations */
          mmcStatus = MMC_setEndianMode(mmcsdHandle, CSL_MMCSD_ENDIAN_LITTLE,
                                        CSL_MMCSD_ENDIAN_LITTLE);
        if(mmcStatus != CSL_SOK)
        {
            printf("API: MMC_setEndianMode Failed\n");
            return(mmcStatus);
        }
       
    //    gLcdBuf[0] = 1;
    //    mmcStatus = MMC_read(mmcsdHandle, 0, 512, gLcdBuf);
    //    if(mmcStatus != CSL_SOK)
    //    {
    //        printf("API: MMC_read Failed\n");
    //        return(mmcStatus);
    //    };
    //   
        return Stat;
    }

  • Thank you for the provided sample code.. My code is very much the same...

    I also have that nasty while loop in the sdcard read and write routines .. I was hoping that you will somehow avoid that :) But I guess that 16 bit to 8 bit conversion must be made (unless someone makes an 16 bit filesystem)

     

    Cheers!