cancel
Showing results for 
Search instead for 
Did you mean: 

Optimizing X-CUBE-CRYPTOLIB for memory constraint

kvkhekale
Associate II

Hello!

I want to use Asymmetric Crypto algorithms like ECC or RSA for my FreeRTOS project running on STM32F051K8.

The controller has 64 KB of flash.

Since X-CUBE-CRYPTOLIB occupies quite large memory footprint, my FLASH is getting overflowed by the .text area, on linking the X-CUBE-CRYPTOLIB library.

I have made following changes to optimize the memory required for X-CUBE-CRYPTOLIB:

  1. Disabled everything else (unnecessary #defines) apart from INCLUDE_ECC in crypto.h file
  2. Optimization settings in Project properties:
    1. -Os optimization for size
    2. Debug level "none"

But still my flash is getting overflowed by around 7000 bytes.

Please tell me what else can I do for memory optimization?

Otherwise, I might have to change the microcontroller with big FLASH memory.

I also have attached error screenshot for the reference. 0690X00000AQxHwQAL.png

1 REPLY 1

The library is provided in binary form so -Os will apply only to your own code, not the library.

You can try to enable link-time optimizations (LTO), but it has history of being error prone. Anyway, you can try it. If your IDE doesn't support it, you'll have to do it manually by adding "-flto" to both compiler and linker settings. Also adding "-ffunction-sections" and "-fdata-sections" (both compiler and linker settings), and "--gc-sections" (linker-only setting) will help too.

Alternatively, use other crypto libraries, like mbed-crypto, micro-ecc, TinyECC, cifra