2025年10月15日

Thonny's back-end error with picocalc

When using Thonny(4.1.7) with picocalc, such error occures.

PROBLEM IN THONNY'S BACK-END: Internal error (thonny.plugins.micropython.mp_back.ProtocolError: Unexpected read during raw paste).

This issue is caused by os.dupterm() in boot.py

Workaround:
  Check USB connected or not before calling os.dupterm()

    SIE_STATUS_REG = 0x50110000 + 0x50
    SIE_CONNECTED  = 1 << 16
    SIE_SUSPENDED  = 1 << 4
    usbConnected   = (machine.mem32[SIE_STATUS_REG] & (SIE_CONNECTED | SIE_SUSPENDED)) == SIE_CONNECTED
                 
    if not usbConnected:
      os.dupterm(pc_terminal)


Check here
posted by とーふ at 22:15| Comment(0) | 組み込みSBC

2025年10月07日

Why reading is slow when using micropython SD card


Symptom
Reading is slow when using micropython's sdcard.py.
Increasing the baud rate does not improve performance.

Cause
The SD card response loop waits for 1 ms. Even a slight delay in response results in a 1 ms wait.

Solution
Change sdcard.py to the following:

def readinto(self, buf):
for i in range(_CMD_TIMEOUT * 50):
self.spi.readinto(self.tokenbuf, 0xFF)
if self.tokenbuf[0] == _TOKEN_DATA:
break
time.sleep_us(20)

Modifed codes are below.
(This entry was translated by google. )
posted by とーふ at 17:05| Comment(0) | 組み込みSBC

2025年09月22日

Why does picocalc hang when writing a file with micropython?(Solved)


phenomenon
 When I try to upload a file to pico using Thonny, it hangs up quite often.

cause
 There is a program that accesses ROM when writing to FLASH ROM.
 When writing to ROMFS, interrupts are disabled and multi-core processing is stopped to prevent ROM access.
 This should not affect the interval timer for cursor display in vtterminal.c or the LCD update process in picodisplay.c.
 However, to stop multi-core processing, you must first call a function (multicore_lockout_victim_init) that indicates that it is okay to stop the cores.
 The function call was included in the source, but for some reason it was commented out, so multi-core was not stopped.

Solution
 The corresponding function has been enabled.

Modifed codes are below.
(This entry was translated by google. )
posted by とーふ at 09:04| Comment(0) | 組み込みSBC

2025年09月20日

picocalcのmicropythonでファイルを書き込むときハングアップする原因

現象
 Thonnyを使って pico にファイルを upload しようとすると結構な確率でハングアップする

原因
 FLASH ROMへの書き込みタイミングでROMアクセスするプログラムがある
 ROMFSへの書き込み処理では、ROMアクセスが発生しないように、割込み禁止&マルチコア停止処理が組み込まれている。
 vtterminal.cのカーソル表示用インターバルタイマや、picodisplay.cのLCD更新処理は影響しないはず。
 しかしマルチコア停止のためには、あらかじめコアを停めても構わないことを指示する関数(multicore_lockout_victim_init)を呼び出しておく必要がある。
 ソース内に関数呼び出しは組み込まれていたが、なぜかコメントアウトしていたので、マルチコアが停止されなかった。

対策
 該当の関数を有効化した。

posted by とーふ at 18:01| Comment(0) | 組み込みSBC

2025年09月17日

PicoCalcのmicropythonでSDカードがやたらに遅いのを解決

よく見かける sdcard.py を使ってるので Baudrate を設定すればいいはずなのに、なんで遅いんだ?
と悩んでいて、sdcard.py の高速版というのを見かけた。
試してみようかとPicoCalcの初期化処理の Picocalc.py 内になる PicoSD の処理をいじってて気が付いた
そもそも、引数で設定した baurate を sdcard.py に渡してない

        self.sd = sdcard.SDCard(
            machine.SPI(self.spi_bus, baudrate=self.baudrate, polarity=0, phase=0,
                        sck=machine.Pin(self.sck_pin),
                        mosi=machine.Pin(self.mosi_pin),
                        miso=machine.Pin(self.miso_pin)),
            machine.Pin(self.cs_pin)
        )

一見良さそうに見えるじゃろ?それが罠なのじゃ
こいつは SPI の初期化時の baudrate を設定しているだけ
sdcard.py は内部でSPIを再設定しているので、sdcard.SDCard の引数として baudrate を設定すべき

        self.sd = sdcard.SDCard(
            machine.SPI(self.spi_bus, baudrate=self.baudrate, polarity=0, phase=0,
                        sck=machine.Pin(self.sck_pin),
                        mosi=machine.Pin(self.mosi_pin),
                        miso=machine.Pin(self.miso_pin)),
            machine.Pin(self.cs_pin),
            baudrate=self.baudrate
        )

エラい遠回りした
posted by とーふ at 21:49| Comment(0) | 組み込みSBC