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.

Stuffing CRC into flash during the programming process

My contract says I must calculate a CRC and compare it to the CRC stored in the last location of flash memory.  How do I stuff that last usable location in flash while I'm loading the rest of the program into flash?  I'd prefer to do this in one step rather than two as I have to send this to our production team to load the program and the objective is to make the process as simple as possible.

Thanks,

Rick

 

  • Rick,

    A brute force method would be to write your CRC algorithm, then run it on your final silicon build on the emulator. Stop the function just before the compare, see what value it came up with, then load that value as a constant into your project code and rebuild. When you rerun it with the rebuilt image it should pass the compare. The only downside to doing it this way if when you make a small tweak to your code you have to manually do this again to get the correct checksum. A more complicated method could get you to an automated process. In that case the best option might be to use hex2000 to generate a hex (text) file. Then you can write a script that will use the same CRC algorithm and calculate what value should be placed into the end of flash. Since the hex file is a text file you could then have the script replace the value for you and you give the hex file to the production team. This assumes your production team is using a programmer that can take hex input.

    Regards,
    Dave Foley

     

  • Thanks for your response Dave.  Let me clarify my question a little bit.  I know my CRC and I have the code already written that calculates the CRC and compares it with the data in the last flash address.  My problem is I don't know how to get the 16 bit CRC value into the flash while I'm programming the flash for the first time.  I'd like to program the code and stuff the last two bytes of flash with my CRC all in one step.  Currently, I would have to program the code, then erase the last 2 bytes of flash, and then stuff the last 2 bytes of flash.  I can do this but I'm not sure I want to write that much of a programming procedure and give our production people that complicated a programming process.

    Incidentally, by last 2 bytes of flash I'm referring to the last 2 available bytes.  I don't think I can use the code security section.

  • Rick,

    The latest C28x compiler (6.0.1) has the ability to embed the CRC for load sections you specify into your out file.  The CRC polynomials are fixed, though, so your check algo would need to change to use the same polynomial. It may also mean trying a newer compiler than you are currently using.

    This feature is documented in www.ti.com/lit/spru513 (assembly tools reference guide).

    Regards,

    Lori

     

  • Richard,

    Correct, you wouldn't want to use the code security section. The flash entry point is also there, so stay away from that as well. Your understanding of flash is slightly incorrect though, you cannot just erase two bytes (or words in our case). You can only erase an entire sector at once. You can program the majority of a sector leaving these two words alone and they will stay erased, then later program a CRC value in without erasing them. I understand this is not what you want to do. Just trying to clarify how the flash operates.

    Basically I think you are asking me how to embed a constant into the flash. What you want to do is declare the value in your .c code, e.g.,

    const Uint16 FlashCRCGoldenValue = 0x1234;

    Also in your .c code you will need to direct the linker as such:

    #ifdef __cplusplus
    #pragma DATA_SECTION("FlashCRCFile")
    #else
    #pragma DATA_SECTION(FlashCRCGoldenValue,"FlashCRCFile");
    #endif

    Then in your .cmd linker file under the "PAGE 1" heading in the MEMORY section you will add:

       FLASH_CRC      : origin = 0x3F7FF0, length = 0x000001     /* Flash CRC Golden Value */

    and in the SECTIONS section add:

       FlashCRCFile: > FLASH_CRC,   PAGE = 1

    You may need to rearrange some other variable in the linker command file as well so this word does not overlap something else already defined. Make sure the address specified in "origin" above is where you want it in flash. I'm not sure what device you are using.

    Regards,
    Dave Foley

     

     

  • Hi David,

    Thanks.  I understand.  However, I have only one issue.  Adding the const instruction in the .c code leads to a problem.  If I see my CRC is 0x1234 and I then put that in my CRC will change accordingly when I load the new code and calculate the CRC.  So I then change the CRC value in the const instruction.  I load the new code and check the CRC and lo and behold, it's changed again.

    I need a way that I can stuff the flash without putting it in the .c code.  Is there a way to embed the number in the .cmd file.  I need the .c code to stay constant or I'll end up chasing my tail.

    Thanks,

    Rick

     

  • Rick,

    No, you don't include the CRC Golden Value in your CRC calculation. Your algorithm should stop prior to reading it so its value does not affect the final CRC. What you are trying to do is to guarantee all the flash contents. By creating a CRC value that reads all of the locations except the CRC Golden Value and then compares it to a read of the CRC Golden Value you have guaranteed all of the flash.

    Regards,
    Dave Foley

     

  • Hi David,

    I think we're saying the same thing as you just wrote.  I guess my misunderstanding was the const Uint16 FlashCRCGoldenValue = 0x1234; instruction.  I gather from your response that this does not get included in the program flash.  It is just a place to put the number until it passes down through the compiler and assember and finally 0x1234 gets stored in the CRC flash address.  I was under the misunderstanding that 0x1234 (because it was in the .c code) would end up in program flash as well as the CRC flash address.

    Thanks,

    Rick

  • Thanks Lori.  I'm downloading spru513 now.  If I'm lucky I'll even find something in there about RAM check too.

    I'm not sure if I have the time left to change polys and compiler versions though. 

    Thanks,

    Rick

  • Rick,

    OK, good. I think we are on the same page now. The "pragma" command and linker command file changes I mentioned will take it out of the .text section and put it only in the FlashCRCFile section.

    Regards,
    Dave Foley

     

  • Thanks David and Lori for your responses. 

    David's option has been tested and verified.