A few days ago for a project that I'm developing I need to use the cryptographic library which is given by ST. Even though the library is given as "CubeMX expansion", when I tried to add it to the CubeMX enviroment it couldn't be possible and an error message appeared saying that this package is not managed on this CubeMX version...
So I looked for some answers in the forums and the community but the answers weren't clear so I decided to find the way to use the library using the CubeMX, then here is what I did:
First at all, download the X-CUBE-CRYPTOLIB from the ST website:
You must to login on your ST account, fill some requierements and after a while the download link will be sent to your e-mail.
Download and extract the library in any folder of your PC:
Now, you have your library to use. Then you have to create your CubeMX project, in my case I created a F103C8 project for my test board:
The most important thing here is to activate the CRC module, whitout it the library won't work well. After that, generate the source code and import it to your workspace, if your are not sure about how to do it check this post, there is a little example:
When you have your project into your work space is time to integrate the crypto library, first create a new folder in you project and call it Middlewares:
After that, go to your file manager where you extract the library and search the folder that match with yor microcontroller family, in my case the STM32F1. An important thing here, the library is divided to folders, one with the microcontrollers that support hardware acceleration cryptography and other with software acceleration cryptography, so you have to choose right.
When you find the right folder, search the Middlewares folder and copy the ST folder:
After that, paste it in to the Middlewares folder of your workspace project:
Now the library is in your project, but you have to configure the paths of the library, to configure this make right click on you project folder and go to the project properties:
Configure the include path by creating a new one with the following description:
And make click in apply:
Configure the library by creating the new path and calling the library, in the library path put the following:
and in the library put:
(The name of the file that contains the library is libSTM32CryptographicV3.0.0_CM3_GCC_ot.a, but the name that you must to put is the one above)
And make click in apply:
Check that the library have been include right:
Now, you can use the library into your project, include the "crypo.h" file on your main source code and use the examples as guide to make your own code, you can find the examples in the "projects" folder inside the folder of your microcontroller family:
Copy the needed lines into your own source code and test it. Attached to this document is my test code, I included 2 examples in the main source, so you can test 2 cryptographic methods, just change the value of the macro CRYP_METHOD to 0 or 1 and build again the project:
This way works also in Atollic TrueStudio. For Keil and IAR just check the right way to include the libraries and paths in your projects.