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.

UCD3138A: There are two different ways to copy "zero_out_integrity_word" to RAM, Which one is better?

Part Number: UCD3138A

Hello,

I found that there are two different ways to copy the codes of "zero_out_integrity_word" to RAM from Pflash and then execute it to clear the Pflash checksum, shown as below. Which way is better?

One way in LLC demo code:

{
        register Uint32 * program_index = (Uint32 *) 0x19000; //store destination address for program
        register Uint32 * source_index = (Uint32 *)zero_out_integrity_word; //Set source address of PFLASH;

        register Uint32 counter;

        for(counter=0; counter < 32; counter++) //Copy program from PFLASH to RAM
        {
         *(program_index++)=*(source_index++);
        }
       }
       {
        register FUNC_PTR func_ptr;
        func_ptr=(FUNC_PTR)0x19000;     //Set function to 0x19000
        func_ptr();
        DecRegs.MFBALR1.bit.RONLY = 1; //restore it to read only
        DecRegs.MFBALR17.bit.RONLY = 1; //restore it to read only
        SysRegs.SYSECR.bit.RESET= 2; //reset device
       }

       return;

The other way in PFC demo code:

   register Uint32 * program_index = (Uint32 *) program_area; //store destination address for program
   register Uint32 * source_index = (Uint32 *) zero_out_integrity_word_start; //Used for source address of PFLASH;
   register Uint32 counter;

   for(counter=0; counter < 32; counter++) //Copy program from PFLASH to RAM
   {
    *(program_index++)=*(source_index++);
   }

   zero_out_integrity_word();
            return;

  • We will get back to you soon.

  • The second way is probably better, but there are lots of other changes all over the code to make it possible.

    The old version is fine unless you are doing multi-image codes with on the fly code version switching. In on-the-fly switching, you have to be able to run code in RAM without ruining the variables, and be able to jump to other places from the code.

    In normal code, whenever you clear the checksum, you are going to reset anyway, so it doesn't matter if you destroy the RAM variables.

    For the second version, you have to change the cyclone.cmd file to make a special program area in RAM where code is compiled to execute in that area but to be stored in the program flash.

       UNION : run = RAM
     {
      .ram_for_program_area
      .zero_out_integrity_word_0 : load = PFLASH, start(_zero_out_integrity_word_start) {zero_out_integrity_word.obj }
      .clear_program_flash : load = PFLASH, start(_clear_program_flash_start) {clear_program_flash.obj }
     }

    There are some other changes as well.  I don't remember them all, but if you search for things like clear_program_flash_start, you will find some of them.