Skip to content

Commit 8120558

Browse files
matthijskooijmancmaglie
authored andcommitted
Fix loops in the SAM banzai() reset function
The code used to say: while (EFC0->EEFC_FSR & EEFC_FSR_FRDY == 0); This triggered a compiler warning, which is why I looked at this line more closely: warning: suggest parentheses around comparison in operand of '&' As the warning indicates, because the == operator has higher precedence than the & operator, the compiler is interpreting this line as: while (EFC0->EEFC_FSR & (EEFC_FSR_FRDY == 0)); Since EEFC_FSR_FRDY is defined as 1, (EEFC_FSR_FRDY == 0) is always false (== 0) and this reduces to: while (EFC0->EEFC_FSR & 0); Which reduces to: while (0); So effectively this line is a no-op. This commit adds parenthesis to restore the intended behaviour.
1 parent ce65ece commit 8120558

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Diff for: hardware/arduino/sam/cores/arduino/Reset.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ void banzai() {
3131
// Set bootflag to run SAM-BA bootloader at restart
3232
const int EEFC_FCMD_CGPB = 0x0C;
3333
const int EEFC_KEY = 0x5A;
34-
while (EFC0->EEFC_FSR & EEFC_FSR_FRDY == 0);
34+
while ((EFC0->EEFC_FSR & EEFC_FSR_FRDY) == 0);
3535
EFC0->EEFC_FCR =
3636
EEFC_FCR_FCMD(EEFC_FCMD_CGPB) |
3737
EEFC_FCR_FARG(1) |
3838
EEFC_FCR_FKEY(EEFC_KEY);
39-
while (EFC0->EEFC_FSR & EEFC_FSR_FRDY == 0);
39+
while ((EFC0->EEFC_FSR & EEFC_FSR_FRDY) == 0);
4040

4141
// From here flash memory is no more available.
4242

0 commit comments

Comments
 (0)