2021-05-22

解除死鎖狀態的 Raspberry Pi Pico

早幾日到手的 Raspberry Pi Pico 不明原因下,Thonny 突然無法識別
但 Arduino 卻能如常能夠在 Raspberry Pi Pico BOOTSEL 模式下安裝 UF2檔案,亦能正確運作
因此在下翻查資料嘗試下解情況
話是「了解」,實際在下根本不知發生甚麼事情導致

偵錯過程

Unable to connect to /dev/ttyACM0: [Errno 2] could not open port /dev/ttyACM0: [Errno 2] No such file or directory: '/dev/ttyACM0'

Backend terminated or disconnected. Use 'Stop/Restart' to restart.
出現這個狀態的最後印象是在下使用 Thonny 編寫 MicroPython 並將程式安裝到 Raspberry Pi Pico
然後 Thonny 突然顯示 /dev/ttyACM0 無法連接,無法將程式安裝到 Raspberry Pi Pico

發生這些情況當然典型的處理方法是重新開機
不論是電腦還是 Raspberry Pi Pico 都嘗試重開機,能否處理問題
結果是失敗,Thonny 仍然顯示無法連接
但在網上尋找資料,並沒有有效的解決方法

Could not find port in 10 seconds
在下嘗試重裝 MircoPython韌體 ,但發現當 Thonny 下載及安裝 MircoPython韌體 時出現錯誤
在下嘗試不經 Thonny 下載及安裝卻沒有出現錯誤,但卻出現另一個錯誤

Couldn't find the device automatically. 
Check the connection (making sure the device is not in bootloader mode) or choose
"Configure interpreter" in the interpreter menu (bottom-right corner of the window)
to select specific port or another interpreter.
在下將 Thonny 連同使用者設定資料完全刪除,重新安裝及設定 結果再次是失敗,即使已經安裝 MircoPython韌體 , Thonny 顯示無法連接到 連接埠
在網上尋找資料,都是無法找到解決方法

Traceback (most recent call last):
  File "/opt/thonny-ide/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
    return self.func(*args)
  File "/opt/thonny-ide/lib/python3.7/site-packages/thonny/workbench.py", line 1960, in toolbar_handler
    handler(*args)
  File "/opt/thonny-ide/lib/python3.7/site-packages/thonny/running.py", line 405, in cmd_run_current_script
    self.execute_current("Run")
  File "/opt/thonny-ide/lib/python3.7/site-packages/thonny/running.py", line 366, in execute_current
    self.execute_editor_content(command_name, self._get_active_arguments())
  File "/opt/thonny-ide/lib/python3.7/site-packages/thonny/running.py", line 341, in execute_editor_content
    ["%" + command_name, "-c", EDITOR_CONTENT_TOKEN] + args, [EDITOR_CONTENT_TOKEN]
  File "/opt/thonny-ide/lib/python3.7/site-packages/thonny/shell.py", line 224, in submit_magic_command
    self.text.submit_command(cmd_line, ("magic",))
  File "/opt/thonny-ide/lib/python3.7/site-packages/thonny/shell.py", line 408, in submit_command
    self._try_submit_input()
  File "/opt/thonny-ide/lib/python3.7/site-packages/thonny/shell.py", line 1089, in _try_submit_input
    self._submit_input(submittable_text)
  File "/opt/thonny-ide/lib/python3.7/site-packages/thonny/shell.py", line 1231, in _submit_input
    get_runner().send_program_input(text_to_be_submitted)
  File "/opt/thonny-ide/lib/python3.7/site-packages/thonny/running.py", line 313, in send_program_input
    self._proxy.send_program_input(data)
  File "/opt/thonny-ide/lib/python3.7/site-packages/thonny/running.py", line 972, in send_program_input
    self._send_msg(InputSubmission(data))
  File "/opt/thonny-ide/lib/python3.7/site-packages/thonny/running.py", line 965, in _send_msg
    self._proc.stdin.write(serialize_message(msg) + "\n")
AttributeError: 'NoneType' object has no attribute 'stdin'
然後同樣是典型方法,就是重新安裝電腦系統測試,但由於在下有大量測試用電腦
因此將其中一部測試電腦重裝,回復至最初狀態下安裝 Thonny ,結果都是失敗
如果連重裝電腦都失敗,可以確定是 Raspberry Pi Pico 的問題
因為安裝最新版本的 Thonny 還顯示其他錯誤,這個錯誤訊息終於在網上找到解決方法

解決方法

最後在 Raspberry Pi 的官方討論區找到一篇文章 rpi pico cannot use micropython anymore
文中回應指下載 flash_nuke.uf2 並安裝到 Raspberry Pi Pico 便可以解決
在下看到來源是 Raspberry Pi 官方的超連結,便到 https://www.raspberrypi.org/documentation/rp2040/getting-started 了解
發現在 https://www.raspberrypi.org/documentation/rp2040/getting-started/#board-specificationsResetting Flash memory
有說明 Raspberry Pi Pico 無法覆寫時的處理方法
下載 flash_nuke.uf2 或使用指令下載或引導檔案到 Raspberry Pi Pico 的分區目錄,便可以重設 Raspberry Pi Pico 的記憶體
MicroPython v1.15 on 2021-04-18; Raspberry Pi Pico with RP2040
Type "help()" for more information.
>>> 

最後, Thonny 能夠偵測到 Raspberry Pi Pico

總結

在下估計是因為使用 Thonny 安裝 MicroPython 時,太快連續安裝導致死鎖錯誤

仔細閱讀說明文件是非常重要,其實官方已經將解決方法放在網頁上
但在下沒有了解清楚,當問題發生時卻花大量時間四處尋找解決方法,足足浪費了2日時間
結果解決方法只是下載一個 UF2檔案 並安裝到 Raspberry Pi Pico 便可以解決

關於重裝電腦來「解決」問題,通常是完全無計可施才使用
即使問題消失,實際問題並沒有解決,只是將問題迴避,當問題再發生,又要重裝電腦,處理上亦很花時間

參考資料

沒有留言 :

張貼留言