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.

OMAP-L138: MMCSD -> Hang during work

Part Number: OMAP-L138

Hello,

I'm using the latest SDK (pdk 1.0.9) and I have a problem with MMCSD.

Sometimes during read/write a program hangs on the MMCSD_v0_transfer fucntion and never goes forward again.

The same problem I have found there  -> http://e2e.ti.com/support/processors/f/791/t/649423 

but I didn't find a solution there..

Could you help me solve this problem?

Best regards,

Patryk

  • Hello Patryk,

    Are you using DMA? I ask because there was a bug in the EDMA PaRAM settings that caused the MMCSD driver to hang when more than 4 MB of data was being transferred. This bug has been fixed and is planned to be released with Processor SDK 6.1.

    If not using DMA, are you observing this hang with all data sizes or just when transferring over a certain amount? And is this with only MMCSD or do you have other modules running in your application?

    Regards,
    Sahin

  • Hello Sahin,

    I'm not using DMA, I know this problem because I reported it myself.

    This problem occurs for all sizes because it occurs for different functions:  f_read, f_write, f_open, f_mount, etc

    In my main application I also have other modules and I am working on a custom board but I did a test where I am only using MMCSD on the LCDK board and sometimes I observe the same problem.

    The function MMCSD_v0_xferStatusFx2() has a very big problem because when I enter it and some error occurs, it is never left and the application becomes useless.

    Regards,

    Patryk

  • Hi Patryk,

    We are trying to reproduce this issue on our end - could you please share what error you are getting? And under which conditions do you observe the hang? 

    If you are able to provide a test case for us that would be helpful as well.

    Regards,
    Sahin

  • Hi Sahin,

    I don't notice any errors because mmcsd hangs and return nothing.

    I am currently left of my company but I am comming back on thursday and I will send my test to you and I will describe when the problem occurs.

    Regards,

    Patryk

  • Hi Sahin, 

    I did some tests using different SD cards and each card behaves differently...

    I have only one card which works properly.

    One card hangs on f_open the other after a few seconds on f_write, etc...

    In my test program LED D4 indicates  the operation status (when blink all works fine).

    Please, try to do the tests for different cards and see if you never run into this problem

    All cards work correctly on other devices...

    I work on the MMCSD_FatfsConsole_lcdkOMAPL138_armExampleProject

    Regards, Patryk

    mmcsd_test.cfg

    /**
     *  \file   main_fatfs_console.c
     *
     *  \brief  Example application main file. This application demonstartes
     *          the file operations on FAT formatted MMCSD device.
     *
     */
    
    /*
     * Copyright (C) 2014-2017 Texas Instruments Incorporated - http://www.ti.com/
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * Redistributions of source code must retain the above copyright
     * notice, this list of conditions and the following disclaimer.
     *
     * Redistributions in binary form must reproduce the above copyright
     * notice, this list of conditions and the following disclaimer in the
     * documentation and/or other materials provided with the
     * distribution.
     *
     * Neither the name of Texas Instruments Incorporated nor the names of
     * its contributors may be used to endorse or promote products derived
     * from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    
    
    /* XDCtools Header files */
    #include <xdc/std.h>
    #include <xdc/cfg/global.h>
    #include <xdc/runtime/System.h>
    #include <stdio.h>
    #include <ti/sysbios/knl/Task.h>
    
    /* BIOS Header files */
    #include <ti/sysbios/BIOS.h>
    #ifdef MMCSD_EDMA_ENABLED
    #include <ti/sysbios/family/arm/a15/Cache.h>
    #include <ti/sdo/edma3/drv/edma3_drv.h>
    #include <ti/sdo/edma3/rm/edma3_rm.h>
    #include <ti/sdo/edma3/drv/sample/bios6_edma3_drv_sample.h>
    #endif
    #include <xdc/runtime/Error.h>
    
    /* TI-RTOS Header files */
    #include <ti/csl/cslr_device.h>
    #include "MMCSD_log.h"
    #include <ti/fs/fatfs/diskio.h>
    #include <ti/fs/fatfs/FATFS.h>
    #include <ti/drv/mmcsd/MMCSD.h>
    #include <ti/drv/mmcsd/soc/MMCSD_soc.h>
    #include <ti/drv/mmcsd/example/fatfs_console/src/fs_shell_app_utils.h>
    
    #include <ti/board/board.h>
    
    #include <ti/drv/gpio/GPIO.h>
    #include <ti/drv/gpio/soc/GPIO_soc.h>
    #include <ti/csl/hw_types.h>
    
    #ifdef MMCSD_EDMA_ENABLED
    #if defined(SOC_K2G)
    /* MMCSD is connected to EDMA_1 for K2G */
    #define MMCSD_EDMACC_NUM 1
    #else
    #define MMCSD_EDMACC_NUM 0
    #endif
    #endif
    
    #define OMAP_LCDK_BOARD //If have not defined OMAP_LCDK_BOARD -> program on a custom board
    /**********************************************************************
     ************************** Macros ************************************
     **********************************************************************/
    /* MUX selection for K2G */
     #define GPIO_MUX_SEL 4
    #ifdef OMAP_LCDK_BOARD
    #define GPIO_PIN_MMC_SDCD_ACTIVE_STATE 0
    #else
    #define GPIO_PIN_MMC_SDCD_ACTIVE_STATE 1
    #define GPIO_LED_EXT1_PIN_NUM           (134U) //GP8[6]
    #include <ti/csl/csl_syscfg.h>
    #endif
    /**********************************************************************
     ************************** Internal functions ************************
     **********************************************************************/
    
    
    /**********************************************************************
     ************************** Global Variables **************************
     **********************************************************************/
    char fname[32];
    uint8_t SD_Buffer[262144];
    
    int licz=0;
    int pomocnicza_fil = 0;
    int licznik_petli = 0;
    
    /* ON Board LED pins which are connected to GPIO pins. */
    typedef enum GPIO_PIN {
        GPIO_PIN_MMC_SDCD      = 0U,
        GPIO_PIN_LED0,
        GPIO_PIN_COUNT
    }GPIO_PIN;
    
    /* GPIO Driver board specific pin configuration structure */
    GPIO_PinConfig gpioPinConfigs[] = {
        /* Output pin : AM335X_ICE V2_LD_PIN */
        GPIO_DEVICE_CONFIG(GPIO_MMC_SDCD_PORT_NUM, GPIO_MMC_SDCD_PIN_NUM) |
        GPIO_CFG_IN_INT_BOTH_EDGES | GPIO_CFG_INPUT,
    #ifdef OMAP_LCDK_BOARD
        GPIO_DEVICE_CONFIG(GPIO_LED0_PORT_NUM, GPIO_LED0_PIN_NUM) |GPIO_CFG_OUTPUT,
    #else
        GPIO_DEVICE_CONFIG(GPIO_LED0_PORT_NUM, GPIO_LED_EXT1_PIN_NUM) |GPIO_CFG_OUTPUT,
    #endif
    };
    
    /* GPIO Driver call back functions */
    GPIO_CallbackFxn gpioCallbackFunctions[] = {
        NULL,
        NULL,
    };
    
    /* GPIO Driver configuration structure */
    #if defined(SOC_K2G) || defined(SOC_OMAPL137) || defined(SOC_OMAPL138)
    GPIO_v0_Config GPIO_v0_config = {
        gpioPinConfigs,
        gpioCallbackFunctions,
        sizeof(gpioPinConfigs) / sizeof(GPIO_PinConfig),
        sizeof(gpioCallbackFunctions) / sizeof(GPIO_CallbackFxn),
        0,
    };
    #else
    GPIO_v1_Config GPIO_v1_config = {
        gpioPinConfigs,
        gpioCallbackFunctions,
        sizeof(gpioPinConfigs) / sizeof(GPIO_PinConfig),
        sizeof(gpioCallbackFunctions) / sizeof(GPIO_CallbackFxn),
        0,
    };
    #endif
    
    /* MMCSD function table for MMCSD implementation */
    FATFS_DrvFxnTable FATFS_drvFxnTable = {
        MMCSD_close,
        MMCSD_control,
        MMCSD_init,
        MMCSD_open,
        MMCSD_write,
        MMCSD_read
    };
    
    /* FATFS configuration structure */
    FATFS_HwAttrs FATFS_initCfg[_VOLUMES] =
    {
        {
            0U
        },
        {
            1U
        },
        {
            2U
        },
        {
            3U
        }
    };
    
    /* FATFS objects */
    FATFS_Object FATFS_objects[_VOLUMES];
    
    /* FATFS configuration structure */
    const FATFS_Config FATFS_config[_VOLUMES + 1] = {
        {
            &FATFS_drvFxnTable,
            &FATFS_objects[0],
            &FATFS_initCfg[0]
        },
    
        {
             &FATFS_drvFxnTable,
             &FATFS_objects[1],
             &FATFS_initCfg[1]
        },
    
        {
             &FATFS_drvFxnTable,
             &FATFS_objects[2],
             &FATFS_initCfg[2]
        },
    
        {NULL, NULL, NULL},
    
        {NULL, NULL, NULL}
    };
    
    FATFS_Handle fatfsHandle = NULL;
    
    Uint32 fatfsShellProcessFlag = 0;
    
    /* Callback function */
    void AppGpioCallbackFxn(void);
    
     void board_initGPIO(void)
    {
        
    #if defined(SOC_K2H) || defined(SOC_K2K) || defined(SOC_K2E) || defined(SOC_K2L) || defined(SOC_K2G) || defined(SOC_C6678) || defined(SOC_C6657) || defined(SOC_OMAPL137) || defined(SOC_OMAPL138)
        GPIO_v0_HwAttrs gpio_cfg;
    
        /* Get the default SPI init configurations */
        GPIO_socGetInitCfg(GPIO_MMC_SDCD_PORT_NUM, &gpio_cfg);
    
        /* Modify the default GPIO configurations if necessary */
    
        /* Set the default GPIO init configurations */
        GPIO_socSetInitCfg(GPIO_MMC_SDCD_PORT_NUM, &gpio_cfg);
    
    #if defined(SOC_K2G)
        /* Setup GPIO interrupt configurations */
        GPIO_socSetIntMux(GPIO_MMC_SDCD_PORT_NUM, GPIO_MMC_SDCD_PIN_NUM, NULL, GPIO_MUX_SEL);
    #endif
    #if defined(SOC_OMAPL137) || defined(SOC_OMAPL138)
        /* Setup GPIO interrupt configurations */
        GPIO_socSetBankInt(GPIO_MMC_SDCD_PORT_NUM, GPIO_MMC_SDCD_PIN_NUM, NULL);
    #endif
    #endif
    
    #ifdef OMAP_LCDK_BOARD
    #else
        //LED ARR_X -> GP8[6]
        hSysCfg->PINMUX3 &= (~(0x00000F00));
        hSysCfg->PINMUX3 |= 0x400;
    #endif
    }
    
    /*
     *  ======== test function ========
     */
    void mmcsd_fatfs_console(UArg arg0, UArg arg1)
    {
    #ifdef MMCSD_EDMA_ENABLED
        EDMA3_DRV_Result edmaResult = 0;
        EDMA3_RM_Handle gEdmaHandle = NULL;
    #endif
    #if defined(SOC_OMAPL137) || defined(SOC_OMAPL138)
        MMCSD_v0_HwAttrs hwAttrsConfig;
    #else
        MMCSD_v1_HwAttrs hwAttrsConfig;
    #endif
    
        /* Perform board specific GPIO init  */
        board_initGPIO();
    #ifdef MMCSD_EDMA_ENABLED
        gEdmaHandle = (EDMA3_RM_Handle)edma3init(MMCSD_EDMACC_NUM, &edmaResult);
    #endif
        if(MMCSD_socGetInitCfg(0,&hwAttrsConfig)!=0) {
           MMCSD_log ("\nUnable to obtain MMCSD config.Exiting. TEST FAILED.\r\n");
           return;
        }
    #ifdef MMCSD_EDMA_ENABLED
        hwAttrsConfig.edmaHandle = gEdmaHandle;
    #endif
        hwAttrsConfig.enableDma = 0;
        hwAttrsConfig.enableInterrupt = 0;
    
        hwAttrsConfig.inputClk = 456000000/2;
    
    
        if(MMCSD_socSetInitCfg(0,&hwAttrsConfig)!=0) {
            MMCSD_log ("\nUnable to set config.Exiting. TEST FAILED.\r\n");
             return;
        }
    
        /* GPIO initialization */
        GPIO_init();
    
        /* Set the callback function */
        GPIO_setCallback(GPIO_PIN_MMC_SDCD, AppGpioCallbackFxn);
    
        /* Enable GPIO interrupt on the specific gpio pin */
        GPIO_enableInt(GPIO_PIN_MMC_SDCD);
    
        /* MMCSD FATFS initialization */
        FATFS_init();
    
        if (GPIO_PIN_MMC_SDCD_ACTIVE_STATE == GPIO_read(GPIO_PIN_MMC_SDCD))
        {
            FATFS_open(0U, NULL, &fatfsHandle);
            fatfsShellProcessFlag = 1;
        }
        else
        {
            MMCSD_log ("\nPlease insert card.\r\n");
        }
    
        while(1)
        {
            if (0 != fatfsShellProcessFlag)
            {
                static FIL fil;
                FRESULT fres;
                static unsigned int cnt = 0;
                static unsigned int completeOpen = 0;
    
                DIR dir;
                static FILINFO fno;
                char buff[256];
    
    
                licznik_petli = 0;
                /* Create file name */
                sprintf(fname, "TestABV%i.txt", licz);
                if(licz >= 1499)
                {
                    break; //1500x10MB
                }
                licz++;
    
                strcpy(buff, "/");
    
                fres = f_open(&fil, fname, FA_CREATE_ALWAYS | FA_READ | FA_WRITE);
    
                fres = FR_OK;
                if (fres == FR_OK)
                {
                    completeOpen = 1;
                    Task_sleep(1000);
                }
                else
                {
                    completeOpen = 0;
                }
                while(completeOpen)
                {
    #ifdef MMCSD_EDMA_ENABLED
                    CacheP_wbInv((void *)(uintptr_t)SD_Buffer, (int32_t)sizeof(SD_Buffer));
    #endif
                    fres = f_write(&fil, SD_Buffer, sizeof(SD_Buffer), &cnt);
                    if(fres == FR_OK)
                    {
                        if(licznik_petli >=40) //10MB
                        {
                            f_close(&fil);
                            break;
                        }
                    }
                    else if(fres == FR_DISK_ERR)
                    {
                        break;
                    }
    
                    fres = f_opendir(&dir, buff);           /* Open the directory */
                    if (fres == FR_OK)
                    {
                        fres = f_readdir(&dir, &fno);       /* Read a directory item */
    
                    }
                    if(fres == FR_OK)
                    {
                        f_closedir(&dir);
                    }
    
                    licznik_petli++;
                    GPIO_toggle(GPIO_PIN_LED0);
                    if(licznik_petli%20 == 0)
                    {
                        licznik_petli = licznik_petli;
                        f_sync(&fil);
    
                    }
                }
            }
        }
    }
    
    /*
     *  ======== main ========
     */
    int main(void)
    {
        Task_Handle task;
        Error_Block eb;
        /* Call board init functions */
        Board_initCfg boardCfg;
        boardCfg = BOARD_INIT_PINMUX_CONFIG | 
            BOARD_INIT_MODULE_CLOCK | BOARD_INIT_UART_STDIO;
        Board_init(boardCfg);
    
        Error_init(&eb);
        task = Task_create(mmcsd_fatfs_console, NULL, &eb);
        if (task == NULL) {
            System_printf("Task_create() failed!\n");
            BIOS_exit(0);
        }
    
        /* Start BIOS */
        BIOS_start();
        
        return (0);
    }
    
    
    /*
     *  ======== Callback function ========
     */
    void AppGpioCallbackFxn(void)
    {
        if (GPIO_PIN_MMC_SDCD_ACTIVE_STATE == GPIO_read(GPIO_PIN_MMC_SDCD))
        {
            FATFS_open(0U, NULL, &fatfsHandle);
            fatfsShellProcessFlag = 1;
        }
        else
        {
            FATFS_close(fatfsHandle);
            fatfsShellProcessFlag = 0;
        }
    }
    

  • Hi Patryk,

    Thanks for the update. I will test this on my end and get back to you.

    By the way, which SD cards are you using?

  • I'm using:

    - Goodram 8 GB SDHC (I have two cards and one works correctly)

    - Sandisk 16 GB SD

    - Sandisk ultra 16gb SDHC

    - and other old microSD cards

  • Hi,

    Any news?

    Regards,

    Patryk

  • Hi Patryk,

    I haven't been able to reproduce the hang on my end yet. The program is creating TestABV0.txt, TestABV1.txt, etc., and filling with NULL characters. How far in are you typically seeing the hang?

    So far I've tried with a Kingston 16GB microSDHC card and a SanDisk 32GB microSDHC card.

    Regards,
    Sahin

  • Hi Sahin, 

    It's different for different cards. I noticed that the problem doesn't occur for all cards. For one card the problem appeared after save 3x10MB, other after 534x10MB. It's random, and I find it worse because we don't notice this problem.

    By the way, I noticed a strange behavior because when I disabled MMU: Mmu.enableMMU = false; the program always works fine and I have never seen a problem on the cards.

    Regards,

    Patryk

  • Hi Patryk,

    Patryk_93 said:

    By the way, I noticed a strange behavior because when I disabled MMU: Mmu.enableMMU = false; the program always works fine and I have never seen a problem on the cards.

    Given this, I would suspect the issue lies in the MMU configuration. What happens if you enable the MMU but disable cache? Do you still see the issue?

    There was an almost identical issue for another device that was resolved in the following thread. Could you please see if the resolution there helps?

    https://e2e.ti.com/support/processors/f/791/t/738509?RTOS-AM5728-Conflict-between-MMU-configuration-and-FATFS

    I've just received a couple more SD cards I'm going try to reproduce this with in the meantime. 

    Regards,
    Sahin

  • Hi Sahin,

    Today I'm doing tests and I noticed that when I have disable the cache and enable the MMU this behavior is the same.

    BTW I also noticed that my other program suspended while doing first operation on the SD card (even though, I had disable MMU/cache... but I noticed it only once and I never reproduced this issue), generaly for disable MMU/Cache program works fine.

    My MMU configuration is only in the *.cfg file.

    Regards,

    Patryk

  • Ohh, I again noticed the suspension of the program with the MMU disable... This means that the MMU only reduces the frequency of the problem..

  • Hi Sahin,

    I did a lot of test today and I noticed that the problem is dependent of the SD card but I think that the MMCSD driver should protect against a situation in which we use inferior cards.

    Regards,

    Patryk

  • Hi Patryk

    Thank you for the persistence on this debug - looks like you are able to attribute this to SD card variability.

    While we try to test the MMC/SD driver with several type of cards , it is unrealistic to expect the driver to be robust against every brand/make of the card.
    These things are always tricky with removal media  like MMC/SD cards and USB sticks... we do our best to try test against several vendors, but it is typically never enough.

    This is where some times the Linux drivers are more robust because they are "community" tested across several platforms and several users. I am assuming your application is purely running on RTOS for both ARM and DSP side?

    It would be good to understand what were the cards brand/type/memory size that you tested and which ones were not working well for you. If time permits we can try to evaluate similar cards to see if we are able to reproduce the issues - however I would not hold that as a commit to add further robustness to the driver in a future release etc.

    Regards

    Mukul 

  • Hi Mukul,

    Thanks for your message!

    This is where some times the Linux drivers are more robust because they are "community" tested across several platforms and several users. I am assuming your application is purely running on RTOS for both ARM and DSP side?

    Yes, My application running purely on RTOS ARM. On the DSP I'm not using RTOS.

    I have only one card which works well. But I have two the same cards and one of them not works fine.

    I noticed that for each cards the "hang problem" occured always at the same point (for example: first cards while writting 524288B other while reading XXX B) but each card has a different weak point.

    List of my cards:

    Regards,

    Patryk

  • Hi,

    I prepared a test program for your friend but I think that also may be useful for you.

    I changed in the ffconfig.h #define _FS_RPATH 0 to > #define _FS_RPATH 2

    You can change ftp user name, ftp password, ip, ip mask and ip gateway in usm_emac.c in project files.

    Below are default value:
    char ftpSetUserName[] = "test";
    char ftpSetPassword[] = "test";
    char *ipAddr = "192.168.1.211";
    char *ipMask = "255.255.255.0";
    char *ipGateway = "192.168.1.254";

    Try to connect the RJ45 cable to use FTP

    Btw, I'm using:

    -> ti-processor-sdk-rtos-omapl138-lcdk-06.00.00.07-Windows-x86-Install.exe

    -> CCS 9.2.0.00013

    If you can't find the card that is the problem, I can send you one of my cards.

    Regards,

    Patryk

    4150.EMAC_TEST2.zip

  • Hi Patryk,

    Thank you for the test program. I'm sorry for the delay with this, we should be able to test this and have a response for you by early next week.

    Regards,
    Sahin

  • Hi Patryk,

    We are actively working on this issue in your other thread below so I will close this one.

    https://e2e.ti.com/support/processors/f/791/t/842448

    Reiterating Mukul's sentiment's above, please kind in mind that we are providing our best effort to get your issue resolved, but we cannot guarantee complete driver robustness against all types of SD cards as different brands/types of SD cards have their own quirks which can unfortunately make it tricky to provide robustness against all card types. 

    Regards,
    Sahin

  • Hi Sahin,

    I'll be watching a linked thread, thank you for your effort.

    Regards,

    Patryk