Skip to main content
chuck guzis
Associate II
May 12, 2023 9:58 PM UTC
Question

Can I use the STM32F4 BSRR with a 32 bit write to set/reset GPIO bits simultaneously?

I've defined the lower 8 bits of a STM32F4 GPIO port as a negative-true open-drain output. My current code uses two 16-bit writes, first to set all 8 bits, then another to selectively clear them. It would seem that I could do this with a single 32 bit write to BSRR by setting the 8 bit complement of the value to be written, and then clearing the bits specified by the value, all with a single write. I haven't tried this yet, but will it work?

In other words, if I want to output (negative logic) 0x12, I'd write 0x001200ed to BSRR.

This topic has been closed for replies.

2 replies

Tesla DeLorean
Guru
May 12, 2023 10:25 PM UTC

It's designed to work with a single write.

The word looks to be correct

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
chuck guzis
Associate II
May 12, 2023 10:42 PM UTC

Thanks; that's what I thought. it's odd that some library APIs only allow for setting or clearing bits, not both simultaneously. I note the the RM does say that in case of conflict (set/reset at the same time) that it's resolved in favor of setting.