- Fri Mar 25, 2022 9:45 am
#94081
Pablo2048 wrote:JPM06 wrote:Thank you both.
=> Everything runs perfectly on a NodeMCU/ESP12, but not on my ESP-01 (512Mo).
...
Once compiled the program occupies 318257 bytes (33%) and the variables 29732 bytes (36%).
The problem is obvious IMHO - if 318257 bytes is 33% guess how much is 100%? -> 1MB so it seems like you selected wrong memory map, not the 512KiB...
Pablo2048, you are certainly right. In my case it wasn't obvious because I did a bad thing
I made my conclusions of what JPM06's problem was before reading down to the code... and compiling text. You gave the answer more concisely.
JPM06 wrote:...
Once compiled the program occupies 318257 bytes (33%) and the variables 29732 bytes (36%).
May be should I use an ESP-01 with 1Mb memory, but I wonder why
...
As for why it may not be obvious to JPM06... JPM06 are you familiar with how OTA works? I'll write this for the beginners that might search and find this topic later.
For a 512KB ESP-01 you only have these four settings available.
Untitled.png
You select the
Flash Size: setting and the Compiler does the following...
- Espressif reserves the first sector (4KB) and the last three sectors at the end.
- EEPROM reserves the fourth sector from the end.
- The compiler set's aside the space for a file system, say... (FS:64KB... will set aside 64/4 = 16 sectors for a file system. These 16 sectors are place just before the EEPROM area.
- The area between the sector 1 and the first sector of the file system is where code is placed.
- OTA splits this in two... call it Code Space A and Code Space B.
This Math is pretty basic.
Code: Select alltotal avail 512 KB
Espressif beginning -4 KB
Espressif end -12 KB
EEPROM -4 KB
File System -64 KB
--------
Left for Code 428 KB
Code Area A and B = 428 / 2 = 214 KB
As you can see your program of 318257 can't fit. In fact, no Arduino IDE compile code can fit and do OTA on a 512KB ESP-01.
Now How OTA Actually Works... - The code that handles placing the your new program when uploaded via OTA is built-in to your program.
- When you compile and upload, the compiler always puts it in Code Area A.
- When you OTA it, the program in A places the new program binary in B and sets the start pointer to B.
- It boots and runs the code in B.
- The next time you OTA... the code in B places the code in A and sets the start pointer to A.
- Back and forth forever.
Now... OTA only knows where A goes and B goes.
It doesn't check to see if it's too big. And in your case, that is a problem. When program in A (that is already overflowing) B's location by at least 311KB - 246KB = 65KB...
... places your new code it places it at the B position... which overwrite the trailing end of A's code AND overwrite the EEPROM area and possibly Espressif's tail-end sectors. It's very surprising you don't get an instant, endless re-booting MPU.
To make a long story shorter... TOO LATE, Inq!
So you're choices are:
- Only compile/upload via Arduino IDE and never do OTA (actually taking OTA out of the source code would be safest) and your EEPROM should start working.
- Switch to a 1MB or larger device.