AnsweredAssumed Answered

When are you allowed to change regs using |= and &= and when are you not?

Question asked by arnold_w on Mar 22, 2016
Latest reply on Mar 22, 2016 by FTITI.Walid
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?

Outcomes