[Solved]Trouble burning MicroPython firmware



  • Hi,

    I'm having trouble getting up and running with MicroPython and would appreciate some help, please.

    I have a M5Stack Fire (with psram) and I'm using a Windows 10 computer.

    I'm trying M5Stack_MicroPython and have been successful at burning a couple of different MicroPython.bin files from various firmware builds (such as https://github.com/m5stack/M5Stack_MicroPython/blob/master/MicroPython_BUILD/firmware/esp32_psram_all_bt/MicroPython.bin)

    >>esptool --chip esp32 --port COM5 erase_flash
    

    Then:

    >>esptool --chip esp32 --port COM5 --baud 460800 write_flash -z 0x1000 MicroPython.bin
    esptool.py v2.6
    Serial port COM5
    Connecting....
    Chip is ESP32D0WDQ6 (revision 1)
    Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
    MAC: 84:0d:nn:nn:nn:nn
    Uploading stub...
    Running stub...
    Stub running...
    Changing baud rate to 460800
    Changed.
    Configuring flash size...
    Auto-detected Flash size: 16MB
    Flash params set to 0x0240
    Compressed 2317264 bytes to 1477673...
    Wrote 2317264 bytes (1477673 compressed) at 0x00001000 in 35.6 seconds (effective 521.0 kbit/s)...
    Hash of data verified.
    
    Leaving...
    Hard resetting via RTS pin...
    

    Then I try to connect with rshell or ampy and nothing happens. Connecting with putty, I see the following (over and over again):

    rst:0x10 (RTCWDT_RTC_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    mode:DIO, clock div:2
    load:0x3f400020,len:462120
    ets Jun  8 2016 00:22:57
    

    Can anyone tell me what I'm doing wrong, please?

    Thanks,
    Andrew



  • @andrewm said in Trouble burning MicroPython firmware:

    Hi,

    I'm having trouble getting up and running with MicroPython and would appreciate some help, please.

    I have a M5Stack Fire (with psram) and I'm using a Windows 10 computer.

    I'm trying M5Stack_MicroPython and have been successful at burning a couple of different MicroPython.bin files from various firmware builds (such as https://github.com/m5stack/M5Stack_MicroPython/blob/master/MicroPython_BUILD/firmware/esp32_psram_all_bt/MicroPython.bin)

    >>esptool --chip esp32 --port COM5 erase_flash
    

    Then:

    >>esptool --chip esp32 --port COM5 --baud 460800 write_flash -z 0x1000 MicroPython.bin
    esptool.py v2.6
    Serial port COM5
    Connecting....
    Chip is ESP32D0WDQ6 (revision 1)
    Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
    MAC: 84:0d:nn:nn:nn:nn
    Uploading stub...
    Running stub...
    Stub running...
    Changing baud rate to 460800
    Changed.
    Configuring flash size...
    Auto-detected Flash size: 16MB
    Flash params set to 0x0240
    Compressed 2317264 bytes to 1477673...
    Wrote 2317264 bytes (1477673 compressed) at 0x00001000 in 35.6 seconds (effective 521.0 kbit/s)...
    Hash of data verified.
    
    Leaving...
    Hard resetting via RTS pin...
    

    Then I try to connect with rshell or ampy and nothing happens. Connecting with putty, I see the following (over and over again):

    rst:0x10 (RTCWDT_RTC_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    mode:DIO, clock div:2
    load:0x3f400020,len:462120
    ets Jun  8 2016 00:22:57
    

    Can anyone tell me what I'm doing wrong, please?

    Thanks,
    Andrew

    Please try this official windows installer. https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/software/M5Burner.zip



  • Usually the firmwares require a few files to burn successfully, it's not enough just to flash the micropython.bin file, you also need to flash bootloader.bin, a spiffs.img file and a partitions_mpy.bin as @ajb2k3 mentioned please try to use the official flashing tools or make sure you write those other files to the correct memory addresses using esptool



  • Thank you both.

    I have to say, however, that the advice to simply 'use M5Burner' is quite an unsatisfying answer as:
    a) M5Burner is magic (aren't we supposed to be learning things here?), and
    b) M5Burner isn't the magic I need yet, in that it has a very limited set of firmwares supported (and I wanted a particular flavour of MicroPython, not UIFlow).

    Your answers did help me, however, to get to the answer I wanted thank you, because I was able to go to the directories inside M5Burner and find the correct commands/addresses for firmware components in the firmware/fw.json file.

    To help anyone else reading this, I was able to burn this firmware:
    https://github.com/m5stack/M5Stack_MicroPython/tree/master/MicroPython_BUILD/firmware/esp32_psram_all_bt

    With this command:

    >> esptool --chip esp32 --port COM5 --before default_reset --after no_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0x1000 bootloader/bootloader.bin 0xf000 phy_init_data.bin 0x10000 MicroPython.bin 0x8000 partitions_mpy.bin
    

    Then using Putty or rshell, I could connect and confirm that it was working.

    Then I pushed the python app I want with rshell - https://github.com/dhylands/rshell - and the rsync command within rshell.

    So thanks for your help, I couldn't have understood the magic without being pointed to it.



  • @andrewm Sorry but micropython is still black magic to me and I'm still learning it myself.

    Current 1.2.3 version uses a modified version of the Loboris firmware and M5Stack is working to create their own specific port due to some issues.
    I do know that REPL is available in the firmware and a Micropython IDE is available through the UIFlow IDE (UIFlow firmware is built on micropython) also adafruits AMPY is useful for exploring and copying files to and from the M5Stack.
    If you are interested in learning more then
    https://forum.micropython.org
    Is a great place to also hang out.

    I take it that you noticed that M5Burner also show the full command line needed to burn the firmware?



  • @ajb2k3 No worries, your reply (and support of the forum, thank you) helped me take another step in the right direction so I appreciate it.

    The thing that bothered my about the UIFlow IDE when I tried it was that I had to push code from the web every time I booted the M5Stack (is there a way to store the code for the next time it boots?). MicroPython proper allows you to upload boot.py and main.py to permanently define the behaviour of the device.

    So far I have used rshell (in place of ampy, etc.) and allows me to do everything else I want (the command 'rsync . /flash' is powerful - it syncs the M5Stack's flash folder with whatever files and directories are in your local directory).

    I've run M5Burner previously, to install UIFlow. I didn't run it this time - I copied what I needed from the firmware/fw.json file.



  • @andrewm said in Trouble burning MicroPython firmware:

    @ajb2k3 No worries, your reply (and support of the forum, thank you) helped me take another step in the right direction so I appreciate it.

    The thing that bothered my about the UIFlow IDE when I tried it was that I had to push code from the web every time I booted the M5Stack (is there a way to store the code for the next time it boots?). MicroPython proper allows you to upload boot.py and main.py to permanently define the behaviour of the device.

    So far I have used rshell (in place of ampy, etc.) and allows me to do everything else I want (the command 'rsync . /flash' is powerful - it syncs the M5Stack's flash folder with whatever files and directories are in your local directory).

    I've run M5Burner previously, to install UIFlow. I didn't run it this time - I copied what I needed from the firmware/fw.json file.

    You can save and load a copy of the file onto a computer and download the program onto the M5Stack by clicking the menu icon (3 horizontal lines)>download but you can't load from the M5Stacks at present.
    When you restart/reset the M5Stack the program will autoload after a few seconds (this gives time to load the program menu or connect to UIFlow).



  • If you install uiflow firmware you have also installed micropython. You can connect to a repl shell, load libraries, and modify main.py. You can use any micropython ide and you aren't required to use uiflow. It is a good option though. I like using upycraft. Even if I am running uiflow I'll still keep a connection to the board open with upycraft to get immediate feedback. With upycraft you have direct access to the filesystem and you can drag and drop files to and from the board. You can also run
    help('modules')
    dir(module)
    where module is one of the listed modules. To learn more of all the built in functions available.