I got an ST7798v IPS 320x240 TFT working on a Bluepill, without too much trouble, using a package 'STM32F1xx/GD32F1xx boards by stm32duino, Version 2022.9.26'. It uses a 4 wire SPI interface and works with both hardware and software SPI.
I'm using the 'graphicstest' example from the 'ADAfruit ST7735 and ST7789 Library'
Unfortunately it doesn't work with 2.8.1. It compiles and runs but nothing apears on the display. From the serial monitor output it appears to run at similar speed to the woprking version. The run time is dominated by the SPI speed so that would suggest that the SPI is running at the same rate. I tried changing from s/w to h/w SPI but it didn't help.
Can anyone suggest any obvious things I may have got wrong when moving to 2.8.1? Any simple tests or things to look for?
I could dig out may oscilloscope to look at the SPI signals but that would be quite a bit of effort (the scope is packed away) that I'd rather avoid for now.
I don't have much experience of the Arduino IDE beyond trying out a few examples and none with stm32duino.
TIA for any suggestions.
TFT on Bluepill works on old stm32duino but not on 2.8.1
Re: TFT on Bluepill works on old stm32duino but not on 2.8.1
Probably related to topic:
viewtopic.php?t=1240
For my board (bluepill and ST7735) i fixed by changing
to
viewtopic.php?t=1240
For my board (bluepill and ST7735) i fixed by changing
Code: Select all
#define TFT_DC PA3
#define TFT_CS PA4
#define TFT_RST PA2
Code: Select all
#define TFT_DC D3 // PA3
#define TFT_CS D4 // PA4
#define TFT_RST D2 // PA2
Re: TFT on Bluepill works on old stm32duino but not on 2.8.1
[EDIT] I managed to get it working - see next post.
Many thanks for the suggestion but unfortunately it doesn't work for me. I changed all pins to those that have pin numbers < 128 - specifically B4, B5, C13, C14 and C15.
I first ran a test using the pins using the old stm32duino which worked fine. At the end of the test it left the display showing some graphics. When I rebuilt it using the latest stm32duino (after changing PC13 to PC_13 etc), it built and downloaded Ok and at the start of the run it cleared the display. That suggests that the SPI is working, to some extent at least, and that the problem lies elsewhere. Debugging this could take me a ton of effort, and whilst it would likely be very educational, I think i'll have to abandon this for the time being - unless anyone can suggest some other simple things to try.
Changing all the pin number types in the ADAfruit library from int8_t to uint8_t is probably not worth my time - but maybe it's not actually a big deal since they are probably only used in a few places (constructors etc) and not in the main graphics code.
PS. My STM32F103C8 Bluepill doesn't have pins D2, D3 and D4. Am I missing something?
Many thanks for the suggestion but unfortunately it doesn't work for me. I changed all pins to those that have pin numbers < 128 - specifically B4, B5, C13, C14 and C15.
I first ran a test using the pins using the old stm32duino which worked fine. At the end of the test it left the display showing some graphics. When I rebuilt it using the latest stm32duino (after changing PC13 to PC_13 etc), it built and downloaded Ok and at the start of the run it cleared the display. That suggests that the SPI is working, to some extent at least, and that the problem lies elsewhere. Debugging this could take me a ton of effort, and whilst it would likely be very educational, I think i'll have to abandon this for the time being - unless anyone can suggest some other simple things to try.
Changing all the pin number types in the ADAfruit library from int8_t to uint8_t is probably not worth my time - but maybe it's not actually a big deal since they are probably only used in a few places (constructors etc) and not in the main graphics code.
PS. My STM32F103C8 Bluepill doesn't have pins D2, D3 and D4. Am I missing something?
Last edited by splin on Sun Aug 04, 2024 11:28 pm, edited 1 time in total.
Re: TFT on Bluepill works on old stm32duino but not on 2.8.1
I finally got it working. I realised I had changed B4 and B5 to B_4 and B_5 but had left PC13, PC14 and PC15 unchanged. I 'fixed' that but it still didn't work.
Reverting to the stm32duino I had problems so I then changed again to:
This worked again. So I tried it with V2.8.1 and it works! If I add the underscores, PB_7, PB_8 etc. it stops working. Clearly I need to investigate the difference between PBx and PB_x.
However I found this bizzare behaviour during my experimentation. I added a print function to show the pin values with values passed in as int8_t and uint8_t to find pins with values < 128:
In the initialisation code section I added:
This always crashes within int8_to_uint8( ) when trying to print the value of PC_15. What is going on? It's only a number; it shouldn't be trying to access pin PC_15.
Reverting to the stm32duino I had problems so I then changed again to:
Code: Select all
#define TFT_CS PB7
#define TFT_DC PB8
#define TFT_RST PB9
#define TFT_MOSI PB0 // Data out
#define TFT_SCLK PB5 // Clock out
However I found this bizzare behaviour during my experimentation. I added a print function to show the pin values with values passed in as int8_t and uint8_t to find pins with values < 128:
Code: Select all
void int8_to_uint8(int8_t INT8a, uint8_t UINT8a, int8_t INT8b, uint8_t UINT8b)
{
Serial.println(F("int8_to_uint8"));
Serial.println(INT8a);
Serial.println(UINT8a);
Serial.println(INT8b);
Serial.println(UINT8b);
}
Code: Select all
int8_to_uint8(PC_13, 0, 0, 0);
int8_to_uint8(PC_13, PC_14, 0, 0);
int8_to_uint8(PC_13, PC_14, PC_15, 0); //crashes here
Re: TFT on Bluepill works on old stm32duino but not on 2.8.1
I find adafruit libraries reliable only for Arduino UNO and Adafruit boards. Anything else is "lucky". They wont support pin numbers greater than 127 because Arduino UNO don't have those numbers and they just don't care.
As for pin names (example PC_13) i look it as 3rd port (A,B,C, 0 indexed), bit 13 (D in hex, 0 indexed), therefore 0x2D (45 in decimal).
As for pin numbers, they are just like on arduino UNO, random number that don't need to represent much, other than convenience...
For example, sketch:
will output
if i select "Bluepill F103CB" from the menu and
if i select "Maple Mini F103CB" from the menu.
As i see it, actual numbers don't need to mean anything as long as digitalWrite(PA0,HIGH) is doing same on all boards ( unless it is called as int8_t ).
As for adafruit library, i rushed and stated that it works for bluepill, but, that is true for STM32F411CE, and i'm still struggling for bluepill and ST7735. After checking with logic analyzer It doesn't work with PA2/3/4 , nor D2/3/4... There is a signal activity on MISO and CLK ( PA7, PA5) pins...
I guess you had more luck than me
As for pin names (example PC_13) i look it as 3rd port (A,B,C, 0 indexed), bit 13 (D in hex, 0 indexed), therefore 0x2D (45 in decimal).
As for pin numbers, they are just like on arduino UNO, random number that don't need to represent much, other than convenience...
For example, sketch:
Code: Select all
#define PIN_1 PA0
#define PIN_2 PA0_ALT1
#define PIN_3 A0
#define PIN_4 D20
#define PIN_5 PA_0
#include <itoa.h>
char number[256];
void setup() {
Serial.begin(9600);
while (!Serial) {
yield();
}
delay(2000);
Serial.print("PIN_1-");
Serial.println(itoa(PIN_1, number, 10));
Serial.print("PIN_2-");
Serial.println(itoa(PIN_2, number, 10));
Serial.print("PIN_3-");
Serial.println(itoa(PIN_3, number, 10));
Serial.print("PIN_4-");
Serial.println(itoa(PIN_4, number, 10));
Serial.print("PIN_5-");
Serial.println(itoa(PIN_5, number, 10));
Serial.println("");
}
void loop() {
}
Code: Select all
PIN_1-192
PIN_2-448
PIN_3-192
PIN_4-20
PIN_5-0
Code: Select all
PIN_1-200
PIN_2-456
PIN_3-192
PIN_4-20
PIN_5-0
As i see it, actual numbers don't need to mean anything as long as digitalWrite(PA0,HIGH) is doing same on all boards ( unless it is called as int8_t ).
As for adafruit library, i rushed and stated that it works for bluepill, but, that is true for STM32F411CE, and i'm still struggling for bluepill and ST7735. After checking with logic analyzer It doesn't work with PA2/3/4 , nor D2/3/4... There is a signal activity on MISO and CLK ( PA7, PA5) pins...
I guess you had more luck than me
Re: TFT on Bluepill works on old stm32duino but not on 2.8.1
Thanks for that - very interesting. I need to spend some time to get to grips with the pin numbers including the difference between PBx and PB_x etc.is there any good documentation or is it a case of examining the source code?
[EDIT] I found a post describing the difference between PinNumber and PinName that makes it much clearer.
I spent some time trying different pins till I found a set that worked (not helped by me somehow damaging PB4 at some point). These are the pins I used; I haven't got hardware SPI working yet so it's rather slow. I'd expect they would work for your ST7735 display:
[EDIT] I found a post describing the difference between PinNumber and PinName that makes it much clearer.
I spent some time trying different pins till I found a set that worked (not helped by me somehow damaging PB4 at some point). These are the pins I used; I haven't got hardware SPI working yet so it's rather slow. I'd expect they would work for your ST7735 display:
Code: Select all
#define TFT_CS PB7
#define TFT_DC PB8
#define TFT_RST PB9
#define TFT_MOSI PB0 // Data out
#define TFT_SCLK PB5 // Clock out