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.

Calculating CRC on Flash Memory

Other Parts Discussed in Thread: HALCOGEN

Hi all,

I have an issue whit calculating the CRC on a flash memory area.

This area is defined in flash memory and it is written periodically every few minutes.

It is written using the function TI_Fee_WriteAsync and the block number is 1.

After the write is finished, there is no error returned by the function and I wait for the Flash status to go back to idle:

do
{
TI_Fee_MainFunction();
stFeeStatus = TI_Fee_GetStatus(GET_LAST_ACTION_STATUS);
}
while (stFeeStatus != IDLE);

After that, I go to calculate the CRC of the flash area using the functions:

trCrcConfig.crc_channel = 0U;
strCrcConfig.mode = CRC_FULL_CPU;

(I'm making sure the start data and size are correct)

/* Reset CRC module channel 0 */
crcChannelReset(ptrCrcRegs, 0U);

/* Calculate CRC */
crcSignGen(ptrCrcRegs, &strCrcConfig);

/* Get the calculated CRC value */
ctCrcValueCalc = crcGetPSASig(ptrCrcRegs, 0U);

When I calculate the CRC the very first time, on that flash memory area, it returns the correct value (I mean, the expected value). but when I write on it with TI_Fee_WriteAsync and then I calculate the CRC again, it doesn't change, it is still the same.

The only way for me to calculate the crc is to use the function TI_Fee_Read so to copy the content into a flash buffer and then calculate the CRC on it. In that case, I see the CRC changing every time i save new values on the flash.

I'm not very sure where the problem could be.

I'm aware that the flash area for bank 1 is above 0xF02XXXXXXU and the flash are I'm try to calculate the CRC is at 0x00039440.

How do I map the bank1 area with with my allocated memory area at 0x00039440? So when i write to the bank1 i can see my allocated memory area changed?

Thanks for your help

Giorgio

  • Hi Giorgio,

    You can calculate the CRC of the whole flash, or part of the flash. RM48 has 2 banks of program flash: bank 0 and bank 1. The data flash is bank 7. Using FEE API is the only way to read the correct updated block data.

    If you calculate the CRC of the flash content at 0x39440, writing data to bank 7 starting at 0xF0200000 will not affect that CRC value. Let us know the details how you calculate the CRC.
  • Hi QJ Wang

    Do I need to Format or erase bank 7 before writing on it?
    Or the Functions TI_Fee_WriteAsync and TI_Fee_WriteSync (together with TI_Fee_MainFunction) will manage to erase the bank 7 if I keep writing multiple time on it?

    I want to write on it every 5 minutes to save the content of a specific section of RAM, but I'm not sure if I have to clear up the bank 7 before I write on.

    My goal is that, if the device is powered off (even for a long time) I can read bank 7 every time I startup so to copy that data back to the specific memory location.

    Also, How to correctly configure Halcogen Fee tab? 

    For bank 7 is would like to have 2 blocks only, where I will save 2 different kinds of data, so sometime I will save on block 1 and some time on block 2. Ideally , If bank7 is 64 KB I would like to have block 1 and 2 of 32Kb each. How many virtual sectors do I have to specify in the Fee tab?


    Thanks again for your help

  • Hi Giorgio,

    The EEPROM should be erased before the first use. After that, you don't need to erase the EEPROM virtual sectors manually, and the FEE APIs will take care of the erasing. The EEPROM is divided into 2 or more virtual sectors which contains 1 or more physical flash sectors.

    The TI_Fee_Init() will identify which Virtual Sector to be used and marks it as Active. The data (with block header) is written to the first empty location in the Active Virtual Sector. If there is insufficient space in the current Virtual Sector to update the data, it switches over to the next Virtual Sector and copies all the valid data from the other Data Blocks in the current Virtual Sector to the new one. After copying all the valid data, the current Virtual Sector is marked as ready for erase and the new one is marked as Active Virtual Sector. Any new data is now written into the new Active Virtual Sector and the Virtual Sector which is marked as ready for erase will be erased in background.

    The total size of the EEPROM is 64KB. A minimum of two Virtual Sectors are required for Flash EEPROM emulation. The total size of all the blocks should be less than the size of the virtual sector. If you use 2 Virtual sector and each VS is 32KB, so the block1 + block2 should be less than 32KB.

    Will you use the block 1 and block 2 to store the same data?
  • Thanks for your response.

    I have to sete of variables stored in memory. They are always the same variables but can be written with different values.

    I would like to store one set of variables separated from the other set so I was thinking to use the fee async write function with parameter block 1 for data set 1 and use the function fee write async with  block 2 as parameter.

    They are always the same variables but if they change in ram I would like to write them to bank 7 block one or two depending on what set of variables change value.

    In this way. If the device is switched off, I can reload the ram variables with the one in the bank 7 after a new start up.

    Is it something I can do? Keep writing every 5 minutes in the same blocks? Assuming I write for each block around 20k of data?

    Thnaks again for your help

  • Hi,

    If the block size is 20KB and you only use 1 block, the first time is data is written in Virtual sector 1, next time the data will be written into the VS 2 since VS 1 doesn't have enough space (32k-20k), and the VS 1 will be erased at the same time.

    If you have 2 blocks and each block is 20KB, it won't work.
  • Hi

    Thnaks for your answer, I understand now.
    So basically I have to reduce the amount of data I write, it should not be a problem.
    I can still have to set of data that I can write on bank 7 block one and block 2 but I have to make sure that I don't fill up the virtual sector 1 after writing both set of data, so next time I will write block one and 2 after five minutes it will go to write them in virtual sector 2 and erase virtual sector 1. So I assume that the function fee read will automatically automatically go reading from the vector my last save it?

    Thanks again
    Giorgio
  • Hi Giorgio,

    The TI_Fee_read() reads the latest valid block data.
  • Hi QJ Wang,

    Last question :)

    So, let's say I have In RAM 2 buffers of 3Kb each, one buffer for my variables set 1 and one buffer for variable set 2. Also, assume that the variables will have a different value from the first time I saved them.

    I use the function TI_Fee_WriteAsync(1U, ptrRamAddr1); to write my first set of variables in block 1and I use TI_Fee_WriteAsync(2U, ptrRamAddr2); to write my second set of variables to block 2.

    After each writes, I call the function TI_Fee_MainFunction(); and I call the 2 writes in sequence:

    stWriteStatus = TI_Fee_WriteAsync(1U, ptrRamAddr1);
    do
    {
    TI_Fee_MainFunction();
    delay();
    stFeeStatus = TI_Fee_GetStatus(0U);
    }while (stFeeStatus != IDLE);

    stWriteStatus = TI_Fee_WriteAsync(2U, ptrRamAddr2);
    do
    {
    TI_Fee_MainFunction();
    delay();
    stFeeStatus = TI_Fee_GetStatus(0U);
    }while (stFeeStatus != IDLE);

    My understanding is that block 1 and block 2 are written starting from 2 different address within Sector 1 if there is still space in sector one.

    After 5 minutes I write block 1 and 2 again. Assuming that the content of my 2 buffers in ram is different when I call TI_Fee_WriteAsync(1U, ptrRamAddr1) and TI_Fee_WriteAsync(2U, ptrRamAddr2), My data will be appended into empty space in Vector one if there is still space? And my 2 new blocks are going to be marked active while the 2 written 5 minutes earlier are going to be marked invalid?

    Also, How the WriteAsync function knows the length of the data buffer I'm passing to it by pointer?

    Thanks again for your help

    Giorgio

  • Hello,

    Your understanding is correct. Each data block contains 24 bytes header. The header consists of block size, block status, checksum and the address of previous address.

    You can use HALCOGen to configure the block. You can also configure the block manually in ti_fee_cfg.c

    ti_fee.cfg.c: