From 5de7f79ee3975720b8cf4b2c6ddb4657c7f240d6 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 18 Feb 2014 20:51:41 +0100 Subject: [PATCH] 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. --- hardware/arduino/sam/cores/arduino/Reset.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hardware/arduino/sam/cores/arduino/Reset.cpp b/hardware/arduino/sam/cores/arduino/Reset.cpp index 6336427c6c0..7485eecfb93 100644 --- a/hardware/arduino/sam/cores/arduino/Reset.cpp +++ b/hardware/arduino/sam/cores/arduino/Reset.cpp @@ -31,12 +31,12 @@ void banzai() { // Set bootflag to run SAM-BA bootloader at restart const int EEFC_FCMD_CGPB = 0x0C; const int EEFC_KEY = 0x5A; - while (EFC0->EEFC_FSR & EEFC_FSR_FRDY == 0); + while ((EFC0->EEFC_FSR & EEFC_FSR_FRDY) == 0); EFC0->EEFC_FCR = EEFC_FCR_FCMD(EEFC_FCMD_CGPB) | EEFC_FCR_FARG(1) | EEFC_FCR_FKEY(EEFC_KEY); - while (EFC0->EEFC_FSR & EEFC_FSR_FRDY == 0); + while ((EFC0->EEFC_FSR & EEFC_FSR_FRDY) == 0); // From here flash memory is no more available.