DEV Community

zhuyue
zhuyue

Posted on

Continue to update the OTA functionality for script programmable controller based on ESP8266

In the past few days, I've updated the code for OTA upgrade of the Simple Script Programmable Controller as well as the PC software

The ESP8266 supports two OTA firmware slots (user1.bin and user2.bin).

It is possible to upload new firmware in one of the non-currently running firmware slots, and then check the new firmware and switch it on the next boot.

For the ESP8266-07S with a Flash space size of 4MByte, the two firmware slots are stored at 0x1000 and 0x81000, respectively. Define SPI_SIZE_MAP as 4 in the Makefile for the boot program to be able to detect the firmware at the address of 0x1000 or 0x81000 and jump to it.

Define APP as 1 and 2 in the Makefile, and compile and generate firmware user1.bin and user2.bin in the two firmware slots.

When OTA upgrade operation is performed, the host computer first sends a command to ESP8266 to query the currently used firmware, if user1.bin is used, then select firmware user2.bin and write it to the Flash space starting from 0x81000, if user2.bin is used, then select firmware user1.bin and write it to the Flash space starting from 0x1000. If user2.bin is used, select firmware user1.bin and write it to the Flash space starting from 0x1000.

After compiling user1.bin and user2.bin and modifying the value of APP, you need to clean the whole project before compiling, otherwise the same user1.bin and user2.bin will be generated.

If you use the same firmware to download to different firmware slots, it will cause the ESP8266 to crash when the next OTA upgrade is performed to erase the data in the spare firmware slot.

Makefile change

Clean project to build another APP

Top comments (0)