cpq / bare-metal-programming-guide

A bare metal programming guide (ARM microcontrollers)
MIT License
3.27k stars 284 forks source link

Efficiency improvement #24

Closed baverrud closed 1 year ago

baverrud commented 1 year ago

In the following function:

static inline void gpio_write(uint16_t pin, bool val) {
  struct gpio *gpio = GPIO(PINBANK(pin));
  gpio->BSRR |= (1U << PINNO(pin)) << (val ? 0 : 16);
}

.. the BSRR |= .. will cause an unnecessary attempt to read the BSRR register, as BSRR is write-only. Replace |= with =. Functionally it will be the same, only a tiny bit more efficient.

cpq commented 1 year ago

Thank you @baverrud

Fixed by https://github.com/cpq/bare-metal-programming-guide/commit/dd4d96d6d90ba3e1150c108df5e4205a0255c294