[BBB] (5.15.x-bone) SPI not working

Hi,

We have custom kernel for 5.15.95-bone-rt-r34 Beaglebone black, I’m enabling spi1 through our dtsi file and it is detected under /dev/spidev1.0.
But when i try to write any values using Adafruit_BBIO.SPI library it is always writing zeros.

I’m disabling HDMI by uncommenting below two lines in /boot/uEnv.txt

  1. disable_uboot_overlay_video=1
  2. disable_uboot_overlay_audio=1

myspi1_pins_default: myspi1_pins_default {
		pinctrl-single,pins = <
			AM33XX_IOPAD(AM335X_PIN_MCASP0_ACLKX, PIN_INPUT | MUX_MODE3) /* (A13) mcasp0_aclkx.spi1_sclk */
			AM33XX_IOPAD(AM335X_PIN_MCASP0_FSX, PIN_INPUT | MUX_MODE3) /* (B13) mcasp0_fsx.spi1_d0 */
			AM33XX_IOPAD(AM335X_PIN_MCASP0_AXR0, PIN_OUTPUT| MUX_MODE3) /* (D12) mcasp0_axr0.spi1_d1 */
			AM33XX_IOPAD(AM335X_PIN_MCASP0_AHCLKR, PIN_OUTPUT| MUX_MODE3)
		>;
	};


&spi1 {
     status = "okay";
     #address-cells = <1>;
     #size-cells = <0>;

     pinctrl-names = "default";
     pinctrl-0 = <&myspi1_pins_default>;
     spidev@0 {
	     compatible = "linux,spidev";
	     symlink = "bone/spi/1.0";
	     reg = <0>;
	     spi-max-frequency = <24000000>;
	     spi-cpha;
            };
};

Even if i use BB-SPIDEV1-00A0.dtbo overlay, it is not writing the values what i’m writing it is always zero.
Can you please let us know what i’m missing while enabling the SPI in kernel and why it is writing zeros

Thanks,
Anusha

The BB-SPIDEV1-00A0.dtbo works on a normal BBB so …

I would start by checking that the overlay is actually being loaded. Have you got a serial console ?

If using the BB-SPI overlay you can check this by doing

ls /proc/device-tree/chosen/overlays

Or add something like this to your overlay, and check for that.

&{/chosen} {
	overlays {
	MY-SPIDEV1-0.kernel = __TIMESTAMP__;
	};
};

I believe older version of uboot did not support devicetree overlays, but if the above is loading then your uboot should work.

Are you using the standard BBB devicetree or have you modified it in any way ?

Check your kernel config options against a stand BBB to make sure you have all the required serial bits.

If you have a DSO it is probably easier to just check for signals. If you have a clock and CS going, then probably nothing wrong with the kernel build. It would be down to the DTS. IF you have nothing it could be the kernel or devicetree still.

If you run a normal BBB kernel does the spi work then ? If yes then certainly for kernel config, if no it is devicetree.

Make sure you have nothing else trying to configure the same pin. This can be time consuming as you will need to check all DTS files that get pulled in.

Hi, Thanks for your quick reply.

debian@arm:~$ ls /proc/device-tree/chosen/overlays
BB-ADC-00A0.bb.org-overlays            BB-SPIDEV1-00A0.kernel
BB-BONE-eMMC1-01-00A0.bb.org-overlays  name


Or add something like this to your overlay, and check for that.
below lines are added, I’ve attached our overlay file you can look at it

&{/chosen} {
	overlays {
	MY-SPIDEV1-0.kernel = __TIMESTAMP__;
	};
};

Are you using the standard BBB devicetree or have you modified it in any way ?
– Yes, we have done the modification based on our requirements. I’ve attached our .dtsi file for refference

If you have a DSO it is probably easier to just check for signals. If you have a clock and CS going, then probably nothing wrong with the kernel build. It would be down to the DTS. IF you have nothing it could be the kernel or devicetree still.
– I checked clock and CS pins using DSO, it is not giving any signal. Clock is always low.

BB-SPIDEV1-00A0.dts (1.9 KB)
am335x-bone-common.dtsi (20.5 KB)

Thanks,
Anusha

How are you checking the SPI ? If using spidev are you loading the spidev kernel module ?

Hi,
As i mentioned earlier, I’m using SPIDEV1 overlay to enable SPI1.
In that overlay i’m giving compatible as “linux, spidev”

I’m testing SPI using Adafruit_BBIO.SPI library

from Adafruit_BBIO.SPI import SPI
spi = SPI(1, 0)  #/dev/spidev1.0
spi.msh = 48000000
spi.bpw = 8  # bits/word
spi.threewire = False
spi.lsbfirst = False
spi.mode = 1
spi.cshigh = False  # chip select (active low) 
spi.open(1,0)

 

msg = spi.xfer2([32, 11, 110, 22, 220])
print("msg = ", msg)
spi.close()

Thanks,
Anusha

Ok a couple of points

  1. you didn’t say is spidev module is loaded.
  2. The adafruit library is pretty old and I don’t think maintained so may be an issue. There is at least one spidev python library which you can try.
  3. In your device tree I see you have compatible = "linux,spidev"; As I understand it you need to modify the spidev kernel driver if you use this. Most of the time compatible = "rohm,dh2228fv"; is used as this does not require any changes. However this is done in the BB-SPI overlay so probably not the cause.

Can you load up a default BBB 5 kernel image with working SPI and dump the kernel config and compare it against your custom config. This might point to differences in the kernel.

Hi,

Even i tried with spidev library but the output is still zeros.

import spidev
spi = spidev.SpiDev()
spi.open(1,0)
value = spi.xfer2([32, 11, 110, 22, 220])
print(value)
spi.close()

Can you load up a default BBB 5 kernel image with working SPI and dump the kernel config and compare it against your custom config. This might point to differences in the kernel.
– are you saying that we need to check with latest demo image of beaglebone black?
(Latest Software Images - BeagleBoard)
If it is that, We’ll not get access to dtsi files in demo images right.
If it is not that, Can you please help by sharing the steps or any links to dump the kernel config for BBB 5 kernel image with working SPI for our reference.

Thanks,
Anusha

No, if you download a 5.x BBB image and flash it to an sd card (no need to flash to emmc), once booted you can do

zcat /proc/config.gz

This will list all the kernel options used to build the kernel. You can then compare it against what you are building. You need as close to your custom kernel version wise, but anything with a 5 kernel will probably do.

You haven’t said if the spidev kernel module is loaded. This is not loaded automatically.

root@beaglebone:~# lsmod | grep spidev
spidev                 20480  0

Thanks for your reply

I’m a newbie to beaglebone black. so i’m trying to test spi using the overlay given in this 5.15.95-bone-rt-r34 image.

It would really help if you could share the link to flash 5.x BBB image or the steps to flash that image, so that i’ll compare with our dtsi file.

root@beaglebone:~# lsmod | grep spidev

this is giving empty, it don’t have anything.
How to load spidev kernel module.

Thanks,
Anusha

Ok no spidev module is probably the cause of your issues.

I think the need to edit

/etc/modules-load.d/modules.conf

and add spidev to the end of the file. This should cause the module to be loaded when booting.

You can also manually load it by doing

modprobe spidev

Do an lsmod command to check it has loaded.

Hi,

For adding kernel module both the methods what you suggested didn’t work for 5.15.95-bone-rt-r34, Verified it using the below command

 lsmod | grep spidev

I installed 5.x BBB using the below command

sudo apt install linux-image-5.10.109-bone-rt-r63
sudo reboot
uname -r
5.10.109-bone-rt-r63


In this 5.10.109-bone-rt-r63 image , spidev kernel module is already added. So i run the below code to test SPI, but output is still zero.

import spidev
spi = spidev.SpiDev()
spi.open(1,0)
value = spi.xfer2([32, 11, 110, 22, 220])
print(value)
spi.close()

Thanks,
Anusha

When you built the custom module did you also compile and install the kernel modules ?

do

ls /lib/modules

You should see a folder that matches your kernel version uname -r

Did you enable the spidev module when compiling the kernel ?

Yes, I have the folder with my kernel version

debian@arm:~$ ls /lib/modules
5.15.95-bone-rt-r34

Did you enable the spidev module when compiling the kernel ?
— Yes it is enabled.

#
# SPI Protocol Masters
#
CONFIG_SPI_SPIDEV=y
# CONFIG_SPI_LOOPBACK_TEST is not set
# CONFIG_SPI_TLE62X0 is not set
CONFIG_SPI_SLAVE=y
CONFIG_SPI_SLAVE_TIME=m
CONFIG_SPI_SLAVE_SYSTEM_CONTROL=m
# CONFIG_SPMI is not set
# CONFIG_HSI is not set
CONFIG_PPS=y
# CONFIG_PPS_DEBUG is not set

Thanks,
Anusha

In your custom compile, check spidev.c

search the file for “rohm,dh2228fv”

In that structure have you got an entry for compatible = "linux,spidev"; ?

The compatible you have in the spidev node in the device tree must match an entry in that structure or the spidev driver won’t load. At least as of the 5.10 kernel I have source for, that is not the case. This could be why modprobe is failing.

In the spidev.c i’ve both “rohm,dh2228fv” and “linux,spidev”. So it should work if i give any one of them right?

static const struct of_device_id spidev_dt_ids[] = {
	{ .compatible = "rohm,dh2228fv" },
	{ .compatible = "linux,spidev" },
	{ .compatible = "lineartechnology,ltc2488" },
	{ .compatible = "semtech,sx1301" },
	{ .compatible = "lwn,bk4" },
	{ .compatible = "dh,dhcom-board" },
	{ .compatible = "menlo,m53cpld" },
	{ .compatible = "cisco,spi-petra" },
	{ .compatible = "micron,spi-authenta" },
	{},
};

But for 5.10 kernel, Even though it has kernel module still it is writing values as zero.

Yes any in that list is fine to use in the devicetree. Also I see that in your custom kernel the spidev driver is compiled in, so no need for modprobe.

So that pretty much leaves the devicetree as the reason you have no output.

Let me just grab a recent BBB image and try it out on my BBB

Ok, so installing Debian 11 from March this year and just adding BB-SPIDEV1-00A0.dtbo to uEnv.txt, no other changes and installing the python spidev module and it appears to work fine.

So are you adding your custom kernel to an already installed Debian image, or are you building the whole from scratch.

What other DTS files have you modified ?

Are you loading any other overlays ?

What is in your uEnv.txt ?

Please share the output of:

sudo beagle-version

Regards,

So are you adding your custom kernel to an already installed Debian image, or are you building the whole from scratch.
– I follwed this link Debian: Getting Started with the BeagleBone Black - Linux Guides - Electronic Component and Engineering Solution Forum - TechForum │ Digi-Key to install debian 5.15.95-bone-rt-r34 image and flashing to sd card by following the steps given in the same link, added some configuration in the am335x-bone-common.dtsi file.
I’m running rebuild.sh after changing any configuration in am335x-bone-common.dtsi file.

What other DTS files have you modified ?
– No. I’ve only modified am335x-bone-common.dtsi that is also for enabling I2C1, I2C2, UART1, UART2, UART4, LCD.

Are you loading any other overlays ?
– No, I’m not adding any other overlays except SPIDEV1
/boot/uEnv.txt

uname_r=5.15.95-bone-rt-r34
enable_uboot_overlays=1
vt.global_cursor_default=0
uboot_overlay_addr5=/boot/dtbs/5.15.95-bone-rt-r34/overlays/BB-SPIDEV1-00A0.dt>
enable_uboot_cape_universal=1
disable_uboot_overlay_video=1
disable_uboot_overlay_audio=1
cmdline=net.ifnames=0 rng_core.default_quality=100 video=LVDS-1:800x480@51.2,ro>

Thanks,
Anusha

@RobertCNelson , Thanks for your reply.

debian@arm:~$ sudo beagle-version
[sudo] password for debian: 
sudo: beagle-version: command not found

Thanks,
Anusha