Topic : store a constant (Checksum) at fixed location in flash

Forum : ARM

Original Post
Post Information Post
January 18, 2016 - 12:33pm
John Porteous

How do I store a constant at a fixed location in the flash from within the GNU GCC compiler.   The __attribute__ 'at' generates a warning to say its being ignored.

This is required to do a simple sum check of the .text segment during program initialisation. e.g.

   csum  = 0;
    fptr = &First_Funct;           // address of first function in main.c - just above the vector table
    cptr = (WORD *)fptr;
    eptr = (WORD *)&_eidata;
    
    while (cptr <= eptr) {
       csum = (csum + *cptr) ;
       cptr ++;
    }    

   while (  csum <> expected)   - error

Replies
Post Information Post
+1
0
-1
January 19, 2016 - 4:13pm
Etienne Cassin

Dear John,

In order to store a constant at a fixed location you need to create a section in your linker script and add your constant in the main.

Please, have a look of the count.rprj example you can find at C:\Raisonance\Ride\Example\ARM\Count:

We added the "count" variable (__attribute__) to the flash section "ram_start1"

For more information you can read GCC linker manual provided at C:\Raisonance\Ride\Doc\ARM\gcc\ld.pdf

I hope it helps.

Regards,

+1
0
-1
January 20, 2016 - 8:56am
John Porteous

thanks

I had already got the declaration as

const WORD expected_chksum  __attribute__((section (".myChecksumSection"))) = 0xEE9B959C ;

the problem I had was fixing location in the linker, given that the LD files get re-written each build.  the 401 startup is in assembler, but adding the following to the end of startup_stm32f401xc.s appears to work

.section .text.myChecksumSection

this puts the section at the end of the vectors and before the code.

what I have found is that changing the expected checksum value also changes the actual checksum, which it shouldnt because it is stored outside of the area being checked.  doing checksum in sections to try and identify,

regards

Dr Johhn

+1
0
-1
January 20, 2016 - 4:33pm
John Porteous

found the problem - the checksum was being stored where I wanted it and again whaere I didn't due to issue in startup file

+1
0
-1
February 1, 2016 - 4:42pm
Etienne Cassin

Note that all LD files get re-written if you choose the default linker script. A part of the LD file will be re-written but not your  specific script when selecting "No" to the default linker script.

You need to add this specific file in your project and specify the path.

Best regards,