cancel
Showing results for 
Search instead for 
Did you mean: 

Sharing functions between two pieces of code

jdcowpland
Associate II
Posted on July 07, 2015 at 16:27

My subject doesn't quite describe what I'm trying to do, but not quite sure how else to explain:

I have a bootloader stored at the start of flash in my STM32f415 (flash location 0x08000000), and my main application is stored further down the line (0x08010000). They both make use of several identical functions, and until now have I have just copied and pasted my C functions into each code base. What I'm now wondering though, is if I were to put these functions into a library file, could I store them at let's say 0x080A0000, and reference the library location to both files, thus saving me the space of including the library in both files? I've been looking into linker scripts and it looks like it might be right way to go (correct me if I'm wrong!) but I'm not quite sure how to implement it.

Any help or suggestions or pointers in the right direction would be greatly appreciated!
1 REPLY 1
Posted on July 07, 2015 at 16:56

Not sure I'd make a system where the boot loader wasn't free standing. That's a recipe for failure.

In Boot ROM situations, you'd typically park all the library routines in the ROM, and provide a definition file to the linker. The .DEF file looking like an ASCII list of the function names, and addresses. Not sure if GNU has a way of doing that, or if it would be simple enough to create a library with the known addresses.

Where things are more likely to move, you can use a table/structure of function pointers, accessed indirectly, or in a manner similar to qsort()

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..