cancel
Showing results for 
Search instead for 
Did you mean: 

How to add external libraries in Keil® MDK-ARM: An example using X-CUBE-CRYPTOLIB

KDJEM.1
ST Employee

Introduction

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:

  • Eliminates the need to write code for complex functions

  • Provides reusable functions that can be referred to within the code without defining them explicitly

  • Reduces application development time and cost

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.

Software prerequisite

Keil® MDK-ARM (V5.38 is used in this article.)

Step-by-step instructions

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..."

picture1.png

 

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’…

KDJEM1_0-1713802159392.png

 

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" 

KDJEM1_3-1713805002137.png

5. Right click on “libSTM32Cryptographic_CM3.a" in the Keil® project and select “Options for file ‘libSTM32Cryptographic_CM3.a'..."

KDJEM1_1-1713802983201.png

 

6. Add the path of “libSTM32Cryptographic_CM3.a" and modify the file type to "Library file" as shown in the below figure:

KDJEM1_2-1713803086889.png

 

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:

KDJEM1_1-1713804711153.png
 
KDJEM1_2-1713804836503.png

 

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"

KDJEM1_4-1713803988773.png

 

10. Add the "cmox_low_level.c" file

KDJEM1_0-1713804574484.png

 


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.

Conclusion

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.

Related links

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

ST wiki: Getting started with the Cryptographic Library

 

Version history
Last update:
‎2024-04-24 06:46 AM
Updated by: