Vendredi 15 mars 2019

SPI A20-Olinuxino-MICRO

Pour la prise en charge de SPI, 2 fihiers sont à modifier
Modification fichier sun7i-a20.dtsi

		spi0: spi@1c05000 {
			compatible = "allwinner,sun4i-a10-spi";
			reg = <0x01c05000 0x1000>;
			interrupts = <GIC_SPI 10 IRQ_TYPE_LEVEL_HIGH>;
			clocks = <&ccu CLK_AHB_SPI0>, <&ccu CLK_SPI0>;
			clock-names = "ahb", "mod";
			dmas = <&dma SUN4I_DMA_DEDICATED 27>,
			       <&dma SUN4I_DMA_DEDICATED 26>;
			dma-names = "rx", "tx";
			#status = "disabled";
			#address-cells = <1>;
			#size-cells = <0>;
			num-cs = <4>;
		};

		spi1: spi@1c06000 {
			compatible = "allwinner,sun4i-a10-spi";
			reg = <0x01c06000 0x1000>;
			interrupts = <GIC_SPI 11 IRQ_TYPE_LEVEL_HIGH>;
			clocks = <&ccu CLK_AHB_SPI1>, <&ccu CLK_SPI1>;
			clock-names = "ahb", "mod";
			dmas = <&dma SUN4I_DMA_DEDICATED 9>,
			       <&dma SUN4I_DMA_DEDICATED 8>;
			dma-names = "rx", "tx";
			#status = "disabled";
			#address-cells = <1>;
			#size-cells = <0>;
			num-cs = <1>;
		};

		spi2: spi@1c17000 {
			compatible = "allwinner,sun4i-a10-spi";
			reg = <0x01c17000 0x1000>;
			interrupts = <GIC_SPI 12 IRQ_TYPE_LEVEL_HIGH>;
			clocks = <&ccu CLK_AHB_SPI2>, <&ccu CLK_SPI2>;
			clock-names = "ahb", "mod";
			dmas = <&dma SUN4I_DMA_DEDICATED 29>,
			       <&dma SUN4I_DMA_DEDICATED 28>;
			dma-names = "rx", "tx";
			#status = "disabled";
			#address-cells = <1>;
			#size-cells = <0>;
			num-cs = <1>;
		};

Modification fichier ~/media/dplus/A20-OLinuXino-MICRO/u-boot/arch/arm/dts/sun7i-a20-olinuxino-micro.dts

	aliases {
		serial0 = &uart0;
		serial1 = &uart6;
		serial2 = &uart7;
		spi0 = &spi1;
		spi1 = &spi2;
	};

#[...]
&spi1 {
	pinctrl-names = "default";
	pinctrl-0 = <&spi1_pins_a>,
		    <&spi1_cs0_pins_a>;
	status = "okay";
		spidev {
			compatible = "spidev";
			#status = "disabled";
			reg = <0>;
			spi-max-frequency = <1000000>;
		};
};

&spi2 {
	pinctrl-names = "default";
	pinctrl-0 = <&spi2_pins_b>,
		    <&spi2_cs0_pins_b>;
	status = "okay";
		spidev {
			compatible = "spidev";
			#status = "disabled";
			reg = <0>;
			spi-max-frequency = <1000000>;
		};
};

Après modification fichier device-tree , il faut recompiler u-boot

export CC=/home/yannick/media/dplus/A20-OLinuXino-MICRO/gcc-linaro-6.4.1-2018.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
${CC}gcc --version

cd ~/media/dplus/A20-OLinuXino-MICRO/u-boot/
make ARCH=arm CROSS_COMPILE=${CC} distclean
make ARCH=arm CROSS_COMPILE=${CC} A20-OLinuXino_MICRO_defconfig
make ARCH=arm CROSS_COMPILE=${CC}
# SDcard dans lecteur USB/SDcard,connecter sur la machine
# dmesg  # pour déterminer le périphérique utilisé
# Suivant périphérique (ex /dev/sde)
cd ..
export DISK=/dev/sde
sudo mount /dev/sde1 /mnt/tmp # montage SDcard Boot
sudo dd if=./u-boot/u-boot-sunxi-with-spl.bin of=${DISK} seek=8 bs=1024
# Copie du fichier device-tree 
sudo cp /home/yannick/media/dplus/A20-OLinuXino-MICRO/u-boot/arch/arm/dts/sun7i-a20-olinuxino-micro.dtb /mnt/tmp/boot/dtbs/4.17.17-armv7-lpae-x15/
# démontage
sudo umount /mnt/tmp

Après compilation en mise en place de la SDcard boot sur la carte A20-OLinuXino-MICRO
Démarrage , connexion SSH

Les pérophériques SPI

ls /dev/spi*

/dev/spidev0.0  /dev/spidev1.0  /dev/spidev2.0

La connectique SPI sur la carte A20-OLinuXino-MICRO

SPI _ Connecteur CLK (pin) MOSI (pin) MISO (pin) CS0 (pin) CS1 (pin)
spi0@0   GPIO-2 “PI11” (19)     “PI10” (17) “PI14” (30)
spi0@0   UEXT1   “PI12” (3) “PI13” (4)    
spi1@0 spi0 UEXT2 “PI17” (9) “PI18” (8) “PI19” (7) “PI16” (10)  
spi2@0 spi1 UEXT1 “PC20” (9) “PC21” (8) “PC22” (7) “PC19” (10)  
spi2@1 spidev1.0 GPIO-3 “PB15” (28) “PB16” (30) “PB17” (32) “PB14” (26)  

**Tester les périphériques SPI **
Programme de test

git clone https://github.com/rm-hull/spidev-test.git

Compilation

cd spidev-test
gcc spidev-test.c -o spidev-test

Pour vérifier le fonctionnement SPI ,il faut relier MISO et MOSI du périphérique
Test spidev0.0, relier pin 7 et 8 UEXT2
Test spidev1.0, relier pin 7 et 8 UEXT1
Test spidev2.0, relier pin 20 et 32 GPIO-3

cd ~/spidev-test
sudo -s
# relier pin 30 et 32 GPIO-3
./spidev_test -D /dev/spidev1.0 -v
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 KHz)
TX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@....�..................�.
RX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@....�..................�.

Analyse dtb

Se connecter ssh sur la carte

sudo mount /dev/mmcblk0p1 /mnt/  # Monter la partition boot
cp /mnt/boot/dtbs/4.17.17-armv7-lpae-x15/sun7i-a20-olinuxino-micro.dtb . # copie fichier dtb en local
dtc -I dtb -O dts -o sun7i-a20-olinuxino-micro.dts sun7i-a20-olinuxino-micro.dtb #Décompiler le fichier dtb en dts

ATTENTION: Seule spidev1.0 est fonctionnel