knowit / snappysense

3 stars 1 forks source link

Investigate flash and RAM size #32

Open lars-t-hansen opened 1 year ago

lars-t-hansen commented 1 year ago

Currently the firmware weighs in at 1013853 bytes flash and 48352 bytes RAM during upload (before dynamic allocation during operation). This is pretty hefty and we should look into what's going on. Especially data seems large, but this could just be eg string constants that are copied into RAM, there are a number of those, including help text for serial commands, which can be removed.

There's no need to have very stringent budgets at this time but the dev env says that the limit for flash is 1310720 bytes (0x140000), for some reason. The device has 4MB Flash, supposedly.

lars-t-hansen commented 1 year ago

A "production" configuration with MQTT + NTP + WEBCONFIG support; logging and serial command server disabled. Compiled with -DCORE_DEBUG_LEVEL=0 -O2.

Total Flash size 952925 bytes. Using platform.io "inspect memory" feature:

home/                        39KB  -- appears to be chip support code
users/                      569KB
  xtensa-esp32-elf           95KB -- mainly libc
  ficeto                    401KB -- esp32-idf
    tls, ip, wifi          ~250KB
    hal, freertos, drivers  ~50KB
    misc components        ~100KB
  lth
    firmware-arduino         38KB -- ie, this is SnappySense proper
    arduino                  34KB
unknown/                    161KB -- more than 1000 tiny text segments

That adds up to > 750KB. The rest is a little nebulous but corresponds closely to the figure reported for "RAM", 201KB. Anyway it's clear that the firmware proper is only about 75KB (ie, 10% of the Flash) and that the rest is "system" code, and a lot of that is the TLS/TCP/IP/WiFi stack.

(LoRa would allow us to ditch MQTT + NTP easily. But WEBCONFIG still requires WiFi, TCP/IP, and HTTP - getting rid of that probably means uploading the config to the device and storing it directly on flash. This impacts the ability to do end-user configuration but with LoRa that is really not much of a concern.)

lars-t-hansen commented 1 year ago

FWIW, with a stub LoRa implementation (basically zero bytes) the total code size drops to about 330KB (release build), as we exclude the entire web stack. This configuration will additionally require a small amount of code to implement i2c-based configuration (#55) and a larger and unknown amount of code to support LoRaWAN. The internet is not much help in figuring out how big the code for LoRa might be but for mbedos (presumably on ARM) there was a report of about 150KB added. That would bring us up to about 500KB for a LoRa build, which is pretty hefty for OTA-over-LoRa (while 1MB over WiFi is pretty trivial). See #26.