AnsweredAssumed Answered

LP4330 (or other) - Calling assembly function located in RAM from C that is in Flash

Question asked by Nathan Smith on Sep 29, 2016
Latest reply on Sep 29, 2016 by A VT

I'm using a LPC4330 with LPCXpresso 8.2.  In the project, most code runs in place in QSPI at 100MHz but I have some functions I need to run very fast so they are located into RAM.


I've been attempting to determine how to call an assembly function located in RAM.  An example of the assembly code is as follows:


    .syntax unified
    .section .ramfunc.$RAM2

    .global    CLZ


    clz r0, r0
    bx lr



This assembly file is part of the project and built with the GCC tool along with the rest of the project.


In a header file I have the C prototype for this assembly function:

__RAMFUNC(RAM2) int CLZ(int x);


The call to this function from C code that is located in Flash compiles using an address for the CLZ call that is in the middle of some other functions.  Therefore I assume something isn't setup right as the linker is just plain confused.


The C code that first attempts to use this assembly function is:

       return CLZ(gbMask) - 1;


The instructions that are compiled into flash are (not the indicated veneer address):


14002780:   mov     r0, r10
14002782:   blx     0x14013db0 <__CLZ_veneer>
14002786:   subs    r0, #1

However the CLZ function is located in RAM where I expect it (From the map file):

                [!provide]                PROVIDE (__start_data_RAM2, .)
                0x10080000       0x16 ./src/mp3codec/asmmisc.o
                0x10080000                MULSHIFT32
                0x10080006                FASTABS
                0x10080010                CLZ

So, I'm expecting the branch call to be to 0x10080010 but instead it is to some other code.  It happens to be some const data that are invalid instructions.


Do I have to do something special to get the C code to link to the assembly properly in the case it is in a different section?  I don't get any compile or link warnings that I can find.  Seems like this should be throwing a warning or an error as it certainly isn't linking to anything valid.