Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By Inq720
#94073 Or... you could get a 1MB ESP-01S. As long as you're binary is under 470KB. It's a plug-in replacement.

https://www.amazon.com/UMLIFE-ESP8266-ESP-01S-Transceiver-Arduino/dp/B093H28TGH
User avatar
By Pablo2048
#94080
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...
User avatar
By Inq720
#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 :oops: 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...

  1. Espressif reserves the first sector (4KB) and the last three sectors at the end.
  2. EEPROM reserves the fourth sector from the end.
  3. 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.
  4. The area between the sector 1 and the first sector of the file system is where code is placed.
  5. 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...
  1. The code that handles placing the your new program when uploaded via OTA is built-in to your program.
  2. When you compile and upload, the compiler always puts it in Code Area A.
  3. When you OTA it, the program in A places the new program binary in B and sets the start pointer to B.
  4. It boots and runs the code in B.
  5. The next time you OTA... the code in B places the code in A and sets the start pointer to A.
  6. 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:
  1. 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.
  2. Switch to a 1MB or larger device.
User avatar
By JPM06
#94082 I posted an answer yesterday night. It seemed to be accepted and published, but to-day it has disappeared. Too bad!
This morning I have received new ESP-01s with 1Mb memory. With them the problem disappears. My program runs fine with 1Mb.
=> I realize now that my IDE was not correctly set for a 0.5Mb chip.
I hope this also explain the erratic functionning of the OTA (that I mentioned in the vanished post). I have still to test that.
Thank you for your help, apologies for the disturbance. Best regards.