Controlling a TFT-LCD Screen with PortInOut.h

Hi everyone

I’m planing to control a TFT-LCD (240x320px) with a Nucleo U575 in parallel interface mode (intel8080).
To do so I think the PortInOut API is the way to go. Unfortunately I don’t really understand the API and it’s documentation. So there are a few questions which maybe one of you can answer :slight_smile:

(API Documentation: PortInOut - API references and tutorials | Mbed OS 6 Documentation)
In the example code the port is defined with “PortIn p(PortA, 0x0000003F);”

  1. What’s the PortA in mbed? Is it the same as the PA-pins on the Nucleo/STM32?
  2. What does the mask(0x0000003F) do? I see that it’s 8 digits for 8pins. What is specified with the number for each pin?
  3. Is it possible to also have a 16pin port or should I better use the BusInOut API in this case?
  4. Did I get it write, that “p.write200)” converts 200 to binary(11001000) and therefore sets pin 0,1,4 high for one cycle?

I hope someone can help me. Thanks in advance!


1 Like


I do not have personal experiences with any control with this but my understanding of documentation is as follows:

Yes, it is.

This is settings how many pins and which pins you will exactly control on this port. So from my understanding 3f is 0011 1111 that means 6 pins will be used.

Usually one port holds settings for 16 pins (0-15). BusInOut will be slowest than Port Out.

For number 200 you need 8 bits, so you have to set the mask to 0x000000FF and after write the pins 4,6,7 will high until you change them.

BR, Jan

Additional hints:

The C++14 standard allows us to use binary literals and digit separator (single quote) so we don’t have to bother with hexadecimal numbers anymore.

For example, to set digits 4, 6, 7 we can write:




Please notice also that:

  • We can use arbitrary number of digits.
  • The digit separator can be placed at any position and it can be used in decimal and hexadecimal literals too (for example `PI = 3.141’592’653’589’793 or MEGA = 1’000’000).
1 Like

Thanks a lot to both of you! this already cleared up many things :slight_smile:
I’ll try to implement the LCD functionality in the next few days. In case of further questions, I’ll come back to you.

This will work, but its slow. A smarter solution is to use FMC (external Memory) interface. This device needs some setup for the configuration, then for the data transfer you just need to write to a RAM address. This can be combined with DMA and you’ll get pretty fast refresh rates.
A GUI library like lvgl works also very good with this.

Hi Jojo
Thanks for the hint. I already checked for the FMC connection. But it semms that mbed doesn’t support that natively, does it?
However if the advantage (refresh rate) is worth it I might be dive deeper into documentations and implement the sources provided by STM…

the FMC is very versatile and not very common for other vendors, so it is hard to create a generic OS driver.
But for a display, where you usually want to have a fast refresh, it makes sense to utilize special hardware devices.
Mbed uses the HAL for STM32, so it is easy to use HAL calls in your driver code. I can supply some example for lvgl drivers. I had recently worked on it, but had to pause again. Will send a link later.

This link might help too.

Hi guys

Thanks for your help.
@hudakz : unfortunately I wasn’t able to reproduce your code for my board (Nucleo U575ZI-Q). Even after hours of hardcoding variables and so on.

@JojoS : could you please share your work? I think I only need the setup of the FMC in Mbed. Once I can send data over the interface I will be able to implement all other stuff myself I think. But I’m currently overwhelmed by all HAL-drivers, the nested functions and files, … I’m just losing track :exploding_head:

Also I think the Firmware Package for the U5xx isn’t complete yet. What I’m missing really badly are the BSP-libraries as these would make the use of the LCD much easier (in STMCube) I think

Hello, the porta in mbed should be MCU programming. Porta generally refers to Port A. generally, 8 pins are represented in the single chip microcomputer. Their 0 1 state is controlled and saved by the variable porta (temporarily, because it is generally a macro). Therefore, porta & = 0x04 means porta = porta & 0x04, which is to set all except the third pin to 0 low level, and the third pin remains unchanged.
By the way, one more thing, TFT display is really a very easy to use display!

Thanks for the explanation.
I had a look on the link to the TFT displays you provided - I already ordered myself some screens and none of the stone-displays is fitting my needs (2.8" max and sunlight readable/transflective + minimal additional components/pcbs needed as it’s for a mobile application)

Thank you anyways

Unfortunately I don’t get the code running.
As this isn’t a problem of Controlling a TFT with mbed but more a migration problem from CubeMX to Mbed (afaik) I just opened another threat on that.

I’d highly appreciate if you could check it out and maybe give me a hint on how to fix it

New topic