/dev/spidev0,0 on the Rock64 - Does anyone know how to enable it?
#3
SPI with user programs (python) for Rock64:
  1. There is only one SPI on rk3328 device with possible 2 chipselects CSN0/CSN1.
  2. Rockchip chose "pin multiplex 2 for SPI" (check pins *_M2 and spi2_* + grf_con_spi_io_sel in TRM) as default. This is wrong choice because only one chipselect (CSN0) is available on pin (GPIO3_B0 (SPI_CSN0_M2)).
  3. Chipselect CSN0 is used in Rock64 to activate embedded SPI-NOR flash (GD25Q128) and therefore unavailable to user (I requested RFE to be optional). Internal BOOTROM can boot only from SPI-NOR/CSN0. SPI is already enabled "okay" in DTS but only with embedded SPI-NOR flash.
  4. Let's enable SPI for user (need set driver "rockchip,spidev") with non-wired CSN1 (dynamically without reboot on ayufan kernel with backported configfs).
    Code:
    # cat >spi1.dts <<EOF
    /dts-v1/;
    /plugin/;

    / {
            compatible = "pine64,rock64";

            fragment@0 {
                    target-path = "/spi@ff190000";
                    __overlay__ {
                            spidev@1 {
                                    compatible="rockchip,spidev";
                                    reg=<1>;
                                    spi-max-frequency=<10000000>;
                            };
                    };
            };
    };
    EOF
    # dtc spi1.dts -o spi1.dtbo
    # mkdir /sys/kernel/config/device-tree/overlays/spi1
    # cat spi1.dtbo > /sys/kernel/config/device-tree/overlays/spi1/dtbo
    # ls /dev/spidev*
    /dev/spidev32766.1
  5. Connect SPI device:
    • pin 19 (GPIO3_A1 (SPI_TXD_M2)) -> device SI
    • pin 21 (GPIO3_A2 (SPI_RXD_M2)) <- device SO (not used in e-paper device)
    • pin 24 (GPIO3_A0 (SPI_CLK_M2)) -> device CLK (There is bug in v2.0 hardware that swapped pins 23/24!)
    • any other pin (for example 26) -> device CS
  6. Let's try SPI with python and AT45DB041D SPI-NOR flash Smile. Because CSN1 is unavailable program must simulate CSN1 before any access of SPI transfer functions.
    Code:
    # apt install python-pip python-setuptools python-dev
    # pip install spidev
    # git clone https://github.com/Leapo/Rock64-R64.GPIO.git
    # ln -s Rock64-R64.GPIO/R64 .
    # ./spi.py
    JEDEC: 1f 24 00 00 00 00

    run with parameters 'sector' or 'erase' or 'compare file' or 'write file'
    # ./spi.py erase
    JEDEC: 1f 24 00 00 00 00

    chip erase ...
    wait  wait  wait  wait  wait  wait  wait  wait  wait  wait  wait  wait  wait  wait  wait  ...  done

    # ./spi.py write file
    : 1f 24 00 00 00 00

    write ...

    00000000 size 100: d0 0d fe ed  ...  wait  wait  wait  wait  wait  wait  
    00000100 size 100: 00 00 00 4c  ...  wait  wait  wait  wait  wait  wait  
    00000200 size 100: 00 00 01 38  ...  wait  wait  wait  wait  wait  wait  
    ...
    # ./spi.py compare file
    JEDEC: 1f 24 00 00 00 00

    compare ...

Demo code is attached. Happy hacking and buy me a Beer.


Attached Files
.zip   spi_demo.zip (Size: 1.03 KB / Downloads: 471)
I left this community in Aug 2019 due to PINE64 refusal to produce/deliver ROCK64-1G version 3 after more than one year of changing statuses to "planning", "evaluating", "releasing", "availability", "estimated availability" and finally "no schedule" Angry. ROCK64 is dead platform without any advantage. Buy Raspberry PI 4 !
Away
  Reply


Messages In This Thread
RE: /dev/spidev0,0 on the Rock64 - Does anyone know how to enable it? - by mcerveny - 08-17-2018, 06:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  irradium (based on crux linux) Rock64 riscv64, aarch64 mara 7 1,005 11-19-2024, 02:54 PM
Last Post: mara
  Upgrading ancient Rock64 timxjr1300 0 56 11-15-2024, 09:50 AM
Last Post: timxjr1300
  arch rock64 does not boot nemnob 1 959 09-20-2024, 11:18 AM
Last Post: AwU2HBg
  DietPi OS for ROCK64 MichaIng 42 43,602 09-01-2024, 06:43 AM
Last Post: RaymondDay
Smile First Lakka image for Rock64! Luke 47 81,030 09-01-2024, 06:05 AM
Last Post: RaymondDay
  Rock64 v2 - did not work song / audio sqw200zu 2 1,863 03-14-2024, 03:09 AM
Last Post: dmitrymyadzelets
  Rock64 won't boot dstallmo 0 636 12-27-2023, 10:34 AM
Last Post: dstallmo
  HDMI doesn't work on rock64 Noung1991 1 1,077 11-21-2023, 08:33 AM
Last Post: as365n4
  Rock64 + Klipper + KlipperScreen Instructions godzilla62 0 1,083 10-22-2023, 01:52 AM
Last Post: godzilla62
  Rock64 Debian 11 (Bullseye) install problem jbize 15 11,233 10-12-2023, 05:14 PM
Last Post: tpaul

Forum Jump:


Users browsing this thread: 1 Guest(s)