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.

MCU-PLUS-SDK-AM243X: Activating FreeRTOS+FAT RAM disk utility

Part Number: MCU-PLUS-SDK-AM243X

Tool/software:

Hi,

I'm failing to activate FreeRTOS+FAT RAM disk. (part of the SDK)

My code:

void vCreateRAMDisk(void)
{
/* Define the size of the RAM disk. */
const uint32_t ulRAMDiskSectorCount = 1024;
const uint32_t ulSectorSize = 512; /* Each sector is 512 bytes. */
const size_t xIOManagerCacheSize = 2048; /* Minimum 2 * ulSectorSize. */
uint8_t *pucRAMDiskBuffer;
FF_Disk_t *pxDisk;

/* Allocate memory for the RAM disk. */
pucRAMDiskBuffer =  p = vPartMalloc( ulRAMDiskSectorCount * ulSectorSize );
if (pucRAMDiskBuffer == NULL)
{
/* Handle error: Not enough memory. */
printf("Not enough memory to allocate RAM disk buffer.\r\n");
return;
}

/* Create the RAM disk. */
pxDisk = FF_RAMDiskInit("RAMDisk", pucRAMDiskBuffer, ulRAMDiskSectorCount, xIOManagerCacheSize);

/* Check the RAM disk was created successfully. */
if (pxDisk != NULL)
{
/* Print disk name. */
printf("RAM disk created.\r\n");

 /* Create a file on the RAM disk. */
 FF_FILE *pxFile = ff_fopen("ram:/example.txt", "w");    <------------------------  fails
 if (pxFile != NULL)
 {
 const char *pcMessage = "Hello, RAM disk!";
 ff_fwrite(pcMessage, 1, strlen(pcMessage), pxFile);
 ff_fclose(pxFile);
 printf("File created successfully on RAM disk.\r\n");
 }
 else
 {
 /* Handle error opening file. */
 printf("Failed to open file on RAM disk.\r\n");
 }
}
else
{
/* Handle error. */
printf("Failed to create RAM disk.\r\n");
}

}

I get to the point where the disk is created but  FF_FILE *pxFile = ff_fopen("ram:/example.txt", "w");    <------------------------  fails

Is there an example TI code that I can use in my app ?

Thanks,

Eli

  • Hi Eli,

    We have the FreeRTOS+FAT support for filesystems in SD/eMMC only as mentioned in the documentation.

    https://software-dl.ti.com/mcu-plus-sdk/esd/AM64X/09_02_01_05/exports/docs/api_guide_am64x/FS_FREERTOS_FAT.html

    So, there are no examples for the RAM disk from TI.

    Regards,

    Prashant

  • Hi Prashant,

    Yes that's what I thought.

    Did you ever tried to activate the ram disk ? 

    It should basically be a call to a single function pxDisk = FF_RAMDiskInit();

    It gets initialized but not mounted because  the prvFormatGetClusterSize() function fails.

    If you have a few minutes to look at it - it'll be a big help.

    Thanks,

    Regards,

    Eli

  • Hi Eli,

    Just out of curiosity, I went ahead and debugged the issue. During the process, I realized the following inconsistencies in your code.

    • const uint32_t ulRAMDiskSectorCount = 1024
      • The number of sectors here are not enough to format the partition as FAT16. If I am not wrong, the minimum partition size should be 4MB for it to be formatted as FAT16.
    • pxDisk = FF_RAMDiskInit("RAMDisk", pucRAMDiskBuffer, ulRAMDiskSectorCount, xIOManagerCacheSize);
      • The name "RAMDisk" here is not correct. This should always start with "/" and then any custom string like "/ramdisk".
    • FF_FILE *pxFile = ff_fopen("ram:/example.txt", "w");
      • The path must start with the previously created identifier like "/ramdisk/example.txt".

    With the above points & a little bit of porting, I was able to create a test function out of your code and make it work successfully.

    /* Section ".bss.buf" is allocated to DDR */
    #define SIZE 0x600000
    uint8_t buf[SIZE] __attribute__((section(".bss.buf")));
    
    FF_Disk_t _pxDisk;
    
    void test_func()
    {
        /* Define the size of the RAM disk. */
        const uint32_t ulSectorSize = 512; /* Each sector is 512 bytes. */
        const uint32_t ulRAMDiskSectorCount = SIZE / ulSectorSize;
        const size_t xIOManagerCacheSize = 2048; /* Minimum 2 * ulSectorSize. */
        uint8_t *pucRAMDiskBuffer;
        FF_Disk_t *pxDisk;
    
        /* Allocate memory for the RAM disk. */
        pucRAMDiskBuffer = (void*)&buf[0];
    
        if (pucRAMDiskBuffer == NULL)
        {
            /* Handle error: Not enough memory. */
            DebugP_log("Not enough memory to allocate RAM disk buffer.\r\n");
            return;
        }
    
        /* Create the RAM disk. */
        pxDisk = FF_RAMDiskInit("/ramdisk", &_pxDisk, pucRAMDiskBuffer, ulRAMDiskSectorCount, xIOManagerCacheSize);
    
        /* Check the RAM disk was created successfully. */
        if (pxDisk != NULL)
        {
            /* Print disk name. */
            DebugP_log("RAM disk created.\r\n");
    
            /* Create a file on the RAM disk. */
            FF_FILE *pxFile = ff_fopen("/ramdisk/example.txt", "w");
            if (pxFile != NULL)
            {
                const char *pcMessage = "Hello, RAM disk!";
                ff_fwrite(pcMessage, 1, strlen(pcMessage), pxFile);
                ff_fclose(pxFile);
                DebugP_log("File created successfully on RAM disk.\r\n");
            }
            else
            {
                /* Handle error opening file. */
                DebugP_log("Failed to open file on RAM disk.\r\n");
            }
        }
        else
        {
            /* Handle error. */
            DebugP_log("Failed to create RAM disk.\r\n");
        }
    }

    Here are the successful logs:

    [19:25:34.120] Starting NULL Bootloader ...
    
    [19:25:34.125] DMSC Firmware Version 9.2.8--v09.02.08 (Kool Koala)
    [19:25:34.129] DMSC Firmware revision 0x9
    [19:25:34.130] DMSC ABI revision 3.1
    
    [19:25:34.179] FF_Partition:
    [19:25:34.181] FF_Format: Secs 12280 Rsvd 1 Hidden 8 Root 32 Data 12247
    [19:25:34.186] FF_Format: SecCluster 1 DatSec 12151 DataClus 12151 pxSet->ulClusterBeginLBA 105
    [19:25:34.194] FF_Format: Clearing entire FAT (2 x 48 sectors):
    [19:25:34.199] FF_Format: Clearing done
    [19:25:34.201] FF_Format: Clearing root directory at 00000069: 32 sectors
    [19:25:34.207] FF_RAMDiskInit: FF_Format:
    [19:25:34.211] FF_RAMDiskInit: FF_Mount:
    [19:25:34.214] RAM disk created.
    [19:25:34.215] File created successfully on RAM disk.

    The RAM disk implementation layer (ff_ramdisk.c) is actually common so you should not see any issues using it with MCU+ SDK after the above resolution. In case you encounter any issues, here are the steps you may follow:

    • Compare the RAM disk layer (ff_ramdisk.c) with the MMCSD layer (ff_mmcsd.c) from TI. This is the only delta.
    • Add debug logs like shown in the above logs by replacing the FF_PRINTF macro with printf or DebugP_log. This is how I debugged & root caused the issue.

    This should be enough to get you going with using the ramdisk layer. But just in case, please note the Free RTOS FAT+ Filesystem support from us will be best effort basis. We expect the customers to leverage the open source community for the open source projects that we use as it is. 

    Regards,

    Prashant

  • Hi Prashant,

    I'll try your suggestion.

    Many Thanks !!!

    Regards,

    Eli