This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28335: How to include function pointer at a specified flash location

Part Number: TMS320F28335


I'm trying to add a function pointer at a specified location in flash. I've tried the following code, but I'm getting nothing written to the specified location in flash; it's just empty (all Fs). I've tried the CODE_SECTION option, but that just places the entire function in that memory space, I just need the pointer there.

In main.c:

#pragma DATA_SECTION(normalOperation, "NORMALOP")

void
normalOperation ( void ){
code here
}

In the linker:

MEMORY
{
PAGE 0:
JUMPTBL    : origin = 0x338000, length = 0x000064
}

SECTIONS
{
NORMALOP        : > JUMPTBL    PAGE = 0
}

When I run this, I get the warning of "#824-D pragma DATA_SECTION can only be applied to a file level symbol definition, not "normalOperation" (declared at line 402) main.c" and no pointer in the specified memory section.

What is the correct way to place a function pointer in flash memory?

  • What about

    #pragma DATA_SECTION(ptr_to_normalOperation, "NORMALOP")

    void (*ptr_to_normalOperation)(void) = normalOperation;

    Best regards

    Johannes

  • When I enter that instead, the code will compile and run, but no pointer gets written to flash.

  • Maybe

    void (* const ptr_to_normalOperation)(void) = normalOperation;

    does the trick.

    Regards

    Johannes

  • This stores the address of where normalOperation starts, and it stores it at the correct location, but does not handle the actual jump, so I can't use it as a jump table to jump to various functions. I feel like we're really close.

  • Hi Christopher,

    I'm afraid I don't know what exactly you want to do.

    If you want to have a table of function pointers it would look like this:

    void (* const function_table[4])(void) = {
      normalOperation,
      foo,
      bar,
      NULL
    };

    In order to call the i-th function from the table you would write

    function_table[i]();

    In order to call normalOperation, you would write

    function_table[0]();

    You will need to write code that decides which of the functions of the table have to be called and actually does the call(s).

    Best regards

    Johannes

  • After some more trial and error, I found the following code worked out for me for jumping directly to specific functions:

    #pragma CODE_SECTION(jumpTable, "JUMPTABLE")
    void jumpTable(void){
    normalOperation();
    anyOtherfunctions();
    ...etc
    }
    or alternatively 
    asm(" LB 0xHEXADDRESS"); if you're trying to branch to a specific address instead of a function
    In the linker file:
    Under Memory:
     JUMPTBL    : origin = 0x338000, length = 0x000064 
    Under sections:
    JUMPTABLE : > JUMPTBL    PAGE = 0
    Since I knew the base address, and each jump was 2 lines of assembly, I could put a bunch of function calls back to back that I could call from anywhere. Not just function pointers, but actual jumps to the function or address desired. Hope this helps someone else!