Tx2 board, how to set spi transfer fixed speed, not max speed

hi, tx2 board,i want to use spi on J21, i used spidev_test demo, but demo can only set max transfer speed, i found the actual transfer speed (SCK pin on oscilloscope)is changing when continuous transfering, now i want to know, how to set the fixed speed when continuous transferring data.

You can check the spidev_test source to know how to set the speed.
The -s to set the speed.

sudo ./spidev_test -D /dev/spidev2.0 -s8000000 -g512 -b32 
1 Like

hi, option “-s” of spidev_test is for setting max speed , but not for actual transfer speed.
puts(" -D --device device to use (default /dev/spidev1.1)\n"
" -s --speed max speed (Hz)\n"
" -d --delay delay (usec)\n"
" -b --bpw bits per word\n"
" -i --input input data from a file (e.g. "test.bin")\n"
" -o --output output data to a file (e.g. "results.bin")\n"
" -l --loop loopback\n"
" -H --cpha clock phase\n"
" -O --cpol clock polarity\n"
" -L --lsb least significant bit first\n"
" -C --cs-high chip select active high\n"
" -3 --3wire SI/SO signals shared\n"
" -v --verbose Verbose (show tx buffer)\n"
" -p Send data (e.g. "1234\xde\xad")\n"
" -N --no-cs no chip select\n"
" -R --ready slave pulls low to pause\n"
" -2 --dual dual transfer\n"
" -4 --quad quad transfer\n");
exit(1);

Suppose the speed should be able configure by the speed_hz of transfer msg.

https://docs.huihoo.com/doxygen/linux/kernel/3.7/spidev_8h_source.html

hi, i am sure i have already set the member “speed_hz” of “struct spi_ioc_transfer” to a constant value when transfer. the problem is still exist.

What’s the spi-max-frequency in device tree.

how to check the spi-max-frequency in device tree ?

33MHz is equal to the vaule read from ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);

Could you check the log from the tegra_spi_setup() in spi-tegra114.c
I can see it the speed change follow the -s4000000 parameter.

[72018.225899] spidev spi0.0: setup 32 bpw, ~cpol, cpha, 4000000Hz

btw,my board is TX2(jetpack4.4, L4T32.4.3), where is spi-tegra114.c, there is only spidev3.0 and spidev3.1 under /dev.
how to check the log from…you said?

Have below command to enable the debug message. spi-tegra114.c is the kernel spi controller driver

sudo su
echo file spi-tegra114.c +p > /sys/kernel/debug/dynamic_debug/control
echo file spi-tegra124-slave.c +p > /sys/kernel/debug/dynamic_debug/control

does the debug info put into “/sys/kernel/debug/dynamic_debug/control” ,after excute cmd you supply?

The message from the kernel message by dmesg command after run the spi test APP

1、excute my cmd “./spidev_test -D /dev/spidev3.0 -s 4000000 -v -p 50000000000000000000000000000000” ,some times
2、dmesg |grep spi ,some latest lo belows:
[ 4551.783029] spidev spi3.0: setup 8 bpw, ~cpol, ~cpha, 33000000Hz
[ 4551.783190] spidev spi3.0: setup 8 bpw, ~cpol, ~cpha, 33000000Hz
[ 4551.783201] spidev spi3.0: setup 8 bpw, ~cpol, ~cpha, 4000000Hz
[ 4551.783270] spi-tegra114 3240000.spi: The def 0x47d08000 and written 0x43c01827
[ 4552.231169] spidev spi3.0: setup 8 bpw, ~cpol, ~cpha, 33000000Hz
[ 4552.231341] spidev spi3.0: setup 8 bpw, ~cpol, ~cpha, 33000000Hz
[ 4552.231353] spidev spi3.0: setup 8 bpw, ~cpol, ~cpha, 4000000Hz
[ 4552.231422] spi-tegra114 3240000.spi: The def 0x47d08000 and written 0x43c01827
[ 4552.695052] spidev spi3.0: setup 8 bpw, ~cpol, ~cpha, 33000000Hz
[ 4552.695213] spidev spi3.0: setup 8 bpw, ~cpol, ~cpha, 33000000Hz
[ 4552.695225] spidev spi3.0: setup 8 bpw, ~cpol, ~cpha, 4000000Hz
[ 4552.695291] spi-tegra114 3240000.spi: The def 0x47d08000 and written 0x43c01827
[ 4553.175260] spidev spi3.0: setup 8 bpw, ~cpol, ~cpha, 33000000Hz
[ 4553.175415] spidev spi3.0: setup 8 bpw, ~cpol, ~cpha, 33000000Hz
[ 4553.175426] spidev spi3.0: setup 8 bpw, ~cpol, ~cpha, 4000000Hz
[ 4553.175493] spi-tegra114 3240000.spi: The def 0x47d08000 and written 0x43c01827
[ 4553.671086] spidev spi3.0: setup 8 bpw, ~cpol, ~cpha, 33000000Hz
[ 4553.671237] spidev spi3.0: setup 8 bpw, ~cpol, ~cpha, 33000000Hz
[ 4553.671247] spidev spi3.0: setup 8 bpw, ~cpol, ~cpha, 4000000Hz
[ 4553.671313] spi-tegra114 3240000.spi: The def 0x47d08000 and written 0x43c01827
[ 4554.163276] spidev spi3.0: setup 8 bpw, ~cpol, ~cpha, 33000000Hz
[ 4554.163457] spidev spi3.0: setup 8 bpw, ~cpol, ~cpha, 33000000Hz
[ 4554.163469] spidev spi3.0: setup 8 bpw, ~cpol, ~cpha, 4000000Hz
[ 4554.163543] spi-tegra114 3240000.spi: The def 0x47d08000 and written 0x43c01827
[ 4554.679142] spidev spi3.0: setup 8 bpw, ~cpol, ~cpha, 33000000Hz
[ 4554.679283] spidev spi3.0: setup 8 bpw, ~cpol, ~cpha, 33000000Hz
[ 4554.679293] spidev spi3.0: setup 8 bpw, ~cpol, ~cpha, 4000000Hz
[ 4554.679357] spi-tegra114 3240000.spi: The def 0x47d08000 and written 0x43c01827

3.my question:
(1).why there is some log about max freq about 33000000Hz?
(2).yesterday, i did not set -s to specify speed, so i think defaults to max freq 33000000Hz, but actually is about 24MHz on oscilloscope.

33000000Hz could be the initialize speed and set to 4000000Hz after the IOCTL from the test utility.

1 Like

i am sure ,actually the speed (using oscilloscope) of transfer data is not the same as specified .
and it can be repeated on your own board, i have no idea why this happened.

What’s the value -s when you check with scope?

i do not use -s, so it is default 33MHz to transfer, but scope is about 24MHz

Maybe the spidev_test default set 24NHz without -s