2022-04-13 06:51 AM
Hi, how can I call C function defined as uint32_t getValue(void) inside startup file (in Reset_Handler routine)? What is needed syntax? I tried importing it and setting it as extern (other standard keywords are not working), but nothing seems to work.
I generated the project using CubeMX and use gcc for compilation. The uC is STM32F479VIT (cortex m4).
Solved! Go to Solution.
2022-04-13 08:34 AM
Correct. An int will be returned in r0, no issues.
Check the map file for getValue or similar entries.
If it is a static function that is never called from C, the compiler might optimize it away at higher opt levels?
hth
KnarfB
2022-04-13 07:03 AM
bl getValue
2022-04-13 07:08 AM
Thank you for your reply. When I call it I have linking error undefined reference to `getValue'. Do I need to import it somehow into startup file, or mark it in C source to get it to work?
2022-04-13 07:14 AM
Check how SystemInit() and main() are called from startup and do the same. However, someho I believe you are on a crash course. Do you realize that you have almost no chance to use the result of this function?
2022-04-13 07:42 AM
Thanks, but as I understand, my function is defined exactly as SystemInit. That is one of the reasons for asking the question. Yes, maybe I omitted something in the process. I thought there is a list of requirements or something that I could use to double-check.
On the other hand, why is almost no chance to use the result? It wouldn't be stored in one of the Rx registers?
2022-04-13 08:12 AM
The result cannot be stored in memory unless you fiddle with linker script.
2022-04-13 08:15 AM
I don't need it in RAM, but as I understand it will be written to the Rx register, so until something overrides the value, it can be used. Or am I mistaken?
2022-04-13 08:34 AM
Correct. An int will be returned in r0, no issues.
Check the map file for getValue or similar entries.
If it is a static function that is never called from C, the compiler might optimize it away at higher opt levels?
hth
KnarfB
2022-04-13 09:20 AM
Thank you for the map file hint. The name I found inside was _Z15getValuev and when I used it everything worked as intended.
2022-04-13 09:24 AM
Oh, this looks like C++ name mangling. You may prevent this by defining the function "extern C" in C++. You're not mistaken with the registers. It's also easy to define RAM space in assembler if needed.
hth
KnarfB