aanrudolph2
Posts: 11
Joined: Sat Oct 12, 2019 2:02 am
Location: Chicago, USA

ST7789/FBTFT Issues

Sat Sep 25, 2021 3:47 pm

Hello all --

I've been searching Google up and down and I can't seem to find what I'm looking for. The other day I grabbed a 1.54" 240x240 display from Adafruit (https://www.adafruit.com/product/3787). I figured since there is another model with RasPi headers running the same driver, I could get this one working. So far no luck; when I use the kernel's FBTFT module, nothing happens. Namely, I do not see a new fbX entry in /dev when I load the kernel module up using insmod/modprobe. I have a scope, but so far I have been having a fair amount of difficulty checking if the Pi is even looking for the display when I load up the kernel module.

When I use Adafruit's installer script (see https://github.com/adafruit/Raspberry-P ... cripts.git, adafruit-pitft.py) I get a new fbX device node, but anything I write to the framebuffer comes up "garbled" on-screen. It appears to have been modified slightly from the kernel's "official" staging source. As a test, I made a 240x240 RAW image in Photoshop with an X on it, and attempted to write that to the display, but only the bottom 3/4 showed any change and it hardly looked like any part of the image I had created.

Has anyone gotten this particular ST7789 display to work using the fbtft kernel staging drivers using a 5.x kernel? From what I've seen in the Raspi, Linus Torvalds, and "official" kernel repositories, the drivers are there, and they exist for ST7789v (I'm hoping the "v" isn't a significant variant here) but after rebuilding the kernel and trying the above I'm still at a loss.

Thanks in advance.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4110
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: ST7789/FBTFT Issues

Mon Sep 27, 2021 9:48 am

[ Moved to Interfacing for more eyeballs - this isn't a Compute Module question ]

aBUGSworstnightmare
Posts: 3586
Joined: Tue Jun 30, 2015 1:35 pm

Re: ST7789/FBTFT Issues

Mon Sep 27, 2021 4:25 pm

If memory serves me right fbtft is only supported under legacy driver, but not FKMS/KMS.

Search the forum as I think an overlay has been discussed/added for an ilitek driver. Should give you an idea what's needed for yours.

aanrudolph2
Posts: 11
Joined: Sat Oct 12, 2019 2:02 am
Location: Chicago, USA

Re: ST7789/FBTFT Issues

Mon Sep 27, 2021 10:29 pm

Thanks for that pointer. I think I found something on another thread you linked to (viewtopic.php?f=63&t=306624&p=1834648). I'll see what I can do with it; I found the TinyDRM source and I guess there's no driver for ST7789v just yet. I might play with it myself and see if I can get something to compile based on the other source present.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11788
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: ST7789/FBTFT Issues

Tue Sep 28, 2021 8:58 pm

https://github.com/torvalds/linux/blob/ ... -st7789v.c
https://github.com/torvalds/linux/blob/ ... 7789v.yaml

I'm not clear as to whether that is using SPI for the video data as well as the control - the ST7789 can be configured in many different ways.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

aanrudolph2
Posts: 11
Joined: Sat Oct 12, 2019 2:02 am
Location: Chicago, USA

Re: ST7789/FBTFT Issues

Tue Sep 28, 2021 9:18 pm

In my case, the Instruction/Data pin is exposed on the PCB. I didn't realize it was configurable in this regard. I'm assuming this "configuration" can't be redone in software?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11788
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: ST7789/FBTFT Issues

Wed Sep 29, 2021 6:23 am

I may be wrong. There are a couple of users of that compatible string in the mainline Linux kernel - https://elixir.bootlin.com/linux/latest ... %2Cst7789v
https://elixir.bootlin.com/linux/latest ... o.dts#L151 appears to be an enabled node, although I still don't get the full plumbing there.
The author of the driver contracts for us working on the display stack, so I'll ping him a message when I'm in the office.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

aBUGSworstnightmare
Posts: 3586
Joined: Tue Jun 30, 2015 1:35 pm

Re: ST7789/FBTFT Issues

Wed Sep 29, 2021 7:46 am

https://www.newhavendisplay.com/appnote ... T7789V.pdf

Might be of interrest although one need to know how the TCON is implemented on your display

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11788
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: ST7789/FBTFT Issues

Wed Sep 29, 2021 11:19 am

6by9 wrote:
Wed Sep 29, 2021 6:23 am
The author of the driver contracts for us working on the display stack, so I'll ping him a message when I'm in the office.
Confirmation from Maxime - that driver is taking pixel data as parallel RGB.

He has pointed out https://github.com/birdtechstep/tinydrm ... r/st7789.c, however the exact initialisation sequence does vary between the attached LCD panel, so it may not work straight off the bat.
I do have a couple of ST7789V panels around, so may have a quick look myself should I have an idle half hour.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

aanrudolph2
Posts: 11
Joined: Sat Oct 12, 2019 2:02 am
Location: Chicago, USA

Re: ST7789/FBTFT Issues

Sat Oct 02, 2021 4:38 pm

This (https://www.adafruit.com/product/3787) is the display I'm using. I'm not sure about TCON or any of the internals. There is a datasheet linked to it (https://cdn-shop.adafruit.com/product-f ... 182902.pdf) that has some additional information but I'm not entirely sure what information I need from it, re. ST7789 configuration. It appears to have a parallel pinout, but the module takes SPI, and I couldn't find a schematic of the board underneath.

aanrudolph2
Posts: 11
Joined: Sat Oct 12, 2019 2:02 am
Location: Chicago, USA

Re: ST7789/FBTFT Issues

Sat Oct 02, 2021 4:45 pm

Well I'll be damned. I apologize for wasting everyone's time. It turns out it was https://www.adafruit.com/product/2088 instead; I just looked at the back of the board after posting my last reply. ST7735. My question remains though; is this supported? I seem to have come across more 7735-related things in the driver source than 7789.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11788
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: ST7789/FBTFT Issues

Sat Oct 02, 2021 5:26 pm

aanrudolph2 wrote:
Sat Oct 02, 2021 4:45 pm
Well I'll be damned. I apologize for wasting everyone's time. It turns out it was https://www.adafruit.com/product/2088 instead; I just looked at the back of the board after posting my last reply. ST7735. My question remains though; is this supported? I seem to have come across more 7735-related things in the driver source than 7789.
https://github.com/torvalds/linux/blob/ ... /st7735r.c

You'll need to rebuild your own kernel with that driver enabled, and create a suitable device tree overlay. You can have a look at viewtopic.php?f=63&t=306624 where I got ILI9341 SPI display working as a secondary display. I've just ordered a couple, of ST7735 displays, so I'll have a play when I get a chance.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

aanrudolph2
Posts: 11
Joined: Sat Oct 12, 2019 2:02 am
Location: Chicago, USA

Re: ST7789/FBTFT Issues

Sat Oct 02, 2021 6:18 pm

Got it. So far it looks like I have that driver installed, so no kernel rebuild necessary.

Code: Select all

aaron@gideon:~ $ uname -r
5.10.60-v8+
aaron@gideon:~ $ sudo modprobe st7735r
aaron@gideon:~ $ sudo lsmod | grep st7735
st7735r                16384  0
drm_mipi_dbi           28672  1 st7735r
fb_st7735r             16384  0
fbtft                  45056  1 fb_st7735r
drm_kms_helper        245760  5 vc4,drm_mipi_dbi,st7735r
drm                   557056  7 gpu_sched,drm_kms_helper,v3d,vc4,drm_mipi_dbi,st7735r
backlight              20480  2 st7735r,drm
Where I'm now lost is with the overlay. I've read the docs several times but one thing I'm still missing is how to properly initialize the driver from the overlay. I used the adafruit18.dts as my example. Per that example, in fragment@1 is it loading the driver with the line compatible = "fbtft,adafruit18";?

I believe I checked that post a little while back; I'll look again now that I have this new information. This is all very much appreciated.

**EDIT** I should have put this in earlier -- the Adafruit overlay _does_ work, but my test pattern (just a big X I drew in Photoshop and saved as a raw file) does not render right. It seems a lot of the common displays are rectangular instead of square. Is there a way to specify the display size to the driver up front?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11788
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: ST7789/FBTFT Issues

Sat Oct 02, 2021 7:56 pm

aanrudolph2 wrote:
Sat Oct 02, 2021 6:18 pm
Got it. So far it looks like I have that driver installed, so no kernel rebuild necessary.

Code: Select all

aaron@gideon:~ $ uname -r
5.10.60-v8+
aaron@gideon:~ $ sudo modprobe st7735r
aaron@gideon:~ $ sudo lsmod | grep st7735
st7735r                16384  0
drm_mipi_dbi           28672  1 st7735r
fb_st7735r             16384  0
fbtft                  45056  1 fb_st7735r
drm_kms_helper        245760  5 vc4,drm_mipi_dbi,st7735r
drm                   557056  7 gpu_sched,drm_kms_helper,v3d,vc4,drm_mipi_dbi,st7735r
backlight              20480  2 st7735r,drm
Where I'm now lost is with the overlay. I've read the docs several times but one thing I'm still missing is how to properly initialize the driver from the overlay. I used the adafruit18.dts as my example. Per that example, in fragment@1 is it loading the driver with the line compatible = "fbtft,adafruit18";?

I believe I checked that post a little while back; I'll look again now that I have this new information. This is all very much appreciated.

**EDIT** I should have put this in earlier -- the Adafruit overlay _does_ work, but my test pattern (just a big X I drew in Photoshop and saved as a raw file) does not render right. It seems a lot of the common displays are rectangular instead of square. Is there a way to specify the display size to the driver up front?
Oh, TINYDRM_ST7735R is defined in the defconfigs - interesting.

So the thing to understand is that there are two display frameworks - the old framebuffer one, and the newer DRM/KMS.
You have the module fb_st7735r which the Adafruit overlay uses. That is a legacy framebuffer driver.
The module st7735r is the DRM/KMS driver.
If you wish to extend your desktop across this display as well as HDMI, then you really want to be using DRM/KMS. If you wish to just render to a buffer, then the old framebuffer overlay is probably sufficient.

Looking at the adafruit overlay, the lines

Code: Select all

				height = <160>;
				width = <128>;
are most likely going to allow you to configure the display size.

For the DRM/KMS driver, the compatible string changes from jianda,jd-t18003-t01 (160x128) to okaya,rh128128t (128x128) to set the resolution.
https://github.com/torvalds/linux/blob/ ... r.yaml#L23
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

aanrudolph2
Posts: 11
Joined: Sat Oct 12, 2019 2:02 am
Location: Chicago, USA

Re: ST7789/FBTFT Issues

Sat Oct 02, 2021 11:54 pm

Gah sorry. Now I really feel stupid for asking all of this.

Yes - the framebuffer/DRM thing I understand. I missed the resolution thing in the DTB -- I guess that's what I get for looking at computer screens all day for work. I'm not looking to mirror anything (I'm trying to avoid X entirely) but I do want to give DRM a shot before I fall back to framebuffer ops.

So far this is the overlay I came up with. I generated the DTBO from it using the instructions on the CM4 Getting Started guide and added it into my config.txt. I only see /dev/dri/card0, /dev/dri/card1, and /dev/dri/renderD128 (which I believe was there before I started tinkering) when I reboot. The DRM kernel module is also not loaded at startup. What am I doing wrong with this overlay?

Code: Select all

/*
 * Device Tree overlay for custom Adafruit Display
 *
 */

/dts-v1/;
/plugin/;

/ {
        compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

        fragment@0 {
                target = <&spi0>;
                __overlay__ {
                        status = "okay";

                        spidev@0{
                                status = "disabled";
                        };

                        spidev@1{
                                status = "disabled";
                        };
                };
        };

        fragment@1 {
                target = <&gpio>;
                __overlay__ {
                        tft_pins: tft_pins {
                                brcm,pins = <25>;
                                brcm,function = <1>; /* out */
                                brcm,pull = <0>; /* none */
                        };
                };
        };

        fragment@2 {
                target = <&spi0>;
                __overlay__ {
                        /* needed to avoid dtc warning */
                        #address-cells = <1>;
                        #size-cells = <0>;

                        tft: tft@0{
                                compatible = "okaya,rh128128t";
                                reg = <0>;
                                pinctrl-names = "default";
                                pinctrl-0 = <&pitft_pins>;
                                spi-max-frequency = <32000000>;
                                rotate = <270>;
                                dc-gpios = <&gpio 25 0>;
                                led-gpios = <&gpio 26 1>;
                        };
                };
        };

        __overrides__ {
                speed =   <&pitft>,"spi-max-frequency:0";
                rotate =  <&pitft>,"rotate:0";
        };
};
Thanks again.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11788
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: ST7789/FBTFT Issues

Sun Oct 03, 2021 8:56 am

I'd worked through largely the same route last night as Amazon should be delivering my panels today.
The only bit that appears to be missing from your overlay is backlight control, so you may or may not get the backlight on.

Code: Select all

/*
 * adafruit-st7735r-overlay.dts
 *
 * ST7735R based SPI LCD displays. Either
 * Adafruit 1.8" 160x128  
 *   or
 * Okaya 1.44" 128x128
 */

/dts-v1/;
/plugin/;

/ {
	compatible = "brcm,bcm2835";

	fragment@0 {
		target = <&spi0>;
		__overlay__ {
			status = "okay";
		};
	};

	fragment@1 {
		target = <&spidev0>;
		__overlay__ {
			status = "disabled";
		};
	};

	fragment@2 {
		target = <&spidev1>;
		__overlay__ {
			status = "disabled";
		};
	};

	fragment@3 {
		target = <&gpio>;
		__overlay__ {
			adafruit_pins: adafruit_pins {
				brcm,pins = <25 24>;
				brcm,function = <1>; /* out */
			};
			backlight_pins: backlight_pins {
				brcm,pins = <18>;
				brcm,function = <1>; /* out */
			};
		};
	};

	fragment@4 {
		target = "/";
		__overlay__ {
			backlight: backlight {
				compatible = "gpio-backlight";
				gpios = <&gpio 18 GPIO_ACTIVE_HIGH>;
			};
		};
	};

	fragment@5 {
		target = <&spi0>;
		__overlay__ {
			/* needed to avoid dtc warning */
			#address-cells = <1>;
			#size-cells = <0>;

			af18: adafruit18@0 {
				compatible = "jianda,jd-t18003-t01";
				reg = <0>;
				spi-max-frequency = <32000000>;
				dc-gpios = <&gpio 24 GPIO_ACTIVE_HIGH>;
				reset-gpios = <&gpio 25 GPIO_ACTIVE_HIGH>;
				rotation = <90>;
				pinctrl-names = "default";
				backlight = <&backlight>;
			};
		};
	};

	__overrides__ {
		128x128 = <&af18>, "compatible=okaya,rh128128t";
		speed = <&af18>,"spi-max-frequency:0";
		rotate = <&af18>,"rotate:0";
	};
};
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4110
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: ST7789/FBTFT Issues

Mon Oct 04, 2021 10:30 am

@aanrudolph2 There are also a few minor areas where @6by9's overlay is preferable:

1. Unless your overlay is specifically for a Pi 4 only, the compatible property should be just "brcm,bcm2835".

2. Overwriting DT nodes (not just properties) from an overlay is a bad idea - the kernel's runtime overlay application won't allow it - because it can break the phandle-based references between nodes. The accepted technique is to have a fragment for each node that needs properties changing - compare your fragment 0 with 6by9's fragments 0-2.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11788
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: ST7789/FBTFT Issues

Mon Oct 04, 2021 11:08 am

I did miss the

Code: Select all

#include <dt-bindings/gpio/gpio.h>
from the start of the file though, so it couldn't parse GPIO_ACTIVE_HIGH.

I also got fragment 4 wrong, as it should be "target-path", not "target".

Code: Select all

/*
 * adafruit-st7735r-overlay.dts
 *
 * ST7735R based SPI LCD displays. Either
 * Adafruit 1.8" 160x128  
 *   or
 * Okaya 1.44" 128x128
 */

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>

/ {
	compatible = "brcm,bcm2835";

	fragment@1 {
		target = <&spidev0>;
		__overlay__ {
			status = "disabled";
		};
	};

	fragment@2 {
		target = <&spidev1>;
		__overlay__ {
			status = "disabled";
		};
	};

	fragment@3 {
		target = <&gpio>;
		__overlay__ {
			adafruit_pins: adafruit_pins {
				brcm,pins = <25 24>;
				brcm,function = <1>; /* out */
			};
			backlight_pins: backlight_pins {
				brcm,pins = <18>;
				brcm,function = <1>; /* out */
			};
		};
	};

	fragment@4 {
		target-path = "/";
		__overlay__ {
			backlight: backlight {
				compatible = "gpio-backlight";
				gpios = <&gpio 18 GPIO_ACTIVE_HIGH>;
				default-on;
			};
		};
	};

	fragment@5 {
		target = <&spi0>;
		__overlay__ {
			/* needed to avoid dtc warning */
			#address-cells = <1>;
			#size-cells = <0>;
			status = "okay";

			af18: adafruit18@0 {
				compatible = "jianda,jd-t18003-t01";
				reg = <0>;
				spi-max-frequency = <32000000>;
				dc-gpios = <&gpio 24 GPIO_ACTIVE_HIGH>;
				reset-gpios = <&gpio 25 GPIO_ACTIVE_HIGH>;
				rotation = <90>;
				pinctrl-names = "default";
				backlight = <&backlight>;
			};
		};
	};

	__overrides__ {
		128x128 = <&af18>, "compatible=okaya,rh128128t";
		speed = <&af18>,"spi-max-frequency:0";
		rotate = <&af18>,"rotate:0";
	};
};
Is loading OK, and I get /sys/class/drm/card2.

Code: Select all

xrandr  --setprovideroutputsource 1 0
xrandr --output Unknown19-1 --auto --right-of HDMI-1
then gets it working as an X extended desktop.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11788
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: ST7789/FBTFT Issues

Mon Oct 04, 2021 1:56 pm

Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “Interfacing (DSI, CSI, I2C, etc.)”