Difference between revisions of "SPI"
(updated by API) |
(updated by API) |
||
Line 20: | Line 20: | ||
status = "okay"; // change "okay" to "disabled" | status = "okay"; // change "okay" to "disabled" | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | Compile kernel (toolchain: [ | + | Compile kernel (toolchain: [https://github.com/friendlyarm/prebuilts/blob/master/gcc-x64/aarch64-cortexa53-linux-gnu-6.4.tar.xz gcc6.4]): |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
make ARCH=arm64 nanopi4_linux_defconfig | make ARCH=arm64 nanopi4_linux_defconfig |
Revision as of 08:47, 26 February 2019
Contents
1 RK3399
The SPI and UART4 share the same pins. You need to modify the kernel's DTS file to enable the SPI.
1.1 Enable SPI in Linux
Download kernel source and edit the DTS file: arch/arm64/boot/dts/rockchip/rk3399-nanopi4-common.dtsi:
git clone https://github.com/friendlyarm/kernel-rockchip --depth 1 -b nanopi4-linux-v4.4.y kernel-rockchip cd kernel-rockchip vim arch/arm64/boot/dts/rockchip/rk3399-nanopi4-common.dtsi
Locate spi1's definition:
&spi1 { status = "disabled"; // change "disabled" to "okay"
Locate uart4's definition in the rk3399-nanopi4-common.dtsi file:
&uart4 { status = "okay"; // change "okay" to "disabled"
Compile kernel (toolchain: gcc6.4):
make ARCH=arm64 nanopi4_linux_defconfig export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin/:$PATH make ARCH=arm64 nanopi4-images
After compilation is done a kernel.img and a resource.img will be generated. You can simply copy them to replace the existing files in your eflasher SD card. We assume your SD card's FRIENDLYARM partition is mounted at the FRIENDLYARM directory and you can run the following commands to update system:
# for Lubuntu cp kernel.img resource.img /media/FRIENDLYARM/lubuntu/ # for FriendlyCore cp kernel.img resource.img /media/FRIENDLYARM/friendlycore-arm64/ # for FriendlyDesktop cp kernel.img resource.img /media/FRIENDLYARM/friendlydesktop-arm64/
Or you can use a USB Type-C cable and the Linux_Upgrade_Tool utility to update system.
1.2 Enable SPI in Android
Edit the DTS file: arch/arm64/boot/dts/rockchip/rk3399-nanopi4-common.dtsi:
cd ANDROID_SOURCE/kernel vim arch/arm64/boot/dts/rockchip/rk3399-nanopi4-common.dtsi
You need to replace "ANDROID_SOURCE" to your real source. In our system it is either Android7's or Android8's source code directory.
Locate spi1's definition:
&spi1 { status = "disabled"; // change "disabled" to "okay"
Locate uart4's definition in the rk3399-nanopi4-common.dtsi file:
&uart4 { status = "okay"; // change "okay" to "disabled"
Compile kernel:
cd ANDROID_SOURCE/ ./build-nanopc-t4.sh -K -M
Use the newly generated "rockdev/Image-nanopc_t4/resource.img" image file to update your system.
2 S5P4418
2.1 Q: S5P4418的/dev目录下只有一个spidev0.0这个设备节点, 怎么添加spidev1.0
对于3.4内核来说,4418 需要修改 arch/arm/plat-s5p4418/nanopi2/device.c;
想要增加一路的话,可先搜索 CONFIG_SPI_SPIDEV , 然后参考已有代码增加另一路的支持;
另外,arch/arm/plat-s5p4418/asb/device.c 有 spi2 的支持,修改时可参考;
3 H5
3.1 SPI TFT
3.2 SPI Flash
FriendlyElec H5的Linux-4.14内核集成了"mxicy,mx25l12805d"的SPI Flash驱动,使用的是SPI0,但是默认并没有使能,相关的dts配置如下:
$ cat linux/arch/arm64/boot/dts/allwinner/sun50i-h5-nanopi.dtsi &spi0 { ... spiflash: spiflash@0 { #address-cells = <1>; #size-cells = <1>; compatible = "mxicy,mx25l12805d"; reg = <0>; status = "disabled"; // disabled表示禁用该驱动 spi-max-frequency = <50000000>; mode = <0>; partition@0 { reg = <0x0 0x1000000>; label = "spi-flash"; }; }; ...
开发人员可以自行修改和编译dts文件将其使能,也可以通过npi-config快速地将其使能,如下:
$ npi-config 6 Advanced Options| Configure advanced setting A5 SPI| Enable/Disable SPI spi0 Enable/Disable spi0[enabled] spidev0.0| SPI0 char device spi-2.8'tft| Matrix-2'8_SPI_Key_TFT spi-flash| SPI0 flash(X)
设置完毕后,dtb里spi flash的status = "okay",需要重启系统才能生效。
启动Linux系统时,看到类似下面的启动信息则说明SPI Flash被成功检测到了:
m25p80 spi0.0: mx25l12805d (16384 Kbytes) 1 ofpart partitions found on MTD device spi0.0 Creating 1 MTD partitions on "spi0.0": 0x000000000000-0x000001000000 : "spi-flash"
SPI Flash在Linux系统下的使用方法如下:
$ cat /sys/class/mtd/mtd0/size # 以byte为单位 $ cat /sys/class/block/mtdblock0/size # 以sector(512 byte)为单位 $ apt-get install mtd-utils $ flash_eraseall -j /dev/mtd0 # 格式成jffs2的格式 $ mount -t jffs2 /dev/mtdblock0 /mnt $ mkfs.ext4 /dev/mtdblock0 # 也格式化为ext4 $ mount -t ext4 /dev/mtdblock0 /mnt
4 H3/H2+
4.1 SPI TFT
4.2 SPI Flash
FriendlyElec H3/H2+的Linux-4.14内核集成了"mxicy,mx25l12805d"的SPI Flash驱动,使用的是SPI0,但是默认并没有使能,相关的dts配置如下:
$ cat linux/arch/arm/boot/dts/sun8i-h3-nanopi.dtsi &spi0 { ... spiflash: spiflash@0 { #address-cells = <1>; #size-cells = <1>; compatible = "mxicy,mx25l12805d"; reg = <0>; status = "disabled"; // disabled表示禁用该驱动 spi-max-frequency = <50000000>; mode = <0>; partition@0 { reg = <0x0 0x1000000>; label = "spi-flash"; }; }; ...
开发人员可以自行修改和编译dts文件将其使能,也可以通过npi-config快速地将其使能,如下:
$ npi-config 6 Advanced Options| Configure advanced setting A5 SPI| Enable/Disable SPI spi0 Enable/Disable spi0[enabled] spidev0.0| SPI0 char device spi-2.8'tft| Matrix-2'8_SPI_Key_TFT spi-flash| SPI0 flash(X)
设置完毕后,dtb里spi flash的status = "okay",需要重启系统才能生效。
启动Linux系统时,看到类似下面的启动信息则说明SPI Flash被成功检测到了:
m25p80 spi0.0: mx25l12805d (16384 Kbytes) 1 ofpart partitions found on MTD device spi0.0 Creating 1 MTD partitions on "spi0.0": 0x000000000000-0x000001000000 : "spi-flash"
SPI Flash在Linux系统下的使用方法如下:
$ cat /sys/class/mtd/mtd0/size # 以byte为单位 $ cat /sys/class/block/mtdblock0/size # 以sector(512 byte)为单位 $ apt-get install mtd-utils $ flash_eraseall -j /dev/mtd0 # 格式成jffs2的格式 $ mount -t jffs2 /dev/mtdblock0 /mnt $ mkfs.ext4 /dev/mtdblock0 # 也格式化为ext4 $ mount -t ext4 /dev/mtdblock0 /mnt