Проверил идею с вызовом функций через указатели - работает
Код:
#include "stdio.h"
#include "stdint.h"
int main(void)
{
#define FUNC_ARR_ADRESS 0x08069000
int (*summ)(int,int);
int (*multiplication)(int,int);
volatile int result;
summ = (uint32_t)*((uint32_t*)FUNC_ARR_ADRESS);
multiplication = (uint32_t)*((uint32_t*)(FUNC_ARR_ADRESS+4));
result = summ(5,8);
result = multiplication(5,8);
result = multiplication(22,4);
while(1)
{
}
}
Сами функции были созданы в другом проекте и залиты во флеш заранее.
Код:
#include <stdio.h>
int summ(int x, int y){
return (x+y);
}
int multiplication(int x, int y){
return (x*y);
}
Код:
* func_arr.cpp
*
* Created on: 08 июня 2016 г.
*/
#include <stdio.h>
typedef void
(* const pFunc)(void);
extern int summ(int, int);
extern int multiplication(int, int);
__attribute__ ((section(" .func_pointer_arr"),used))
pFunc func_pointers_array[] =
{
pFunc(summ),
pFunc(multiplication),
pFunc(0x0),
pFunc(0x0)
};
Опции линкера
Код:
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
CCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 0
FLASH (rx) : ORIGIN = 0x08069800, LENGTH = 44K
FUNC_ARR (rx) : ORIGIN = 0x08069000, LENGTH = 2K
INTERRUPTS_STUB (rx) : ORIGIN = 0x8000000, LENGTH = 4K
FLASHB1 (rx) : ORIGIN = 0x00000000, LENGTH = 0
EXTMEMB0 (rx) : ORIGIN = 0x00000000, LENGTH = 0
EXTMEMB1 (rx) : ORIGIN = 0x00000000, LENGTH = 0
EXTMEMB2 (rx) : ORIGIN = 0x00000000, LENGTH = 0
EXTMEMB3 (rx) : ORIGIN = 0x00000000, LENGTH = 0
MEMORY_ARRAY (xrw) : ORIGIN = 0x00000000, LENGTH = 0
}
Код:
SECTIONS
{
/*
* For Cortex-M devices, the beginning of the startup code is stored in
* the .isr_vector section, which goes to FLASH
*/
.isr_vector_stub :
{
. = ALIGN(4);
_isr_stub = .;
KEEP(*(.isr_vector_stub))
. = ALIGN(4);
} >INTERRUPTS_STUB
.func_pointer_arr :
{
. = ALIGN(4);
_func_p_arr = .;
KEEP(*(.func_pointer_arr))
. = ALIGN(4);
} > FUNC_ARR