Question
When are you allowed to change regs using |= and &= and when are you not?
Posted on March 22, 2016 at 10:12
I have recently reversed-engineer some HAL source code and I see that sometimes a temporary variable is used to manipulate a register, for example
uint32_t tmp = 0;
tmp = hdma->Instance->CR;
tmp |= hdma->Init.MemBurst | hdma->Init.PeriphBurst;
hdma->Instance->CR = tmp;
At other times, the register is changed directly, for exaple:
#define __HAL_SPI_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= SPI_CR1_SPE)
What is the rule here?