on 2024-04-24 06:47 AM
A library is a collection of reusable, compiled, and tested code that can facilitate the coding of application functionalities. It is designed to support both the code developer and code compiler during the build process and the running process of the application. A library implements many functions, variables, and parameters.
Example advantages of library usage:
The main objective of this article is to describe the steps for integrating an external library from an achieve file (*.a) in your project, like as X-CUBE-CRYPTOLIB, when using the Keil® toolchain. The project example in this article is based on the STM32L1 MCU series 32-bit Arm® Cortex®-M3.
Keil® MDK-ARM (V5.38 is used in this article.)
The following steps show how to integrate an external library in your project when using the Keil® MDK-ARM toolchain. 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, you can add the cryptographic library by following these steps:
1. Right click on "Project: Cryptolib" and select "Add Group..."
2. Create a new group called, our example is: "Middlewares/STM32Cryptographic"
3. Right click on "Middlewares/STM32Cryptographic" and select "Add Existing Files to Group Middlewares/STM32Cryptographic’…
4. The project example in this article is based on the STM32L1 MCU series 32-bit Arm® Cortex®-M3.
For this reason, it is necessary to add "libSTM32Cryptographic_CM3.a" from "STM32CubeExpansion_Crypto_Vx.x.x\Middlewares\ST\STM32_Cryptographic\lib"
5. Right click on “libSTM32Cryptographic_CM3.a" in the Keil® project and select “Options for file ‘libSTM32Cryptographic_CM3.a'..."
6. Add the path of “libSTM32Cryptographic_CM3.a" and modify the file type to "Library file" as shown in the below figure:
7. Right click on the project and select “Options for Target". Select "C/C++(AC6)" and add the path by following the steps below as demonstrated by the images:
8. Copy the "cmox_low_level_template.c" file from "\STM32CubeExpansion_Crypto_Vx.x.x\Middlewares\ST\STM32_Cryptographic\interface" folder to your project specific source folder "\Core\Src" and rename it into "cmox_low_level.c."
9. Right click on "Application/User/Core" and select "Add Existing Files to Group Application/User/Core"
10. Add the "cmox_low_level.c" file
11. Open the "cmox_low_level.c" file and replace /* #include "stm32<series>xx_hal.h"*/ with #include "stm32l1xx_hal.h"
12. Update main.c by inserting "#include cmox_crypto.h"
13. Check that no problem happened by rebuilding all files. There must be no error and no warning.
In conclusion, after following the steps outlined in this article, you should be able to add an external library to Keil® like the X-CUBE-CRYPTOLIB library. By integrating this library, users can quickly access its functions with a simple header file. If you encounter any issues, we suggest that you create a post in the ST community for further assistance.
ST wiki: Getting started with the Cryptographic Library