Other Parts Discussed in Thread: HALCOGEN
Hi
I'm new to the Hercules processors. I'm using the Hercules Safety MCU Development Kit and I'm having a problem reading & writing large amounts of data to the EEPROM using the TI FEE Driver.
I've included a copy of my code below which I adapted from example_TI_Fee_Write_Read.c
I've configured the TI FEE driver in Halcogen to use 16 blocks each with a size of 2048 bytes and 4 virtual sectors
I'm using a simple 8-bit checksum to determine if the data is read back correctly and always after reading block 7 I get a checksum mismatch. I also checked the last error and job result after each read and write and they don't indicate any problems.
See my screenshots of the Halcogen FEE Driver configuration and my code below
/* USER CODE BEGIN (0) */ #include "ti_fee.h" /* USER CODE END */ /* Include Files */ #include "sys_common.h" /* USER CODE BEGIN (1) */ /* FEE Block Size */ #define BLOCK_SIZE 2048 TI_FeeJobResultType JobResult=JOB_OK; TI_FeeModuleStatusType Status=UNINIT; TI_Fee_ErrorCodeType Error=Error_Nil; Std_ReturnType oResult=E_OK; unsigned char read_data[BLOCK_SIZE]={0}; uint8 SpecialRamBlock[BLOCK_SIZE]; unsigned char pattern; uint16 u16writecounter; unsigned int FeeVirtualSectorNumber; unsigned char VsState, u8EEPIndex; unsigned char u8VirtualSector; uint8 Test_Recovery; uint8 Test_Cancel; void delay(void) { unsigned int dummycnt=0x0000FFU; do { dummycnt--; } while(dummycnt>0); } /* USER CODE END */ /** @fn void main(void) * @brief Application main function * @note This function is empty by default. * * This function is called after startup. * The user can use this function to implement the application. */ /* USER CODE BEGIN (2) */ /* USER CODE END */ int main(void) { /* USER CODE BEGIN (3) */ unsigned int BlockNumber; unsigned int BlockOffset, Length; unsigned char *Read_Ptr=read_data; unsigned int loop; /* Initialize RAM array.*/ uint8 RandomData[7] = { 0xBAU, 0x28U, 0x4BU, 0x27U, 0x64U, 0xB4U, 0x7BU }; for(loop=0;loop<BLOCK_SIZE;loop++)SpecialRamBlock[loop] = RandomData[loop%7]; /* Calculate 8 bit checksum of RAM array data */ uint8 Checksum1 = 0; for(loop=0;loop<BLOCK_SIZE;loop++) Checksum1 += SpecialRamBlock[loop]; Checksum1 = ~Checksum1 + 1; /* Format all EEPROM */ TI_Fee_Format(0x5A5A5A5AU); /* Initialize FEE. This will create Virtual sectors, initialize global variables etc.*/ TI_Fee_Init(); do { TI_Fee_MainFunction(); delay(); Status=TI_Fee_GetStatus(0 ); } while(Status!= IDLE); /* Write the blocks into EEP Asynchronously. Block size is configured in ti_fee_cfg.c file. */ for (BlockNumber = 1; BlockNumber <= TI_FEE_NUMBER_OF_BLOCKS; BlockNumber++) { TI_Fee_WriteAsync(BlockNumber, &SpecialRamBlock[0]); do { TI_Fee_MainFunction(); delay(); Status=TI_Fee_GetStatus(0); } while(Status!=IDLE); /* Check for errors after write */ Error = TI_FeeErrorCode(0); JobResult = TI_Fee_GetJobResult(0); if (Error != Error_Nil || JobResult != JOB_OK) while(1); } /* Read the blocks */ BlockOffset = 0; for (BlockNumber = 1; BlockNumber <= TI_FEE_NUMBER_OF_BLOCKS; BlockNumber++) { Length = Fee_BlockConfiguration[BlockNumber-1].FeeBlockSize; oResult=TI_Fee_Read(BlockNumber,BlockOffset,Read_Ptr,Length); do { TI_Fee_MainFunction(); delay(); Status=TI_Fee_GetStatus(0); } while(Status!=IDLE); /* Calculate 8 bit checksum of data read from EEPROM */ uint8 Checksum2 = 0; for(loop=0;loop<BLOCK_SIZE;loop++) Checksum2 += *(Read_Ptr+loop); Checksum2 = ~Checksum2 + 1; if (Checksum1 != Checksum2) { /* Checksums don't match */ Error = TI_FeeErrorCode(0); JobResult = TI_Fee_GetJobResult(0); /******************** Always gets stuck here after reading block 7 ****************************/ while(1); } for(loop=0;loop<BLOCK_SIZE;loop++) *(Read_Ptr+loop) = 0; } /* Invalidate a written block */ for (BlockNumber = 1; BlockNumber <= TI_FEE_NUMBER_OF_BLOCKS; BlockNumber++) { TI_Fee_InvalidateBlock(BlockNumber); do { TI_Fee_MainFunction(); delay(); Status=TI_Fee_GetStatus(0); } while(Status!=IDLE); } /* Format bank 7 */ TI_Fee_Format(0xA5A5A5A5U); while(1); /* USER CODE END */ return 0; } /* USER CODE BEGIN (4) */ /* USER CODE END */