Difference between revisions of "SPI/zh"
(→Linux下启用SPI) |
(→H5) |
||
Line 72: | Line 72: | ||
==H5== | ==H5== | ||
+ | ===使用/dev/spidev0.0=== | ||
+ | 在板子上执行下面的命令: | ||
+ | <syntaxhighlight lang="sh"> | ||
+ | $ wget https://github.com/friendlyarm/linux/blob/sunxi-4.14.y/tools/spi/spidev_test.c | ||
+ | $ gcc spidev_test.c -o spidev_test | ||
+ | $ ./spidev_test -D /dev/spidev0.0 -S 1024 -I 1000 | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
===使能SPI1=== | ===使能SPI1=== | ||
H5的SPI1和UART3的引脚是复用的,我们默认提供的配置是使能UART3,禁用SPI1,内核设备树的配置如下:<br> | H5的SPI1和UART3的引脚是复用的,我们默认提供的配置是使能UART3,禁用SPI1,内核设备树的配置如下:<br> | ||
Line 149: | Line 158: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
设置完毕后,dtb里spi flash的status = "okay",需要重启系统才能生效。<br> | 设置完毕后,dtb里spi flash的status = "okay",需要重启系统才能生效。<br> | ||
− | {{Linux-SPIFlash/zh}} | + | {{Linux-SPIFlash/zh}} |
− | + | ||
==H3/H2+== | ==H3/H2+== |
Revision as of 10:12, 23 December 2019
Contents
1 RK3399
RK3399下,SPI由于与UART4共用引脚,所以需要修改内核DTS文件。
1.1 Linux下启用SPI
下载内核源代码,编辑内核目录下的dts文件 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
首先找到 spi1 的定义:
&spi1 { status = "disabled"; // 将其中的 disabled 改为 okay
然后在 rk3399-nanopi4-common.dtsi 文件到找到 uart4 的定义:
&uart4 { status = "okay"; // 将其中的 okay 改为 disabled
最后重新编译内核 (编译器: gcc6.4):
make ARCH=arm64 nanopi4_linux_defconfig export PATH=/opt/FriendlyARM/toolchain/6.4-aarch64/bin/:$PATH make ARCH=arm64 nanopi4-images
编译完成后会生成 kernel.img resource.img 这两个文件,将其拷贝到eflasher系统的SD卡覆盖旧文件即可, 假设SD卡的FRIENDLYARM分区挂载到FRIENDLYARM目录,更新命令如下:
# 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/
也可以用线刷工具来更新。
1.2 Android下启用SPI
Android下修改方法如下:
编辑内核目录下的dts文件 arch/arm64/boot/dts/rockchip/rk3399-nanopi4-common.dtsi:
cd ANDROID_SOURCE/kernel vim arch/arm64/boot/dts/rockchip/rk3399-nanopi4-common.dtsi
其中,ANDROID_SOURCE请替换为真实的 Android7或Android8源代码目录。
首先找到 spi1 的定义:
&spi1 { status = "disabled"; // 将其中的 disabled 改为 okay
然后再在 rk3399-nanopi4-common.dtsi 文件到找到 uart4 的定义:
&uart4 { status = "okay"; // 将其中的 okay 改为 disabled
最后重新编译内核:
cd ANDROID_SOURCE/ ./build-nanopc-t4.sh -K -M
更新 rockdev/Image-nanopc_t4/resource.img 到开发板即可,可以将resource.img拷贝到安装有 eflasher 系统的TF卡中,位置是FriendlyARM分区的androidX 目录,替换里面的resource.img文件,然后用TF卡重刷系统。
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 使用/dev/spidev0.0
在板子上执行下面的命令:
Invalid language.
You need to specify a language like this: <source lang="html4strict">...</source>
Supported languages for syntax highlighting:
4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, aimms, algol68, apache, applescript, arm, asm, asp, asymptote, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, caddcl, cadlisp, cfdg, cfm, chaiscript, chapel, cil, clojure, cmake, cobol, coffeescript, cpp, csharp, css, cuesheet, d, dart, dcl, dcpu16, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, ezt, f1, falcon, fo, fortran, freebasic, freeswitch, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, haxe, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, ispfpanel, j, java, java5, javascript, jcl, jquery, kixtart, klonec, klonecpp, latex, lb, ldif, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, nagios, netrexx, newlisp, nginx, nimrod, nsis, oberon2, objc, objeck, ocaml, octave, oobas, oorexx, oracle11, oracle8, oxygene, oz, parasail, parigp, pascal, pcre, per, perl, perl6, pf, php, pic16, pike, pixelbender, pli, plsql, postgresql, postscript, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, pys60, python, q, qbasic, qml, racket, rails, rbs, rebol, reg, rexx, robots, rpmspec, rsplus, ruby, rust, sas, scala, scheme, scilab, scl, sdlbasic, smalltalk, smarty, spark, sparql, sql, standardml, stonescript, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, upc, urbi, uscript, vala, vb, vbnet, vbscript, vedit, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xpp, yaml, z80, zxbasic
$ wget https://github.com/friendlyarm/linux/blob/sunxi-4.14.y/tools/spi/spidev_test.c $ gcc spidev_test.c -o spidev_test $ ./spidev_test -D /dev/spidev0.0 -S 1024 -I 1000
3.2 使能SPI1
H5的SPI1和UART3的引脚是复用的,我们默认提供的配置是使能UART3,禁用SPI1,内核设备树的配置如下:
linux/arch/arm64/boot/dts/allwinner/sun50i-h5-nanopi.dtsi
&spi1 { // against uart3_rts_cts_pins status = "disable"; spidev1: spi@1 { compatible = "nanopi,spidev"; reg = <0>; spi-max-frequency = <10000000>; }; }; &uart3 { pinctrl-names = "default"; pinctrl-0 = <&uart3_pins>, <&uart3_rts_cts_pins>; status = "okay"; };
如果想使能SPI1,需要修改设备树如下:
&spi1 { // against uart3_rts_cts_pins status = "okay"; spidev1: spi@1 { compatible = "nanopi,spidev"; reg = <0>; spi-max-frequency = <10000000>; }; }; &uart3 { pinctrl-names = "default"; pinctrl-0 = <&uart3_pins>, <&uart3_rts_cts_pins>; status = "disable"; };
另外,使用npi-config/zh也可以实现上述目的。
3.3 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"; }; }; ...
可以在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 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"; }; }; ...
可以在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