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.

RTOS/TM4C1292NCPDT: EEPROM read/Write Issue

Part Number: TM4C1292NCPDT

Tool/software: TI-RTOS

HI,

My application need to store boot up parameters in EEPROM, and it will be used through out the program execution and these values will be frequently get updated from application software.

Initially these values available in flash sector(programmed through J-Tag) and it will written into EEPROM on first boot, there after firmware will use use the values from EEPROM memory.

earlier i have used these variables from flash sector itself. Since EEPROM endurance is more when compared to flash, i have moved flash sector to EEPROM sector. 

I am getting HW exception that leads infinite loop, when replacing with EEPROM APIs instead of flash APIs and also i am observing some other task stack usage is getting full, even though that task is not running.

The followings code is used earlier.

void flashWrite(BOOT_STRUCT *stFlashData)
{
    int ret;

    ret = FlashErase((uint32_t ) FLASH_COMMON_MEMORY_ADDRESS);
    if(ret != NULL)
    {
        System_printf("FLash memory is not erased successfully\n");
    }

    ret = FlashProgram((uint32_t *)stFlashData,
            FLASH_COMMON_MEMORY_ADDRESS, 2048);
    if(ret != NULL)
    {
        System_printf("FLash memory is not programmed successfully\n");
    }

    System_flush();
}

BOOT_STRUCT  flashRead(BOOT_STRUCT *stFlashData)
{
	stFlashData = ((BOOT_STRUCT  *)FLASH_COMMON_MEMORY_ADDRESS );
	return *stFlashData;
}

and i am replacing with following APIs.

#define EPROM_START_ADDRESS          0x0
#define BOOT_PARAMETER_SIZE          1024

void EpromWrite(BOOT_STRUCT *stEpromData)
{
    ret = EEPROMMassErase();
    if(ret != 0)
    {
        System_printf("Eeprom Erase Failed: Error No - %d\n", ret);
    }

    ret = EEPROMProgram((uint32_t *)stEpromData, EPROM_START_ADDRESS,
                        BOOT_PARAMETER_SIZE);
    if(ret != 0)
	{
        System_printf("EPROM data write failed: Error No - %d\n", ret);
    }

}


//for Reading the data the folowing APIs is used.
EEPROMRead((uint32_t *)stEpromData, EPROM_START_ADDRESS,
	                                                BOOT_PARAMETER_SIZE);

i have checked using breakpoints and  EEPROM read succeed always. i will be able to see the values in read data structure. The HW exception occurs, after read complete and trying to execute some other routine. but when replace with flash API its working fine.

Can you please help me finding the solution? is there any other dependencies before EEPROM write/Read.

i using the following versions of tool set.

CCS8.1

tirtos_tivac_2_16_01_14

TivaWare_C_Series-2.1.4.178

Regards

Bala

  • Hi Bala,
    No exactly sure what is wrong. You are passing the (uint32_t *)stEpromData as the first parameter to the EEPROMRead. How and where did you define this pointer variable? I know you typecast to (uint32_t *). But is it possible that it was not aligned to a word boundary when it was originally declared? Next, If you look at the below API description it says that hte pui32Data must point to at least ui32Count bytes of available memory. This is something to check to. Why don't you lower the BOOT_PARAMETER_SIZE size? Start with a small value like 4 and gradually increase. Does the size play a role in the problem?

    Prototype:
    void
    EEPROMRead(uint32_t *pui32Data,
    uint32_t ui32Address,
    uint32_t ui32Count)
    Parameters:
    pui32Data is a pointer to storage for the data read from the EEPROM. This pointer must point
    to at least ui32Count bytes of available memory.
    ui32Address is the byte address within the EEPROM from which data is to be read. This
    value must be a multiple of 4.
    ui32Count is the number of bytes of data to read from the EEPROM. This value must be a
    multiple of 4.
  • Hi Charles,

    thank you for your quick reply.

    Charles Tsai said:
    You are passing the (uint32_t *)stEpromData as the first parameter to the EEPROMRead. How and where did you define this pointer variable? I know you typecast to (uint32_t *). But is it possible that it was not aligned to a word boundary when it was originally declared?

    Its the structure pointer typecasted into uint32_t*. the below is the structure definition. Do meant the size of the structure should be word aligned. how do measure the size of this structure or find how it will be aligned  in cortex-m4 controller?

    typedef struct BootDataStructure
    {
        bool bUpdateFlag;           
        bool bNif;                  
        bool bRif;                  
        bool bValidatedFlag;        
        bool bBootedFlag;          
        char cBaseIPAddr[32];       
        char cIPAddr[32];           
        char cIPMask[32];          
        char cIPGateAddr[32];      
        char cDomain[32];           
        char cTftpIPAddr[32];       
        char cCurrentImageName[32];    
        char cGoldenImageName[32];     
        char cFileName[32];            
        char cSerialNum[32];            
        char cPartNum[32];              
        char cModuleConfigNum[32];        
        uint8_t ui8DiSourceSink;       
        uint8_t ui8UsrPgmTaskPriMin;    
        uint8_t ui8UsrPgmTaskPriMax;    
        uint8_t ui8AiMedian[8];        
        uint16_t ui16BootDiLed;         
        uint16_t ui16BootDoLed;         
        uint16_t ui16DiDebounceM;       
        uint16_t ui16AiFormatM;         
        uint16_t ui16AoutRangeM;        
        uint16_t ui16AinRangeM;         
        uint16_t ui16AoutRangeA;       
        uint16_t ui16AoutRangeB;       
        uint16_t ui16AoutFormatM;       
        uint16_t ui16AoutFormatA;       
        uint16_t ui16AoutFormatB;      
        uint16_t ui16DoSourceSink;     
        uint16_t ui16ClkInDIV;
        uint16_t ui16ClkOutDIV;
        uint16_t ui16downloadStatus;    
        uint16_t ui16SerBaud;          
        uint16_t ui16SerSignal;         
        uint16_t ui16CicDecimate[8];    
        uint16_t ui16DiDebounce[12];    
        uint16_t ui16AiRange[8];        
        uint16_t ui16AiFormat[8];       
        uint16_t ui16AinRange0Gain[8];  
        uint16_t ui16AinRange1Gain[8]; 
        uint16_t ui16AinRange2Gain[8];  
        uint16_t ui16AinRange3Gain[8];  
        uint16_t ui16AinRange0Offset[8];   
        uint16_t ui16AinRange1Offset[8];    
        uint16_t ui16AinRange2Offset[8];    
        uint16_t ui16AinRange3Offset[8];    
        uint16_t ui16AoutRange0Gain[6];     
        uint16_t ui16AoutRange1Gain[6];     
        uint16_t ui16AoutRange2Gain[6];     
        uint16_t ui16AoutRange3Gain[6];
        uint16_t ui16AoutRange0Offset[6];
        uint16_t ui16AoutRange1Offset[6];   
        uint16_t ui16AoutRange2Offset[6];   
        uint16_t ui16AoutRange3Offset[6];    
        uint32_t ui32DowmloadCRC;           
        uint32_t ui32CurrentImageLocation;  
        uint32_t ui32SignatureData;         
    }BOOT_STRUCT;
    

    Charles Tsai said:
    Next, If you look at the below API description it says that hte pui32Data must point to at least ui32Count bytes of available memory.

    Only this structure we are trying to write and read it back. infact the operation as follows.

    Boot loader(bare metal code) running at flash sector 0x0 is writing data into eeprom and Firmware(RTOS code) which is running 0x4000 is reading back. no write is attempted in the main firmware. 

    Regards

    Bala

  • Hi Charles,

    The problem was i am trying to read more than the size of data structure from EEPROM and that causes the other task memory is getting corrupted. and also the data structure is not word aligned earlier.

    Now the issue has been resolved by making data structure word aligned and reading and writing size of structure variables.

    your quick reply resolved my issues. thank you.

    Regards
    Bala