Two ways of configuring FLASH for ESP8266?

I am trying to understand how to configure flash size for ESP8266 board because I have Arduino Uno wifi with ATmega328 and ESP8266 with 16 MB of flash on the same PCB.

What I did first was to here find a board which has 16 MB flash (WEMOS D1 mini Pro) and after I configured the environement as:

platform = espressif8266
board = d1_mini_pro
framework = arduino
upload_speed = 921600

everything worked as expected.

However, I then remembered some old webUI project where flash was configured like this by build_flags = -Wl,-Teagle.flash.4m1m.ld:

; eagle.flash.512k0.ld 512K (no SPIFFS)
; eagle.flash.512k64.ld 512K (64K SPIFFS)
; eagle.flash.512k128.ld 512K (128K SPIFFS)
; eagle.flash.1m0.ld 1M (no SPIFFS)
; eagle.flash.1m64.ld 1M (64K SPIFFS)
; eagle.flash.1m128.ld 1M (128K SPIFFS)
; eagle.flash.1m144.ld 1M (144K SPIFFS)
; eagle.flash.1m160.ld 1M (160K SPIFFS)
; eagle.flash.1m192.ld 1M (192K SPIFFS)
; eagle.flash.1m256.ld 1M (256K SPIFFS)
; eagle.flash.1m512.ld 1M (512K SPIFFS)
; eagle.flash.2m.ld 2M (1M SPIFFS)
; eagle.flash.4m1m.ld 4M (1M SPIFFS)
; eagle.flash.4m2m.ld 4M (2M SPIFFS)
; eagle.flash.4m.ld 4M (3M SPIFFS)
; eagle.flash.8m.ld 8M (7M SPIFFS)
; eagle.flash.16m.ld 16M (15M SPIFFS)

platform = espressif8266
board = esp12e
build_flags = -Wl,-Teagle.flash.4m1m.ld

but here in PlatformIO documentation it says the right way of configuring the size is by using:

board_build.ldscript = eagle.flash.*.ld

I was trying to find the documentation about -T build flag but I couldn’t find it anywhere.

My questions are:

  1. Where is the documentation about -T build flag?

  2. Is there any difference between configuring the flash size by using the mentioned build flag and using board_build.ldscript option?

Is this a UNO Board (ATmega328) + ESP8266 as “co processor” ?
If so, how can the ESP8266 be programmed? Or is it just a stupid “coprocessor” running default AT-Firmware?

I would recommend to switch directly to an ESP8266 or even better ESP32 / ESP32-S3 since the ESP8266 is outdated and discontinued.

The ATmega328 is very limited: 16 MHz, just a few kb flash and ram.
The ESP32 is runing at 160 / 240 MHz, has dual core, megabytes of flash and dozens of kb RAM and can be programmed in the same way as an uno (using Arudino framework).

Why using an atmega328 as bottleneck?

I posted a link to the board listing where you can see how it can be used. There are 7 DIP switches, switches #3 and #4 are for connecting CH340 to ATmega328, switches #5 and #6 are for connecting CH340 to ESP8266, DIP #7 is to pull GPIO0 to GND to program ESP8266 and switches #1 and #2 are to connect ATmega328’s TX/RX to ESP8266’s RX/TX.

So using is very elegant by configuring two environments in platformio.ini, uploading firmware to each microcontroller and then, if you want, you can enable direct communication between both microcontrollers over UART.

The board has LEDs for both microcontrollers and a button for ESP8266. And, of course, it has level shifting.

I’ve been using microcontrollers since 16C84 (yes, C, not 16F84) which has 1 KB of EEPROM program memory (not FLASH) and 36 bytes of RAM and amazing things have been done even with those.

Later I started using 16F84 which has whole 68 bytes of RAM. I still have 25 years old circuit where 16F84 reads joystick, generates PAL video signal, generates music and graphics for playing Tetris on the TV - everything in 1 KB.

Then arrived 16F628A and I couldn’t believe it has whole 2 KB of flash memory and enormous 224 bytes of RAM :slight_smile:

There are still devices installed at some factories that I made with ATmega8, it took me a year to make a firmware and there was still plenty of free program memory so I don’t need more than ATmega328 for what I am doing and ESP8266 has waaaaay more resources than I need. I do have ESP32 and RP2040 boards too but I use them only when I need to.

BTW, I have Mega 2560 wifi boards too which have ATmega2560 and ESP8266.

But back to the topic - any info on -T build flag?

Sorry, I don’t know that board and I was too lazy to read through the whole advertising description of Aliexpress. :wink:

The information on this page is unfortunately very misleading. The description says 32MB, on the back of the PCB it says 8MB, but you have a 16MB variant… oookay… :wink:

Thanks for the explanation! Now I understand :slight_smile:

I have read too many questions where users have gone the wrong way. A large application for a small ATmega which is then supposed to connect via an ESPxx - awkwardly connected via UART etc… It often made more sense to run everything on the ESPxx. Which is also less error-prone in these cases.

Yeah, the good old times…

The flash size is set via board_build.ldscript. Does it not work for you?

At Arduino/tools/sdk/ld at master · esp8266/Arduino · GitHub you will find a list of other ldscripts that are also available to you.

Sorry but I don’t know a -T compiler flag.

Now that I checked the flash chip, it’s neither 32 MB nor 8 MB :-)))) It is 32 Mbit = 4 MB flash :-)) The chip is XMC 25QH32CHIG. Here is the exact model of the flash chip.

I am not sure why I thought there is 16 MB of flash but there was some reason. I think someone in the comments wrote: “The flash is not 32 MB, it is 16 MB”, or similar or I was looking at some other listing and ordered from another.

But that isn’t a problem, I could probably find a larger SPI flash with the same pinout if I needed.

Silkscreen markings are not very useful, for example the DIP switches for enabling communication between both microcontrollers are marked with MCU+WVPI which was probably meant to be MCU+WIFI. And there is a button near ESP8266 marked with ESP reboot but by tracing I found the button is connected to ESP8266’s pin 12 (GPIO13 / MTCK) and, as I’ve described here in the comments, can be used as input button.

But I can’t complain after buying those boards for $8 and these Mega 2560 boards with ESP8266 for under $20 while in my country Mega 2560 board costs $395 (of course, it doesn’t have ESP8266) which is insane because that is here almost half of the average month’s salary.

Arduino libraries (if used) can often be stripped down from 5 or even 10 KB to just a few 100s of bytes but I tend to write my own routines which do only what I need.

But the main reason why I am using AVR is because the requirement for this project is the firmware has to be locked and the microcontroller will work under heavy EMI which I know AVR can handle very well but am not sure about ESPxx microcontrollers. That’s why ESP will do only some non-critical tasks or I even might do everything with ATmega. I know there are some encription options for protecting ESP firmware but I’ve made a decision to use AVR’s lock bits.

It does work, but I was surprised when I saw the documentation because I was using -T flag. I think I learnt that a few years ago from this source code and it works - very nice web interface framework for ESP8266 by the way.

Seems as -T flag was used before and board_build.ldscript was introduced some time after. Because, when I now compile the old project using -T flag there is a note:

Warning! '-Wl,-T' option for specifying linker scripts is deprecated. Please use 'board_build.ldscript' option in your 'platformio.ini' file.
Compiling .pio\build\myboard\src\main.cpp.o
Generating LD script .pio\build\myboard\ld\

That confirms the -T flag was really used before but strangely, I can’t find any documentation about that :-/

My “default” board is ESP32-S3 N16R8 (16 MB Flash + 8 MB PSRAM) costs around $5 at aliexpress

I don’t know what EMI means, but it sounds like flash encryption / copy protection to me. The ESP actually supports this quite well. But I have never used it.
The Arduino framework of the ESP32 series is now well developed. Switching from an ATxxx should not be a problem - as long as there is not too much low-level programming with registers etc.

I switched from the ESP8266 series (which is now discontinued) to the ESP32-S3 series which offers a much better architecture.

I already suspected something like that. I couldn’t find anything about the -T flag either.

I was looking at this very board because S3 can work as HID device and the board has two USB connectors. I wanted to use it for making virtual pinball controller with accelerometers and feedback similar to this one but it can be done with ATmega32U4 too.

EMI = ElectroMagnetic Interference.

For example, if a microcontroller is near some VFD and you are using internal pull-ups or even 10k external pull-ups that might be a problem because EMI can induce enough voltage to randomly switch the state of some microcontroller’s inputs. I once had a problem when microcontroller was often restarting “without a reason” and in that case I could solve the problem by replacing 10k pull-up resistor on RST pin with 4k7 resistor but sometimes quite a few other measures must be taken to make the device working under strong EMI.

This time the microcontroller will be near gasoline engine (sparks are very strong source of EMI) and near the transmitter for which I am sure AVR can do without problems but I am not sure for ESPs because I didn’t test them under such conditions.

I started programming with Z80 assembly back in the 80s and after using AVRs for more than 10 years I don’t like using a microcontroller which would in certain device be utilized only 1% or 2%

If something can be made using $0.5 microcontroller with just 4 pins then I will use it and replace the microcontroller only if I need more resources.

And yes, I am using registers all the time. Just compare the size of Arduino generated firmware for toggling the LED which is over 1 KB with the “normal” code accessing the registers which is under 10 bytes.

I like using microcontroller where I very well know every detail of how the firmware works and every framework adds additional level of abstraction which I try to avoid whenever I can.

That’s why I am using newer generations of microcontrollers only when I really have to. I have a feeling AVRs working at much lower clock and at 5V are more robust than ESPs when used in harsh conditions.

There should be the old documentation somewhere. I am still looking for it.

One connector is native USB, the other runs via a UART to USB chip (as with many other boards).

Oh, I was on the wrong track :sweat_smile:
I didn’t know the English abbreviation for it.

To keep it short: I totally agree with the rest of your post :slight_smile: