cancel
Showing results for 
Search instead for 
Did you mean: 

Struggling to port an ILI9341 driver (display) from Arduino code to STM32 HAL, can someone check my code?

ABbb.1
Associate

Hello everyone,

I'm trying to write a driver for the ILI9341 display (8 bit parallel mode, not SPI) using the ST HAL. I couldn't get the libraries I found online working, I imagine for the same reason I can't get mine to work. Obviously I have double checked my wiring.

I took an existing Arduino library, stripped a bunch of code away and verified it worked on an Arduino. Then I changed the Arduino specific calls (pinMode, digitalWrite, digitalRead and delay) and converted them into ST HAL equivalent.

The code I attached is supposed to print the display ID (I have removed the auto-generated comments). On Arduino it prints `0x9341` (which is correct), instead the ST version prints `0x1a1a1a1a`.

I'm using a Nucleo 64 STM32L053R8T6 board and STM32CubeIDE. I have attached a screenshot of the configurations of the pins, but I also configure them at runtime (see the functions ILI9341_PrepareDataPinsForWriting and ILI9341_PrepareDataPinsForReading)

I have also added a screenshot of the IDE and of the back of the display.

I understand I'm asking for a lot, it's just that I've spent a week trying to get this stuff working and it's probably something stupid.

1 ACCEPTED SOLUTION

Accepted Solutions
ABbb.1
Associate

This is a bit embarrassing, but I did find the issue today.

I had defined the pins to use like this:

#define LCD_RD .port = GPIOC, .pin = 1

Instead of using a number for the pin I should have used the macros:

#define LCD_RD .port = GPIOC, .pin = GPIO_PIN_1

When I was testing the wiring I did find this issue and fix it, except I didn't commit it so i accidentally lost it later

View solution in original post

2 REPLIES 2
ABbb.1
Associate

This is a bit embarrassing, but I did find the issue today.

I had defined the pins to use like this:

#define LCD_RD .port = GPIOC, .pin = 1

Instead of using a number for the pin I should have used the macros:

#define LCD_RD .port = GPIOC, .pin = GPIO_PIN_1

When I was testing the wiring I did find this issue and fix it, except I didn't commit it so i accidentally lost it later

Thank you for sharing your code and yhour solution.

I was searching for days for the same thing.

Thanks to your code I was able to find the culprit:

 

 

uint32_t portD_data_msk  = LL_GPIO_PIN_0 | LL_GPIO_PIN_1 | LL_GPIO_PIN_8 | LL_GPIO_PIN_9  | LL_GPIO_PIN_10 | LL_GPIO_PIN_14 | LL_GPIO_PIN_15;
LL_GPIO_SetPinMode(GPIOD, portD_data_msk, LL_GPIO_MODE_OUTPUT);

see:
__STATIC_INLINE uint32_t LL_GPIO_GetPinMode(GPIO_TypeDef *GPIOx, uint32_t Pin)
{
  return (uint32_t)(READ_BIT(GPIOx->MODER,
                             (GPIO_MODER_MODER0 << (POSITION_VAL(Pin) * 2U))) >> (POSITION_VAL(Pin) * 2U));
}

 


Is a bad idea as SetPinMode does not! accept multiple pin masks, see RM0090 p281. MODER has multiple bits per IO.