ST7781 and STM32

I have trouble finding a library that works with the display's STM32 (St7781) according to the SWTFT library for arduino UNO.
Mcufriends recognizes it as 0xD3D3 and tells me to force it to 9481 (with 480x320 resolution), while the resolution I used with arduino is 320x240.
I found the same library brought to STM32 but it gives me errors in the compilation, of which I attach library and error list.
I'm using the arduino ide.
If someone can help me solve the problem of errors (which I don't understand) or show me some other library.
by reading the registers, again with mcufriends_kbv I get:

Read Registers on MCUFRIEND UNO shield
controllers either read as single 16-bit
e.g. the ID is at readReg(0)
or as a sequence of 8-bit values
in special locations (first is dummy)

reg(0x0000) 80 80	ID: ILI9320, ILI9325, ILI9335, ...
reg(0x0004) 84 84 84 84	Manufacturer ID
reg(0x0009) 89 89 89 89 89	Status Register
reg(0x000A) 8A 8A	Get Power Mode
reg(0x000C) 8C 8C	Get Pixel Format
reg(0x0061) E1 E1	RDID1 HX8347-G
reg(0x0062) E2 E2	RDID2 HX8347-G
reg(0x0063) E3 E3	RDID3 HX8347-G
reg(0x0064) E4 E4	RDID1 HX8347-A
reg(0x0065) E5 E5	RDID2 HX8347-A
reg(0x0066) E6 E6	RDID3 HX8347-A
reg(0x0067) E7 E7	RDID Himax HX8347-A
reg(0x0070) F0 F0	Panel Himax HX8347-A
reg(0x00A1) A1 A1 A1 A1 A1	RD_DDB SSD1963
reg(0x00B0) B0 B0	RGB Interface Signal Control
reg(0x00B4) B4 B4	Inversion Control
reg(0x00B6) B6 B6 B6 B6 B6	Display Control
reg(0x00B7) B7 B7	Entry Mode Set
reg(0x00BF) BF BF BF BF BF BF	ILI9481, HX8357-B
reg(0x00C0) C0 C0 C0 C0 C0 C0 C0 C0 C0	Panel Control
reg(0x00C8) C8 C8 C8 C8 C8 C8 C8 C8 C8 C8 C8 C8 C8	GAMMA
reg(0x00CC) CC CC	Panel Control
reg(0x00D0) D0 D0 D0	Power Control
reg(0x00D2) D2 D2 D2 D2 D2	NVM Read
reg(0x00D3) D3 D3 D3 D3	ILI9341, ILI9488
reg(0x00D4) D4 D4 D4 D4	Novatek ID
reg(0x00DA) DA DA	RDID1
reg(0x00DB) DB DB	RDID2
reg(0x00DC) DC DC	RDID3
reg(0x00E0) E0 E0 E0 E0 E0 E0 E0 E0 E0 E0 E0 E0 E0 E0 E0 E0	GAMMA-P
reg(0x00E1) E1 E1 E1 E1 E1 E1 E1 E1 E1 E1 E1 E1 E1 E1 E1 E1	GAMMA-N
reg(0x00EF) EF EF EF EF EF EF	ILI9327
reg(0x00F2) F2 F2 F2 F2 F2 F2 F2 F2 F2 F2 F2 F2	Adjust Control 2
reg(0x00F6) F6 F6 F6 F6	Interface Control

errori.txt (148 KB)

SWTFTShield.zip (133 KB)

Mcufriends recognizes it as 0xD3D3 and tells me to force it to 9481 (with 480x320 resolution), while the resolution I used with arduino is 320x240.

You have bought a write-only display. (or mis-wired a readable display)

Most Mega2560 shields and Adapters are write-only.

The library can not diagnose anything if it can't read the controller.
Hence 0xD3D3 means that you have to tell it the ID e.g. tft.begin(0x7783); (which is the ID for a ST7781 chip).

Please post a link to the actual display that you have bought. e.g. Ebay Sale.
Or a photo of the pcb side.

You have 35 posts. Surely I do not have to repeat the same "post a link" every time.

David.

I attach the photo.
I use nucleo stm32103rb

You have a regular "Blue 2.8 inch" shield.
It is readable. I have never heard of ST7781 on a Blue shield.

It should work 100% on Uno, Mega, Zero, Due, ..., Nucleo

If you want to use a BluePill you need to use the "recommended" wiring. i.e.

//LCD pins  |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 | |RD |WR |RS |CS |RST| |SD_SS|SD_DI|SD_DO|SD_SCK|
//STM32 pin |PA7|PA6|PA5|PA4|PA3|PA2|PA1|PA0| |PB0|PB6|PB7|PB8|PB9| |PA15 |PB5  |PB4  |PB3   | **ALT-SPI1**

Then it will work 100%.

If you want to use SPECIAL wiring, you need to write a "SPECIAL"

David.

Oops. The Blue shield should work 100% on the Nucleo-F103

Please run example sketches. Let me know any problems. I only have a Red 2.4 Shield with ST7781.

David.

on the "nucleo" board, I simply inserted the TFT module on the pins prepared for arduino.
I saw that there is no correspondence between LCD and STM328 (eg LCD_D0 => arduino PB8).
in which file do I find where the connections between LCD and board are set ?
I can try to make the connection with jumpers or, as you said, use a special wiring.
I don't know where to put it and how to write it, if you could give me an example.
in the tests I did using the mcufriends_kbv library on both arduino and STM32 the screen simply remains white.

Thank you

You plug the Blue shield into the Nucleo.

Every male pin on the shield should mate with corresponding black female socket CN5, CN6, CN8, CN9.

Note that you will have 2 "un-married females" at the top on each side. i.e. n.c., IOREF on the left and SCL, SDA on the right.

  1. Select Nucleo-64 and STMF103RB in the Arduino IDE.
  2. Run all the library examples.

The STM Core from STMicroelectronics is very compatible.
It knows all the Arduino digital pin numbers and Analog pin numbers. You do not need to say PB13 unless you are using the non-Arduino pins on CN7 and CN10

Make sure that you have selected the correct Nucleo-64 board and Serial Port.
Leave all the other options as default.

The TFT library will also work with Roger's Core but ordinary Arduino sketches might need tweaking.

David.

for example:

#include <Adafruit_GFX.h>    // Core graphics library
#include <MCUFRIEND_kbv.h>   // Hardware-specific library
MCUFRIEND_kbv tft;

#include <Fonts/FreeSans9pt7b.h>
#include <Fonts/FreeSans12pt7b.h>
#include <Fonts/FreeSerif12pt7b.h>

#include <FreeDefaultFonts.h>

#define BLACK   0x0000
#define RED     0xF800
#define GREEN   0x07E0
#define WHITE   0xFFFF
#define GREY    0x8410

void setup(void)
{
    Serial.begin(9600);
    uint16_t ID = tft.readID();
    if (ID == 0xD3) ID = 0x9481;
    tft.begin(ID);
    tft.setRotation(0);
}

void loop(void)
{
    tft.fillScreen(BLACK);
    showmsgXY(20, 10, 1, NULL, "System x1");
    showmsgXY(20, 24, 2, NULL, "System x2");
    showmsgXY(20, 60, 1, &FreeSans9pt7b, "FreeSans9pt7b");
    showmsgXY(20, 80, 1, &FreeSans12pt7b, "FreeSans12pt7b");
    showmsgXY(20, 100, 1, &FreeSerif12pt7b, "FreeSerif12pt7b");
    showmsgXY(20, 120, 1, &FreeSmallFont, "FreeSmallFont");
    showmsgXY(5, 180, 1, &FreeSevenSegNumFont, "01234");
    showmsgXY(5, 190, 1, NULL, "System Font is drawn from topline");
    tft.setTextColor(RED, GREY);
    tft.setTextSize(2);
    tft.setCursor(0, 220);
    tft.print("7x5 can overwrite");
    delay(1000);
    tft.setCursor(0, 220);
    tft.print("if background set");
    delay(1000);
    showmsgXY(5, 260, 1, &FreeSans9pt7b, "Free Fonts from baseline");
    showmsgXY(5, 285, 1, &FreeSans9pt7b, "Free Fonts transparent");
    delay(1000);
    showmsgXY(5, 285, 1, &FreeSans9pt7b, "Free Fonts XXX");
    delay(1000);
    showmsgXY(5, 310, 1, &FreeSans9pt7b, "erase backgnd with fillRect()");
    delay(10000);
}

void showmsgXY(int x, int y, int sz, const GFXfont *f, const char *msg)
{
    int16_t x1, y1;
    uint16_t wid, ht;
    tft.drawFastHLine(0, y, tft.width(), WHITE);
    tft.setFont(f);
    tft.setCursor(x, y);
    tft.setTextColor(GREEN);
    tft.setTextSize(sz);
    tft.print(msg);
    delay(1000);
}

in console:

Build options changed, rebuilding all
Sketch uses 34700 bytes (26%) of program storage space. Maximum is 131072 bytes.
Global variables use 1064 bytes (5%) of dynamic memory, leaving 19416 bytes for local variables. Maximum is 20480 bytes.
2019-05-11T17:13:13 INFO common.c: Loading device parameters....
2019-05-11T17:13:13 INFO common.c: Device connected is: F1 Medium-density device, id 0x20036410
2019-05-11T17:13:13 INFO common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x20000 bytes (128 KiB) in pages of 1024 bytes
2019-05-11T17:13:13 INFO common.c: Attempting to write 34996 (0x88b4) bytes to stm32 address: 134217728 (0x8000000)
st-flash 1.5.1

Flash page at addr: 0x08000000 erased
Flash page at addr: 0x08000400 erased
Flash page at addr: 0x08000800 erased
Flash page at addr: 0x08000c00 erased
Flash page at addr: 0x08001000 erased
Flash page at addr: 0x08001400 erased
Flash page at addr: 0x08001800 erased
Flash page at addr: 0x08001c00 erased
Flash page at addr: 0x08002000 erased
Flash page at addr: 0x08002400 erased
Flash page at addr: 0x08002800 erased
Flash page at addr: 0x08002c00 erased
Flash page at addr: 0x08003000 erased
Flash page at addr: 0x08003400 erased
Flash page at addr: 0x08003800 erased
Flash page at addr: 0x08003c00 erased
Flash page at addr: 0x08004000 erased
Flash page at addr: 0x08004400 erased
Flash page at addr: 0x08004800 erased
Flash page at addr: 0x08004c00 erased
Flash page at addr: 0x08005000 erased
Flash page at addr: 0x08005400 erased
Flash page at addr: 0x08005800 erased
Flash page at addr: 0x08005c00 erased
Flash page at addr: 0x08006000 erased
Flash page at addr: 0x08006400 erased
Flash page at addr: 0x08006800 erased
Flash page at addr: 0x08006c00 erased
Flash page at addr: 0x08007000 erased
Flash page at addr: 0x08007400 erased
Flash page at addr: 0x08007800 erased
Flash page at addr: 0x08007c00 erased
Flash page at addr: 0x08008000 erased
Flash page at addr: 0x08008400 erased2019-05-11T17:13:14 INFO common.c: Finished erasing 35 pages of 1024 (0x400) bytes
2019-05-11T17:13:14 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL core id
2019-05-11T17:13:14 INFO flash_loader.c: Successfully loaded flash loader in sram

Flash page at addr: 0x08008800 erased

  1/35 pages written
  2/35 pages written
  3/35 pages written
  4/35 pages written
  5/35 pages written
  6/35 pages written
  7/35 pages written
  8/35 pages written
  9/35 pages written
 10/35 pages written
 11/35 pages written
 12/35 pages written
 13/35 pages written
 14/35 pages written
 15/35 pages written
 16/35 pages written
 17/35 pages written
 18/35 pages written
 19/35 pages written
 20/35 pages written
 21/35 pages written
 22/35 pages written
 23/35 pages written
 24/35 pages written
 25/35 pages written
 26/35 pages written
 27/35 pages written
 28/35 pages written
 29/35 pages written
 30/35 pages written
 31/35 pages written
 32/35 pages written
 33/35 pages written
 34/35 pages written2019-05-11T17:13:17 INFO common.c: Starting verification of write complete

 35/35 pages written2019-05-11T17:13:17 INFO common.c: Flash written and verified! jolly good!

I attach the an screen capture setting

But the screen is white.

I'm sorry, you were right.
now I forced to 0x7783 and it works almost everything,
the lines, rectangles and triangles can be seen in steps.
give me time to take the photos I send you.

photos1

photo 2

#7 implies that you are using the Font_Simple example.

I plugged a Red ST7781 shield into Nucleo.
Selected Board Nucleo-64 with STM32F103RB
and built that example:

...
Using board 'Nucleo_64' from platform in folder: C:\Users\David Prentice\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.5.0
Using core 'arduino' from platform in folder: C:\Users\David Prentice\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.5.0
...
Using library Adafruit_GFX_Library at version 1.4.10 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_GFX_Library 
Using library Mcufriend_kbv at version 2.9.9-Beta in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Mcufriend_kbv 
Using library SPI at version 1.0 in folder: C:\Users\David Prentice\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.5.0\libraries\SPI 
"C:\\Users\\David Prentice\\AppData\\Local\\Arduino15\\packages\\STM32\\tools\\arm-none-eabi-gcc\\6-2017-q2-update/bin/arm-none-eabi-size" -A "C:\\Users\\DAVIDP~1\\AppData\\Local\\Temp\\arduino_build_180119/Font_simple.ino.elf"
Sketch uses 34848 bytes (26%) of program storage space. Maximum is 131072 bytes.
Global variables use 1064 bytes (5%) of dynamic memory, leaving 19416 bytes for local variables. Maximum is 20480 bytes.
...

It uploaded fine (via Mass Storage) but STLink would have been the same.

It obviously detected the correct ID because the sketch ran fine.

That particular example shows nothing on the Serial Terminal.
I have updated the example on the GitHub Beta.

Your photo is not from that example sketch.
I have never seen a

Flash written and verified! jolly good!

report.

Please take notes on paper.
There is obviously something going wrong for you.
I would like to solve your problem.

I repeated the "build" with Roger's core. That worked fine too.
And I even ran the LCD_ID_readreg example:

Re⸮Read Registers on MCUFRIEND UNshield
controllers either read as single 16-bit
e.g. the ID is at readReg(0)
or as a sequence of 8-bit values
in special locations (first is dummy)

reg(0x0000) 77 83 ID: ILI9320, ILI9325, ILI9335, ...
reg(0x0004) 00 00 00 00 Manufacturer ID
reg(0x0009) 00 00 00 00 00 Status Register
reg(0x000A) 00 00 Get Power Mode
reg(0x000C) 00 00 Get Pixel Format
reg(0x0061) 00 00 RDID1 HX8347-G
reg(0x0062) 00 00 RDID2 HX8347-G
reg(0x0063) 00 00 RDID3 HX8347-G
reg(0x0064) 00 00 RDID1 HX8347-A
reg(0x0065) 00 00 RDID2 HX8347-A
reg(0x0066) 00 00 RDID3 HX8347-A
reg(0x0067) 00 00 RDID Himax HX8347-A
reg(0x0070) 00 00 Panel Himax HX8347-A
reg(0x00A1) 00 00 00 00 00 RD_DDB SSD1963
reg(0x00B0) 0E 0C RGB Interface Signal Control
reg(0x00B4) 00 00 Inversion Control
reg(0x00B6) 00 44 00 44 00 Display Control
reg(0x00B7) 36 0D Entry Mode Set
reg(0x00BF) 00 00 00 00 00 00 ILI9481, HX8357-B
reg(0x00C0) 00 00 00 00 00 00 00 00 00 Panel Control
reg(0x00C8) 00 00 00 00 00 00 00 00 00 00 00 00 00 GAMMA
reg(0x00CC) 00 00 Panel Control
reg(0x00D0) 00 00 00 Power Control
reg(0x00D2) 00 01 00 01 00 NVM Read
reg(0x00D3) 00 00 00 00 ILI9341, ILI9488
reg(0x00D4) 00 00 00 00 Novatek ID
reg(0x00DA) 00 00 RDID1
reg(0x00DB) 00 00 RDID2
reg(0x00DC) 00 00 RDID3
reg(0x00E0) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 GAMMA-P
reg(0x00E1) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 GAMMA-N
reg(0x00EF) 00 00 00 00 00 00 ILI9327
reg(0x00F2) B0 00 B0 00 B0 00 B0 00 B0 00 B0 00 Adjust Control 2
reg(0x00F6) 21 11 21 11 Interface Control

You can see the ID in reg(0x0000). The ST7781 does not "read" many registers but it shows ID ok.

David.

p.s. I am using 2.9.9-Beta. Your 2.9.8 Release will be exactly the same. In fact the ST7781 has been supported since about 2012.

the photos are of the sketch "graphictest_kbv", the sketch Font-simple is OK.
i have installed also the udev rulues.
I am trying to install (as you indicated) roger's core, but when I try to upload the sketch readreg gives me the unintentional error (I'm using linux mint 64bit) and I can't understand.

/home/.../Arduino/hardware/Arduino_STM32/tools/linux/stlink_upload: line 2: /home/.../Arduino/hardware/Arduino_STM32/tools/linux/stlink/st-flash: No such file or directory

I never suggested using Roger's core.

I would stick with the regular STM core from STMicroelectronics. Regular sketches all work well with the STM core.

First off, I would plug the shield into a Uno or Mega. Make sure that the display works ok.
Then plug into your Nucleo. Everything should work exactly the same.

If you have a problem, write notes on paper. Number each step.

Then you can post the numbered steps in your message.

Yes, this will take 20 minutes from your life. But it means you get accurate replies.

I use Windows. But the Arduino IDE, Library Manager, Board Manager, ... should all look and feel exactly the same in Linux or Mac.

David.

I thank you for your patience.
For roger's core I understood that it was an alternative, and I wanted to try it.
later I'll try to do what you told me.

I tried lostesso sketch (graphictest_kbv) on arduino uno and the problem is the same.
but I noticed that the step lines (on both boards) are only horizontal, as can be seen from the attached photo.

I solved the problem by forcing the ID a = 0x9325 and both arduino a and "nucleo" works
Thank you again for your patience.

Please run LCD_ID_readreg and copy-paste from the Serial Terminal.
You should get something similar to #11

Even if you force the ID in graphictest_kbv, the Serial Terminal will tell you what ID the library found.
And the Adafruit Tests screen shows the ID too.

What ID does it say to you?

The ST7781 is very different to the ILI9325. It has similar registers but they need different values.

The whole point of my library is to read the controller ID and behave correctly.

There is something very unusual about your "horizontal step lines".
I am intrigued.

David.

sorry, for not having answered you.
I solved the problem by forcing ID of the TFT to 0x9325 ILI9325.
so it works both on an arduino one and on the NUCLEO board.

You wrote that in #16.

I asked what ID was reported by the examples. Most examples report to Serial Terminal at 9600 baud.
Or the graphictest_kbv reports the ID on the "Adafruit Tests" screen.

ST7781 and ILI9325 or ILI9325D are different. I would not expect the display to work with the wrong initialisation (i.e. wrong ID)

David.