1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-25 09:16:07 +03:00

Switch to writing BSRR which only affects the state of pins with high bits in the mask rather than all pins like ODR.

This commit is contained in:
Scott Shawcroft 2016-06-12 11:52:50 -07:00
parent 708638f87b
commit 46941032f3

View file

@ -171,8 +171,22 @@ void IOToggle(IO_t io)
{ {
if (!io) if (!io)
return; return;
uint16_t mask = IO_Pin(io); uint32_t mask = IO_Pin(io);
IO_GPIO(io)->ODR ^= mask; // Read pin state from ODR but write to BSRR because it only changes the pins
// high in the mask value rather than all pins. XORing ODR directly risks
// setting other pins incorrectly because it change all pins' state.
#if defined(STM32F40_41xxx) || defined(STM32F411xE)
if (IO_GPIO(io)->ODR & mask) {
IO_GPIO(io)->BSRRH = mask;
} else {
IO_GPIO(io)->BSRRL = mask;
}
#else
if (IO_GPIO(io)->ODR & mask)
mask <<= 16; // bit is set, shift mask to reset half
IO_GPIO(io)->BSRR = mask;
#endif
} }
// claim IO pin, set owner and resources // claim IO pin, set owner and resources