TFT_eSPI w/ STM32F405 Feather and ILI9341 Display

I'm using Setup29_ILI9341_STM32.h and when uncomment out this line:

// Define STM32 to invoke STM32 optimised driver
//#define STM32 // This seems to break the code

Not only does the screen STOP working but I also lose any serial output. Is there something else I need to do?

Have you loaded the STM32 Cores boards package via the Boards manager menu option?

Yes, I even removed and reinstalled it just to be sure.

It is not only selecting this option, you must indicate in the configuration the CS, DC and RESET pins in which you connected your screen.

In STM32 as a general rule the SPI1 bus has as pinout PA4 (CS), PA5 (SCK), and PA7 (MOSI).

On the feather-F405, the bus printed on the board points to SPI2. Be careful with that detail. Most SPI libraries work with SPI1 by default.

The pinout of that board indicates analog signals for the SPI1 bus

A0-PA4
A1-PA5-SCK-SPI1
A3-PA7-MOSI-SPI1

I have the pins defined correctly because if I comment out that line the screen and serial both work (my code has debug statements written out to the standard serial port). Once I enable that line the screen doesn't get anything written to it and zero output happens on the serial port.

Yes, I did look into the pin naming but it does grab the hardware SPI port if I don't define SCK and MOSI. I am physically connected to PB13 (SCK) and PB14 (MOSI) and without defining those pins specifically in the setup file it works:

// Can use Ardiuno pin references, arbitrary allocation, TFT_eSPI controls chip select
#define TFT_CS   D10 // Chip select control pin to TFT CS
#define TFT_DC   D9 // Data Command control pin to TFT DC (may be labelled RS = Register Select)
#define TFT_RST  D11 // Reset pin to TFT RST (or RESET)
//#define TFT_MISO D24   // Define SPI pins
//#define TFT_MOSI D25
//#define TFT_SCLK D23

TBH, I'm still a bit confused how STM32Duino code assigns and uses pin configuration but obviously somehow SPI2 port is getting mapped to the "standard" SPI port.

The TFT_eSPI library uses SPI1 interface. Looking at the Adafruit board documentation I think this will work. Connect the display to the board as follows:

A1 to TFT SCK
A2 to TFT MISO
A3 to TFT MOSI

Do not define these pins in the setup file, as they are used by default by the library.

You can define the TFT_CS, TFT_DC and TFT_RST to other unused pins.

I just went to try that and for some reason Arduino crashes whenever I try to start it (even after a reboot). When I go to the command prompt (Windows 10) and run the arduino_debug.exe command I get

java.lang.NullPointerException

This was just working this morning so I'm not sure what's up so I'll have to dig into this a bit more tomorrow before I can test your idea.

See reports here and here. Looks like a problem with 1.8.12 of the IDE.

Solution may be here.

OK, thanks for finding those, I posts I found were a bit more drastic that your last one (just deleting the cache folder and package_index.json. After I did that the IDE opened up again.

I'll get to the testing in a little bit after I finish something else.

So with your change ( I only moved SCK and MOSI, I'm not using MISO) I am getting output on the serial console now but nothing is displayed on the LCD.

The only change to the setup file was uncommenting the #define STM32

Run the test and diagnostic example "Read_User_Setup" to check if the pins reported agree with your settings and wired connections.

When I run Read_User_setup I'm back to not getting any output on the serial Port and still no output on the LCD.

I power cycle and went back to my sketch and my sketch does produce serial output but twice I flashed the Read_User_Setup sketch and both times I got nothing on the LCD or serial output

Comment out #define STM32 and run "Read_User_Setup". The sketch does not show anything on the screen, it just reports the settings picked up by the compiler and reports them to the serial monitor window.

Nothing on the serial output even after commenting out the #define STM32.

I remember I had a similar issue when using PlatformIO and I had to chage the serial statements to SerialUSB or something like that even though in Windows Device Manager they just show up as standard serial ports (in my case COM10)

I've never connected MISO and it the screen has worked but maybe that has something to do with these troubles?

I would verify some simple examples such as the Blink and ASCIITable examples to see if your setup is OK.

Bear in mind that the Adafruit board has more complex settings needs that simpler Arduino boards.

Run though the tutorial here and in particular check that under the under the menu USB Support option, select CDC supercedes USART so that Serial points to the USB port not the hardware serial.

Then is all is well run the "Read_User_Setup" again and report the output here. Dont forget to set the correct baud rate in the serial window...

But everything does work when I run my sketch and have commented out #define STM32 and using the pins marked SCK (PB13) and MO (PB15) on the Adafruit board (BTW their pinout page of the board is wrong, it lists both MOSI and MISO connected to PB14 but the schematic shows PB15).

I remember when I was working in PlatformIO I had to change the serial port name before I could get any serial output using your library. I don't remember for sure but I think when using the Adafruit library the serial output worked in PlatformIO.

In the Arduino IDE and my sketch and your library both Serial output and the LCD work.

If I try your debug code nothing works.
If I enable #define STM32 nothing works
If I enable #define STM32 AND move the LCD connection to A1/A3 the serial output works but the LCD still doesn't
In Arduino IDE I have not had to change any serial port defines (I just user Serial.print not Serial3.print)
If I use the Adafruit library both serial port and LCD work without changing anything "under the hood"

So there definitely is something strange going on here. Since everything works with the Adafruit libraries and they also work with your libraries my settings and connections should be correct.

The problems happen when I try to enable #define STM32 or run your Read_User_setup program

GeorgeIoak:
But everything does work when I run my sketch and have commented out #define STM32 and using the pins marked SCK (PB13) and MO (PB15) ...

So my understanding is you can get the TFT_eSPI library to run the display and output to the serial port if you comment out #define STM32.

In that case I do not understand why you cannot run the "Read_User_Setup" program with the #define STM32 commented out.

Further to my last post I have had a look at the Adafruit documentation, as you say there are inconsistencies but the board markings look OK.

When #define STM32 is commented out the standard Arduino SPI code is used. The standard Arduino code uses SPI port 1 and it will recognize that SPI 1 port pins are not used and use bit bashing of the linbes (software SPI) which will be relatively slow. This is why the Adafruit and TFT_eSPI libraries both run and will run for any pin settings.

To get a performance improvement (if you need it) the SPI port 1 pins need to be used (A1, A2, A3 as described earlier), in this case both the Adafruit library and TFT_eSPI (#define STM32 commented out) should both run with the pin change but you should see a performance improvement as now SPI port 1 is being used with SPI transfers being handled in hardware (rather than bit bashing in software).

To get even higher perfoamnce with TFT_eSPI then we would need to get it working with the #define STM32 as then the library can use DMA and optimised SPI drivers. However in the first instance get it working with A1, A2 and A3 SPI pins as above first with #define STM32 commented out because if that does not work then there is no point in trying the optimised drivers.

OK, let me take some notes and run some tests again using both your library and the Adafruit library. I can't explain why the "Read_User_setup" program never works but there must be something different with the serial port definitions since I know without changing any hardware I can get output on the serial port using either library.