Hi all, I could use some help because I'm really struggling here
I've a project based on the SAMV71Q21B, built using MPLAB-X and Harmony 3 for BSP and drivers code generation.
The problem is that I can't figure out how to run a function from ram (I need to read the unique ID from flash and the access must be done from ram because when
accessing that specific flash controller register no code can be fetched from flash).
Moreover, all the examples and responses on github or forums that I've found refer to GCC compiler, not XC32, and the linker scripts and startup code are quite different for the two:
- in the GCC linker script there is a 'relocate' region defined, but not on the XC32 linker
- in the GCC startup code there is the relevant memory initialization code that copies the relocate section to ram, but not on the XC32 startup version
- in the XC32 startup version there is a call to a '__pic32c_data_initialization()' which I suspect could be the one that copies the relocatable code, but it's a closed library function so I can't tell.
I've started adding this attribute in front of the relevant function:
__attribute__ ((ramfunc,section(".ramfunc"),long_call, unique_section,noinline)) void utils_base_unique_id(uint8_t *uid)
{ [READ ID FROM FLASH CODE] }
but when compiling a get a bunch of errors I don't understand, it seems like the linker is moving other unrelated code to the relocate section:
/opt/microchip/xc32/v4.00/bin/bin/../../lib/gcc/pic32c/8.3.1/../../../../bin/bin/pic32c-ld: Link Warning: attributes for input section '.RAMFUNC$.__stub' conflict with output section '.RAMFUNC$'
/opt/microchip/xc32/v4.00/bin/bin/../../lib/gcc/pic32c/8.3.1/../../../../bin/bin/pic32c-ld: section .text.CLK_MainClockInitialize%449 LMA [004a264c,004a26df] overlaps section .text.sys_init%448 LMA [004a25b4,004a2657]
/opt/microchip/xc32/v4.00/bin/bin/../../lib/gcc/pic32c/8.3.1/../../../../bin/bin/pic32c-ld: section .bss.resp.13237%53 VMA [20420e7c,20420f03] overlaps section .RAMFUNC$ VMA [20420dec,20420e8f]
Link Error: can't load section .RAMFUNC$ contents
/opt/microchip/xc32/v4.00/bin/bin/../../lib/gcc/pic32c/8.3.1/../../../../bin/bin/pic32c-ld: BFD (Microchip xc32 v4.00) 2.32.0.20190703 internal error, aborting at /data01/build/bamboo/xml-data/build-dir/M32DEV-BGT38-JOB1/src/gcc-8-merge/binutils/bfd/elf32-pic32c.c:324 in bfd_pic32_process_data_section
I've tried to add the missing relocate section to my linker script (copied from the gcc script) but I get a similar but different error:
/opt/microchip/xc32/v4.00/bin/bin/../../lib/gcc/pic32c/8.3.1/../../../../bin/bin/pic32c-ld: Please report this bug.
/opt/microchip/xc32/v4.00/bin/bin/../../lib/gcc/pic32c/8.3.1/../../../../bin/bin/pic32c-ld: Link Warning: attributes for input section '.data.uxCriticalNesting' conflict with output section '.relocate'
/opt/microchip/xc32/v4.00/bin/bin/../../lib/gcc/pic32c/8.3.1/../../../../bin/bin/pic32c-ld: Link Warning: attributes for input section '.ramfunc.utils_base_unique_id.__stub' conflict with output section '.relocate'
/opt/microchip/xc32/v4.00/bin/bin/../../lib/gcc/pic32c/8.3.1/../../../../bin/bin/pic32c-ld: section .dinit%204 LMA [00485610,0048773f] overlaps section .relocate LMA [00484390,0048561f]
/opt/microchip/xc32/v4.00/bin/bin/../../lib/gcc/pic32c/8.3.1/../../../../bin/bin/pic32c-ld: section .text.CLK_MainClockInitialize%414 LMA [004a38cc,004a395f] overlaps section .text.sys_init%413 LMA [004a3834,004a38d7]
/opt/microchip/xc32/v4.00/bin/bin/../../lib/gcc/pic32c/8.3.1/../../../../bin/bin/pic32c-ld: section .bss.ucHeap%1 VMA [20401a80,2040ba7f] overlaps section .relocate VMA [20400800,20401a8f]
Link Error: can't load section .data.uxCriticalNesting contents
/opt/microchip/xc32/v4.00/bin/bin/../../lib/gcc/pic32c/8.3.1/../../../../bin/bin/pic32c-ld: BFD (Microchip xc32 v4.00) 2.32.0.20190703 internal error, aborting at /data01/build/bamboo/xml-data/build-dir/M32DEV-BGT38-JOB1/src/gcc-8-merge/binutils/bfd/elf32-pic32c.c:324 in bfd_pic32_process_data_section
/opt/microchip/xc32/v4.00/bin/bin/../../lib/gcc/pic32c/8.3.1/../../../../bin/bin/pic32c-ld: Please report this bug.
Does anyone have a sample code for th V71 or another SAM using XC32 and running a function from ram?
Any help really appreciated
Attached my startup code (vanilla) and my slightly modified linker script with the ramfunc section added commented out (renamed to TXT because .ld is not allowed)