Bug: spi_flash.py not working on BTT boards with SD_SPI_SPEED = 400000

Basic Information:

Printer Model: Voron Switchwire
MCU / Printerboard: BTT SKR Mini E3 V3
Klipper Version: v0.11.0-0-ge02b7256
klippy.log - unneeded in this context
Shell output
spi_flash_shell_output.txt (3.4 KB)

Describe your issue:

In SKR 1.4 Turbo Problem with spi_flash: reduce speed to 400K · Issue #5465 · Klipper3d/klipper · GitHub, a user found that reducing the SPI Flash speed (variable SD_SPI_SPEED) down to 400K was causing issues with the SD card update script needed for updates on BigTreeTech boards. This issue was closed, but I’ve been experiencing it for months and manually working around it.

Resetting the variable to the previous 4000000 (4M), enables this script to work with the SKR Mini E3 V3 board. Unclear to me why this is the case, but I think this issue should be reopened.

Basic Information:

  • Printer Model: Voron 2.4
  • MCU / Printerboard: Spider 2.2
  • Klipper Version: v0.11.0-169-g83308a10
  • klippy.log - unneeded in this context
  • Shell output:

Describe your issue:

The error message with spi speed set to default: 400K

Flashing /home/pi/klipper/out/klipper.bin to /dev/ttyAMA0
Checking FatFS CFFI Build...
Connecting to MCU...Connected
Checking Current MCU Configuration...Done
MCU needs restart: is_config=1, is_shutdown=0
Attempting MCU Reset...Done
Waiting for device to reconnect...Done
Connecting to MCU...Connected
Initializing SD Card and Mounting file system...

SD Card Flash Error: Failed to Initialize SD Card. Is it inserted?
Traceback (most recent call last):
  File "/home/pi/klipper/scripts/spi_flash/spi_flash.py", line 1647, in main
    spiflash.run()
  File "/home/pi/klipper/scripts/spi_flash/spi_flash.py", line 1587, in run
    self.run_reactor_task(self.run_sdcard_upload)
  File "/home/pi/klipper/scripts/spi_flash/spi_flash.py", line 1570, in run_reactor_task
    k_reactor.run()
  File "/home/pi/klipper/klippy/reactor.py", line 292, in run
    g_next.switch()
  File "/home/pi/klipper/klippy/reactor.py", line 340, in _dispatch_loop
    timeout = self._check_timers(eventtime, busy)
  File "/home/pi/klipper/klippy/reactor.py", line 158, in _check_timers
    t.waketime = waketime = t.callback(eventtime)
  File "/home/pi/klipper/klippy/reactor.py", line 48, in invoke
    res = self.callback(eventtime)
  File "/home/pi/klipper/scripts/spi_flash/spi_flash.py", line 1542, in run_sdcard_upload
    self.mcu_conn.configure_mcu(printfunc=output_line)
  File "/home/pi/klipper/scripts/spi_flash/spi_flash.py", line 1359, in configure_mcu
    self._configure_mcu_spibus(printfunc=printfunc)
  File "/home/pi/klipper/scripts/spi_flash/spi_flash.py", line 1328, in _configure_mcu_spibus
    "Failed to Initialize SD Card. Is it inserted?")
SPIFlashError: Failed to Initialize SD Card. Is it inserted?

Change SD_SPI_SPEED = 4000000

Flashing /home/pi/klipper/out/klipper.bin to /dev/ttyAMA0
Checking FatFS CFFI Build...
Connecting to MCU...Connected
Checking Current MCU Configuration...Done
MCU needs restart: is_config=1, is_shutdown=0
Attempting MCU Reset...Done
Waiting for device to reconnect...Done
Connecting to MCU...Connected
Initializing SD Card and Mounting file system...

SD Card Information:
Version: 2.0
SDHC/SDXC: True
Write Protected: False
Sectors: 62333952
manufacturer_id: 3
oem_id: SD
product_name: SE32G
product_revision: 8.128
serial_number: 2174F315
manufacturing_date: 8/2019
capacity: 29.7 GiB
fs_type: FAT32
volume_label: UNTITLED
volume_serial: 2130514434
Uploading Klipper Firmware to SD Card...Done
Validating Upload...Done
Firmware Upload Complete: firmware.bin, Size: 26020, Checksum (SHA1): 7B08ECCCC5823C01FA284C6AAC7768F45091153F
Attempting MCU Reset...Done
Waiting for device to reconnect...Done
Connecting to MCU...Connected
Verifying Flash...Version matched...Done
Firmware Flash Successful
Current Firmware: v0.11.0-169-g83308a10
Attempting MCU Reset...Done
SD Card Flash Complete

Reference GitHub issue #5465, which has been closed.

What is the best way to reopen this ticket and change the board rate back to 4000000 (4M)?

Hi @Sineos, sorry to ping you. Do you remember this SD_SPI_SPEED issue raised over at Github? #5465

I have been personally experiencing this issue and I have seen a few here in this forum having the same issue with the change of the SPI speed from 4M to 400K. Since the change last year I have no longer been able to flash the Spider via the flash-sdcard.sh. I have to manually change the SD_SPI_SPEED to 4M every time I git pull klipper.

Since your username was on the original issue and you confirmed this was the issue, are you able to assist?

Actually this is quite strange. I had this issue once with my SKR 1.4T board (where I posted in the mentioned GH issue) but I have not been able to reproduce it. Directly flashing it works without a hitch and I flash really often.
Maybe @Arksine has an idea.

Thanks for the prompt reply. Let’s hope @Arksine can shine some light on the change?