Hi… I’m combining the ESP-NOW “receiver for the many-to-one” code example in the eBook Learning ESP32 using Arduino IDE (i.e Module 8 Unit 4) with the BLE sender code (i.e. Module 5 Unit 1), and the compiled code apparently overflows the available 1.4MB memory This is the errror:
Sketch uses 1486542 bytes (113%) of program storage space. Maximum is 1310720 bytes.text section exceeds available space in board
I reduced Serial.print to a bare minimum, but is it that I’m calling in too many .h files ?
#include <esp_now.h>
#include <WiFi.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
I would have thought the compiler would use only the functions necessary in these .h files, but Arduino IDE is a bit strange, so I’m not sure. …. or it just might mean too much code for the little ESP32.
Any suggestions for getting this code to fit? (I’m going to be migrating to LoRa and would have the same problem I guess). Thanks for any help (using an SD card, for example)
I have an easy way that works for me. I use FRAM external memory modules. Currently I use 8K x 8 via I2C but SPI is available as well as larger modules. I keep all my messages etc in that non volatile RAM. The trick is to write a sketch that puts the messages into that memory so you can find them. They will support trillions of R/W cycles and there is no delay in reading or writing them. They can be cascaded upto 8 deep without any hardware changes other then a jumper select. They make 4Mbit devices (512K x 8). I have a simple pointer table that points to each message.
Hi Gil … thanks for a response. I’m not clear how an external memory would help (an SD card or your FRAM module). The problem, if I understand it, is that the object code built by the Adruino IDE in order to implement an ESP-NOW receiver and a BLE sender is just too big to fit in the code memory of the ESP32. Presumably the callback functions and other functions cause it. Am I missing something you can explain?
You are correct object code will not execute from there. Although it is non volatile It is good for data but not much else. Since the SD card has data it can store that. I am not that familiar with that machine but is it possible to do overlays where you overwrite the object code for a new function.
Hi Joe.
There is a BLE library that occupies much less space than the original one, and it’s very similar.
Some of our readers have used that library and had very good results, but I never tried it.
The library is this: https://github.com/h2zero/NimBLE-Arduino
I hope this helps.
Regards.
Sara
YES !! Sara you are a marvel of knowledge 🙂 So, the BLE_notify sketch alone takes of 85% of the available 1.3MB memory in my ESP32 – no wonder it “broke” the download with other code included. The NimBLE_server sketch (in the examples in the library; this acts similar to the _notify sketch) takes up 41 % 🙂 When I combined the ESP-NOW multi-client receiver with this NimBLE_server, it takes up 70%, and works !! (lots more work to make it do what I want, but it receives ESP-NOW packets from a sender, and connects to my cellphone’s nRF_connect app, receiving data. …. Happy camper here 🙂
Thank you !
… to further my understanding: according to the Espressif datasheet for my ESP32-WROOM-32D module, it is supposed to have 32Mbits (4 MB) of “external” flash, connected via SPI to the ESP32 chip, all neatly packaged inside that metal enclosure. SRAM internal to the ESP32 chip itself is 1/2 MB but this isn’t where “flashed” code resides – it must be in the “external” SPI flash.
So why is the Arduino IDE telling me I have 1.3 MB max available for program storage? … is there something I should be specifying somewhere to use more of the 4 MB flash?
Hi.
Check your Arduino IDE settings on the following:
- Tools > Flash size
- Tools > Partition scheme
You can choose a different partition scheme to have more space for the app (the sketch itself).
I hope this helps.
Regards,
Sara
Hi Sara …you nailed it again 🙂 So, I checked your suggestion, and here is what I have listed at the bottom of the IDE when I do a compile as explained at the beginning of this question:
“ESP32 Dev Module, Disabled, Default 4MB with spiffs (1.2M APP/1.5MB SPIFFS), 240 Mhz(WiFi/BT), QIO, 80Mhz, 4MB (32Mb), 115200, None on Com7”
Under Tools/Partition Scheme, I have that “Default 4MB with spiffs (1.2M APP/1.5MB SFIFFS) selected.
There are actually 12 Schemes listed ! So I tried the “8M Flash (3MB APP/1.5MB FAT)” and it fits !! I get the following:
Sketch uses 1486542 bytes (44%) of program storage space. Maximum is 3342336 bytes.
Wow ! … so why does the Arduino IDE choose a Default with only 1.2MB APP, when for the device picked, it should know that there’s 4MB Flash and using one of the schemes which maximize use of this is the proper one to use! (there are 3 schemes with provide 3MB APP flash!). … it even selects the Tools/Flash Size of 4MB, so it should know better! .. what am I not understanding?
Anyway, this does solves my size issue, even though the nimBLE works fine and fits in 0.9MB space (hopefully there aren’t any “gotcha’s” when using nimBLE instead of the normal BLE). Thank you for your time and help! — JoeM
Hi.
Just to let you know that you can even create your own partition schemes.
At the moment, we don’t have any tutorials about that subject.
But you’ll find some information about that if you search for “ESP32 custom partition table” or “ESP32 custom partition scheme”.
I’ll mark this issue as resolved. If you need further help, you just need to open a new question in our forum.
Regards,
Sara
So Sara, you’re not aware of a good reason why the Arduino IDE would choose a 1.2MB App space, knowing that 4MB of flash are available for the device being used (i.e. it knows because it chose 4MB under Tools/Flash Space) … why would it prevent use of that additional memory when nothing else is using it, and force smaller programs on the user. … any explanation you can think of ?
oh .. not so simple. Choosing the Tools/Partition Scheme of “8M Flash (3MB APP/1.5MB FAT)” did allow the design to fit, but it wouldn’t come out of reset — apparently the upload put it in an illegal area of Flash. Using “Huge APP (3MB no OTA/1MB SPIFF)” does fit and work (but of course no Over The Air capability). I explored your suggestion of custom partition schemes, and this link was very helpful: https://iotespresso.com/how-to-set-partitions-in-esp32/ … in showing where each of the Scheme Partitions are located (i.e. by going to …\tools\partitions in my PC).
Again, thanks for the help, and marking this as resolved is fine by me 🙂