Skip to main content
Davorin
Associate III
June 1, 2020
Solved

8-bit parallel access to GPIO

  • June 1, 2020
  • 4 replies
  • 3503 views

Good evening (o;

Google and this forum didn't return much information regarding accessing a GPIO port directly in 8-bit mode for read/write...for example to control a 8-bit TFT module...

The HAL library also has no function for it....

I assume it is possible..but only when digging more into low-level direct register access?

thanks in advance

richard

Best answer by waclawek.jan

Which STM32?

You don't need anything special for read: you simply read the whole 16 bits of the port and then mask out whichever part you want.

GPIO registers are byte-writable, so you can write the lower or upper half of GPIOx_ODR; you'd need to cast appropriately, e.g.

*(__IO uint8_t *)&GPIOC->ODR = somedata;

*(((__IO uint8_t *)&GPIOC->ODR ) + 1) = somedata;

> The HAL library also has no function for it....

Cube/HAL, as any "library", inevitably implements only a fraction of possible functionality, the "most usuall" functions. As soon as you want something less usual, it more gets into way than helps.

JW

4 replies

Tesla DeLorean
Guru
June 1, 2020

Which STM32? There are literally hundreds of them at this point with different implementation details.

Some of the parts allow GPIOD->ODR to be accessed byte wide. You'd need to group bits as 0 thru 7, and 8 thru 15

You can create patterns you can write a subset of bits via GPIOD->BSRR in a single action.

RMW on GPIOD->ODR is also possible.

>>The HAL library also has no function for it....

Why add layers of chaff to perform intrinsic functionality optimally.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
waclawek.jan
waclawek.janBest answer
Super User
June 1, 2020

Which STM32?

You don't need anything special for read: you simply read the whole 16 bits of the port and then mask out whichever part you want.

GPIO registers are byte-writable, so you can write the lower or upper half of GPIOx_ODR; you'd need to cast appropriately, e.g.

*(__IO uint8_t *)&GPIOC->ODR = somedata;

*(((__IO uint8_t *)&GPIOC->ODR ) + 1) = somedata;

> The HAL library also has no function for it....

Cube/HAL, as any "library", inevitably implements only a fraction of possible functionality, the "most usuall" functions. As soon as you want something less usual, it more gets into way than helps.

JW

XR.1
Senior
September 29, 2024

Hi, reading/writing groups of bits at once is "very usual":

Captura de pantalla de 2024-09-28 23-26-46.png

 

Davorin
DavorinAuthor
Associate III
June 1, 2020

Well I just got a few Nucleos here (and some are still on the way ;o) to experiment with the STM32 family....as a kinda like the CubeIDE, despite the fact it is just a brushed up Eclipse on Java (which I never liked ;o).

So I have some projects in mind need different features, like USB, Ethernet, SPI, TFT and from time to time 8bit access...so haven't studied in detail the datasheets yet how the GPIO registers are set up....just thought that more people would have the need for parallel GPIO access....

PS: As I wrote this I received another answer (o;

Anyway...thanks for the quick replies and the good pointers.....

and I have to admit it is really fun to play around with different Nucleo boards and the CubeIDE....tried platformio and mbed os IDE first...but never was either successful or could achieve results that fast :)

berendi
Principal
June 2, 2020

What do you mean by 8-bit access? Simply reading/writing 8 I/O pins at once, or is there a memory bus like signaling with read and write lines? In the latter case pick a MCU that has FMC or FSMC and read about its capabilities in the reference manual.

Do not ever assume that HAL or the generated code does what you think it should do.