cancel
Showing results for 
Search instead for 
Did you mean: 

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

chuck guzis
Associate III

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.

2 REPLIES 2

It's designed to work with a single write.

The word looks to be correct

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
chuck guzis
Associate III

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.