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.

Trouble writing multiple words with EEPROMProgram

Other Parts Discussed in Thread: TM4C1290NCPDT, EK-TM4C1294XL, TM4C1294NCPDT

I am having difficulties getting multiple words to be written to the EEPROM using the EEPROMProgram method.  Are you aware of any problems with this method? 

I’ve been testing with 4 words.  The first three words always seems to be written correctly to EEPROM.  However, the fourth word is never written as expected.

Microcontroller:               TM4C1290NCPDT

Code Details

Test method()
{
…
  // Testing for multiple word WriteData method
  uint32_t read1[4] = {0, 0, 0, 0};
  IEeprom_API.ReadData(1600, read1, 16);
  
  // Uncomment one of the following arrays to write during a particular test run         
   uint32_t write[] = {0x12345678, 0x23456789, 0x34567890, 0x45678901};
// uint32_t write[] = {0x00345678, 0x00456789, 0x00567890, 0x00678901};
// uint32_t write[] = {0x123456FF, 0x234567FF, 0x345678FF, 0x456789FF};

  uint32_t writeStatus = IEeprom_API.WriteData(1600, write, 16);

  uint32_t read2[6] = {0, 0, 0, 0};
  IEeprom_API.ReadData(1600, read2, 16);

  // breakpoint set on line of code here to see what values are in read1, write, and read2 arrays
…
}

// My WriteData method which calls the EEPROMProgram method
WriteData(uint32_t StartAddress, uint32_t * pData, uint32_t DataSize) method
{
…
  if( GetBlockProtection() != eNoProtection)
  {
    SetBlockProtection(eNoProtection);
  }

  // This is the method call I expected to work
  ProgramStatus = MAP_EEPROMProgram( pData, StartAddress, DataSize);

  // I tried this method call which still did not work
//  ProgramStatus = EEPROMProgram( pData, StartAddress, DataSize);

  // The following code segment works fine.  Here we are programming a single word at a time.
  //  When this code segment is used all four bytes are written every time the test has been run.
//  uint32_t address = StartAddress;
//  uint8_t numLoops = DataSize/4;

//  for( int i = 0; i < numLoops; i++ )
//  {
//    ProgramStatus = MAP_EEPROMProgram( pData+i, address, sizeof(uint32_t));
//    address += 4;
//  }

  SetBlockProtection(eFullProtection);
…
}

Here are the results of a GOOD run of the code, writing a single word at a time with the [MAP_]EEPROMProgram method

read1[ ] = 0x12345678, 0x23456789, 0x34567890, 0x45678901 // Initial values in EEPROM
write[ ] = 0x123456FF, 0x234567FF, 0x345678FF, 0x456789FF // Values written to EEPROM
read2[ ] = 0x123456FF, 0x234567FF, 0x345678FF, 0x456789FF // Final values read from EEPROM

The results are that the 4 words were correctly written to the EEPROM (i.e. read2 == write)

Here are the results of a FAILED run of the code when trying to writing multiple words from the [MAP_]EEPROMProgram method

read1[ ] = 0x12345678, 0x23456789, 0x34567890, 0x45678901 // Initial values in EEPROM
write[ ] = 0x123456FF, 0x234567FF, 0x345678FF, 0x456789FF // Values written to EEPROM
read2[ ] = 0x123456FF, 0x234567FF, 0x345678FF, 0x45678901 // Final values read from EEPROM

The results are that the first three words were correctly written to the EEPROM but the fourth word was not (i.e. read2[3] != write[3])

I have stopped in the debugger before the call to the [MAP_]EEPROMProgram method and verified the expected variables being passed into it.

Please let me know if you are aware of any problems in this regard and provide any suggestions for fixing this issue.

  • The ROM user guide defines the parameters passed using EEPROMProgram as follows:

    • pui32Data points to the first word of data to write to the EEPROM.
    • ui32Address defines the byte address within the EEPROM that the data is to be written to. This value must be a multiple of 4.
    • ui32Count defines the number of bytes of data that is to be written. This value must be a multiple of 4.

    Can you verify that the values being passed match these constraints/definitions? Specifically, I can't tell what is being passed for address and datasize.

  • Hi Chuck,

     To validate your concerns I replaced the multi-word call to EEPROMProgram with the following line with the address and data size hard-coded as follows:

      // Temporary hard-coded values for EEPROMProgram testing
      ProgramStatus = MAP_EEPROMProgram( pData, 1600, 16);
    

     For one test run I also stopped the debugger and validated the value of all four words in pData.

    This was still only writing the first three words as before.  Even when I did multiple passes without stopping for debugging until after the call to EEPROMProgram (just to ensure that stopping the debugger at that location was not causing some kind of problem).

    Regards,

    Jim

  • Hello Jim,

    Can you please provide the data with the following information

    1. If instead of using MAP_EEPROMProgram call, you call EEPROMProgram, does the issue occur?
    2. Did you check the EEPROM for the contents?

    Regards
    Amit
  • Hello Amit,

    Yes I did try that. I just tried it again with the values hard-coded as I did for Chuck.

    ProgramStatus = EEPROMProgram( pData, 1600, 16);

    Same results. First three bytes written, but the fourth was not.

    Regards,
    Jim
  • Hello Jim,

    Attached is a sample code based on your post. I have a EK-TM4C1294XL and I have tested the same and it works fine.

    Note that I am using Flash version of the API and TivaWare release 2.1.2.111

    //*****************************************************************************
    //
    // eeprom.c - Example demonstrating the EEPROM Features
    //
    // Copyright (c) 2010-2014 Texas Instruments Incorporated.  All rights reserved.
    // Software License Agreement
    //
    //   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.
    //
    // This is part of revision 2.1.0.12573 of the Tiva Firmware Development Package.
    //
    //*****************************************************************************
    
    #include <stdbool.h>
    #include <stdint.h>
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/eeprom.h"
    #include "driverlib/uart.h"
    #include "utils/uartstdio.h"
    
    //*****************************************************************************
    //
    // This function sets up UART0 to be used for a console to display information
    // as the example is running.
    //
    //*****************************************************************************
    void
    InitConsole(void)
    {
        //
        // Enable GPIO port A which is used for UART0 pins.
        // TODO: change this to whichever GPIO port you are using.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    
        //
        // Configure the pin muxing for UART0 functions on port A0 and A1.
        // This step is not necessary if your part does not support pin muxing.
        // TODO: change this to select the port/pin you are using.
        //
        GPIOPinConfigure(GPIO_PA0_U0RX);
        GPIOPinConfigure(GPIO_PA1_U0TX);
    
        //
        // Enable UART0 so that we can configure the clock.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    
        //
        // Use the internal 16MHz oscillator as the UART clock source.
        //
        UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    
        //
        // Select the alternate (UART) function for these pins.
        // TODO: change this to select the port/pin you are using.
        //
        GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
        //
        // Initialize the UART for console I/O.
        //
        UARTStdioConfig(0, 115200, 16000000);
    }
    
    //*****************************************************************************
    //
    // Program Example for EEPROM Feature of
    // Set Define of EEPROM_500K for endurance of 500K when doing alternate page
    // write in circular fashion
    // Set Define of EEPROM_15M for endurance of 15M when doing cycling througj
    // two pages.
    //
    //*****************************************************************************
    int
    main(void)
    {
    	uint32_t ui32EEPROMInitStatus;
    	uint32_t ui32EEPROMReadData[4];
    	uint32_t ui32Index;
    	bool     bStatus;
    
    	bStatus = true;
    
    	SysCtlClockFreqSet((SYSCTL_XTAL_16MHZ | SYSCTL_OSC_INT | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480 ),
    	                                               120000000 );
        //
        // Set up the serial console to use for displaying messages.  This is
        // just for this example program and is not needed for PWM0 operation.
        //
        InitConsole();
    
        //
        // Display the setup on the console.
        //
        UARTprintf("EEPROM Feature Example\n");
    
        //
        // The PWM peripheral must be enabled for use.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0);
    
        //
        // Wait and Initialize EEPROM
        //
        while(!SysCtlPeripheralReady(SYSCTL_PERIPH_EEPROM0));
    
        ui32EEPROMInitStatus = EEPROMInit();
        if(ui32EEPROMInitStatus == EEPROM_INIT_ERROR)
        {
        	//
        	// Error in Initialization. Check the EEPROM Status register
        	//
        	UARTprintf("EEPROM Initialization Error\n");
        	while(1);
        }
    
        //
        // Feature Specific Test Begins here
        //
        uint32_t ui32EEPROMWriteData[] = {0x12345678, 0x23456789, 0x34567890, 0x45678901};
     // uint32_t ui32EEPROMWriteData[] = {0x00345678, 0x00456789, 0x00567890, 0x00678901};
     // uint32_t ui32EEPROMWriteData[] = {0x123456FF, 0x234567FF, 0x345678FF, 0x456789FF};
        for(ui32Index=0;ui32Index<4;ui32Index++)
        {
        	//
        	// Clear the read buffer
        	//
        	ui32EEPROMReadData[ui32Index]  = 0x0;
        }
    
        //
        // Program the Words to Page-0 and Page-1
        //
        EEPROMProgram((uint32_t *)ui32EEPROMWriteData,1600,16);
    
        //
        // Read the Words back from Page-0 and Page-1
        //
        EEPROMRead((uint32_t *)ui32EEPROMReadData,1600,16);
    
        //
        // Check if Read and Write Match
        //
        for(ui32Index=0;ui32Index<4;ui32Index++)
        {
        	if(ui32EEPROMReadData[ui32Index] != ui32EEPROMWriteData[ui32Index])
        	{
        		UARTprintf("Mismatch Write %x and read %x\n",ui32EEPROMWriteData[ui32Index],ui32EEPROMReadData[ui32Index]);
    
        	}
        }
    
        if(bStatus)
        {
        	UARTprintf("Test passed\n");
        }
        else
        {
        	UARTprintf("Test Failed\n");
        }
    
        while(1);
    
    }
    

    Regards

    Amit

  • I am using a TM4C1294NCPDT and CCS 6.1.2 and had a question after reading this thread.
    Quoting from this thread:
    “2. Did you check the EEPROM for the contents?”
    Can the contents of the EEPROM be viewed in the CCS debugger via the memory view and if so what is the address?
    Thanks,
    Doug
  • Doug Baker said:
    Can the contents of the EEPROM be viewed in the CCS debugger

    Eeprom content can not be viewed directly from CCS - the memory block is separate from the main memory structure.

    As for the first doubt, note that the Eeprom functions return a value to indicate successful operation (or failure). Is that being used?

    Bruno