From 0034dea7747f8ab384df09f01708bbe9bc6582df Mon Sep 17 00:00:00 2001 From: Steins7 Date: Mon, 8 May 2023 21:03:52 +0200 Subject: [PATCH] Make gpio writes atomic --- drivers/gpio.c | 6 +++--- drivers/gpio.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/gpio.c b/drivers/gpio.c index 409347d..be603b4 100644 --- a/drivers/gpio.c +++ b/drivers/gpio.c @@ -36,7 +36,7 @@ void gpio_configure(enum GpioPort port, enum GpioPin pin_mask, rcc_enable(RCC_AHB_NONE, RCC_APB1_NONE, RCC_APB2_IOPA << port); //reset outputs before configuring anything - regs->PORTS[port].BRR.word |= pin_mask; + regs->PORTS[port].BRR.word = pin_mask; //clear config for selected port, then apply new config, 8 first pins uint32_t mask = 0; @@ -72,9 +72,9 @@ void gpio_reset(enum GpioPort port, enum GpioPin pin_mask) void gpio_write(enum GpioPort port, enum GpioPin pin_mask, bool value) { if (value) { - regs->PORTS[port].BSRR.word |= pin_mask; + regs->PORTS[port].BSRR.word = pin_mask; } else { - regs->PORTS[port].BRR.word |= pin_mask; + regs->PORTS[port].BRR.word = pin_mask; } } diff --git a/drivers/gpio.h b/drivers/gpio.h index 36b2b75..9e5c2a5 100644 --- a/drivers/gpio.h +++ b/drivers/gpio.h @@ -101,7 +101,8 @@ void gpio_reset(enum GpioPort port, enum GpioPin pin_mask); /** * Write a value to output gpios on a single port. The GpioPin enum can be used * as mask to reset multiple pins at the same time. In push-pull input mode, - * configure the pull up/down. Has no effect otherwise + * configure the pull up/down. Has no effect otherwise. Writes are atomic + * operations */ void gpio_write(enum GpioPort port, enum GpioPin pin_mask, bool value);