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.

CCS: Integrating FATFS in my code

Expert 1130 points
Part Number: TMDSIDK437X


Tool/software: Code Composer Studio

Hi Team,

I can you help me understand what is missing. I am stuck with this code...

I am trying to perform 'ls' command with the below code.

it seems that I always get the number of files read is 0

I am using terminal pushes for debug and I always get 1..1c..2, when running the below code, 

which means f_opendir and f_readdir seems to work , but the returned file name

(gFsShellAppUtilsFileInfo.fname[0]) is  always NULL

TerminalOutPush("1..");
/* Open the current directory for access. */
strcpy(gFsShellAppUtilsCwd, "0:");
fresult = f_opendir(&gFsShellAppUtilsDirObj, gFsShellAppUtilsCwd);
if (FR_OK != fresult)
{
TerminalOutPush("1a..");  code never goes here .. no error
state = 2;
break;
}

/* Read an entry from the directory. */
fresult = f_readdir(&gFsShellAppUtilsDirObj, &gFsShellAppUtilsFileInfo);
if (FR_OK != fresult)
{
TerminalOutPush("1b.."); code never goes here .. no error
state = 2;
break;
}

/* If the file name is blank, then this is the end of the listing. */
if('\0' == gFsShellAppUtilsFileInfo.fname[0])
{
TerminalOutPush("1c..");code always enters here on the first read
TerminalOutPush(gFsShellAppUtilsFileInfo.fname);
state = 2;
break;
}

/* If the attribute is directory, then increment the directory count. */
if(AM_DIR == (gFsShellAppUtilsFileInfo.fattrib & AM_DIR))
{
dirCount++;
TerminalOutPush("1d.."); code never goes here .. no directories read
}
else // its a file
{
fileCount++;  code never goes here .. file count is zero
totalSize += gFsShellAppUtilsFileInfo.fsize;
TerminalOutPush("1e..");
}

  • Hello R2d2,

    Please provide more information. What are you trying to do? What processor are you using? What kind of software are you running? What version is that software?

    Regards,

    Nick

  • Hi nick,

    I am using idkam437x ethercat slave full example , with addtional code

    I am in the proccess of adding fatfs capabilies to the project.

    I started by adding the fat fs example to my project ( after trying it out)

    I than had to change the cfg file ( based on ethercat full example) for it to compile.

    I am now testing the merge by trying to implement a dir commad.

    I initialize the fat fs as in the example and f_opendir seems to work without error but as you see , i cant understand why i dont get any response...

  • playing around with the code , I tried to make it as simple as it gets so that help will be simpler...

    when I run the below code 

    FATFS_Handle fsHandle = NULL;
    FATFS_Error ferr;

    /* MMCSD FATFS initialization */

    ferr = FATFS_init();  <<<< returned value here is 0

    ferr = FATFS_open(0U, NULL, &fsHandle); <<<< returned value here is -1


    I am using the the following FATFS config variables

    /* 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] =
    {
    //#if defined (SOC_AM65XX) || defined (SOC_J721E) || defined (SOC_J7200)
    // { /* MMC1 is SD card for AM65xx GP EVM */
    // 1U
    // },
    //#else
    {
    0U
    },
    //#endif
    {
    1U
    },
    {
    2U
    },
    {
    3U
    }
    };

    /* FATFS objects */
    FATFS_Object FATFS_objects[_VOLUMES];

    /* FATFS configuration structure */
    const FATFSConfigList FATFS_config = {
    {
    &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}
    };

    any idea what's wrong ?

  • more digging....more questions

    oddly enough , it seems to be associated with board_init configuration

    say I have a test function

    void Test(void)
    {

    FATFS_Error ferr;

    FATFS_init();

    ferr = FATFS_open(0U, NULL, &fsHandle);

    UART_printf("\nopenferr=%d.................\n",ferr);

    }

     


    and I want to call it right after board_init. my code will look like :

    void common_main()
    {

    Board_init(BOARD_INIT_PINMUX_CONFIG | BOARD_INIT_MODULE_CLOCK |
    BOARD_INIT_ICSS_PINMUX | BOARD_INIT_UART_STDIO);

    // this is the first line in the ethercat full example...


    Test();

    ....

    }

    if I use BOARD_INIT_ICSS_PINMUX it will fail

    once I remove it Test() has no errors

    Any idea how to resolve this ?

  • anyone..?

  • Hi,

    >>if I use BOARD_INIT_ICSS_PINMUX it will fail

    Have you tried to enable the option with default fatfs example instead of your integrated project to see if it works?

    Regards, 

    Garrett

  • Hi Garrett,

    if I add BOARD_INIT_ICSS_PINMUX to the board init @ fat fs example , it crashes

    Does this helps ? 

    I need to know 2 things

    1) how to solve this

    2) how should it be considered \ does it have any implications with respect to a custom board design 

    Thanks

  • Any leads guys?

  • Hi,

    When  the BOARD_INIT_ICSS_PINMUX is added, idkAM437x_icssPinMuxFlag is set and skip MMCSD module config, see packages\ti\board\sc\idkAM437x\idkAM437x.c and idkAM437x_pinmux.c

    /* MMCSD */

    if((S_PASS == status) && (idkAM437x_icssPinMuxFlag == 0U))
    {
    status = PINMUXModuleConfig(CHIPDB_MOD_ID_MMCSD, 0U, NULL);
    }

    "The default Board_init() function from Processor SDK has the exclusive ‘BOARD_INIT_ICSS_PINMUX’ and ‘BOARD_INIT_PINMUX_CONFIG’ (CPSW). But from the AM437x IDK schematic, it appears to be no conflict in terms of pin muxing, so you need to remove the ‘idkAM437x_icssPinMuxFlag’ in the board library and rebuild, then you can try to concurrently configure both". see https://e2e.ti.com/support/processors/f/791/p/778872/2883725.

    You may check if there is pin mux conflict with CPSW and ICSS on your board, and if not, pleas try to update board library as well, and see if it works.

    Regards,

    Garret

  • Part Number: TMDSIDK437X

    Hi Team,

    I want to continue the discussion the started at https://e2e.ti.com/support/tools/ccs/f/81/t/902871

    (I tired to put this as under the same topic but maybe since topic is closed  it was missed)

    after I found that when I add BOARD_INIT_ICSS_PINMUX to the board_init of the fatfs example , the code crashes,

    Garret found the idkAM437x_icssPinMuxFlag in the pdk package that makes disables the MMCSD pinmux when BOARD_INIT_ICSS_PINMUX  is set,

    and suggested to change and re-compile the PDK

    working with PDK 1_0_17 , I could not compile it till yesterday , when Frank found a bug in the make file.

    Now , I have modified the code so that the flag idkAM437x_icssPinMuxFlag  is commented out

    /* MMCSD */

    if((S_PASS == status) /*&& (idkAM437x_icssPinMuxFlag == 0U)*/)
    {
    status = PINMUXModuleConfig(CHIPDB_MOD_ID_MMCSD, 0U, NULL);
    }

    when I try this , it still doesn't work : when I add the highlighted part to the FATFS Board_init code at main_console.c

     boardCfg = BOARD_INIT_PINMUX_CONFIG | BOARD_INIT_UART_STDIO | BOARD_INIT_MODULE_CLOCK | BOARD_INIT_ICSS_PINMUX;

    the example hangs. I tired with and without FATFS_GPIO_ENABLED define , but it does not seems to be associated with it

    I need help in understanding the reasoning for the flag , so that we can be sure that the planned custom board design will be successful,

    as well as solve this for the IDKAM437x which will allow me to continue test and develop the application

    Thanks

    R2

  • any leads ?

  • please see attached image - from the schematics

    is this the limitation ? If I remove R514 , will it allow me have both fat fs and ethercat , but without endat ?

  • Hi,

    Sorry, I just got chance to look into the issue. Can you please check if CONTROL_MODULE 0x44E1_0000 with offset 8F4h to see if the pad mode is set to mode 0 (refer to datasheet, pin B2)? If it's true and you don't have Endat firmware run, the resistor R514 should be irrelevant.

    Did you step into the code to see if the 'not working' symptom is the same with idkAM437x_icssPinMuxFlag update?

    Regards,

    Garrett

  • Hi ,

    I did try to remove the flag. I had issues rebuilding the xx17 pdk , which turned out to be a bug which Frank showed be ho to bypass.

    when I remove the flag and rebuild the pdk (with Frank's bypass) , the fatfs example no longer hangs when I add the PRUICSS board init flag , but it does not work , and fatfs errors are returned whatever I do.

    can you please further explain what I need to test :

    "Can you please check if CONTROL_MODULE 0x44E1_0000 with offset 8F4h to see if the pad mode is set to mode 0 (refer to datasheet, pin B2)"

    where do I look for for the "CONTROL_MODULE" ?

  • Hi,

    CONTROL_MODULE is described in TRM section 7. By checking the registers with offset as below from CCS, you can confirm the pin are multiplexed properly:

    8F0h CTRL_CONF_MMC0_DAT3 Section 7.3.1.106
    8F4h CTRL_CONF_MMC0_DAT2 Section 7.3.1.107
    8F8h CTRL_CONF_MMC0_DAT1 Section 7.3.1.108
    8FCh CTRL_CONF_MMC0_DAT0 Section 7.3.1.109
    900h CTRL_CONF_MMC0_CLK Section 7.3.1.110
    904h CTRL_CONF_MMC0_CMD Section 7.3.1.111

    Regards,

    Garrett