Josverl / micropython-stubber

Generate and maintain stubs for different MicroPython ports to use with VSCode and Pylance, PyRight, Thonny, PyCharm or MyPy
https://micropython-stubber.readthedocs.io
Other
183 stars 13 forks source link

mpflash: Failing flash without --serial #559

Closed Josverl closed 5 months ago

Josverl commented 7 months ago

reported by @wovo

The unneeded firmware scan is done when --serial is not specified ( either explicit or as '?') in this case there is a pile-on effect as the board is not correctly identified and tha flash fails.

mpflash --verbose flash --board ?      
[?] Which port do you want to flash to auto ?:                                                                                                              
 > esp32
   esp8266
   mimxrt
   nrf
   renesas-ra
   rp2
   samd
   stm32

[?] Which esp32 board firmware do you want to flash to auto ?:
   v1.22.2 Arduino Nano ESP32 with ESP32S3
 > v1.22.2 Generic ESP32 module with SPIRAM
   v1.22.2 ESP32C3 module with ESP32C3
   v1.22.2 FeatherS2 Neo with ESP32-S2FN4R2
   v1.22.2 FeatherS2 with ESP32-S2
   v1.22.2 FeatherS3 with ESP32-S3
   v1.22.2 Generic ESP32S2 module with ESP32S2
   v1.22.2 Generic ESP32S3 module with Octal-SPIRAM
   v1.22.2 LILYGO TTGO LoRa32 with ESP32
   v1.22.2 LOLIN_C3_MINI with ESP32-C3FH4
   v1.22.2 LOLIN_S2_MINI with ESP32-S2FN4R2
   v1.22.2 LOLIN_S2_PICO with ESP32-S2FN4R2
   v1.22.2 M5Stack ATOM with ESP32-PICO-D4

22:26:35 | 🐞 FlashParams(ports=['3', '2', 'e', 's', 'p'], boards=['ESP32_GENERIC'], versions=['stable'],
fw_folder=WindowsPath('C:/Users/josverl/Downloads/firmware'), serial='auto', erase=True, bootloader=True, cpu=None)
22:26:36 | 🐞 D:\MyPython\micropython-stubber\.venv\Scripts\python.exe -m mpremote connect COM20 run 
D:\MyPython\micropython-stubber\src\mpflash\mpflash\mpremoteboard\mpy_fw_info.py
22:26:37 | ℹ️ Try (2) to find a firmware for the board UNKNOWN_BOARD
22:26:37 | ℹ️ Try (3) to find a firmware for the board ESP32_UNKNOWN_BOARD
22:26:37 | ❌ No v1.22.2 firmware found for UNKNOWN_BOARD on COM20.
22:26:37 | ❌ No boards were flashed

also the ports parameter is returned incorrectly

Originally posted by @Josverl in https://github.com/micropython/micropython/discussions/14395#discussioncomment-9322066

Josverl commented 7 months ago

mpflash v0.7.6 has been updated to interactively ask for the serial port if --board ? has been specified but no --serial has been specified. in addition the list of serial ports has been improved by adding the comports description (if available) .

mpflash flash --board ? Should allow you to select the serial port ,Micropython Port , and Board and then continue to flash the esp32/esp8266

@wovo, @beetlegigg Could you verify if this version works for you ?

Below a sample run

> mpflash flash --board ?
[?] Which serial port do you want to flash ?:
 > COM8 Microsoft USB Serial Device (COM8)
   COM20 Silicon Labs CP210x USB to UART Bridge (COM20)
   COM21 Microsoft USB Serial Device (COM21)
   Other

[?] Which port do you want to flash to COM8 Microsoft USB Serial Device (COM8) ?:
 > esp32
   esp8266
   mimxrt
   nrf
   renesas-ra
   rp2
   samd
   stm32

Cancelled by user

PS D:\MyPython\micropython-stubber\src\mpflash> mpflash flash --board ?
[?] Which serial port do you want to flash ?:
   COM8 Microsoft USB Serial Device (COM8)
 > COM20 Silicon Labs CP210x USB to UART Bridge (COM20)
   COM21 Microsoft USB Serial Device (COM21)
   Other

[?] Which port do you want to flash to COM20 Silicon Labs CP210x USB to UART Bridge (COM20) ?:                                                                                                  
 > esp32
   esp8266
   mimxrt
   nrf
   renesas-ra
   rp2
   samd
   stm32

[?] Which esp32 board firmware do you want to flash to COM20 Silicon Labs CP210x USB to UART Bridge (COM20) ?:
   v1.22.2 Arduino Nano ESP32 with ESP32S3
 > v1.22.2 Generic ESP32 module with SPIRAM
   v1.22.2 ESP32C3 module with ESP32C3
   v1.22.2 FeatherS2 Neo with ESP32-S2FN4R2
   v1.22.2 FeatherS2 with ESP32-S2
   v1.22.2 FeatherS3 with ESP32-S3
   v1.22.2 Generic ESP32S2 module with ESP32S2
   v1.22.2 Generic ESP32S3 module with Octal-SPIRAM
   v1.22.2 LILYGO TTGO LoRa32 with ESP32
   v1.22.2 LOLIN_C3_MINI with ESP32-C3FH4
   v1.22.2 LOLIN_S2_MINI with ESP32-S2FN4R2
   v1.22.2 LOLIN_S2_PICO with ESP32-S2FN4R2
   v1.22.2 M5Stack ATOM with ESP32-PICO-D4

23:44:59 | ℹ️ Updating ESP32_GENERIC on COM20 to 1.22.2
23:44:59 | ℹ️ Flashing C:\Users\josverl\Downloads\firmware\esp32\ESP32_GENERIC-v1.22.2.bin on ESP32_GENERIC on COM20
23:44:59 | ℹ️ Running esptool --chip esp32 --port COM20 erase_flash 
....
beetlegigg commented 7 months ago

BTW This looks as if it will be a very useful tool and thanks for your efforts. No luck with the install on my macOS yet. I post the terminal output so you can see the commands I entered.

iMacBG:~:% mpflash --version
mpflash, version 0.7.6

iMacBG:~:% mpflash flash --board ?
zsh: no matches found: ?

iMacBG:~:% mpflash list
Error: Failed to get mcu_info for /dev/cu.Bluetooth-Incoming-Port

<img width="642" alt="image" src="https://github.com/Josverl/micropython-stubber/assets/34552737/d9cec4e6-c0be-45a7-8906-00e2e81322d7">

iMacBG:~:% mpflash list --ignore cu.Bluetooth-Incoming-Port
00:16:39 | ❌ Error: No such option: --ignore

iMacBG:~:% mpflash flash --serial cu.usbmodem141101 --board rp2
00:18:46 | ❌ Board rp2 not found in board_info.json
00:18:46 | ❌ No boards were flashed

iMacBG:~:% mpflash flash --serial cu.usbmodem141101            
Error: Failed to get mcu_info for /dev/cu.Bluetooth-Incoming-Port

00:19:44 | ℹ️ Try (2) to find a firmware for the board PICO
00:19:44 | ℹ️ Updating PICO on cu.usbmodem141101 to 1.22.2
00:19:44 | ℹ️ Entering bootloader on PICO on cu.usbmodem141101
00:19:44 | ℹ️ failed to access cu.usbmodem141101 (it may be in use by another program)
00:19:46 | ℹ️ Erasing not yet implemented for UF2 flashing.
00:19:46 | ⚠️ OS darwin not tested/supported
Waiting for mcu to mount as a drive ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━   0% -:--:--00:19:46 | ❌ pumount only works on Linux
00:19:46 | ❌ pumount only works on Linux
Waiting for mcu to mount as a drive ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━   0% -:--:--00:19:47 | ❌ pumount only works on Linux
00:19:47 | ❌ pumount only works on Linux
Waiting for mcu to mount as a drive ━━━━╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━  10% -:--:--00:19:48 | ❌ pumount only works on Linux
00:19:48 | ❌ pumount only works on Linux
Waiting for mcu to mount as a drive ━━━━━━━━╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━  20% 0:00:0900:19:49 | ❌ pumount only works on Linux
00:19:49 | ❌ pumount only works on Linux
Waiting for mcu to mount as a drive ━━━━━━━━━━━━╺━━━━━━━━━━━━━━━━━━━━━━━━━━━  30% 0:00:0800:19:50 | ❌ pumount only works on Linux
Waiting for mcu to mount as a drive ━━━━━━━━━━━━╺━━━━━━━━━━━━━━━━━━━━━━━━━━━  30% 0:00:0800:19:50 | ❌ pumount only works on Linux
Waiting for mcu to mount as a drive ━━━━━━━━━━━━━━━━╺━━━━━━━━━━━━━━━━━━━━━━━  40% 0:00:0700:19:51 | ❌ pumount only works on Linux
Waiting for mcu to mount as a drive ━━━━━━━━━━━━━━━━╺━━━━━━━━━━━━━━━━━━━━━━━  40% 0:00:0700:19:51 | ❌ pumount only works on Linux
Waiting for mcu to mount as a drive ━━━━━━━━━━━━━━━━━━━━╺━━━━━━━━━━━━━━━━━━━  50% 0:00:0600:19:52 | ❌ pumount only works on Linux
Waiting for mcu to mount as a drive ━━━━━━━━━━━━━━━━━━━━╺━━━━━━━━━━━━━━━━━━━  50% 0:00:0600:19:52 | ❌ pumount only works on Linux
Waiting for mcu to mount as a drive ━━━━━━━━━━━━━━━━━━━━━━━━╺━━━━━━━━━━━━━━━  60% 0:00:0500:19:53 | ❌ pumount only works on Linux
00:19:53 | ❌ pumount only works on Linux
Waiting for mcu to mount as a drive ━━━━━━━━━━━━━━━━━━━━━━━━━━━━╺━━━━━━━━━━━  70% 0:00:0400:19:54 | ❌ pumount only works on Linux
00:19:54 | ❌ pumount only works on Linux
Waiting for mcu to mount as a drive ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╺━━━━━━━  80% 0:00:0300:19:55 | ❌ pumount only works on Linux
00:19:55 | ❌ pumount only works on Linux
00:19:56 | ❌ Failed to flash PICO on cu.usbmodem141101
00:19:56 | ❌ No boards were flashed
iMacBG:~:% 
Josverl commented 7 months ago

Thanks for testing - I understand the error you are experiencing on the rp2. the flash process for the rp2 and other .uf2 boards is :

the ignore is for all commands - to it should be like this: mpflash --ignore cu.Bluetooth-Incoming-Port list or mpflash --verbose --ignore cu.Bluetooth-Incoming-Port list to show more info

What I can do is make a change so at least the pumount tool is not used on macos. Ill post an update here If I have something to test.

Josverl commented 5 months ago

as far as I am aware this now works as expected, but I have no hardware to verify first hand. Please feel free to re-open if this this is still a problem