Accessing BeaglePlay GPIOs and CSI

Hi,

I have some questions on the BeaglePlay.

  1. GPIO’s: How do I read/write to the GPIOs? I don’t see the config-pin tool, so I’ve tried doing this using “gpioset” and “gpioget”, but all the microbus pins as well as the user button return “device or resource busy”. I’m not sure if exporting the pin ( sudo echo xx > /sys/class/gpio/export ) will work. Its not clear to me how these pins are mapped to gpio numbers. I’m definitely missing something here and a would appreciate it if someone could point me in the right direction.

  2. Is there a device tree file available for the Sony IMX219 (RPi Camera Module 2) camera? This camera is not detected on the BeaglePlay.

Thanks in Advance
Renier

This might help, but is not a complete solution.
k3-am625-beagleplay-csi2-imx219.dts (1.7 KB)

  • Copy this file to /opt/source/dtb-5.10-ti/src/arm64/overlays
  • cd /opt/source/dtb-5.10-ti/
  • make the following change to Makefile:
debian@BeaglePlay:/opt/source/dtb-5.10-ti/src/arm64$ git diff
diff --git a/src/arm64/overlays/Makefile b/src/arm64/overlays/Makefile
index 1b2f6e4..82cce7b 100644
--- a/src/arm64/overlays/Makefile
+++ b/src/arm64/overlays/Makefile
@@ -29,7 +29,8 @@ dtbo-$(CONFIG_ARCH_K3) += \
        robotics-cape.dtbo \
        k3-am625-beagleplay-bcfserial-no-firmware.dtbo \
        k3-am625-beagleplay-csi2-ov5640.dtbo \
-       k3-am625-beagleplay-lt-lcd185.dtbo
+       k3-am625-beagleplay-lt-lcd185.dtbo \
+       k3-am625-beagleplay-csi2-imx219.dtbo

  • make

this should generate src/arm64/overlays/k3-am625-beagleplay-csi2-imx219.dtbo overlay file that is copied over to /boot/firmware and /boot/firmware/extlinux/extlinux.conf is updated accordingly.

NOTE:

  • I do have arducam imx219 probing
  • I dont seem to be able to use bayer2rgb to be able to do the capture properly
# Set to Bayer 8 bit mode as that is all that bayer2rgb can support.
media-ctl -V '"imx219 4-0010":0[SRGGB8_1X8/640x480]'
# This is'nt working - complains of out of memory, but have'nt debugged.
gst-launch-1.0 v4l2src device=/dev/video0 io-mode=4 ! video/x-bayer,width=640,height=480,format=rggb ! bayer2rgb ! video/x-raw,format=BGRx ! autovideosink

# This just dumps a black screen
gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-bayer,width=640,height=480,format=rggb ! bayer2rgb ! video/x-raw,format=BGRx ! autovideosink

on GPIO access directly for mikrobus - you might want to disable the mikrobus nodes to natively control the gpios… I think the mikrobus might be taking control of the gpios.

gpioinfo is the command you want.

To free up IO, you need to disable nodes in the device tree that currently control those IO.

Here’s a device tree overlay that disables the LEDs:

/dts-v1/;
/plugin/;

/ {

        fragment@0 {
                target-path = "/";

                __overlay__ {
                        leds {
                                status = "disabled";
                        };
                };
        };
};

compile this

dtc -I dts -O dtb leds-disable.dts -o leds-disable.dtbo

and copy it to the boot overlay folder

sudo cp leds-disable.dtbo /boot/firmware/overlays/

add a line to the end of /boot/overlays/extlinux/extlinux.conf to use this overlay on boot:

fdtoverlays /overlays/leds-disable.dtbo

and reboot.

gpioinfo will show these pins are unused

	line   3:       "USR0"       unused  output  active-high
	line   4:       "USR1"       unused  output  active-high
	line   5:       "USR2"       unused  output  active-high
	line   6:       "USR3"       unused  output  active-high

now you can use these pins with gpiod. Also note that these pins are part of gpiochip2. here’s some python that grabs gpiochip2, gpioline 3, and flashes one of the LEDs.

import gpiod
import time

LED_USR0_PIN = 3

gpiochip = gpiod.Chip("gpiochip2", gpiod.Chip.OPEN_BY_NAME)
led_usr0_line = gpiochip.get_line(LED_USR0_PIN) 
led_usr0_line.request(consumer="gpio-example", type=gpiod.LINE_REQ_DIR_OUT)     
led_usr0_line.set_value(1)
time.sleep(0.5)
led_usr0_line.set_value(0)      
time.sleep(0.5)
led_usr0_line.release()
1 Like

Thanks for the feedback @Nishanth_Menon and @toddm.

I’m getting the same results for the CSI camera where it dumps a black screen. I’ve noticed that the driver used is the j721e-csi2rx. Is this correct?

debian@BeaglePlay:~$ v4l2-ctl --all
Driver Info:
	Driver name      : j721e-csi2rx
	Card type        : j721e-csi2rx
	Bus info         : platform:30102000.ticsi2rx
	Driver version   : 5.10.162
	Capabilities     : 0xa5200001
		Video Capture
		Read/Write
		Streaming
		Extended Pix Format
		Device Capabilities
	Device Caps      : 0x25200001
		Video Capture
		Read/Write
		Streaming
		Extended Pix Format
Media Driver Info:
	Driver name      : j721e-csi2rx
	Model            : TI-CSI2RX
	Serial           : 
	Bus info         : platform:30102000.ticsi2rx
	Media version    : 5.10.162
	Hardware revision: 0x00000001 (1)
	Driver version   : 5.10.162
Interface Info:
	ID               : 0x03000015
	Type             : V4L Video
Entity Info:
	ID               : 0x00000013 (19)
	Name             : 30102000.ticsi2rx context 0
	Function         : V4L2 I/O
	Pad 0x01000014   : 0: Sink
	  Link 0x02000017: from remote pad 0x1000003 of entity '30102000.ticsi2rx': Data, Enabled, Immutable
Priority: 2
Video input : 0 (30102000.ticsi2rx context 0: ok)


I’ve noticed that the driver used is the j721e-csi2rx. Is this correct

Yep
Same csi2 Rx driver for all k3 devices.

Hi toddm,

i would like to use the CS from the mikrobus as an unused output active-high could you tell me how to know what overlay it is. I used linux-mikrobus but it didn’t work.
Thanks

@gravel,

I’m not sure how to disable the linux-mikrobus node with an overlay. It doesn’t seem to respect the status = “disabled”

that’s also what I was thinking.
thx for the help

What are the changes I need to make in the Makefile?

The following output is displayed when I execute ‘/opt/source/dtb-5.10-ti/src/arm64$ git diff’
“diff --git a/Makefile b/Makefile
old mode 100644
new mode 100755”

not sure what the question is. are you asking how to apply a diff?

I will assume that is the question and try to explain:

this is what is called a unified diff format:

This means:

  1. edit src/arm64/overlays/Makefile
  2. change the line k3-am625-beagleplay-lt-lcd185.dtbo to add \ at the end (to indicate continued line)
  3. add k3-am625-beagleplay-csi2-imx219.dtbo

Hi @gravel,

I have been trying to use the mikrobus pins as gpio also. After installing gpiod using both apt and pip3, I succeeded in running gpioinfo and noted the lines labeled “MIKROBUS_GPIO01_*” were incidentally already labeled as “unused”. Subsequently, I adapted the python script provided above by @toddm (thanks! :slightly_smiling_face:). After attaching an LED and protective circuitry to the mikrobus pin labeled “pwm”, I essentially wrapped the code requesting a line and setting its direction and value inside a function so as to allow myself to naturally cycle through the mikrobus gpio lines one-by-one to see which line number matched the signal name. Here is the code I used, noting that some of the syntax is modified in accordance with the documentation obtained by using, help(gpiod)

import gpiod
import time
def test_line(line_num):
… LED_USR0_PIN = line_num
… gpiochip = gpiod.chip(“gpiochip3”, gpiod.chip.OPEN_BY_NAME)
… mikro_gpio_line = gpiochip.get_line(LED_USR0_PIN)
… config = gpiod.line_request()
… config.consumer = “gpiod_example”
… config.request_type = gpiod.line_request.DIRECTION_OUTPUT
… mikro_gpio_line.request(config, 1)
… mikro_gpio_line.set_value(1)
… time.sleep(0.5)
… mikro_gpio_line.set_value(0)
… time.sleep(0.5)
… mikro_gpio_line.release()

Since the output of gpioinfo had listed the mikrobus gpios as taking up lines 7-14 and 22-25 from gpiochip3, I simply entered sequential integers beginning with 7 into the above function and by my LED flashing observed that ‘PWM’ corresponded to gpio line 11. With respect to your original question, I’d be surprised if ‘CS’ were not among those lines mentioned above… EDIT: ‘CS’ corresponds to line 13 on gpiochip3.

Something that needs be mentioned also is that I am already loading a device tree overlay in /boot/firmware/extlinux/extlinux.conf, which is one of those pre-compiled and included with debian bullseye and is enabled by the following line:

fdtoverlays /overlays/k3-am625-beagleplay-release-mikrobus-set-gpios-all.dtbo

I’m honestly not sure if this .dtbo is entirely necessary as I had previously applied it while toying with the mikrobus pins. It’s also essential to raise the topic of taking sufficient precautions when using the gpio pins with external circuitry, such as a current-blocking diode to prevent accidental loading onto the io pins - eg. via a loose ground connection - which could possibly seriously damage to on-board components.

Good luck and hope this helps :smiley:
N

UPDATE:

I just investigated this further and indeed confirmed that the device tree overlay I used is responsible for availing the mikrobus gpio lines to the user. As mentioned earlier this overlay is found in /boot/firmware/overlays/k3-am625-beagleplay-release-mikrobus-set-gpios-all.dtbo and it came with the monthly release of debian bullseye (minimal) I got from here.