I'm trying to keep an unreferenced function in the memory and later call it from another file. My files are like this:
main/linker.lf:
Code: Select all
[sections:fnreg]
entries:
fnreg
[scheme:fnreg]
entries:
fnreg -> dram0_data
[mapping:map]
archive: libmain.a
entries:
fn1 (fnreg);
fnreg -> dram0_data KEEP() SURROUND(fnreg)
Code: Select all
#include "esp_log.h"
extern void (*_fnreg_start)();
extern void (*_fnreg_end)();
void call_fns() {
void (**fn)() = &_fnreg_start;
ESP_LOGI("CALL_FNS", "%x - %x", (uint32_t) &_fnreg_start, (uint32_t) &_fnreg_end);
for (; fn < &_fnreg_end; fn++) {
(*fn)();
}
}
void app_main(void) {
call_fns();
}
Code: Select all
#include "esp_log.h"
static void fn1() {
ESP_LOGI("FN1", "fn1 is called");
}
static void (*reg_func)()
__attribute__((__section__("fnreg")))
__attribute__((__used__)) = fn1;
Code: Select all
idf_component_register(SRCS "registry.c" "fn1.c"
INCLUDE_DIRS "."
LDFRAGMENTS "linker.lf")
Note that I'm using the latest esp-idf version at github.