cancel
Showing results for 
Search instead for 
Did you mean: 

How to add external libraries in STM32CubeIDE

B.Montanari
ST Employee

Summary

This article shows how to integrate a library, in the form of an achieve file (*.a) in your project, so you can use the functions of the library with a simple header file. 

Introduction

A library can be defined as a set of nonvolatile resources that are used by computer programs. This means avoiding the need to write specific codes from scratch. These resources could be functions, documentation, configuration data, objects, subroutines, and many other functionalities. When a program invokes a library, all the functioning processes happen inside that library and not in the program itself.

In many programming environments, there is already a standard library used for the compiled language containing the system services most needed. Even so, since library code is used by different noncorrelated programs, there is also the possibility to use external libraries.

This article has the goal to instruct on adding external libraries to the STM32CubeIDE interface. This is demonstrated by using the X-CUBE-CRYPTOLIB as an example.

1. Prerequisites

To follow this article’s proposal, the STM32CubeIDE version 1.10.0 or later software and the desirable external library is required.

2. Steps

The following steps show how to add the library on the STM32CubeIDE. For this demonstration, the external library X-CUBE-CRYPTOLIB is used. X-CUBE-CRYPTOLIB can be downloaded from st.com, clicking this link will redirect you to the site.

After creating a project for any chosen board, go to Project > Properties > C/C++ Build > Settings > Tool Settings > MCU GCC Linker > Libraries.

 

BMontanari_0-1705353822184.png
 

 

BMontanari_1-1705353822195.png

After following these steps, it is possible to add the library and its respective path like in the image below. When including the library name for statics libraries.a, it cannot contain the “lib” prefix and the extension “.a”. For the library added in this example “libSTM32Cryptographic_CM0_CM0PLUS.a" the library name at STM32CubeIDE is “STM32Cryptographic_CM0_CM0PLUS.”

BMontanari_2-1705353822203.png

Now that the external library is linked to the project, the header file can be included by doing the following: Navigate to Project -> Properties -> C/C++ Build -> Settings -> Tool Settings -> MCU GCC Compiler. Include paths, and then add the path to the header file.

BMontanari_3-1705353822221.png

Conclusion

In conclusion, adding external libraries to STM32CubeIDE can greatly enhance the functionality of your project. With the steps outlined in this article, it can be done easily. By integrating the X-CUBE-CRYPTOLIB library, users can quickly access its functions with a simple header file. The same can be obtained for any custom library as well.

Related links

X-CUBE-CRYPTOLIB - STM32 cryptographic firmware library software expansion for STM32Cube - STMicroelectronics

STM32CubeIDE quick start guide - User manual

Databrief - STM32CubeIDE - Integrated development environment for STM32 products

Comments
nicolas
Associate III

The Getting started with the Cryptographic Library ask to add a library without telling how, it would be great to add a link to this guide.

There is another way to add the library STM32Cryptographic_CM0_CM0PLUS by starting with ":" and using the filename (the X-CUBE-CRYPTOLIB examples use this method):
:libSTM32Cryptographic_CM0_CM0PLUS.a

For search path, quotation mark is optional when using slash instead of backslash.

If the Middlewares is copied into the project folder, relative path can be used like this:
../Middlewares/ST/STM32_Cryptographic/lib
"..\Middlewares\ST\STM32_Cryptographic\lib"

Tobi_as
Associate

Hello,

thanks for the instructions, but, unfortunately it doesnt work for me, I got this error:

collect2.exe: error: ld returned 1 exit status

make: *** [makefile:64: Zam_PC.elf] Error 1

"make -j8 all" terminated with exit code 2. Build might be incomplete.

 

16:41:18 Build Failed. 2 errors, 1 warnings. (took 6s.469ms)

Version history
Last update:
‎2024-06-05 07:12 AM
Updated by:
Contributors