0
\$\begingroup\$

I am working on a project using the NUCLEOF103RB development board that interfaces with a fingerprint sensor over UART. I am using the TrueStudio IDE and would like to develop a "library" for the sensor that I would then want to import into my main project. I'm also using the HAL peripheral driver libraries to use the UART peripheral.

I have built static standalone libraries on a linux system using something similar to this: Creating a shared and static library with the gnu compiler (gcc). How does one go about doing something similar on TrueStudio/ARM gcc?

Many thanks!

\$\endgroup\$
4
  • \$\begingroup\$ Do you want a "static" library or a "shared" library? For the former, just link it in when you build the project. But "shared" implies that you have multiple tasks running under some kind of OS, but only one copy of the library code that they all use. \$\endgroup\$
    – Dave Tweed
    Commented May 30, 2019 at 13:43
  • \$\begingroup\$ Are you wanting to create a pre-compiled library with potentially multiple C source files compiled into a single library file? If so then remember that you may need to recompile your library for different devices. \$\endgroup\$
    – brhans
    Commented May 30, 2019 at 14:16
  • \$\begingroup\$ Yes, that's what I mean - a precompiled single file library. The device that I am working on interfaces with 4 devices - an EEPROM (SPI), an RFID (I2C), GSM (UART1) and fingerprint sensor (UART2). My idea is that I keep building the device specific functionalities in their respective libraries, in isolation, and then bring them together in the main project. Recompiling for different target should not be a problem. \$\endgroup\$
    – ankitm
    Commented May 30, 2019 at 14:52
  • 3
    \$\begingroup\$ There's really little reason to do this as a compiled library. Instead, you probably want something like a source code "library" as a git submodule. There is very little cost to recompiling it from source in every complete build (typically only changed files need to be recompiled during ongoing work), and a lot of compatibility advantage to doing so. \$\endgroup\$ Commented May 30, 2019 at 15:00

2 Answers 2

1
\$\begingroup\$

It's in the User Guide.

enter image description here

Keep in mind that the resulting library is usable only on a single microcontroller series. It'd be fine as long as you are using it on a single series (e.g. STM32F4xx), and some peripherals are compatible across series, so they might just work (see the STM32 porting guides), but sometimes they are only register level compatible, needing a recompile using another set of headers.

Recompiling for different target should not be a problem.

Unfortunately the documentation writers don't share your opinion.

enter image description here

So you'd end up with several copies of the library sources, where updates have to be copied around and recompiled several times.

What to do instead?

You can add source files outside your project folder to the project

To add a link to a file, right-click on a source folder and select New, File. In the dialog click on the Advanced button and select Link to file in the file system.

It does even support adding a whole external directory this way.

\$\endgroup\$
0
\$\begingroup\$

The library will end up being statically linked into firmware binary that runs in flash anyway. The concept of dynamic library makes little sense on a STM32 as you don't have an OS that can load programs and libraries and run them in RAM. Just write a .c and .h file and use those in all your projects you want.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Yes, this is how I'm doing it right now. Was looking for a more "elegant" way to do it since I wish to update the libraries (I have 4 devices for which I'd need the libraries) independent of the main project. \$\endgroup\$
    – ankitm
    Commented May 30, 2019 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.