Configuring SPI pins in Beaglebone AI

Hello,

No issue @Mahaboob . Just trying to lay some groundwork here.

Seth

P.S. I could only get one to work, i.e. as I do not have the excess SPI device listed in a .dts file.

Hello,

@Mahaboob , did you ever get your idea working for your device?

Seth

Hi,

@Seth, Sorry for the late reply. As discussed above, I tried to compile BONE-SPI1_1.dts from the folder /opt/source/dtb-4.19-ti/src/arm/overlays. I got Error: BONE-SPI1_0.dts:21.23-24 syntax error FATAL ERROR: Unable to parse input tree. I compiled using this command dtc -O dtb -o BONE-SPI1_0.dtbo -b 0 -@ BONE-SPI1_0.dts.
I am adding BONE-SPI1_0.dts file for reference.

root@beaglebone:/opt/source/dtb-4.19-ti/src/arm/overlays# cat BONE-SPI1_0.dts
/*

/dts-v1/;
/plugin/;

/*

  • Helper to show loaded overlays under: /proc/device-tree/chosen/overlays/
    */
    &{/chosen} {
    overlays {
    BONE-SPI1_0 = TIMESTAMP;
    };
    };

/*

  • Update the default pinmux of the pins.
  • See these files for the phandles (&P9_* & &P8_*)
  • BeagleBoard-DeviceTrees/v4.19.x-ti-overlays/src/arm/am335x-bone-common-univ.dtsi
  • BeagleBoard-DeviceTrees/v4.19.x-ti-overlays/src/arm/am572x-bone-common-univ.dtsi
    /
    &ocp {
    P9_28_pinmux { pinctrl-0 = <&P9_28_spi_cs_pin>; }; /
    CS /
    P9_30_pinmux { pinctrl-0 = <&P9_30_spi_pin>; }; /
    MOSI /
    P9_29_pinmux { pinctrl-0 = <&P9_29_spi_pin>; }; /
    MISO /
    P9_31_pinmux { pinctrl-0 = <&P9_31_spi_sclk_pin>; }; /
    CLK */
    };

/*

  • See these files for the phandles (&bone_*) and other bone bus nodes

  • BeagleBoard-DeviceTrees/v4.19.x-ti-overlays/src/arm/bbai-bone-buses.dtsi

  • BeagleBoard-DeviceTrees/v4.19.x-ti-overlays/src/arm/bbb-bone-buses.dtsi
    */
    &bone_spi_1 {
    status = ā€œokayā€;
    #address-cells = <1>;
    #size-cells = <0>;

    channel@0 {
    reg = <0>;
    compatible = ā€œspidevā€;
    symlink = ā€œbone/spi/1.0ā€;
    spi-max-frequency = <16000000>;
    spi-cpha;
    };
    };

Otherside, I searched BONE-SPI1_0.dtbo directly on the folders (/lib/firmware) and (/proc/device-tree/chosen/overlays/). Yet to work on the SPI loop back test and come back to you again with the results.

Hello @Mahaboob ,

I think we are getting close. Did you try to add the .dts file to a copy/fork of the Beagleboard.org DeviceTrees repo?

I think they made a nice makefile for use with making the .dts files into .dtb files for use w/ make.

Seth

P.S. Here is the 4.19.x kernel repo from github.com:

  1. GitHub - beagleboard/BeagleBoard-DeviceTrees: Linux kernel device trees and device tree overlays for BeagleBoard.org open hardware single board computers and add-on boards.

Once in clone or fork of your own, type make after adding in your .dts to the src/arm/ dir.

BeagleBoard-DeviceTrees/am5729-beagleboneai-roboticscape.dts at v4.19.x-ti-overlays Ā· beagleboard/BeagleBoard-DeviceTrees Ā· GitHub is the file in question, right?

So, if you add a section like the mcspi towards the end of the file for your own SPI device, I think the Makefile may handle the build of the file to .dtb format for the computer to read.

Alsoā€¦if you receive some errors, post those errors in this format please.


I am having this error

And etcā€¦

Christmas happened over here. So, I need to pull out the BBAI again to test things. Please give me time. Do you need HDMI? See here: BeagleBoard-DeviceTrees/am5729-beagleboneai.dts at v4.19.x-ti-overlays Ā· beagleboard/BeagleBoard-DeviceTrees Ā· GitHub .

Also,

I found that there are only one available chipselect on the AI supposedly, i.e. see here:


// spi_gpio (bit banged SPI)
&{/} {
	// For CTAG SW 8ch overlay
	bone_spi_gpio_ad193x: bone_spi_gpio_ad193x {
		status = "disabled";
		compatible = "spi-gpio";
		#address-cells = <1>;
		#size-cells = <0>;

		sck-gpios = <gpio_P8_32 GPIO_ACTIVE_HIGH>;
		mosi-gpios = <gpio_P8_33 GPIO_ACTIVE_HIGH>;
		miso-gpios = <gpio_P8_14 GPIO_ACTIVE_HIGH>;
		cs-gpios = <gpio_P8_17 GPIO_ACTIVE_HIGH>;
		num-chipselects = <1>;

		ad193x: ad193x@0{
			compatible = "analog,ad1938";
			reset-gpio = <gpio_P8_34 GPIO_ACTIVE_HIGH>;
			reg = <0>; //corresponds to cs
			spi-max-frequency = <100000>;
		};
	};
};

Do you think changing the ā€œreflectiveā€ files associated w/ the BBAI and Cape for SPI will work. If so and if you think we can do the change, by all means, keep questions and answers available.

Seth

P.S. I will keep up the ideas if you keep replying. I have not found a quick answer yet, i.e. as I am still working on this idea.

@Mahaboob ,

Seth here again. So, it seems we need to account for the spidevN.N device in /dev/. I am reading now on how to propose this change on the AI outside of just .dts files. I really need to read up.

Seth

Hi,

@Seth I have tested the SPI loop back test. The results are below and it seems SPI Bus writes, but it doesnā€™t read.

root@beaglebone:~# ./ProcessingUnit -D /dev/spidev1.1 -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 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ā€¦
root@beaglebone:~# ./ProcessingUnit -H -D /dev/spidev1.1 -v
spi mode: 0x1
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 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ā€¦
root@beaglebone:~# ./ProcessingUnit -s 1000000 -H -D /dev/spidev1.1 -v
spi mode: 0x1
bits per word: 8
max speed: 1000000 Hz (1000 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 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ā€¦

Thanks and Regards,

Mahaboob

@Seth I have cloned into ubuntu machine and try to make all. I have received the following errors.

ubuntu@ubuntu:~/Downloads/BeagleBoard-DeviceTrees$ make all
/bin/sh: 1: dtc: not found
/bin/sh: 1: dtc: not found
/bin/sh: 1: dtc: not found
/bin/sh: 1: dtc: not found
/bin/sh: 1: dtc: not found
/bin/sh: 1: dtc: not found
/bin/sh: 1: dtc: not found
/bin/sh: 1: dtc: not found
/bin/sh: 1: dtc: not found
/bin/sh: 1: dtc: not found
DTC src/arm/am335x-bonegreen-gateway.dtb
/bin/sh: 1: dtc: not found
Makefile:185: recipe for target ā€˜src/arm/am335x-bonegreen-gateway.dtbā€™ failed
make[1]: *** [src/arm/am335x-bonegreen-gateway.dtb] Error 127
Makefile:147: recipe for target ā€˜all_armā€™ failed
make: *** [all_arm] Error 2
ubuntu@ubuntu:~/Downloads/BeagleBoard-DeviceTrees$ make clean
/bin/sh: 1: dtc: not found
/bin/sh: 1: dtc: not found
/bin/sh: 1: dtc: not found
/bin/sh: 1: dtc: not found
/bin/sh: 1: dtc: not found
/bin/sh: 1: dtc: not found
/bin/sh: 1: dtc: not found
/bin/sh: 1: dtc: not found
/bin/sh: 1: dtc: not found
/bin/sh: 1: dtc: not found
CLEAN src/arm & src/arm/overlays

Yes, I need to use HDMI, Thatā€™s why I have chosen the LXQT version of BeagleBone AI Image.

Mahaboob

Hello @Mahaboob ,

Okay. Are you using this HDMI, SPI, and .dts file w/ the RoboticsCape on the AI? I noticed it was associated with your ./version output.

Also, I think HDMI takes up some pins of the SPI device you are trying to use. I listed the link in one of my posts.

Here: BeagleBoard-DeviceTrees/am5729-beagleboneai.dts at v4.19.x-ti-overlays Ā· beagleboard/BeagleBoard-DeviceTrees Ā· GitHub

That line in the repo, Line 309, seems to make me think that the HDMI pin takes first-call over the SPI device you are tying to produce. If this is the case, I think a workaround is needed.

Do I know the workaround? No. Do I think the HDMI pins are associated w/ the SPI device pins needed? Yes.

Seth

P.S. You will need the Device Tree Compiler for the BeagleBoard-DeviceTrees repo and an ARM machine, i.e. BBB or whatever to test.

Install Ubuntuā€™s ā€œdevice-tree-compilerā€ package with aptā€¦

HDMI is always enabled on the BBAI, doesnā€™t matter what image you chooseā€¦

Regards,

1 Like

Hello,

@RobertCNelson Installed the ā€œdevice-tree-compilerā€ in BB-AI, compiled the BeagleBoard-DeviceTrees using make all option and generated the dtb and dtbo. In uEnt.txt file, I have overridden the overlay as follow

###Overide capes with eeprom
uboot_overlay_addr0=BBAI-SPI0_1.dtbo

Thereby in folder /dev/ consists of spidev1.0, spidev1.1, and spidev2.1. I observed the pin description in the dts file as below,

&ocp {
P9_23_pinmux { pinctrl-0 = <&P9_23_spi_cs_pin>; }; /* CS /
P9_18_pinmux { pinctrl-0 = <&P9_18_spi_pin>; }; /
MOSI /
P9_21_pinmux { pinctrl-0 = <&P9_21_spi_pin>; }; /
MISO /
P9_22_pinmux { pinctrl-0 = <&P9_22_spi_sclk_pin>; }; /
CLK */
};

Using config-pin option I tried configuring the P9_23 for spi_cs, But there is no option to configure spi_cs. Hence I referred am5729-beagleboneai-roboticscape.dts and altered as P9_17_pinmux { pinctrl-0 = <&P9_17_spi_cs_pin>; }; /* CS */ , recompile it, and used in the uEnv.txt file. Still, I couldnā€™t access the SPI Hardware. I tried changing the Bus and device as 1.0, 1.1, and 2.1. Donā€™t know whatā€™s going wrong.

In BBB and BBBW, I can access the SPI Hardware using following SPI Values,
#define SPI_BUS 2
#define SPI_DEVICE 0
#define SPI_MODE 1
#define SPI_BITSPERWORD 8
#define SPI_SPEED 1000000
#define SPI_LSBSETTING 0
#define SPI_DELAY 0

Regards

Mahaboob

Hello,

@RobertCNelson and @silver2row I have created a custom device tree by referring to the blog in this link https://community.element14.com/challenges-projects/project14/visionthing/b/blog/posts/beaglebone-ai-survival-guide-v3-18-pwm-i2c-analog-digital-read-write-vision-ai-video-text-overlays-audio-hardware#jive_content_id_INTRODUCTION. The beaglebone ai custom device tree as follows,

#include ā€œam5729-beagleboneai.dtsā€
// make it easy to determine which dtb youā€™re currently running on
// (via /proc/device-tree/chosen/)
/ {
chosen {
base_dtb = ā€œam5729-beagleboneai-custom.dtsā€;
base_dtb_timestamp = TIMESTAMP;
};
};
// eventually these should be available in a header

#define P9_17a (0x3400 + 4 * 243)
#define P9_18a (0x3400 + 4 * 242)
#define P9_21b (0x3400 + 4 * 241)
#define P9_22b (0x3400 + 4 * 240)

// enable mcspi2
&mcspi2 {
status = ā€œokayā€;
clock-frequency = <16000000>;
pinctrl-names = ā€œdefaultā€;
pinctrl-0 = <&mcspi2_pins>;
spi-cpha;
};
&dra7_pmx_core {
mcspi2_pins: spi2 {
pinctrl-single,pins = <
DRA7XX_CORE_IOPAD( P9_17a, PIN_OUTPUT_PULLUP | MUX_MODE0 ) // spi 2 cs0
DRA7XX_CORE_IOPAD( P9_18a, PIN_OUTPUT_PULLUP | MUX_MODE0 ) // spi 2 d0
DRA7XX_CORE_IOPAD( P9_21b, PIN_OUTPUT_PULLUP | MUX_MODE0 ) // spi 2 d1
DRA7XX_CORE_IOPAD( P9_22b, PIN_OUTPUT_PULLUP | MUX_MODE0 ) // spi 2 sclk

;
};
};

I can be able to compile the dts file successfully, But still, spi2 driver didnā€™t show up in the folder /dev/. I have referred to the following links,

Please do the needful.

Thank you,

Mahaboob

@RobertCNelson ,

Helloā€¦since @Mahaboob wants to use the HDMI and SPI2 pins on the BBAI, does this in fact cancel out the SPI2 pins on the BBAI since HDMI is used?

Also, @Mahaboob , P9_Whatever and P8_Whatever (P9_23 for instance) has no relevance on the BBAI from what I know now. I think using this specific pin, P9_22b for instance, does not affect the BBAI like it once did with the BBB or other am335x boards since pinmuxing the BBAI is a bit different.

For example, I could easily say with the BBB from the Adafruit_BBIO library:


from Adafruit_BBIO.SPI import SPI # Taken directly from their library on github
from time import sleep

#spi = SPI(bus, device) #/dev/spidev<bus>.<device>

# /dev/spidev0.0
spi = SPI(1,0)
print(spi.xfer2([32, 11, 110, 22, 220]))
spi.close()

ā€¦

I think using another instance of commands with the source would be better. I know muxing may be the issue now since I am not quite sure how to go about it.

Seth

P.S. There are other SPI libs. out there in userland but I think the HDMI is used on the AI now instead of being able to access the SPI2 device(s). Please correct me, i.e. as I am learning too.

not an issue on teh BBAIā€¦ The HDMI is dedicated pins, NOT on the headerā€¦

Regards,

@Mahaboob ,

Okayā€¦So, @RobertCNelson said that the HDMI pins are not taking up the SPI2 pins. This means there must be a wayā€¦

I will continue to try. I will reply once I can configure something reasonable.

Seth

Hello @Mahaboob ,

This file, "am5729-beagleboneai.dts", does not include the required SPI definitions needed for the am5729-beagleboneai-roboticscape.dts file to associate itself w/ the correct SPI definitions.

ā€¦

I am sure there is a reason that I am not familiar w/ currently.

Seth

Hi @silver2row,

Yes, Hence I included the ā€œam5729-beagleboneai.dtsā€ file in my custom dtb file also with the spi definitions. Please refer my ā€œam5729-beagleboneai-custom.dtsā€.

Thank you,

Mahaboob

1 Like

Okay,

Soā€¦I thought it would be easier than what has been introduced to me so far. Just for statistics here:

  1. Kernel v4.19.x-ti-overlays is the one we are working on under

andā€¦

  1. These are three includes needing to be made outside of what is already produced by you and the Element14 link?
    a. #include <dt-bindings/board/am572x-bone-pins.h>
    b. bbai-bone-buses.dtsi // I think you can call this file whatever and still get the same thing accomplished.
    c. #include <dt-bindings/gpio/gpio.h> // I think this is needed for CSā€¦

andā€¦

  1. Please look at these line and the surrounding parts: BeagleBoard-DeviceTrees/bbai-bone-buses.dtsi at 8cdbf11687263f83cbff969d79a19ce8b52aae37 Ā· silver2row/BeagleBoard-DeviceTrees Ā· GitHub .

andā€¦

  1. For some reason, which I do not like, people use the phrase dummy. Read on:

// For dummy refrence when peripheral is not available. &{/} { not_available: not_available { // Use &not_available phandle when bus not available! // This node is responsible to create these entries, // /sys/firmware/devicetree/base/__symbols__/not_available // /sys/firmware/devicetree/base/not_available }; };

So, maybe we should be trying to create a dummy reference in the nodes and child nodes of the .dtsi, .dts, and then compile them along w/ other files until satisfaction.

I am sorry that I spoke up but I have been needing to find a way to learn more. Me helping you helps me learn what it is that I have been wanting to learn. DT!

Seth

P.S. Oh and @Mahaboob , I am thinking of this as us two working together on this subject and not just me handing out ideas, answers, and knowledge. Even though a 100% correct answer is easier on everyone, it is by far not as fun! Fun!

Hi @silver2row,

Thank you, Yes I am trying with Kernel v4.19.x-ti-overlays, and let me include these files in the next device tree compilation and check.

  1. #include <dt-bindings/board/am572x-bone-pins.h>, 2) #include <dt-bindings/gpio/gpio.h>.

In bbai-bone-buses.dtsi file, SPI section is left empty.

Seth, I am also in the DT learning stage and it is completely new to me. I referred to this link for DT. https://www.devicetree.org/. We will work together and hope we will complete this one.

Mahaboob

1 Like

Hello,

I know for a bit there was some talk b/c of GSoC 2021 about Bone-Buses being a thing where the pin-functionality for the BBB could be ported to the BBAI. Sadly, I have not seen quite the same support for it during my further investigation. Now, I could be wrong.

I will keep it up.

Seth

P.S. Canceling out what, and posting it here, things do not work help as much as making it known what does work.