janjongboom / sam-lorawan-mbedos5

Mbed OS 5 LoRaWAN stack running on SAML21 and SAMR34 Xplained Pro
Apache License 2.0
6 stars 1 forks source link

LoRa stack footprint #1

Closed martinichka closed 2 years ago

martinichka commented 6 years ago

comparing MBED LoRa stack on size with Semtech's stack

MBED 64749 bytes Semtech: 57284 byes

Both compiled with optimization on size (-g0 -Os, NDEBUG, libnano etc) and an example that sends LoRa messages. Tested with exact the same mbed-os.

Is there room for optimization in the code of the MBED LoRa stack? Because for now the Semtech stack allows to use a 64KB uC and the MBED LoRa stack requires a 128KB uC (asuming the added business logic will fit in a few kilobytes).

janjongboom commented 6 years ago

You can compile with --stats-depth=100 to see more information. I see f.e. that the Mbed TLS AES module takes 11K of flash, which seems excessive, maybe this is fixable by disabling some unused features in the TLS config.

@hasnainvirk Any idea how we can get this down more? I also see unused modules take up space, even though they shouldn't. E.g. SX1272 radio takes up 242 bytes of flash even though it's not used.

hasnainvirk commented 6 years ago

AES ROM tables are placed in flash by default. If you can spare 11K of RAM, that would be one ugly way to get some flash out. Just thinking out loud, how much flash space is taken up by traces ? .. I assume a significant amount. I think you should turn off traces and compile with release profile, like: mbed compile --profile release

@martinichka , you can save upto 6.2 K of ROM by trading off speed with ROM for calculating AES ciphers.

/* Disable some of the speed optimizations on AES code to save
 * ~6200 bytes of ROM. According to comments on the mbedtls PR 394,
 * the speed on Cortex M4 is not even reduced by this. */
#define MBEDTLS_AES_FEWER_TABLES

Copy the snippet above and paste it in mbedtls_lora_config.h

@janjongboom Those stray bytes coming from SX1272 are just one of the many stray bytes coming in because of Callback class templates. Will talk to Chris.