/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: 220)
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
  how to use spidev0.1? jclab-joseph 0 22 09-18-2021, 06:09 PM
Last Post: jclab-joseph
  DietPi OS for ROCK64 MichaIng 19 5,029 09-17-2021, 02:38 PM
Last Post: MichaIng
  slarm64 (unofficial slackware) Rock64 RK3328 (aarch64) mara 117 73,032 09-10-2021, 03:01 PM
Last Post: mara
  rock64-debian-mrfixit-190531.img.xz : missing /usr/lib/dri/rockchip_dri.so popi 5 432 08-12-2021, 04:55 AM
Last Post: igorp
  openwrt for the rock64 wilsonYan 15 7,396 06-28-2021, 09:50 PM
Last Post: wilsonYan
  Centos 8 Stream on Rock64 ayoungdukie 1 523 06-07-2021, 11:50 AM
Last Post: zer0sig
  Talos on ROCK64 cjyar 2 583 06-04-2021, 11:50 AM
Last Post: cjyar
  CentOS 7 for Rock64 pineadmin 3 3,571 05-30-2021, 08:20 AM
Last Post: ayoungdukie
  Rock64 CRUX-ARM (aarch64) mara 0 412 05-27-2021, 02:22 PM
Last Post: mara
  RETRO-GAMING: UPDATED RELEASE OF RECALBOX FOR THE ROCK64 Mrfixit2001 32 27,432 05-22-2021, 07:01 AM
Last Post: fartadeadrian

Forum Jump:


Users browsing this thread: 2 Guest(s)