TMS320C6678: In Tms320c6678, Not getting the data from the slave.

Part Number: TMS320C6678

Tool/software:

Dear TI Team,

We are working on the I2C protocol at TMS320C6678's EVM. We are using the I2C to write and read on the EEPROM. We transmitted the data on EEPROM successfully by Master.     

But, We still have not received (retrieved) data from the slave.

PFA, for the code review, if there is any issue or missing MASK or CFN, CMD or something else please provide us with some resolution on it.

void  main() {
    I2CMasterInit(I2CR,EEPROM_I2C_SLAVE_ADDR,I2C_OWN_ADDR);
   
    //I2CSlaveInit(I2CR,I2C_OWN_ADDR,EEPROM_I2C_SLAVE_ADDR);
while(1){
    I2C_EEPROM_TEST();
}
}




void I2C_EEPROM_TEST(void) {
    int i,j;

    uint8_t writeData[] = {0x12, 0x34, 0x56, 0x78};  // Example data to write
    uint8_t readData[4];  // Buffer to store read data


    EEPROMWrite(I2CR, EEPROM_I2C_SLAVE_ADDR, writeData, sizeof(writeData));
    EEPROMRead(I2CR, EEPROM_I2C_SLAVE_ADDR, readData, sizeof(readData));

    // Print the read data
    printf("Read data from EEPROM:\n");
    for (i= 0; i < sizeof(readData); i++) {
        printf("Data %d: 0x%02X\n", i, readData[i]);

    }

    // Print the Write data
    printf("Write data from EEPROM:\n");
    for (j= 0; j < sizeof(writeData); j++) {
        printf("Data %d: 0x%02X\n", j, writeData[j]);

    }

}


void I2CMasterInit(CSL_I2cRegsOvly i2c,uint32_t slavAdd,uint32_t ownAddr){

    I2CMasterDisable((uint32_t)i2c);
  
    I2CMasterInitExpClk((uint32_t)i2c,166660000,1000000000,8000000);

    /* Set I2C slave address. */
    I2COwnAddressSet((uint32_t)i2c,ownAddr);
    I2CMasterEnable((uint32_t)i2c);
    I2CSlaveEnable((uint32_t)i2c);
    I2CMasterStart((uint32_t)i2c);
}

// Function to initialize I2C slave
void I2CSlaveInit(CSL_I2cRegsOvly i2c,uint32_t ownAddr,uint32_t slavAdd) {

    I2COwnAddressSet((uint32_t)i2c,ownAddr);
    I2CSlaveEnable(slavAdd);
}





void EEPROMWrite(CSL_I2cRegsOvly i2c, uint32_t address, uint8_t *data, uint32_t length) {

    uint32_t  i ;

    I2CMasterSlaveAddrSet((uint32_t)i2c, address);
  
    // Set data count
    I2CSetDataCount((uint32_t)i2c, length + 2); // +2 for EEPROM address
 


    I2CMasterControl((uint32_t)i2c,I2C_CFG_MASK_TX|I2C_CFG_MASK_START,I2C_CFG_CMD_TX|I2C_CFG_CMD_START);
  

    // Send the EEPROM address (high byte and low byte)
    I2CMasterDataPut((uint32_t)i2c, (address >> 8) & 0xFF);
  
    I2CMasterDataPut((uint32_t)i2c, address & 0xFF);
  
    // Send data bytes
    for (i = 0; i < length; i++) {
        I2CMasterDataPut((uint32_t)i2c,data[i]);
      
    }
    I2CMasterControl((uint32_t)i2c,I2C_CFG_MASK_TX|I2C_CFG_MASK_START,I2C_CFG_CMD_TX|I2C_CFG_CMD_START);
  
    I2CMasterStop((uint32_t)i2c);
   
    // Stop the I2C transmission
    I2CMasterControl((uint32_t)i2c, I2C_CFG_MASK_STOP, I2C_CFG_CMD_STOP);


}



void EEPROMRead(CSL_I2cRegsOvly i2c, uint32_t address, uint8_t *data, uint32_t length) {
    uint32_t  i;

    I2CMasterSlaveAddrSet( (uint32_t)i2c, address);
   

    // Set data count
    I2CSetDataCount((uint32_t)i2c, 2); // +2 for EEPROM address
   

    // Start the I2C transmission to write the EEPROM address
    I2CMasterControl((uint32_t)i2c, I2C_CFG_MASK_TX | I2C_CFG_MASK_START, I2C_CFG_CMD_TX | I2C_CFG_CMD_START);
  
    // Send the EEPROM address (high byte and low byte)
    I2CMasterDataPut((uint32_t)i2c, (address >> 8) & 0xFF);
   
    I2CMasterDataPut((uint32_t)i2c, address & 0xFF);
   

    // Start the I2C reception
    I2CMasterControl((uint32_t)i2c, I2C_CFG_MASK_RX | I2C_CFG_MASK_START | I2C_CFG_MASK_STOP, I2C_CFG_CMD_RX | I2C_CFG_CMD_START | I2C_CFG_CMD_STOP);
   
    // Set data count
    I2CSetDataCount((uint32_t)i2c, length); // +2 for EEPROM address
    // Read data bytes
    for ( i= 0; i < length; i++) {
      data[i] = I2CMasterDataGet((uint32_t)i2c);
    

    }


}

Warmest regards,

Krishn Singh Chauhan

  • Krishn Singh Chauhan,

    Is it TI EVM? If yes, please follow the steps given in this FAQ and reply me

    whether you are able to flash and boot the bootloader from EEPROM ? in TI EVM?

    [FAQ] TMS320C6678: How to flash the IBL ( Intermediate Boot loader ) into EEPROM and how to flash the application binary into NOR? How to boot the IBL + Application binary? - Processors forum - Processors - TI E2E support forums

    Regards

    Shankari G

  • Hi Shankari G,

    Greetings of the day.

    Thanks for the update, Yes.

    In our case, We want I2C communication between the EEPROM ( the write-and-read operation, 0x50 or 0x51 address of the EEPROM). But we only transmit or write the data via the master and the slave didn't send or read (retrieve) the data from the master. We are facing an issue with the slave, it's unable to communicate with the master.

    Please check the provided code, If there is any issue with MASK, CONFIGURATION OR COMMAND.

    Please guide us for the same.

    Warmest regards,

    Krishn Singh Chauhan

  • Krishn Singh Chauhan,

    Is it TI EVM? or your custom board?

    It is I2C communication only. The READ, Write and verify happens successfully on my TI-EVM.

    I hope you know, here the master is C6678 DSP and the slave device is EEPROM.

    In which step you are failing in the FAQ? 

    --

    Please check the provided code, If there is any issue with MASK, CONFIGURATION OR COMMAND.

    If it is a TI EVM, you need not modify any code.

    It will work straight away.

    Regards

    Shankari G

  • Hi Shankari G,

    1. Yes, It's TI DSP(TMDSEVM6678LE).

    2. Yes, We wrote or transmitted data on the EEPROM via the I2C on the TI DSP(TMDSEVM6678LE).

    3. Yes, We use TI DSP(TMDSEVM6678LE) as master and EEPROM as slave (address 0x50 and 0x51).

    We want to check the master and slave TX-RX communication between the  I2C(TI DSP) and EEPROM. With this condition, I2C (TI DSP) is the master and EEPROM is the slave. We also provided a code for the same.



    POV,

    We are not getting the data from the EEPROM as a slave on the I2C(TI DSP as master), We are unable to diagnose this issue.

    We can transmit the data through the I2C(TI-DSP master) to EEPROM(slave), but We are unable to retrieve the data from the EEPROM(slave). 

    That's why we shared a code for the same, We hope your team will inspect it and resolve this issue.

    please resolve this issue.

    Note:  If there is any issue in our code, if we missed the  MASK, CONFIGURATION OR COMMAND, Please let us know.

    Warmest regards,

    Krishn Singh Chauhan

     

  • Ok,

    --

    When we refer to TI-DSP -------> It is the processor device --- "C6678"

    When we refer to TI-EVM --------> It is the Evaluation module ( TI Hardware board with C6678 processor device)

    ---

    PLEASE ANSWER ALL MY QUESTIONS below. Please Help me to help you....

    Please post me the screenshot of what you tried in CCS.

    I hope you used the "EEPROM writer" which is located in "\ti\pdk_c667x_2_0_16\packages\ti\boot\writer\eeprom\evmc6678l\bin\eepromwriter_evm6678l.out "

    --

    If it is a TI-EVM-(Hardware board) , Please make me understand why do you use your own code to flash the EEPROM via I2C?

    Because the working code was already available right in the processor SDK 6.3 ?

    Does the code you posted is your own code? 

    ---

    In the below steps, up to which step you carried out? Please post me the screenshot of what you tried in CCS.

    --

    Step2: -- Flashing IBL

    1. Set the DIP switch into "NO-BOOT" mode. "SW3,SW4,SW5 and SW6"

        SW3(off, on, on, on),

        SW4(on, on, on, on),

        SW5(on, on, on, on),

        SW6(on, on, on, on)

    1. Modify the eepromwriter_input.txt located at "C:\ti\pdk_c667x_2_0_16\packages\ti\boot\writer\eeprom\evmc6578l\bin"

    file_name = i2crom.bin
    bus_addr = 0x51
    start_addr = 0
    swap_data = 0

    1. Flashing steps as follows ( Flashing IBL into EEPROM using EEPROM writer)
    2. Set your C6678EVM to NO BOOT. Power on, launch target configuration in CCS, and connect to Core 0. Be sure the GEL file is used and DDR is initialized.
    3. Copy the IBLbinary you want to flash to "C:\ti\pdk_c667x_2_0_16\packages\ti\boot\writer\eeprom\evmc6678l\bin" directory.
    4. Rename the binary you copied in the previous step to “i2crom.bin”.
    5. In CCS, select Core 0 and open the Memory Browser. In the Memory Browser window, right click and select “Load Memory”
    6. Load your "i2crom.bin" to 0x0C000000. Do so by selecting i2crom.bin file and select the file type as binary. click Next, and input 0x0C000000 as Start Address
    7. Load C:\ti\pdk_c667x_2_0_16\packages\ti\boot\writer\eeprom\evmc6678l\bin\eepromwriter_evm6678l.out
    8. Run Core 0. This will program the flash memory.

    If it succeeds, the console will print “EEPROM programming completed successfully” like below.

    Regards

    Shankari G

  • Hi Shankari G,

    Sorry for the late reply,

    Thanks for the update,

    Yes, It's TI EVM(TMDSEVM6678LE).

    We tried our code to write and read operations (to test the internal EEPROM, Which is connected to DSP I2C through the I2C on the EEPROM (internal EEPROM's addresses 0x50 and 0x51).

    We also posted the snap of the code and tried both addresses. But the issues are the same. And Right now we don't want to use BOOT configuration for that.

    Please inspect the above code for us, We already mentioned the top of this thread.

    if you need more information related to this please let us know.

    Warmest regards,

    Krishn Singh Chauhan

  • Hi Shankari G,

    Any update on it? We'll be waiting for your acknowledgment.

    Warmest regards,

    Krishn Singh Chauhan

  • Krishn Singh Chauhan

    If it is a TI-EVM-(Hardware board) , Please make me understand why do you use your own code to flash ( i.e., write)  the EEPROM via I2C?

    Because the working code was already available right in the processor SDK 6.3 ?

    ---

    You can use the same EEPROM writer code for a random read-write via I2C.

    You need not use/flash the Boot loader code.

    Regards

    Shankari G

  • Hi Shankari G,

    Greetings for the day,

    Thanks for your valuable time and for giving us priority to help us.

    Yes, It's TI EVM-(TMDSEVM6678LE Hardware board).

    We want to check master-slave communication using the EEPROM via I2C. That's why, we wrote the code. Is it possible to code or not?

    if it doesn't need our code to write to EEPROM via I2C. Then how can we write to the EEPROM via I2C?

    If there is any other source for that, please provide us with and guide us too.

    Note: We use the internal EEPROM for that.

    Warmest regards,

    Krishn Singh Chauahn

  • Krishn Singh Chauahn

    Please install processor SDK 6.3 and once you install, you will find the EEPROM code at location:- 

    \ti\pdk_c667x_2_0_16\packages\ti\boot\writer\eeprom.

    Reviewing the customer code is beyond the scope of Forum support.

    The following is the extract from the src folder of EEPROM. For the complete code, download and install processor SDK 6.3.

    https://software-dl.ti.com/processor-sdk-rtos/esd/C667x/latest/index_FDS.html

    This sample code encloses the master slave communication only. You can use it. 

    /******************************************************************************
     * Copyright (c) 2011 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.
     *
     *****************************************************************************/
    
    /**************************************************************************************
     * FILE PURPOSE: EEPROM writer utility
     **************************************************************************************
     * FILE NAME: eepromwriter.c
     *
     * DESCRIPTION: A simple EEPROM writer using platform lib APIs to program the EEPROM
     *              with an image that the ibl can read.
     *
     ***************************************************************************************/
    #include <stdlib.h>
    #include <stdio.h>
    #include<ctype.h>
    #include <string.h>
    #include "platform.h"
    #include "types.h"
    
    /* EEPROM writer utility version */
    char version[] = "01.00.00.05";
    
    
    /* The input file name is hard coded */
    char *input_file = "eepromwriter_input.txt";
    
    /* Parameters defined in the input_file */
    #define FILE_NAME      "file_name"
    #define BUS_ADDR       "bus_addr"
    #define START_ADDR     "start_addr"
    #define SWAP_DATA      "swap_data"
    
    /* Memory address to store the write data */
    #define WRITE_DATA_ADDRESS     0x0C000000
    
    /******************************************************************************
     * Structure:   EEPROM_WRITER_INFO_T
     *
     *              EEPROM writer control data. This structure should be filled in
     *              by the user before running
     ******************************************************************************/
    #define MAX_LINE_LENGTH 40
    typedef struct EEPROM_WRITER_INFO_tag
    {
        char        file_name[MAX_LINE_LENGTH]; /* CCS format data file name */
        uint32_t    busAddr;                    /* Slave bus address */
        uint32_t    startAddr;                  /* Start address to write */
        uint32_t    swapData;                   /* Swap byte in the 32-bit word of the data */
        uint32_t    deviceTotalBytes;           /* Total number of bytes available in the device */
        uint32_t    writeBytes;                 /* Number of bytes to be written into the device */
        uint8_t     *writeData;                 /* Address to store the write data */
        uint8_t     *readData;                  /* Address to store the read data */
    
    } EEPROM_WRITER_INFO_T;
    
    EEPROM_WRITER_INFO_T eepromWriterInfo;
    
    /* OSAL functions for Platform Library */
    uint8_t *Osal_platformMalloc (uint32_t num_bytes, uint32_t alignment)
    {
    	return malloc(num_bytes);
    }
    
    void Osal_platformFree (uint8_t *dataPtr, uint32_t num_bytes)
    {
        /* Free up the memory */
        if (dataPtr)
        {
            free(dataPtr);
        }
    }
    
    void Osal_platformSpiCsEnter(void)
    {
        return;
    }
    
    void Osal_platformSpiCsExit (void)
    {
        return;
    }
    
    /******************************************************************************
     * Function:    print_platform_errno
     ******************************************************************************/
    void
    print_platform_errno
    (
        void
    )
    {
        printf ("Returned platform error number is %d\n", platform_errno);
    }
    
    /******************************************************************************
     * Function:    form_block
     *
     *      Form a block of data to write to the NOR. The block is
     *      created as a byte stream from the 4 byte stream in which
     *      the MSB is always sent first.
     ******************************************************************************/
    void
    formBlock
    (
        uint32_t      *data,
        uint32_t      blockSize,
        uint8_t       *scratch
    )
    {
        uint32_t i, j;
    
        /* Convert the data to a byte stream */
        for (i = j = 0; j < blockSize; i++, j+=4)
        {
            scratch[j+0] = (data[i] >> 24) & 0xff;
            scratch[j+1] = (data[i] >> 16) & 0xff;
            scratch[j+2] = (data[i] >>  8) & 0xff;
            scratch[j+3] = (data[i] >>  0) & 0xff;
        }
    }
    
    /******************************************************************************
     * Function:    flash_eeprom
     *
     *              Write the data from memory to EEPROM.
     *              Returns TRUE if the data is written successfully
     *                      FALSE if the data write fails
     ******************************************************************************/
    Bool
    flash_eeprom
    (
        PLATFORM_DEVICE_info    *p_device
    )
    {
        uint8_t       *scrach_block;
    
        printf ("Writing %d bytes from DSP memory address 0x%08x to EEPROM bus address 0x%04x starting from device address 0x%04x ...\n",
                eepromWriterInfo.writeBytes,
                (uint32_t)eepromWriterInfo.writeData,
                eepromWriterInfo.busAddr,
                eepromWriterInfo.startAddr);
    
        if (eepromWriterInfo.swapData)
        {
    	    scrach_block = malloc(eepromWriterInfo.deviceTotalBytes);
    	    if (scrach_block == NULL)
    	    {
    	        printf ("Can not allocate scratch block memory!\n");
    	        return (FALSE);
    	    }
            formBlock((uint32_t *)(eepromWriterInfo.writeData), eepromWriterInfo.deviceTotalBytes, scrach_block);
    	}
    	else
    	{
    		scrach_block = eepromWriterInfo.writeData;
    	}
    
        if(platform_device_write(p_device->handle, eepromWriterInfo.startAddr, scrach_block, eepromWriterInfo.writeBytes) != Platform_EOK)
        {
            print_platform_errno();
            if (eepromWriterInfo.swapData)
            	free (scrach_block);
            return FALSE;
        }
    
    	if(eepromWriterInfo.swapData)
        	free (scrach_block);
    
        return TRUE;
    }
    
    /******************************************************************************
     * Function:    flash_verify
     *
     *              Read back the data file that was just flashed.
     *              Returns TRUE if the data verified correctly.
     *                      FALSE if the data verification failed
     ******************************************************************************/
    Bool
    flash_verify
    (
        PLATFORM_DEVICE_info    *p_device
    )
    {
        uint32_t    i, j;
        uint8_t     *scrach_block;
        uint32_t    *read_data_w;
    
        printf ("Reading %d bytes from EEPROM bus address 0x%04x to DSP memory address 0x%08x starting from device address 0x%04x ...\n",
                eepromWriterInfo.writeBytes,
                eepromWriterInfo.busAddr,
                (uint32_t)eepromWriterInfo.readData,
                eepromWriterInfo.startAddr);
    
        if (eepromWriterInfo.swapData)
        {
    	    scrach_block = malloc(eepromWriterInfo.deviceTotalBytes);
    	    if (scrach_block == NULL)
    	    {
    	        printf ("Can not allocate scratch block memory!\n");
    	        return (FALSE);
    	    }
    	}
    	else
    	{
    		scrach_block = eepromWriterInfo.readData;
    	}
    
        if(platform_device_read(p_device->handle, eepromWriterInfo.startAddr, scrach_block, eepromWriterInfo.writeBytes) != Platform_EOK)
        {
            print_platform_errno();
            return FALSE;
        }
    
        printf ("Verifying data read ...\n");
    
        if (eepromWriterInfo.swapData)
        {
            /* Convert the packed data */
            read_data_w = (uint32_t *)(eepromWriterInfo.readData);
            for  (i = 0, j = 0; i < eepromWriterInfo.deviceTotalBytes; i += 4)
                read_data_w[j++] = (scrach_block[i+0] << 24) | (scrach_block[i+1] << 16) | (scrach_block[i+2] << 8) | scrach_block[i+3];
       }
    
    
        for (i = 0; i < eepromWriterInfo.writeBytes; i++)
        {
            if (eepromWriterInfo.readData[i] != eepromWriterInfo.writeData[i])
            {
                printf ("Failure at byte %d, expected 0x%08x, read 0x%08x\n", i, eepromWriterInfo.writeData[i], eepromWriterInfo.readData[i]);
                return (FALSE);
            }
        }
    
        return (TRUE);
    }
    
    int32_t 
    xtoi
    (
        char            *xs, 
        uint32_t        *result
    )
    {
        uint32_t    szlen = strlen(xs);
        int32_t     i, xv, fact;
        
        if (szlen > 0)
        {
            /* Converting more than 32bit hexadecimal value? */
            if (szlen>8) return 2; /* exit */
            
            /* Begin conversion here */
            *result = 0;
            fact = 1;
            
            /* Run until no more character to convert */
            for(i=szlen-1; i>=0 ;i--)
            {
                if (isxdigit(*(xs+i)))
                {
                    if (*(xs+i)>=97)
                    {
                        xv = ( *(xs+i) - 97) + 10;
                    }
                    else if ( *(xs+i) >= 65)
                    {
                        xv = (*(xs+i) - 65) + 10;
                    }
                    else
                    {
                        xv = *(xs+i) - 48;
                    }
                    *result += (xv * fact);
                    fact *= 16;
                }
                else
                {
                    // Conversion was abnormally terminated
                    // by non hexadecimal digit, hence
                    // returning only the converted with
                    // an error value 4 (illegal hex character)
                    return 4;
                }
            }
            return 0;
        }
        
        // Nothing to convert
        return 1;
    }
    
    
    /******************************************************************************
     * Function:    parse_input_file
     ******************************************************************************/
    static Bool
    parse_input_file
    (
        FILE*               fp
    )
    {
        char line[MAX_LINE_LENGTH];
        char tokens[] = " :=;\n\r";
        char *key, *data;
    
        memset(line, 0, MAX_LINE_LENGTH);
    
        fgets(line, MAX_LINE_LENGTH, fp);
        key  = (char *)strtok(line, tokens);
        data = (char *)strtok(NULL, tokens);
    
        if(strlen(data) == 0)
        {
           return FALSE;
        }
    
        if(strcmp(key, FILE_NAME) != 0)
        {
            return FALSE;
        }
    
        strcpy (eepromWriterInfo.file_name, data);
    
        fgets(line, MAX_LINE_LENGTH, fp);
        key  = (char *)strtok(line, tokens);
        data = (char *)strtok(NULL, tokens);
    
        if(strlen(data) == 0)
        {
           return FALSE;
        }
    
        if(strcmp(key, BUS_ADDR) != 0)
        {
            return FALSE;
        }
    
        if ((data[0] == '0') && (data[1] == 'x' || data[1] == 'X'))
        {
            if (xtoi (&data[2], &eepromWriterInfo.busAddr) != 0)
            {
                return FALSE;
            }
        }
        else
        {
            eepromWriterInfo.busAddr = (uint32_t)atoi(data);
        }
    
        fgets(line, MAX_LINE_LENGTH, fp);
        key  = (char *)strtok(line, tokens);
        data = (char *)strtok(NULL, tokens);
    
        if(strlen(data) == 0)
        {
           return FALSE;
        }
    
        if(strcmp(key, START_ADDR) != 0)
        {
            return FALSE;
        }
    
        eepromWriterInfo.startAddr = (uint32_t)atoi(data);
    
        fgets(line, MAX_LINE_LENGTH, fp);
        key  = (char *)strtok(line, tokens);
        data = (char *)strtok(NULL, tokens);
    
        if(strlen(data) == 0)
        {
           return FALSE;
        }
    
        if(strcmp(key, SWAP_DATA) != 0)
        {
            return FALSE;
        }
    
        eepromWriterInfo.swapData = (uint32_t)atoi(data);
    
        return TRUE;
    }
    
    /******************************************************************************
     * Function:    find_file_length
     ******************************************************************************/
    static Bool
    find_file_length
    (
        FILE*               fp
    )
    {
        char        line[MAX_LINE_LENGTH];
        char        *pEnd;
        char        *ext;
        uint32_t    data_len, write_addr;
    
        memset(line, 0, MAX_LINE_LENGTH);
    
        ext = strrchr(eepromWriterInfo.file_name, '.');
    
    
        if (ext && (strcmp(ext, ".dat") == 0))
        {
            
            fgets(line, MAX_LINE_LENGTH, fp);
            
            /* Read the write address from the CCS header */
            strtoul (line,&pEnd,16);
            strtoul (pEnd,&pEnd,16);
            write_addr = strtoul (pEnd,&pEnd,16);
            strtoul (pEnd,&pEnd,16);
            
            /* Read the data length */
            data_len = (strtoul (pEnd,NULL,16)) * 4;
        }
        else
        {
            /* find the data length by seeking to the end and getting position */
            fseek(fp, 0, SEEK_END);
            data_len = ftell(fp);
            fseek(fp, 0, SEEK_SET);
        }
    
        if (data_len > (eepromWriterInfo.deviceTotalBytes - eepromWriterInfo.startAddr))
        {
            printf ("The data file is too big to fit into the device.\n");
            return FALSE;
        }
    
        eepromWriterInfo.writeBytes = data_len;
        if (write_addr != WRITE_DATA_ADDRESS)
            write_addr = WRITE_DATA_ADDRESS;
        eepromWriterInfo.writeData  = (uint8_t *)write_addr;
        eepromWriterInfo.readData   = (uint8_t *)(write_addr + eepromWriterInfo.deviceTotalBytes);
    
        return TRUE;
    }
    
    /******************************************************************************
     * Function:    main
     ******************************************************************************/
    void main ()
    {
        FILE                    *fp;
        platform_init_flags     init_flags;
        platform_init_config    init_config;
        PLATFORM_DEVICE_info    *p_device;
        Bool                    ret;
    
        printf("EEPROM Writer Utility Version %s\n\n", version);
    
        fp = fopen(input_file, "r");
        if (fp == NULL)
        {
            printf("Error in opening %s input file\n", input_file);
            return;
        }
    
        ret = parse_input_file(fp);
        fclose (fp);
    
        if (ret == FALSE)
        {
            printf("Error in parsing %s input file\n", input_file);
            return;
        }
    
        /* Initialize main Platform lib */
        memset(&init_config, 0, sizeof(platform_init_config));
        memset(&init_flags, 0x01, sizeof(platform_init_flags));
        init_flags.pll = 0;
        init_flags.ddr = 0;
        init_flags.phy = 0;
    
        if (platform_init(&init_flags, &init_config) != Platform_EOK)
        {
            printf ("Platform init failed!\n");
            print_platform_errno();
            return;
        }
    
        p_device = platform_device_open(eepromWriterInfo.busAddr, 0);
        if (p_device == NULL)
        {
            printf ("EEPROM device open failed!\n");
            print_platform_errno();
            return;
        }
        eepromWriterInfo.deviceTotalBytes = p_device->block_count * p_device->page_count * p_device->page_size;
    
        /* Open and find the length of the data file */
        fp = fopen (eepromWriterInfo.file_name, "rb");
        if (fp == NULL)
        {
            printf ("Failed to open file %s\n", eepromWriterInfo.file_name);
            print_platform_errno();
            platform_device_close(p_device->handle);
            return;
        }
    
        /* Parse the CCS format file */
        ret = find_file_length(fp);
        fclose (fp);
        if (ret == FALSE)
        {
            printf("Error in parsing CCS file %s\n", eepromWriterInfo.file_name);
            platform_device_close(p_device->handle);
            return;
        }
    
        /* Write the EEPROM */
        if (flash_eeprom (p_device) == FALSE)
        {
            printf ("EEPROM write failed\n");
            platform_device_close(p_device->handle);
            return;
        }
    
        /* verify the flash */
        if(flash_verify (p_device) == FALSE)
        {
            printf ("EEPROM read verify failed\n");
            platform_device_close(p_device->handle);
            return;
        }
    
    
        printf ("EEPROM programming completed successfully\n");
    
        platform_device_close(p_device->handle);
    
        return;
    }
    
    
    
    
    

    Regards

    Shankari G

  • Hi Shankari G,

    Thanks for the update,

    We followed the above code, and now we are facing the error.

    we mentioned below.

    showing the output as:

    [C66xx_0] EEPROM Writer Utility Version 01.00.00.05

    Error in opening eepromwriter_input.txt input file

    Warmest regards,

    Krishn Singh Chauhan

  • Krishn Singh Chauhan

    While executing the code on the board, are you also opened the same file in Notepad?

    If yes, you should close the "*.txt" and then try again. Sometimes, Your Windows + CCS may have a resource conflict in accessing the "*.txt" by both CCS and notepad at the same time. 

    In your screenshot, it shows like that.

    ----

    And more over, this .txt "opening a text file"  is not needed for your requirement for just reading and writing to EEPROM.

    You can feed the details directly into your code like bus number --> 0x51 etc..

    ---

    By any chance you renamed the filename without the ".txt" extension?

    THE ERROR IN YOUR SCREENSHOT IS 

    This program is looking for a file with file name, "eepromwriter_input.txt" at a particular location but it could not find.

    In my setup it works perfectly. Which means you could do it too.

    Follow this video material, I have created for you.

    Regards

    Shankari G

  • Hi Shankari G,

    Thanks for the update.

    Kindly close this thread.

    Warmest regards,

    Krishn Singh Chauhan

  • Ok, I hope you succeeded too.

    Closing the thread!