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.

TMS570LS3137: Read/Write from SD Card

Part Number: TMS570LS3137
Other Parts Discussed in Thread: HALCOGEN, , TMS570LC4357

Hello everyone !!

I have a question about this card. I want to know how I can read on an SD card. For example, I have to pass 8 bytes to the SD card, and I wanted to know if there is an instruction to write these 8 bytes.

Then, I would need to read those bytes and transmit them by CAN protocol.

Is there any instruction to do this, or any example on the SD card to write and read data?

If not, can I do this with EEPROM memory, read and write from a specific place?

Thank you so much for your help,

  • Hi Federico,

    I have a question about this card. I want to know how I can read on an SD card. For example, I have to pass 8 bytes to the SD card, and I wanted to know if there is an instruction to write these 8 bytes.

    Then, I would need to read those bytes and transmit them by CAN protocol.

    Is there any instruction to do this, or any example on the SD card to write and read data?

    In general SD cards will use FAT file system to access the data. Using this library, we can write data in the form of files. Example we can create a text file and can write the data to that file, and we can again read that data whenever required.

    To do this we have different API's will be available, example:

    1. Open the File:

               Use the “f_open” function to open the file. If the file does not exist. This function can create a new file.

    1. Write Data:

              Use the “f_write” function to write the data to the opened file. You need to provide the file handle, buffer containing data to be written, number of bytes to write and a pointer to the actual number of bytes written.

    1. Read Data:

               Use the “f_read” function to read the data of the opened file.

    1. Close the File:

                After writing the data, close the file using “f_close” function.

    For demo example you can refer below link:

    (+) TMS570LS3137: I couldn't find the SD Card library for the corresponding MCU. - Arm-based microcontrollers forum - Arm-based microcontrollers - TI E2E support forums

    If not, can I do this with EEPROM memory, read and write from a specific place?

    Yes, you can do with EEPROM as well. We have FEE(Flash Emulated EEPROM) driver, using this driver the Flash Bank-7 in the device can be used as EEPROM.

    You can just find this example in HALCoGen itself.

    Go to the "Help Topics" section:

    Here in examples section, you can find the example called "example_TI_Fee_write_Read"

    Here you can find, step by step instructions to create the Fee example.

    And also refer FEE user guide to understand the routines:
    6052.TI FEE User Guide.pdf

    --
    Thanks & regards,
    Jagadish.

  • Hello Jagadish, thank you for your help.

    I downloaded the example for the SD card, and I noticed that it is for an RM48 HDK. Can I use this project in my TMS570LS3137? 

    Thank you !!

    Fede

  • Hi Federico,

    My suggestion would be below.

    Don't try to debug directly, instead of just create a new project for TMS570LS3137 and do the HALCoGen modifications as per the RM48 and generate the code.

    Now include SD card application related files to the TMS570LS3137 project and make sure no build errors. Once you did that then try to debug the project.

    --
    Thanks & regards,
    Jagadish.

  • Hello Jagadish,

    Perfect, I'll try it!

    Thank you for your help!

  • Sorry, I didn't find the .hcg in the SD example. Could you share it?

    Thank you! 

  • Sorry, I didn't find the .hcg in the SD example. Could you share it?

    Just now i realized that, let me check with my colleague.

  • Hi Federico,

    Please use below project, it has .hcg file as well.

    7356.RM48 HDK RevE SDCard Demo.zip

    --
    Thanks & regards,
    Jagadish.

  • Hello Jagadish!

    I noticed that the RM48 HDK project is a little different from the TMS570.

    For example, on the PINMUX item, in the RM48 there is a 'USB Device' option that there is not on the TMS570.

    RM48:

    TMS570:

    And another doubt about it. I  want to use the SD card in a FreeRTOS project. The RM48 maks that need it the 'Enable RTI Driver'. Is this necessary? Because I cannot enable the RTOI with the FreeRTOS project. 

    Thank you for your help!

  • Hi Federico,

    For example, on the PINMUX item, in the RM48 there is a 'USB Device' option that there is not on the TMS570.

    USB PINMUX configuration is not required, you can ignore that and try to follow other configurations.

    And another doubt about it. I  want to use the SD card in a FreeRTOS project. The RM48 maks that need it the 'Enable RTI Driver'. Is this necessary? Because I cannot enable the RTOI with the FreeRTOS project.

    RTI is also no need to enable, i just verified all the RTI API's in the RM48 project actually they are not calling any of those RTI API's. So you can ignore RTI configurations as well.

    --
    Thanks & regards,
    Jagadish.

  • Perfect, tahak you for your help.

    I tried the code, but I received a _dabort on the f_mount  function. I'm not sure if this is the step by step to record on the SD card.

       /** - Configure MibSPI3 for SD card application */
        spiInit();
       //     esmInit();
        /* USER CODE END */
    
        //    _mpuInit_();
    
            int nStatus;
            FRESULT iFResult;
            FATFS g_sFatFs;
            //
            // Mount the file system, using logical disk 0.
            //
            iFResult = f_mount(0, &g_sFatFs);
            if(iFResult != FR_OK)
            {
        
                while(1);
                }
    
            // Declarar un objeto FIL para representar el archivo
              FIL file;
    
              // Ruta del archivo que deseas abrir o crear
               const TCHAR *filePath = "mi_archivo.txt";
    
               // Modo de acceso al archivo
               BYTE mode = FA_READ | FA_WRITE | FA_OPEN_ALWAYS;
    
               // Llamar a la función f_open
               FRESULT result = f_open(&file, filePath, mode);
    
    
               // Verificar el resultado
               if (result == FR_OK) {
                   // El archivo se abrió o creó exitosamente
                   
                   /// record_function
    
                   f_close(&file);
               } else {
                   // Se produjo un error al abrir o crear el archivo
               }
    
               return 0;

  • Which board are you using?

    TI HDK board or any custom board?

    Did you copy all the utils folder files to your new project from RM48?

  • Hello Jagadish, 

    I'm using the TMS570LS3137 board. Yes, I copied all of those files.

    I was debugging, and the issue is  on the chk_mounted function (is inside the f_open function)

    Maybe I'm missing a step before f_open?

    This is my main.c code

    void main(void){
    
        canInit();
        sciInit();
        adcInit();
        /** - Configure MibSPI3 for SD card application */
        spiInit();
    
    
            int nStatus;
            FRESULT iFResult;
            FATFS g_sFatFs;
            //
            // Mount the file system, using logical disk 0.
            //
            /*
            iFResult = f_mount(0, &g_sFatFs);
            if(iFResult != FR_OK)
            {
                while(1);
            }
    */
    
            // Declarar un objeto FIL para representar el archivo
              FIL file;
    
              // Ruta del archivo que deseas abrir o crear
               const TCHAR *filePath = "mi_archivo.txt";
    
               // Modo de acceso al archivo (puedes ajustar según tus necesidades)
               BYTE mode = FA_READ | FA_WRITE | FA_OPEN_ALWAYS;
    
               // Llamar a la función f_open
               FRESULT result = f_open(&file, filePath, mode);
    
    
               // Verificar el resultado
               if (result == FR_OK) {
                   // El archivo se abrió o creó exitosamente
                   while(1);
                   // Aquí puedes realizar operaciones adicionales en el archivo si es necesario
    
                   // No olvides cerrar el archivo cuando hayas terminado con él
                   f_close(&file);
               } else {
                   // Se produjo un error al abrir o crear el archivo
                   // Puedes manejar el error de acuerdo a tus necesidades
               }
    
               return 0;
    
    
           // RTOSFunction();
    
    }

    Then, I tried whit this function before the f_open.

            iFResult = f_mount(0, &g_sFatFs);
            if(iFResult != FR_OK)
            {
                while(1);
            }
    

    And when the program enters on the f_mount, go a _dabort on the following line:

    rfs = FatFs[vol]; /* Get current fs object */

    Not sure why got a _dabort on this line.

    Thank you for your help.

  • Hi Federico,

    I don't have TMS570LS3137 HDK board to test this issue.

    I tested the below code on my TMS570LC4357 and i didn't see any issues with the code.

    TMS570LC43x_HDK_SDCard_mibspiDMA.zip

    And i didn't face any abort issues, so can you please verify your code with this code?

    I saw here they are disabling cache etc

    So, make sure those things and try again at your end.

    --
    Thanks & regards,
    Jagadish.

  • Hello Jagadish! I'm using the TMS570LS3137, and I initiated the SPI interface (not the mibspi) Is that correct? Or I should to use the mibspi to use the SD card? Thank you 

  • Hi Federico,

    Apologies for the delay, i am on vacation for last week.

    Hello Jagadish! I'm using the TMS570LS3137, and I initiated the SPI interface (not the mibspi) Is that correct? Or I should to use the mibspi to use the SD card? Thank you 

    Actually, either SPI or MibSPI can be used, it is not a problem. Make sure the other things by comparing your project with the project that i shared.

    --
    Thanks & regards,
    Jagadish.