2020-04-15 12:44 PM
I saw somewhere a very basic examples how to do basic GPIO. But now I can't find it. Most of my bookmarks for this forum do not work anyway, all though they not are so old.
But could some one write examples of how to write or read one pin or several at once. And toggling of course.
Edit: It probably doesn't matter, but I'm currently using STM32F746 and H750
2020-04-15 01:22 PM
GPIOD->ODR is the output register, bit 0 PD0, bit 15 PD15
GPIOD->BSRR is the set/reset register, single write equivalent of RMW on ODR
GPIOD->BSRR = (1 << 4) | (1 << 8) | (1 << (0 + 16)); // Set PD4, PD8, Clear PD0
One of the other guys had a safe toggle macro
2020-04-15 01:24 PM
Ah, That was quick, thank you.
Is the reset always like this, 1 << (0 + 16)?
2020-04-15 01:34 PM
Well there's the Reference Manual if you want to understand the mechanics.
The GPIO bank has 16 pins, for the set/reset register the low order 16-bits SET the pin HIGH, the high order 16-bits CLEAR the pin LOW
You can write the whole 32-bit in a single write, so it is faster/safer than doing the equivalent RMW on the ODR
Toggle ALL PINS would look something like
uint32_t tmp = GPIOD->ODR;
GPIOD->BSRR = (tmp << 16) | (~tmp & 0xFFFF);
2020-04-15 01:43 PM
I have to check the manual. It may be even been the manual I saw these. Google didn't find anything more about this.
So, upper bits set and lower bits reset, what happens if I set and reset a pin. A short?
2020-04-15 02:08 PM
If both bits are set the reference manual say (search for GPIOx_BSRR):
If both BSx and BRx are set, BSx has priority.
2020-04-15 05:02 PM
The BSRR is great. The reference manual has all this info. Open it up and search for the term "BSRR" and read carefully everywhere it occurs.
2020-04-16 08:42 AM
I searched from a couple of Reference manuals and they didn't have any code examples. In my opinion there is no good place on the net where input, out and toggling are given well and all in one place
.
2020-04-16 10:04 PM
You are looking for it at the wrong place. Bitwise operations, i.e. how to set a certain bit, are explained in C textbooks.