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.

TM4C123 EEPROM

hi,

    i am using tm4c123 series of controller in which 2kb internal flash is there.now the problem is i was able to store max of 500 bytes in the eeprom.

i would like to save much data in that,so i tried to change the functions to support character in staid of integer even though it is behaving in the same fashion.

can any one suggest me with any solutions.

thanks & regards,

  • Hello Shyam,

    Since the device has 2KB of EEPROM out of which you are using 128 bytes, then clearly isn't there space available in the order of 1920 bytes still?

    Regards

    Amit

  • hi amit,

                      actually sorry i have mentioned 128 bytes instaid of 500 bytes if i use the same functions given in library with intiger arguments,because it takes the word*4 for storing.

                    Now what i am trying is to store the max of 2000 bytes each byte for each address location and unsuccessful to do.

                   you can check out  write and read function which i tryed.

    void
    EEPROMRead(uint8_t *pui32Data, uint32_t ui32Address, uint32_t ui32Count)
    {
    //
    // Check parameters in a debug build.
    //
    ASSERT(pui32Data);
    ASSERT(ui32Address < SIZE_FROM_EESIZE(HWREGB(EEPROM_EESIZE)));
    ASSERT((ui32Address + ui32Count) <=
    SIZE_FROM_EESIZE(HWREGB(EEPROM_EESIZE)));
    //ASSERT((ui32Address & 3) == 0);
    //ASSERT((ui32Count & 3) == 0);

    //
    // Set the block and offset appropriately to read the first word.
    //
    HWREGB(EEPROM_EEBLOCK) = EEPROMBlockFromAddr(ui32Address);
    HWREGB(EEPROM_EEOFFSET) = OFFSET_FROM_ADDR(ui32Address);

    //
    // Convert the byte count to a word count.
    //
    // ui32Count += 4;

    //
    // Read each word in turn.
    //
    while(ui32Count)
    {
    //
    // Read the next word through the autoincrementing register.
    //
    *pui32Data = HWREGB(EEPROM_EERDWRINC);

    //
    // Move on to the next word.
    //
    pui32Data++;
    ui32Count--;

    //
    // Do we need to move to the next block? This is the case if the
    // offset register has just wrapped back to 0. Note that we only
    // write the block register if we have more data to read. If this
    // register is written, the hardware expects a read or write operation
    // next. If a mass erase is requested instead, the mass erase will
    // fail.
    //
    if(ui32Count && (HWREGB(EEPROM_EEOFFSET) == 0))
    {
    HWREGB(EEPROM_EEBLOCK) += 1;
    }
    }
    }

    //*****************************************************************************
    //
    //! Writes data to the EEPROM.
    //!
    //! \param pui32Data points to the first word of data to write to the EEPROM.
    //! \param ui32Address defines the byte address within the EEPROM that the data
    //! is to be written to. This value must be a multiple of 4.
    //! \param ui32Count defines the number of bytes of data that is to be written.
    //! This value must be a multiple of 4.
    //!
    //! This function may be called to write data into the EEPROM at a given
    //! word-aligned address. The call is synchronous and returns only after
    //! all data has been written or an error occurs.
    //!
    //! \return Returns 0 on success or non-zero values on failure. Failure codes
    //! are logical OR combinations of \b EEPROM_RC_INVPL, \b EEPROM_RC_WRBUSY,
    //! \b EEPROM_RC_NOPERM, \b EEPROM_RC_WKCOPY, \b EEPROM_RC_WKERASE, and
    //! \b EEPROM_RC_WORKING.
    //
    //*****************************************************************************
    uint32_t
    EEPROMProgram(uint8_t *pui32Data, uint32_t ui32Address, uint32_t ui32Count)
    {
    unsigned long ui32Status;

    //
    // Check parameters in a debug build.
    //
    ASSERT(pui32Data);
    ASSERT(ui32Address < SIZE_FROM_EESIZE(HWREGB(EEPROM_EESIZE)));
    ASSERT((ui32Address + ui32Count) <=
    SIZE_FROM_EESIZE(HWREGB(EEPROM_EESIZE)));

    // comment this because code is modified to support byte write operations done by shyam
    // ASSERT((ui32Address & 3) == 0);
    // ASSERT((ui32Count & 3) == 0);

    //
    // Make sure the EEPROM is idle before we start.
    //
    do
    {
    //
    // Read the status.
    //
    ui32Status = HWREGB(EEPROM_EEDONE);
    }
    while(ui32Status & EEPROM_EEDONE_WORKING);

    //
    // Set the block and offset appropriately to program the first word.
    //
    HWREGB(EEPROM_EEBLOCK) = EEPROMBlockFromAddr(ui32Address);
    HWREGB(EEPROM_EEOFFSET) = OFFSET_FROM_ADDR(ui32Address);

    //
    // Convert the byte count to a word count.
    //
    // ui32Count += 4;

    //
    // Write each word in turn.
    //
    while(ui32Count)
    {
    //
    // This is a workaround for a silicon problem on Blizzard rev A. We
    // need to do this before every word write to ensure that we don't
    // have problems in multi-word writes that span multiple flash sectors.
    //
    if(CLASS_IS_BLIZZARD && REVISION_IS_A0)
    {
    _EEPROMSectorMaskSet(ui32Address);
    }

    //
    // Write the next word through the autoincrementing register.
    //
    HWREGB(EEPROM_EERDWRINC) = *pui32Data;

    //
    // Wait for the write to complete.
    //
    do
    {
    //
    // Read the status.
    //
    ui32Status = HWREGB(EEPROM_EEDONE);
    }
    while(ui32Status & EEPROM_EEDONE_WORKING);

    //
    // Make sure we completed the write without errors. Note that we
    // must check this per-word because write permission can be set per
    // block resulting in only a section of the write not being performed.
    //
    if(ui32Status & (EEPROM_EEDONE_NOPERM | EEPROM_EEDONE_INVPL))
    {
    //
    // An error was reported that would prevent the values from
    // being written correctly.
    //
    if(CLASS_IS_BLIZZARD && REVISION_IS_A0)
    {
    _EEPROMSectorMaskClear();
    }
    return(ui32Status);
    }

    //
    // Move on to the next word.
    //
    pui32Data++;
    ui32Count--;

    //
    // Do we need to move to the next block? This is the case if the
    // offset register has just wrapped back to 0. Note that we only
    // write the block register if we have more data to read. If this
    // register is written, the hardware expects a read or write operation
    // next. If a mass erase is requested instead, the mass erase will
    // fail.
    //
    if(ui32Count && (HWREGB(EEPROM_EEOFFSET) == 0))
    {
    HWREGB(EEPROM_EEBLOCK) += 1;
    }
    }

    //
    // Clear the sector protection bits to prevent possible problems when
    // programming the main flash array later.
    //
    if(CLASS_IS_BLIZZARD && REVISION_IS_A0)
    {
    _EEPROMSectorMaskClear();
    }

    //
    // Return the current status to the caller.
    //
    return(HWREGB(EEPROM_EEDONE));
    }

       thanks & regards,

  • Hello Shyam,

    Yes, it is always written as a word. So to optimize the EEPROM space, what you would need to do is

    1. To program a byte, first read the corresponding word from EEPROM

    2. Update only the required byte location

    3. Write it back to EEPROM

    E,g, Byte-2 on Word 0

    > Read Word 0 into a variable by calling EEPROMRead

    > AND variable with 0xFF00FFFF

    > Left Shift by 16 bits the Byte-2 and then OR with the variable

    > Program the EEPROM the updated Word 0 using EEPROMProgram

    Regards

    Amit

  • Amit Ashara said:
    Yes, it is always written as a word. So to optimize the EEPROM space, what you would need to do is

     Hi Amit, Word I suppose is not intended as 16 bit but also "word length" too, so Integer on TIVA follow as for C habit the integer and is 32bit.

    http://en.wikipedia.org/wiki/Integer_%28computer_science%29

     Writing as I supposed one byte per LongWord you can just fit 2048/4 ->512 LWord wasting just 3/4 of storage.

     I think our poster is not converting as you pointed 4 byte to 4 bytes Lword but just 1 bytes  to a LongWord.

  • Hello Roberto,

    Yes, that is correct. Using a Word of EEPROM to store a byte leaves 3/4 of the EEPROM unused when the write size is 32-bit for every EEPROM location. That is why to best utilize the EEPROM memory space, I suggested doing a SW movement of byte.

    Regards

    Amit