clinkerembeddedfirmwarexc32

MPLAB X32 compiler and moving function to RAM causes linker error


I'm using Microchips XC32 C compiler and tools to build an executable for a SAM E70 processor.

I have to create a function that is executed from RAM and not ROM/flash memory memory, because this function uses special instructions to read a unique 128 bits at the beginning of flash.

So I've defined the beginning of the function like this:

__ramfunc__ void ReadUniqueID(uint32_t *pdwUniqueID)
{
    uint32_t status;

    if (pdwUniqueID == NULL)
        return;
    printf("ReadUniqueID begin\r\n", pdwUniqueID[0]);

According to the documentation, __ramfunc__ is supposed to ensure that the function is executed from ram.

However, when linking, the following errors occur.

c:\program files\microchip\xc32\v3.01\bin\bin\..\..\lib\gcc\pic32c\8.3.1\..\..\..\..\bin\bin/pic32c-ld.exe: Link Warning: attributes for input section '.RAMFUNC$.__stub' conflict with output section '.RAMFUNC$'
c:\program files\microchip\xc32\v3.01\bin\bin\..\..\lib\gcc\pic32c\8.3.1\..\..\..\..\bin\bin/pic32c-ld.exe: section .text.Reset_Handler%184 LMA [0044ba08,0044bb8b] overlaps section .text%180 LMA [0044b3bc,0044ba0f]
c:\program files\microchip\xc32\v3.01\bin\bin\..\..\lib\gcc\pic32c\8.3.1\..\..\..\..\bin\bin/pic32c-ld.exe: section .bss%44 VMA [2045fff4,2045ffff] overlaps section .RAMFUNC$ VMA [2045ff58,20460007]
Link Error: can't load section .RAMFUNC$ contents

Solution

  • The problem turned out to be that I was using printf() in the "ramfunc" function. I removed the printf()'s and all was working as expected.