Forum > Embedded - ARM
using c libraries in embedded fpc project
MiR:
Things will get easier when you start simple, set your first goal to blink a led when creating bindings to c-objects is something new for you.
to do so check how the functions that you are using are exported from the object file, are they exported as simple symbols or are they name mangled. Arduino uses c++ internally so chances are high that the symbols are name mangled.
arm-none-eabi-nm will help you to find this out.
look for the symbols marked with the big letter T, those are the symbols defined in the object file. Do the look like simple plain names or are there crazy letters arround the symbol name?
When there are crazy letters then I‘d propose to stop just there, the stuff is name mangled and c++code. Things will get complicated, please trust me.
play arround with something that is not written in C++ like libopencm3 to get your feet wet.
Michael
diego bertotti:
thanks for the info
now IT WORKS!!! or maybe i don't see error at compile time. dont know at runtime yet.
look the names of functions in the c source code
************************************
void HardwareTimer::pause(void) {
timer_pause(this->dev);
}
void HardwareTimer::resume(void) {
timer_resume(this->dev);
}
************************************
and now look the functions real names at the .o file
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program project_ext_c_lib; uses cortexm3; Procedure _ZN13HardwareTimer5pauseEv; cdecl; external;// name 'pause'; {$L HardwareTimer.o} Procedure _ZN13HardwareTimer6resumeEv; cdecl; external;// name 'pause'; {$L HardwareTimer.o} begin _ZN13HardwareTimer5pauseEv; _ZN13HardwareTimer6resumeEv; end.
and result on Messages windows was:
******************************
Compile Project, OS: embedded, CPU: arm, Target: project_ext_c_lib: Success
******************************
a nightmare!
diego bertotti:
good news!
i found this way
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program project_ext_c_lib; uses cortexm3; Procedure pause; cdecl; external name '_ZN13HardwareTimer5pauseEv'; Procedure resume; cdecl; external name '_ZN13HardwareTimer6resumeEv'; Function getCount: word; cdecl; external name'_ZN13HardwareTimer8getCountEv'; Procedure setCount(count: word); cdecl; external name'_ZN13HardwareTimer8setCountEt'; {$L HardwareTimer.o} begin pause; resume; setCount(getCount); end.
and compiled without error!
Cyrax:
--- Quote from: diego bertotti on April 16, 2020, 12:25:16 am ---...
look the names of functions in the c source code
************************************
void HardwareTimer::pause(void) {
timer_pause(this->dev);
}
void HardwareTimer::resume(void) {
timer_resume(this->dev);
}
************************************
...
--- End quote ---
That isn't C, it is C++. And your program will burn and crash if run due to need for a pointer for the C++ class (this, it will be need to passed as hidden parameter).
diego bertotti:
thanks cyrax
the object file (HardwareTimer.o) have this assembler (using objdump.exe)
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- 00000000 <_ZN13HardwareTimer5pauseEv>: 0: 6803 ldr r3, [r0, #0] 2: 2200 movs r2, #0 4: 681b ldr r3, [r3, #0] 6: 015b lsls r3, r3, #5 8: f103 4384 add.w r3, r3, #1107296256 ; 0x42000000 c: 601a str r2, [r3, #0] e: 4770 bx lr 00000000 <_ZN13HardwareTimer6resumeEv>: 0: 6803 ldr r3, [r0, #0] 2: 2201 movs r2, #1 4: 681b ldr r3, [r3, #0] 6: 015b lsls r3, r3, #5 8: f103 4384 add.w r3, r3, #1107296256 ; 0x42000000 c: 601a str r2, [r3, #0] e: 4770 bx lr
look the project assembler (project_ext_c_lib.s)
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---# [project_ext_c_lib.lpr]# [11] begin mov r12,r13 push {r11,r14} sub r11,r12,#4 sub r13,r13,#44 bl fpc_initializeunits# [13] pause; bl _ZN13HardwareTimer5pauseEv# [14] resume; bl _ZN13HardwareTimer6resumeEv# [15] setCount(getCount); bl _ZN13HardwareTimer8getCountEv uxth r0,r0 uxth r0,r0 bl _ZN13HardwareTimer8setCountEt# [16] end. bl fpc_do_exit add r13,#44 pop {r11,r15}.Lc1:
it seems will not crash, but will don't work because i don't call before the initializing function, then this pointer is actually null, then compiler put empty function
Navigation
[0] Message Index
[#] Next page
[*] Previous page