K22F VBAT register file causes hardfault on battery failure

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

K22F VBAT register file causes hardfault on battery failure

810 Views
scottm
Senior Contributor II

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

Labels (1)
0 Kudos
Reply
3 Replies

577 Views
scottm
Senior Contributor II

No responses yet, so I'll share what I've got so far.  I found the Kinetis Peripheral Module Quick Reference (KQRUG) - a document I've never come across before and that I can't seem to find through browsing the documentation library - and it includes a little information.  It shows a dual Schottky diode being used to provide alternate power from VDD, and on page 50 it says:

If VBAT supply is not present, then accesses to the RTC registers may not occur and could result in a core-lockup type reset in the MCU.

It would be nice if a warning was given about access to the VBAT register file. It does say this:

The RTC interrupt is asserted whenever a status flag and the corresponding interrupt
enable bit are both set... and when the VBAT power supply is powered down.

I don't see that that solves my problem of needing to check (without crashing) that VBAT is powered, since I can't make any reads or writes to the RTC control registers if it's not.

If there was just a single status bit in the CPU's power domain that reflected the status of VBAT, that would make things so much easier.

Scott

0 Kudos
Reply

577 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Scott,

Sorry for the later reply.

The Kinetis product doesn't have VBAT voltage detection feature.

As you mentioned before, customer could use below design to make sure there with power supply to VBAT pin:

pastedImage_1.png

Or, there need to use an ADC pin to detect the VBAT voltage with setting time interval.


Have a great day,
Ma Hui

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

577 Views
scottm
Senior Contributor II

Ok, next question - where should I have gone to find this information in the documentation?  And is there a documentation feedback process?

Thanks,

Scott

0 Kudos
Reply