Board defs for Fysetc Spider are wrong if using UART

Basic Information:

Printer Model: Voron V2.4
MCU / Printerboard: Fysetc Spider 1.0 + 2.3

Fill out above information and in all cases attach your klippy.log file. Pasting your printer.cfg is not needed

Describe your issue:

Hi ! I have a Fysetc Spider 1.0 and 2.3 and I’m facing the same issue on both. They are wired using UART to the Pi (not USB). And I’m not able to flash them using ./scripts/flash-sdcard.sh .
It returns this error :

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 1237, in main
    spiflash.run()
  File "/home/pi/klipper/scripts/spi_flash/spi_flash.py", line 1177, in run
    self.run_reactor_task(self.run_sdcard_upload)
  File "/home/pi/klipper/scripts/spi_flash/spi_flash.py", line 1160, 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 1132, in run_sdcard_upload
    self.mcu_conn.configure_mcu(printfunc=output_line)
  File "/home/pi/klipper/scripts/spi_flash/spi_flash.py", line 953, in configure_mcu
    "Failed to Initialize SD Card. Is it inserted?")
SPIFlashError: Failed to Initialize SD Card. Is it inserted?

However when I change the klipper/scripts/spi_flash/board_defs.py file and put swspi defs into it like I reported in this issue : Klipper's flash-sdcard.sh script can't find the SD card. · Issue #38 · FYSETC/FYSETC-SPIDER · GitHub It works ! So my guess is that the board defs are wrong, or have I miss something ?

I have had the same issue with my Spider 2.2.

It’s due to the change in SD SPI speed from 4M to 400K.

I made a comment here - Bug: spi_flash.py not working on BTT boards with SD_SPI_SPEED = 400000

Changed SD_SPI_SPEED = 4000000 in the spi_flash.py and was able to flash via the flash-sdcard script.

This worked for me and is quicker than changing the board definitions to software. But still have the issue of making the klipper install dirty and having to fix it every time.

I wonder if there is some reason this has not been fixed, it sounds like it happens to more than just Spider V2.2 boards.

The official SD Card specification states that the SPI clock should be set at 400KHz during initialization. I made the change in 2022 because I discovered that some of my cards failed to initialize at 4MHz. That said, because we feed the commands through Klipper to the SD card, we are technically out of spec anyway, and its possible that the slower speed is causing other SD cards to fail.

I suspect the issue is tied to the SD Card rather than the board/mcu, thus it makes sense to add a “fast spi” option to the flash-sdcard.sh script itself. I already have the patch done and will push it shortly. I haven’t had a chance to test it as I have Katapult on most of my devices, however I will push a draft PR for others to test until I can restore original bootloader on some of my devices.

The draft PR is now up at spi_flash: add support for fast SPI speeds by Arksine · Pull Request #6443 · Klipper3d/klipper · GitHub

1 Like

I have tested the attached branch and detected no regressions, so it has been changed from draft status to ready for review/merge.

I do need users who are experiencing the issue at 400KHz to checkout the PR, run flash-sdcard.sh with the -s option, and confirm that it resolves the issue. Thanks.

I am new to working with Git and I was not sure how to apply the PR. So I did it by hand seeing as there are not many changes. It looks like it works fine to me. After applying the patch I ran the command as normal and it failed. Then I ran it again with the -s option and it worked.

I will include the output below for verification.

Thank you for replying and getting this going.

Nick

nick@saitama:~/klipper $ ./scripts/flash-sdcard.sh /dev/ttyAMA0 fysetc-spider
Flashing /home/nick/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
Requested SPI Clock Frequency: 400000
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/nick/klipper/scripts/spi_flash/spi_flash.py", line 1327, in _configure_mcu_spibus
    self.fatfs.mount(printfunc)
  File "/home/nick/klipper/scripts/spi_flash/spi_flash.py", line 327, in mount
    raise OSError("flash_sdcard: failed to mount SD Card, returned %s"
OSError: flash_sdcard: failed to mount SD Card, returned FR_NOT_READY

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/nick/klipper/scripts/spi_flash/spi_flash.py", line 1655, in main
    spiflash.run()
  File "/home/nick/klipper/scripts/spi_flash/spi_flash.py", line 1590, in run
    self.run_reactor_task(self.run_sdcard_upload)
  File "/home/nick/klipper/scripts/spi_flash/spi_flash.py", line 1573, in run_reactor_task
    k_reactor.run()
  File "/home/nick/klipper/klippy/reactor.py", line 292, in run
    g_next.switch()
  File "/home/nick/klipper/klippy/reactor.py", line 340, in _dispatch_loop
    timeout = self._check_timers(eventtime, busy)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nick/klipper/klippy/reactor.py", line 158, in _check_timers
    t.waketime = waketime = t.callback(eventtime)
                            ^^^^^^^^^^^^^^^^^^^^^
  File "/home/nick/klipper/klippy/reactor.py", line 48, in invoke
    res = self.callback(eventtime)
          ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nick/klipper/scripts/spi_flash/spi_flash.py", line 1545, in run_sdcard_upload
    self.mcu_conn.configure_mcu(printfunc=output_line)
  File "/home/nick/klipper/scripts/spi_flash/spi_flash.py", line 1362, in configure_mcu
    self._configure_mcu_spibus(printfunc=printfunc)
  File "/home/nick/klipper/scripts/spi_flash/spi_flash.py", line 1330, in _configure_mcu_spibus
    raise SPIFlashError(
SPIFlashError: Failed to Initialize SD Card. Is it inserted?
nick@saitama:~/klipper $ ./scripts/flash-sdcard.sh -s /dev/ttyAMA0 fysetc-spider
Flashing /home/nick/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
Requested SPI Clock Frequency: 4000000
Initializing SD Card and Mounting file system...

SD Card Information:
Version: 2.0
SDHC/SDXC: True
Write Protected: False
Sectors: 31116288
manufacturer_id: 3
oem_id: SD
product_name: SU16G
product_revision: 8.128
serial_number: E02E4721
manufacturing_date: 10/2012
capacity: 14.8 GiB
fs_type: FAT32
volume_label: b'SPIDER'
volume_serial: 2057008142
Uploading Klipper Firmware to SD Card...Done
Validating Upload...Done
Firmware Upload Complete: firmware.bin, Size: 32428, Checksum (SHA1): 00FAC96489A9EBBCB8FF4427B74F6F0928C6DB85
Attempting MCU Reset...Done
Waiting for device to reconnect...Done
Connecting to MCU...Connected
Requested SPI Clock Frequency: 4000000
Verifying Flash...Version matched...Done
Firmware Flash Successful
Current Firmware: v0.12.0-58-g25bc649c-dirty-20240101_151304-saitama
Attempting MCU Reset...Done
SD Card Flash Complete
nick@saitama:~/klipper $