[fpc-devel] Need an elegant way to preset a specific memory area in elf files

Michael Ring mail at michael-ring.org
Fri Apr 18 16:27:33 CEST 2014


I need to preset 4 longWords at a specific memory location in flash of 
the microcontroller that define the startup behaviour of the chip.

I came up with two solutions, but both more feel like a hack than a 
proper way to do things, any ideas how to do this better?



a) by hijacking the declaration of a typed array constant in the linker 
script:

program x;
const
   devcfg : array[0..3] of longWord = ( 
$12345678,$87654321,$ffffffff,$00000000 );

linker script:

   .devcfg :
     KEEP(*(.data.n_tc*_devcfg))
   } > devcfg

or

b) by creating specialized units (very unflexible)

unit pic32mx8mhzpll;
interface
implementation
procedure dummy;assembler;nostackframe;
   asm
     .section ".devcfg,\"ax\", at progbits"
     .long 0x12345678
     .long 0x87654321
     .long 0x12345678
     .long 0x87654321
     .text
   end;
end.






More information about the fpc-devel mailing list