I have been trying to port this example to an ST Nucleo L073RZ with a SX1276MB1LAS LoRa WAN radio. It has 20KB of SRAM, 10KB of which are being taken by uninitialized data.
After setting the main stack size to 1024 and disabling memory debug I can get the example to a point where it will join but will then later fail on the next uplink with an error code of -1014 which indicates that the crypto library failed. The failure is a result of the crypto library unable to allocate memory.
I have tried the default, develop, and release profile; all with the same result.
Any thoughts on what else I can disable to free up more SRAM would be helpful.
Thank you,
Parker MacKenzie
- Compiler GCC
- mbed compile -m nucleo_l073rz -t GCC_ARM
- Changes to mbed_app.json (beyond setting the device eui, app key, and app eui):
"lora.phy": 8,
"main_stack_size": { "value": 1024 },
"lora-spi-mosi": { "value": "D11" },
"lora-spi-miso": { "value": "D12" },
"lora-spi-sclk": { "value": "D13" },
"lora-cs": { "value": "D10" },
"lora-reset": { "value": "A0" },
"lora-dio0": { "value": "D2" },
"lora-dio1": { "value": "D3" },
"lora-dio2": { "value": "D4" },
"lora-dio3": { "value": "D5" },
"lora-dio4": { "value": "D8" },
"lora-dio5": { "value": "D9" },
"lora-rf-switch-ctl1": { "value": "NC" },
"lora-rf-switch-ctl2": { "value": "NC" },
"lora-txctl": { "value": "NC" },
"lora-rxctl": { "value": "NC" },
"lora-ant-switch": { "value": "NC" },
"lora-pwr-amp-ctl": { "value": "NC" },
"lora-tcxo": { "value": "NC" }
Digging a bit deeper with a little more debugging.
Summary
Long story short, after the uninitialized variables are allocated in the RAM there is not a lot of space for the heap. Finding a way to significantly cut these back should help. The example definitely runs out of memory, likely there is some heap left when it fails but it is likely too fragmented to carve off a 280 Byte chunk. Any thoughts or suggestions would be welcome.
Here are the details
As mentioned in the last post the device is running out of memory. With the main stack size set to 1024 the device will run out of dynamic memory (heap) attempting to send a packet in the aes_ctx_alloc() called by the mbedtls_cipher_setup attempting to allocate 1 block of 280 Bytes through calloc.
First here is the static analysis of the image which shows that 13K of the 20K of SRAM is being used for data and bss (should leave 7K +- for heap)...
Of the remaining 7K Bytes of static ram almost 6K of it is being allocated to heap: