Skip to main content
MRoen.1
Associate
Jan 10, 2021 10:09 PM UTC
Solved

Does writing to a port directly (GPIOx->ODR) conflict with fixed hard peripherals on that same port?

I'm planning on using a STM32F411CE in an application where the SDIO hard peripheral is connected to a SD-card in 4-bit mode. I also need to use both PA and PB ports in a rather high-speed fashion, so I'd like to set them one 16-bit word at a time (instead of bit-by-bit). If I write a word to say, PB, where bits 4, 5 & 15 are already allocated by the SDIO peripheral, will there be issues? Is there a way to mask off those 3 bits so I won't ruin the SD transfers?

If this specific question is mentioned in any manuals or other places, please point me there. I'm capable of RTFM, I just didn't know where to look. :)

This topic has been closed for replies.
waclawek.jan
waclawek.janBest answer
Super User
Jan 10, 2021 11:01 PM UTC

GPIO chapter of RM and pin AF assignment table in Datasheet.

To have pins assigned to a peripheral, they have to be set as AF in GPIO_MODER. To output value from ODR a different setting, Out, is set in GPIO_MODER.

JW

7 replies

waclawek.jan
waclawek.janBest answer
Super User
Jan 10, 2021 11:01 PM UTC

GPIO chapter of RM and pin AF assignment table in Datasheet.

To have pins assigned to a peripheral, they have to be set as AF in GPIO_MODER. To output value from ODR a different setting, Out, is set in GPIO_MODER.

JW

MRoen.1
MRoen.1Author
Associate
Jan 10, 2021 11:19 PM UTC

Right, so that means, pins that are set as "AF" aren't affected by data written to the ODR. Excellent! That's one thing less to be concerned about. :) Then I can complete the PCB schematic with more confidence. Thanks!

TDK
Jan 11, 2021 4:22 AM UTC

Alternatively, writing to GPIOx->BSRR will let you set or reset only the pins you want without messing with the others.

"If you feel a post has answered your question, please click ""Accept as Solution""."
waclawek.jan
Super User
Jan 11, 2021 2:36 PM UTC

The 'F412 DISCO board features a microSD connector https://www.st.com/en/evaluation-tools/32f412gdiscovery.html so may serve as a test vehicle for initial experiments.

JW

MRoen.1
MRoen.1Author
Associate
Jan 11, 2021 3:35 PM UTC

Excellent tip, thank you Jan!

Now I just have to manage my impulses to refrain from finishing the new PCB, in favour of testing the concept on a proven dev-board, just like a well-behaved engineer is supposed to. Hmm... :smirking_face: We'll see...

waclawek.jan
Super User
Jan 11, 2021 8:50 PM UTC

It's like a textbook: you read it (or maybe even skim through it) it once, when you buy it; then it gathers dust on the shelf until that one day whey you need to look up that particular thing...

JW

Piranha
Principal III
Jan 13, 2021 2:20 PM UTC

Besides datasheet and reference manual, the AN4899 gives additional details on GPIO. :)