Howto use the SPI bus to mount a 2nd SD Card on Luckfox Lyra board

  • In the mainline Linux kernel, there is an mmc_spi driver that enables direct control of SD cards via SPI. However, we currently have no relevant testing or usage experience with it. Note that the SPI controller on the RK3506 does not support multi-line modes, so the data rate may not be ideal.
  • Code: Select all

    # ls /dev
    block            mmcblk1p1    rve        tty30  tty6         vcsa6
    char             mmcblk1p2    shm        tty31  tty60        vcsu
    console          mmcblk1p3    snd        tty32  tty61        vcsu1
    cpu_dma_latency  mmcblk1p4    spidev0.0  tty33  tty62        vcsu2
    disk             mmcblk1p5    stderr     tty34  tty63        vcsu3
    fd               mmcblk1p6    stdin      tty35  tty7         vcsu4
    full             mmcblk1p7    stdout     tty36  tty8         vcsu5
    gpiochip0        mpi          tty        tty37  tty9         vcsu6
    gpiochip1        mpp_service  tty0       tty38  ttyFIQ0      video0
    gpiochip2        null         tty1       tty39  ttyS3        video1
    gpiochip3        ptmx         tty10      tty4   ttyS4        video10
    hwrng            pts          tty11      tty40  ubi_ctrl     video11
    i2c-3            ram0         tty12      tty41  urandom      video12
    iio:device0      ram1         tty13      tty42  usb-ffs      video13
    initctl          ram10        tty14      tty43  v4l          video14
    input            ram11        tty15      tty44  v4l-subdev0  video15
    iomux            ram12        tty16      tty45  v4l-subdev1  video16
    kmsg             ram13        tty17      tty46  v4l-subdev2  video17
    log              ram14        tty18      tty47  vcodec       video18
    loop-control     ram15        tty19      tty48  vcs          video19
    loop0            ram2         tty2       tty49  vcs1         video2
    loop1            ram3         tty20      tty5   vcs2         video20
    loop2            ram4         tty21      tty50  vcs3         video3
    loop3            ram5         tty22      tty51  vcs4         video4
    loop4            ram6         tty23      tty52  vcs5         video5
    loop5            ram7         tty24      tty53  vcs6         video6
    loop6            ram8         tty25      tty54  vcsa         video7
    loop7            ram9         tty26      tty55  vcsa1        video8
    media0           random       tty27      tty56  vcsa2        video9
    media1           rga          tty28      tty57  vcsa3        zero
    mem              rk_dma_heap  tty29      tty58  vcsa4
    mmcblk1          rknpu        tty3       tty59  vcsa5
    #
    
    The /dev/mmcblk1 is my OS SDCard / Slot already installed on the board.
    Neither /dev/mmcblk0 or /dev/mmcblk2 is created by the code below.

    See below vvv
    Last edited by jlsilicon on 2026-04-25 15:21, edited 4 times in total.
  • I tested the code below :

    Code: Select all

    vi  test_sdcardos.py
    
    import os , sys 
    from periphery import SPI
    
    # Open the SPI device :
    spi = SPI("/dev/spidev0.0", 0, 1000000)
    print("spi=" + str(spi))
    
    sd_device_0   = "/dev/mmcblk0p1" # Typical SD node in Linux
    sd_device_2   = "/dev/mmcblk2p1" # 
    mount_point = "/mnt/sdcard"
    
    # Create mount : 
    if not os.path.exists(mount_point):
        os.makedirs(mount_point)
    
    # MOUNT : #
    if ( os.system(f"mount {sd_device_0} {mount_point}") & 255 == 0 ) : 
        print(f"X ERR : Os.mount({sd_device_0} {mount_point})")
    
        if ( os.system(f"mount {sd_device_2} {mount_point}") & 255 == 0 ) : 
            print(f"X ERR : Os.mount({sd_device_2} {mount_point})")
            sys.exit(1) 
    
    # Test WRITE File : #
    with open(f"{mount_point}/hello.txt", "w") as f:
        f.write("Hello from Luckfox Ubuntu!")
    
    print("SD Card Accessed Successfully")
    
    python3  test_sdcardos.py
    
    
    But, it Fails :

    Code: Select all

    python3 "test_sdcardos.py"
    
      spi=SPI (device=/dev/spidev0.0, fd=3, mode=0, max_speed=1000000, bit_order=msb, bits_per_word=8, extra_flags=0x00000000)
    m
      mount: /mnt/sdcard: special device /dev/mmcblk0p1 does not exist.  
      X ERR : Os.mount(/dev/mmcblk0p1 /mnt/sdcard)
        mount: /mnt/sdcard: special device /dev/mmcblk2p1 does not exist.
        X ERR : Os.mount(/dev/mmcblk2p1 /mnt/sdcard)
    
    Why does it not create a MMC device ?

    -

    Code: Select all

    # sudo modprobe mmc_spi
    modprobe: FATAL: Module mmc_spi not found in directory /lib/modules/5.10.160
    # sudo modprobe mmc_spi
    modprobe: FATAL: Module mmc_spi not found in directory /lib/modules/5.10.160
    # sudo modprobe spi_dev
    modprobe: FATAL: Module spi_dev not found in directory /lib/modules/5.10.160
    # sudo depmod -a
    depmod: ERROR: could not open directory /lib/modules/5.10.160: No such file or directory
    depmod: FATAL: could not search modules: No such file or directory
    #
    Modules Not present - now what do I do ???
    Last edited by jlsilicon on 2026-04-25 16:09, edited 3 times in total.
  • Can you please give instructions on how to mount /dev/mmcblk0 for spi0.0 on Lyra board
  • see below
    Last edited by jlsilicon on 2026-04-27 1:44, edited 2 times in total.
  • These chips really don't provide much to work.
    Using LuckFox Pico Mini :

    I tried DTS :

    Code: Select all

    SPI is enabled on :
    SD CS     -> G48 
    SD SCK   -> G49 
    SD MOSI -> G50 
    SD MISO -> G51 
    
    vi spi-bitbang-sd.dts

    Code: Select all

    /dts-v1/;
    /plugin/;
    
    / {
        compatible = "brcm,bcm2835"; // Change for your specific board
    
        fragment@0 {
            target = <&gpio>;
            __overlay__ {
                bitbang_spi_pins: bitbang_spi_pins {
                    brcm,pins = <49 50 51 48>; // SCK, MOSI, MISO, CS
                    brcm,function = <1 1 0 1>; // OUT, OUT, IN, OUT
                };
            };
        };
    
        fragment@1 {
            target = <&soc>;
            __overlay__ {
                /* Define the bitbang SPI bus */
                spi_bitbang: spi-bitbang {
                    compatible = "spi-gpio";
                    #address-cells = <1>;
                    #size-cells = <0>;
                    pinctrl-names = "default";
                    pinctrl-0 = <&bitbang_spi_pins>;
                    
                    sck-gpios = <&gpio 49 0>;
                    mosi-gpios = <&gpio 50 0>;
                    miso-gpios = <&gpio 51 0>;
                    cs-gpios = <&gpio 48 0>;
                    num-chipselects = <1>;
    
                    /* Define the SD Card on the bus */
                    sdcard: mmc@1 {
                        compatible = "mmc-spi-slot";
                        reg = <1>; // CS 1
                        spi-max-frequency = <1000000>; // Keep low for bitbang
                        voltage-ranges = <3300 3300>;
                    };
                };
            };
        };
    };
    

    Code: Select all

      dtc -@ -I dts -O dtb -o spi-bitbang-sd.dtbo spi-bitbang-sd.dts
    
      mkdir  /boot/overlays/
      sudo cp spi-bitbang-sd.dtbo /boot/overlays/ 
    
    vi /boot/config.txt
    dtoverlay=spi-bitbang-sd

    Rebooted ...

    dmesg | less

    Code: Select all

    [   55.147440] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /spi@ff500000/status
    [   55.147488] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /spi@ff500000/pinctrl-0
    [   55.147505] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /spi@ff500000/spidev@0/status
    property: /spi@ff500000/spidev@0/spi-max-frequency
    [   55.149225] rockchip-spi ff500000.spi: no high_speed pinctrl state
    
    [   55.154351] rockchip-spi ff500000.spi: chipselect 0 already in use
    
    [   55.154381] spi_master spi0: spi_device register error /spi@ff500000/fbtft@0
    
    [   55.154400] spi_master spi0: Failed to create SPI device for /spi@ff500000/fbtft@0
    
    [   55.154410] rockchip-spi ff500000.spi: probed, poll=0, rsd=0
    [   56.930116] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /i2c@ff460000/status
    [   56.930166] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /i2c@ff460000/clock-frequency
    [   56.930182] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /i2c@ff460000/pinctrl-0
    [   57.673690] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /serial@ff4e0000/pinctrl-0
    [   57.673736] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /serial@ff4e0000/status
    [   57.675000] ff4e0000.serial: ttyS4 at MMIO 0xff4e0000 (irq = 61, base_baud = 1500000) is a 16550A
    [   58.254364] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /serial@ff4d0000/pinctrl-0
    [   58.254414] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /serial@ff4d0000/status
    [   58.255675] ff4d0000.serial: ttyS3 at MMIO 0xff4d0000 (irq = 62, base_baud = 1500000) is a 16550A
    ls /dev
    - only mmcblk1 mmcblk1p1 mmcblk1p2 mmcblk1p3 mmcblk1p4 mmcblk1p5 mmcblk1p6 mmcblk1p7
    - no mmcblk0 or mmcblk2
    Last edited by jlsilicon on 2026-04-27 1:51, edited 1 time in total.
  • As mentioned in the previous post, we have no experience testing or using the mmc_spi driver, and this is not covered under technical support(https://wiki.luckfox.com/intro). Therefore, we are unable to address any issues you may encounter during its use. Based on the information you've provided, it appears that the CONFIG_MMC_SPI option is not enabled in the kernel, and the SPI node in the device tree also requires modification. Attempting to add an MMC device through user-space operations is not feasible.
    Also, please note that the dtb overlay implementation on the RK3506 differs significantly from that on the Raspberry Pi. The dtb overlay you provided will certainly not work on the Luckfox Lyra. We recommend manually modifying the device tree using the SDK, as compiling it will provide more detailed information for identifying device tree configuration issues. Lastly, we suggest that you first familiarize yourself with the SDK development approach for the Luckfox Lyra by referring to the Wiki. Much of the information you've provided so far follows Raspberry Pi practices, which are not applicable to the Luckfox Lyra.
  • Pretty sad lack of support here for your chips.

    * adafruit-circuitpython-sdcard - does Not work.
    * Spi-fat-fuse - does not work.
    * dts file format for spi - does Not work.

    What does work on these boards ???
  • The solutions you mentioned are all built for the Raspberry Pi ecosystem. Currently, no other ecosystem in the world can match the Raspberry Pi's level of completeness. The development approach of the Luckfox Lyra is fundamentally different from that of the Raspberry Pi, which means it cannot take advantage of the Raspberry Pi software ecosystem. If you're not comfortable with or can't fully embrace this kind of native Linux development style, I would suggest sticking with a Raspberry Pi to accomplish what you need.