nodemcu/ESP8266 using Arduino IDE - Firmware? - arduino

I guess I'm having a basic understanding issue regarding the nodemcu/ESP8266 when it is used with the Arduino IDE and/or visual micro (for MS Visual Studio).
Everytime I upload a program/sketch which is obviously written in C in this case, it is compiling and uploading a binary of about 280kb, even if it is only a simple "blink" example.
Is it some kind of firmware being uploaded everytime or is it just monsterious libraries needed for the ESP to work with the Arduino IDE?
If it is firmware, do you normally "update" the firmware to a more recent build when working with the Arduino IDE? When using the nodemcu LUA firmware, there are periodic updates.
Thanks!

Basically, you build the firmware, which is a combination of your own code, and lots of other code/libraries.
All the other parts are part of the Arduino ESP8266 core, which does indeed get updates (it lives here: https://github.com/esp8266/Arduino). And it itself contains the Espressif SDK, which also gets updates (https://github.com/esp8266/Arduino/tree/master/tools/sdk).
Like NodeMCU you can get periodic updates, but they are of the core, and the only way to get them into your firmware is to recompile your sketch.

This is completely normal - When writing code for an interpreted language like Lua for the ESP/NodeMCU, you're just uploading what is a relatively small text file(s), as the code needed to run it is already on the chip, and doesn't change.
However, when you start working with compiled languages like C (With the Espressif SDK only, for example), or C++ with the Arduino IDE, you are replacing the entire firmware each time your code changes. This includes the TCP/IP stack, WiFi management, the logic controlling the PHY/MAC interface, the mini OS, and a host of other bits to make your ESP8266 work. Even if your code appears to be just a simple "blink" sequence, there's a lot of code running behind the scenes to make it possible, leading to the large sketch size.
Generally, every change to your sketch code will produce a complete copy of everything needed to create a bootable, runnable binary for the ESP8266. This is what is causing the 280KiB file. Since each copy of your code includes the newest (Or at least whatever is in your IDE at the time) copy of the system level code, there is no separate update process - Each time you upload your sketch, the system code is updated too.
Additionally, there is some extra overhead from the Arduino abstraction on the Espressif SDK, leading to a larger resulting binary size.

Related

is it possible to upload several sketches to an Arduino board

I have a project that is divided into two sections
each one of them requires an independent sketch,
I wanna upload the two sketches into the same Arduino card without one of them ruining the other's work, is that possible? if yes how to please
if no any other alternatives
No.
But you could combine both rather independent parts and add some logic to find out which part should be active, currently.
E.g. When a button (-combination) is pressed at restart, Arduino runs the test mode, else it runs in standard mode.
You can have multiple tabs in the Arduino IDE to handle the modes more independently, but all code is coexisting in flash memory after upload.
What you can do is have two seperate bin files (IDE menu Sketch / Export compiled binary) and have both of them include OTA code so you can update the binary as needed. The bin files can be stored locally on an SD card or remotely on a web server if the board has networking capabilities. Once updated the processor will reboot and start with updated code.
Look at ArduinoOTA for more information.

Is Arduino able to update only part of firmware?

I'm building a new project, and need to choose an MCU board.
What I'm trying is firmware's partial update. I will appoint part of firmware(like functions) on specific flash sector, and update only the sector so I don't need to erase&write the whole flash.
On my previous project, STM32F4DISCOVERY worked really fine but I wonder is Arduino could be an option.
Is it possible to set an memory address for firmware(i.e. funcA->0x0030, funcB->0x0090)
Is there a way to jump flash cursor(execute the code on specific memory address)
Can Arduino dynamically erase/write on flash memory itself?
Boards.txt file holds a reference to the Linker Script where memory regions are configured including starting address and length of flash and RAM.
FlashAsEEPROM is a library used to write/read the flash memory where EEPROM is not available.

Should I reinstall nodemcu firmware if I uploaded a arduino sketch?

I have a nodemcu v3 and I'm trying some basic stuff
I installed the esp8266 board in Arduino IDE and then I uploaded a blink example.
But now I'm trying to upload Lua code using ESPLorer but I doesn't work properly. I press in open and set the baud rate to 115200 but I just get some infinite Chinese letters.
Should I reinstall the firmare or something?
There is a very good answers at https://stackoverflow.com/a/43509569/131929 and https://stackoverflow.com/a/47510019/131929.
Should I reinstall the firmare or something?
First you should make up your mind whether you want to conveniently program in Lua or whether you want to stick with Arduino (running on the NodeMCU-clone board). It is an either-or question. Flashing on of them to the module will erase the respective other.
And no, in case you want to use the NodeMCU firmware, you should not use those outdates binaries from 2015. Build a recent version conveniently in the cloud: https://nodemcu.readthedocs.io/en/latest/en/build/.
P.S. if you're interested why I call yours a clone board you may want to read https://frightanic.com/iot/comparison-of-esp8266-nodemcu-development-boards/ from yours truly.
You must erase the flash of your NodeMCU before a new upload. If you ignore that, your software don't run appropriately. To do that, I'm using esptool:
python esptool.py --port COM9: erase_flash
In that example COM9: is the name of my USB/serial interface.
After that you can flash for example your ESP8266 with that line of code to add a boot part:
python esptool.py --port COM9: write_flash -fm dout 0x00000 boot_v1.5.bin
Use the preview line of code and adapt it to upload other parts of the map of the flash memory.

ESP8266 Not running Arduino code when uploaded

I have just recently got some ESP8266's and Ive been trying to use the Arduino IDE 1.8 to program them. (I have also used versions 1.6.5 and 1.6.9).
I have successfully ported a custom build from here and it runs perfectly, I upload Lua code and it runs with no problem.
But when I try to run the Arduino code (Such as the blink example found on this tutorial, with an LED on GPIO 2) that successfully uploads every time, the code never runs. In the Serial program on my PC, I won't see any text, (and the LED will be constantly on).
I followed several online tutorials saying pretty much the same procedure and no luck. Has anyone else experienced this issue and know the solution? Thanks!

Writing to flash ROM for an embedded OS on atmega328p (h8write equivalent for avr)

I'm currently reading a Japanese book on embedded OS/RTOS es except that I am not using the recommended hardware as I already had a seeeduino microcontroller.(atmega328p) The book is about KOZOS "12 steps to making your own embedded OS" by Sakai Hiroaki(It's hiro-something)
I'm stuck at the part where I need to write into the flash ROM of the atmega328p because the author is using a different chip called H8. He uses a software called h8write and uses that in his OS, but I honestly have no idea what is going on at this point, and what the avr replacement for h8write would be. I've looked around to no avail as there is minimal documentation on what h8write does aside from the "it helps you write to flash ROM" that shows up in the book.
This is the first time I'm doing lower layer stuff and it's frankly terrifying...
I'm using ubuntu 14.04 if that helps.
If I understand correctly, the h8write program is supposed to run on your computer and transfer the compiled to the microcontroller. You are using a seeeduino, which is an Arduino compatible board, with Ubuntu. The standard way of programming on this environment is with the arduino software:
install the arduino package (sudo apt-get install aruino)
type the command arduino from a terminal emulator: this brings an IDE where you can type your code
connect the seeeduino to an USB port
click on the button with a right-pointing arrow: this will take care of everything (compiling, linking and uploading to the seeeduino)
Once you are comfortable with this workflow, you can try to get your hands dirty with low-level stuff. The Arduino IDE is built on top of smaller utilities like avr-gcc, avr-libc, avr-as and avrdude. Avrdude is the program used to transfer the compiled program to the Arduino/seeeduino, i.e. write to the flash. You can use these utilities directly, from the command line. This is however complicated by the fact that you will need to pass many command-line arguments, so I recommend you automate the process using a Makefile. Thankfully there is a generic Arduino Makefile available that makes this quite easy:
install the generic Arduino Makefile: sudo apt-get install arduino-mk
read the instructions in the comments at the top (the Makefile is at /usr/share/arduino/Arduino.mk)
write your own project-specific Makefile as per these instructions
type make to compile your program
type make upload to upload to the seeeduino (i.e. write the flash).
This application note tells you how to write the flash memory during program run.
A very good tutorial on how to use the PROGMEM attribute in AVR microcontrollers can be found here

Resources