Function Pointer in Struct causing ADuC7X2X to not execute program


I have recently started porting software from several micro-controller families to use the ADuC7 series exclusively.

In a command line interface library (based on the work of Anthony Massa and Michael Barr) I have a struct in the header file:

typedef struct
     char const    *name;
     void          (*function)(void);
} command_t;

extern command_t const cmd_tab[];

and a table of functions with corresponding labels in the .c file

 command_t const cmd_tab[COMMAND_TABLE_SIZE] =
          {"CMD",         cmd_all,},               
          {"DAQ",          cmd_daq,},               
          {"HELP",     cmd_help,},               
          {"$",          cmd_inst,},               
          {"ID",          cmd_id,},
          {NULL,      NULL }

This has been functional on numerous Atmel microcontrollers, as well as the Intel XScale PXA255. The ARM compiler in uVision does not return any warnings or errors during compiling and linking. Currently the table is not being used. Just having the table in the .c file with NULL or functions prevents the controller from starting when I call something such as cmd_line();. I am unsure if this is a compiler problem (I have used GNU GCC up to this point). Any advice would be appreciated.


  • 0
    •  Analog Employees 
    on Aug 15, 2017 3:26 PM over 3 years ago

    One guess is that you don't have any start-up code in your project or that the start up code is not being located at the start of the memory space correctly.

    You calling the function means that the const table is being used. That would have the implication that the compiler cannot optimize it away. If this was being placed first in the read-only memory space then you would see the effect above.

    A guess of course, so provide a small build able example rather than just the source files and I will be able to confirm.

  • Attached is a .zip file of the project I have been using to test the library.

    Comment / un-comment cmd_line(); (line 50) in main.c to produce the fault.

    This has only been tested on ADuC702X devices. Right now I am using the ADuC7020 evaluation board.



  • 0
    •  Analog Employees 
    on Aug 16, 2017 9:39 AM over 3 years ago

    The code ends up in  the SWI_Handler() when this code is included.

    In fact, it is the inclusion of the printf that gets pulled in when this code is included that seems to trigger the issue, and you can replicate the issue by putting a printf() in main(). Therefore it is nothing to do with the cli.c code or the function pointers.

    Ending up in the SWI handler in many cases indicates that you need to re-target the standard library in some way...some libraries will use semi-hosting default implementations which use this SWI exception as their hook.

    I'm not familiar enough with the GCC compiler to tell you exactly what you need to do here, but hopefully this is a hint in the right direction.

  • 0
    •  Analog Employees 
    on Aug 2, 2018 3:55 PM over 2 years ago
    This question has been assumed as answered either offline via email or with a multi-part answer. This question has now been closed out. If you have an inquiry related to this topic please post a new question in the applicable product forum.

    Thank you,
    EZ Admin