Incorrect value returned by CySysGetResetReason

Hello guys,
can someone please help me make sense of this, I’m trying to detect the reason for the restart, but the below never returns true when WDT resets the board… basically if i don’t feed the WDT the board will resets and returns a value of 00000011 which is not what CY_SYS_RESET_WDT is since that corresponds to 00000001 as shown below.

void setup(){
uint32_t reason;

  reason = CySysGetResetReason(CY_SYS_RESET_WDT | CY_SYS_RESET_PROTFAULT | CY_SYS_RESET_SW);
  Serial.printf("reason%08X\n", reason); //outputs 00000011
  Serial.printf("CY_SYS_RESET_WDT %08X\n", CY_SYS_RESET_WDT); //outputs 00000001
  Serial.printf("CY_SYS_RESET_WDT_SHIFT %08X\n", CY_SYS_RESET_WDT_SHIFT);//outputs 00000000
  Serial.printf("CY_SYS_RESET_PROTFAULT %08X\n", CY_SYS_RESET_PROTFAULT);//outputs 00000008
  Serial.printf("CY_SYS_RESET_SW %08X\n", CY_SYS_RESET_SW);//outputs 00000010

      if (CySysGetResetReason(CY_SYS_RESET_WDT) == CY_SYS_RESET_WDT)
      {
          Serial.print("Disabled the WDT CY_SYS_RESET_WDT\n");
      } 
}

is this a bug or am i doing it wrong?

Hi jayjay,

Can’t see what would be wrong with your code.

So it seems that after a WDT-triggered reset, Heltec firmware sets the SYSRESETREQ bit in the CM0P_AIRCR register to issue a 2nd reset before handing control to the user program.

I’d say an undocumented feature, but not in the ironic sense of a bug.

Hi @peterm,
I’m not sure i follow, my issue is that i get a reason: 00000011 which is no where to be found on the documentation, therefore i can’t reply on it as the proper reason for the reset. So it seems to me that the bootloader may be changing the bits before pushing them which in my opinion would be wrong…

I hope one of Heltec team jumps in and shines some light into this…

cheers,
Jay.

Hi jayjay,

Heltec firmware seems to do a software reset. I don’t know how else the RESET_SW bit can be set in the REG_CAUSE register: it can only be cleared by software, not set.
They must have a good reason for doing this - don’t think it’s a bug.
So forget the CY_SYS_RESET_SW - ignore its value.

To see what Heltec firmware is doing:

unsigned int reason;
void setup() {
  Serial.begin(115200);

  reason = CySysGetResetReason(CY_SYS_RESET_WDT | CY_SYS_RESET_PROTFAULT | CY_SYS_RESET_SW);
  Serial.printf("reason: %08X\n", reason); // outputs 00000011
  *(volatile uint32 *)CYREG_RES_CAUSE = 1<<4; // clr RESET_SOFT bit
}

void loop() {
  reason = CySysGetResetReason(CY_SYS_RESET_WDT | CY_SYS_RESET_PROTFAULT | CY_SYS_RESET_SW);
  Serial.printf("reason after clearing 'reset-soft' bit: %08X\n", reason); //outputs 00000011
  Serial.println("reset board to run again");
  while(1);
}

Output:

Copyright @2019-2020 Heltec Automation.All rights reserved.
reason: 00000010
reason after clearing 'reset-soft' bit: 00000000
reset board to run again

After pushing reset button:

Copyright @2019-2020 Heltec Automation.All rights reserved.
reason: 00000010
reason after clearing 'reset-soft' bit: 00000000
reset board to run again