cancel
Showing results for 
Search instead for 
Did you mean: 

8-bit parallel access to GPIO

Davorin
Senior

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

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

4 REPLIES 4

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 Venmo Up vote any posts that you find helpful, it shows what's working..

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

Davorin
Senior

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

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.