cancel
Showing results for 
Search instead for 
Did you mean: 

How to place some functions from precompiled library (eg. Crypto supplied by ST) into TCMs?

DLouk.1
Associate II

I would like to place some of the functions of ST Crypto library (cmox_crypto) into the ITCM to increase the performance on STM32H750x MCU. I would also like to place some of the associated data (tables) into ITCM or DTCM. However, the functions are provided in the precompiled library (*.a), and code is in .text section. I can place the entire .text into ITCM through linker script, but I'd like to do it selectively and only for some functions.

Will attaching the __attribute__((section(".itcm_text"))) to the functions prototypes in *.h files work?

Even if it does, there are many nested calls there and modifying all references is difficult. Does anyone know a better way of assigning sections to symbols through some linker directives or a script file?

What is the best way to do the same for data?

5 REPLIES 5
Pavel A.
Evangelist III

> Will attaching the __attribute__((section(".itcm_text"))) to the functions prototypes in *.h files work?

No

If the .a library is not built with per-function text sections, there is no good way to extract a single function. The linker can report dependencies of functions (what is called by your function).

DLouk.1
Associate II

Pavel, I already checked that attributes on prototypes do not work.

What other options may be available? For instance, un-archiving the library and then specifying explicitly the files that should go to each section in the linker scripts? Will it override the default section in the *.o files which are extracted from library?

DLouk.1
Associate II

For those interested: here is how I managed to partially solve the problem:

  1. Dearchive the *,a library (in my case it is libSTM32Cryptographic_CM7.a) into a separate directory using 7-zip. It will create a collection of *.o files; there is also a 1.txt file listing the functions defined in each module.
  2. dir /b >file_list.txt to create a list of all *.o files; open it in editor
  3. cut the list of names of all *.o files only and paste them in the new section definition. In my case, it will look as follows

.itcm_text :

{

. = ALIGN(4);

itcm_text_start = .;

*(.itcm_text) /* Fast-executing code */

*(.itcm_text*) /* Fast-executing code */

cmox_aesfast_decrypt.c.o

cmox_aesfast_encrypt.c.o

cmox_aessmall_decrypt.c.o

cmox_aessmall_encrypt.c.o

cmox_aes_common.c.o

cmox_bn.c.o

....

. = ALIGN(4);

itcm_text_end = .;

} >ITCMRAM /* AT >FLASH*/ 

The AT>FLASH will be needed only if the program is designed for flash storage.

This is a brute force method, but the linker will only pick the modules which are called from the user program, and eliminates the unused modules.

Interestingly, the trick moved not only the code, but also the constant tables for the cryptographic functions into ITCM. It might be good to place them in the DTCM for faster access, but I did not yet learn how to do it.

0693W00000Nq8DdQAJ.png 

DLouk.1
Associate II

One more hint: the sections are defined as following; that allows to aggregate and remap them:

0693W00000Nq8FPQAZ.png

Pavel A.
Evangelist III

You don't have to unpack the library. LD can specify members of archive in place of object files, see here.

the syntax is ‘archive:file’