Just started with TX2, and I’ve problems getting anything out from the SPI on J21. Running R32.1, Jetpack 4.2.
I’ve modified the SPI on 3240000 in the tegra186-quill-p3310-1000-a00-00-base.dtb:
spi@3240000 {
compatible = "nvidia,tegra186-spi";
reg = <0x0 0x3240000 0x0 0x10000>;
interrupts = <0x0 0x27 0x4>;
iommus = <0x11 0x20>;
dmas = <0x25 0x12 0x25 0x12>;
dma-names = "rx", "tx";
nvidia,clk-parents = "pll_p", "clk_m";
clocks = <0x10 0x4a 0x10 0x10d 0x10 0x261>;
clock-names = "spi", "pll_p", "clk_m";
resets = <0x10 0x2b>;
reset-names = "spi";
status = "okay";
linux,phandle = <0x18f>;
phandle = <0x18f>;
spidev@0 {
compatible = "spidev";
reg = <0x0>;
spi-max-frequency = <25000000>;
};
};
This is compiled with device tree compiler and flashed with flash.sh on host computer.
This is my program on the TX2:
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/spi/spidev.h>
struct spi_ioc_transfer xfer;
void spi_write(int nbytes,char value[10],int file)
{
char tx[10];
char rx[10];
tx[0] = value[0];
tx[1] = value[1];
xfer.tx_buf = (unsigned long)tx;
xfer.rx_buf = (unsigned long)rx;
xfer.len = nbytes;
xfer.speed_hz = 12000000;
xfer.bits_per_word = 8;
xfer.delay_usecs = 0;
printf("Bytes=%d\r\n",ioctl(file, SPI_IOC_MESSAGE(1), xfer));
printf("TX: %02x %02x\n", tx[0], tx[1]);
printf("RX: %02x %02x\n", rx[0], rx[1]);
}
void main(void)
{
char buf[10];
int file = open("/dev/spidev3.0",O_RDWR);
buf[0] = 0xf0;
buf[1] = 0x55;
spi_write(2,buf,file);
close(file);
}
I get spidev listed in lsmod and spidev3.0 is in the /dev folder. The result from running as root is:
Bytes=2
TX: f0 55
RX: 00 00
Thankful for any ideas of how to get further, it seems that I’ve missed something.