AnsweredAssumed Answered

K22F VBAT register file causes hardfault on battery failure

Question asked by SCOTT MILLER on Mar 30, 2017
Latest reply on Apr 7, 2017 by SCOTT MILLER

I'm using the VBAT register file to back up some counters, and I'm finding that attempting to access the register file if the battery is missing or dead causes a hardfault.  I don't see any provision for checking the status of VBAT in software first - if there's a status bit, I can't find it documented.

 

Is there a safe way to test this, short of having to wire up a separate input pin to the battery and dealing with the additional drain on the battery and loss of a pin that's needed elsewhere?  As it stands, I can't use the VBAT register file at all - a failed backup battery shouldn't do more than reset the RTC and some associated counters, but right now a dead or missing battery will crash the whole system.

 

I don't see anything in AN4503 about avoiding this situation.  Is there some other documentation that covers proper use of the VBAT register file?

 

The other problem I was having was that the flash programmer was trying to initialize the VBAT section when downloading, and it would likewise crash if VBAT was unpowered.  This was particularly puzzling because Codewarrior would get stuck in a mode where it would say there was an error, but no errors would show up in the console.  I had to clean the project and restart Codewarrior to clear it.  The fix for the root cause of this problem was to use the nobits flag in the section attribute:

 

__attribute__ ((section (".vbat,\"aw\",%nobits@")))

 

I'm including that fix here in case anyone else runs into the same problem.  Doesn't help my runtime problems, though.

 

Scott

Outcomes