Adsense HTML/JavaScript

Monday, October 18, 2021

Flash MicroPython firmware on ESP32-C3

Updated@2022-06-19

~ Flash MicroPython v1.19 firmware on ESP32-C3 (ESP32-C3-DevKitM-1/NodeMCU ESP-C3-32S-Kit)

It is aimed to flash MicroPython firmware on ESP32-C3-DevKitM-1 with unknown ESP32-C3 (revision 3) and 4MB flash. I can't find any official installation instruction, it's found out by my guessing and trying. Not sure is it correct approach, it seem work for me anyway.

Download MicroPython for ESP32-C3:

Visit https://micropython.org/download/all/, search "esp32c3" firmware for ESP32-C3, download the .bin file. It's esp32c3usb-20211018-unstable-v1.17-84-gba940250a.bin I tried.

Identify port and chip/flash:

To identify the ESP32 device connected USB port, chip and flash, refer to the last post.

It's unknown ESP32-C3 (revision 3) and 4MB flash on  ESP32-C3-DevKitM-1, connected to /dev/ttyUSB0.

Flash MicroPython firmware:

Erase flash, enter the command:

$ esptool.py --port /dev/ttyUSB0 erase_flash
Flash firmware with:
$ esptool.py --chip esp32c3 -p /dev/ttyUSB0 -b 460800 \
--before=default_reset --after=hard_reset write_flash --flash_mode dio \
--flash_freq 80m --flash_size 4MB \
0x0 esp32c3usb-20211018-unstable-v1.17-84-gba940250a.bin
* write firmware to on ESP flash from 0x0

Wrote 1495696 bytes (888871 compressed) at 0x00000000 in 26.6 seconds (effective 449.2 kbit/s)...

ref:

To verify that data in flash matches a local file:

$ esptool.py verify_flash --diff yes 0x0 <.bin>

ref:


MicroPython code tried:

mpyESP32C3_info.py
"""
MicroPython/ESP32C3 exercise run on ESP32-C3-DevKitM-1,
to display info.
"""
import uos
import usys
import machine
import esp

print("from uos.uname():")
for u in uos.uname():
    print(u)
print()

print("from usys:")
print("usys.platform: ", usys.platform)
print("usys.implementation: ", usys.implementation)
print()

print("====================================")
print(usys.implementation[0], uos.uname()[3],
      "\nrun on", uos.uname()[4])
print("====================================")
print("Flash size:", esp.flash_size())
print("CPU frequency:", machine.freq(), "(Hz)")
mpyESP32C3_RGB.py
"""
MicroPython/ESP32C3 exercise run on ESP32-C3-DevKitM-1,
to control the onboard GB LED (WS2812), driven by GPIO8.
"""

import uos
import usys
import machine
import neopixel
import time

print("====================================")
print(usys.implementation[0], uos.uname()[3],
      "\nrun on", uos.uname()[4])
print("====================================")

np = neopixel.NeoPixel(machine.Pin(8), 1)

np[0] = (0, 0, 0)
np.write()
time.sleep(1)
np[0] = (100, 100, 100)
np.write()
time.sleep(1)
np[0] = (0, 0, 0)
np.write()
time.sleep(1)

for i in range(256):
    np[0] = (i, 0, 0)
    np.write()
    time.sleep_ms(10)
for i in range(256):
    np[0] = (0, i, 0)
    np.write()
    time.sleep_ms(10)
for i in range(256):
    np[0] = (0, 0, i)
    np.write()
    time.sleep_ms(10)

for i in range(256):
    np[0] = (255-i, 255-i, 255-i)
    np.write()
    time.sleep_ms(10)



It's another form of the flash command, modified from  Getting started with MicroPython on the ESP32 > Deploying the firmware, change starting address to 0x0.

$ esptool.py --chip esp32c3 --port /dev/ttyUSB0 write_flash -z \
0x0 esp32c3usb-20211018-unstable-v1.17-84-gba940250a.bin
but it take longer time.

Wrote 1495696 bytes (888871 compressed) at 0x00000000 in 79.6 seconds (effective 150.4 kbit/s)...




More ESP32-C3/MicroPython exercises:

3 comments:

  1. THANK YOU! No idea why the ESP32-C3 needs to be written starting at 0x0, rather than 0x1000, but sure enough it does. I couldn't figure out why nothing could seem to be written to my device (M5Stack STAMP-C3), but basically nothing was working. Now, it's successfully running the generic ESP32-C3 MicroPython. Won't run the one I compiled myself, but now I can keep working on that now that I know it'll have a possibility of working.

    ESP-ROM:esp32c3-api1-20210207
    Build:Feb 7 2021
    rst:0x1 (POWERON),boot:0xc (SPI_FAST_FLASH_BOOT)
    SPIWP:0xee
    mode:DIO, clock div:1
    load:0x3fcd6100,len:0x121c
    load:0x403ce000,len:0x744
    load:0x403d0000,len:0x26c4
    entry 0x403ce000
    MicroPython v1.17 on 2021-09-02; ESP32C3 module with ESP32C3
    Type "help()" for more information.

    ReplyDelete
    Replies
    1. Just for reference, for anyone else finding this on Google, this is my functioning command on Windows. COMx obviously needs to be set to the appropriate COM# port. My device didn't reset as commanded, I had to push the physical RST button afterwards.

      esptool.py -p COMx -b 1000000 --before default_reset erase_flash
      esptool.py -p COMx -b 1500000 --before default_reset write_flash -z 0x0 esp32c3-20210902-v1.17.bin

      Delete
  2. Thank you brother I own you a lot thanks for

    ReplyDelete