Accessing VBAT register file hard faults K22 with KSDK 2.4.1

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

Accessing VBAT register file hard faults K22 with KSDK 2.4.1

Jump to solution
1,182 Views
lucasrangit
Contributor III

Attempting to access RFVBAT->REG[0] hard faults my K22 (with KSDK 2.4.1).

I've used the VBAT register file before on previous designs with different Kinetis parts (KL27). I know it is supported by the K22 from the reference manual.

The only difference is my current design doesn't have VBAT connected but that should still allow me to read/write the register (and see that values are not preserved). I read in "Kinetis Quick Reference User Guide, Rev. 3, 05/2014" section 5.1.2.1 that "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.", is the same true for the VBAT register file RFVBAT?

I've tried accessing the first 32-bit register directly and via the REG[8] array. Both hard fault.

// from MK22F51212.h
typedef struct {
  __IO uint32_t REG[8];
} RFVBAT_Type;
#define RFVBAT_BASE                              (0x4003E000u)
#define RFVBAT                                   ((RFVBAT_Type *)RFVBAT_BASE)

#if FSL_FEATURE_SOC_RFVBAT_COUNT
#define VBAT_REG (*((unsigned int*)RFVBAT_BASE))
uint32_t vbat_reg()
{
 RFVBAT_Type *base = RFVBAT;
 uint8_t reg = 0;
 uint32_t val;

 val = VBAT_REG;
 val = base->REG[reg];

 return val;
}
#endif
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

  1. How should I troubleshoot this?
  2. Is there a peripheral clock I need to enable? I don't see one for the RFVBAT in fsl_clocks.h.
  3. Do I need to configure the AIPS-Lite Peripheral Bridge in order to access the VBAT register file on slot 62? As a test, I tried accessing the FlexTimer (FTM0) on slot 56 and it worked.
Labels (1)
Tags (3)
0 Kudos
Reply
1 Solution
1,033 Views
mjbcswitzerland
Specialist V

Hi Lucas

Attempted access to RTC registers using VBAT will result in a hard fault if the VBAT is below its threshold (or not present).

See the following: How to detect if VBAT supply is present for RTC to work? 

In the uTasker project the following is used to test VBAT presence in operation to avoid needing to recover from a hard fault when the battery is not present, is removed during operation or its voltage drops below its lower limit. [A DMA read failure is easy to recover from]

            unsigned long ulRegCopy;
            POWER_UP_ATOMIC(6, RTC);                                     // ensure the RTC is powered
            if (DMA_ERROR_OCCURRED == fnConfigDMA_buffer(4, 0, sizeof(ulRegCopy), (void *)RTC_BLOCK, &ulRegCopy, (DMA_DIRECTION_INPUT | DMA_LONG_WORDS | DMA_SINGLE_CYCLE | DMA_FIXED_ADDRESSES | DMA_SW_TRIGGER_WAIT_TERMINATION), 0, 0)) { // configure the transfer, start and wait for termination
                // RTC cannot be accessed - probably due to missing VBAT voltage
                // - avoid RTC access
            }
            else {
                // ulRegCopy has the present RTC_TSR content, meaning that the RTC could be accessed
                //
                fnStartRTC(0);                                           // start the RTC if it isn't yet operating
            }

Regards

Mark


Complete Kinetis solutions, training and support: http://www.utasker.com/kinetis.html
Kinetis K22:
- http://www.utasker.com/kinetis/FRDM-K22F.html
- http://www.utasker.com/kinetis/TWR-K22F120M.html
- http://www.utasker.com/kinetis/BLAZE_K22.html
- http://www.utasker.com/kinetis/tinyK22.html

RTC and time keeping: http://www.utasker.com/docs/uTasker/uTasker_Time.pdf

View solution in original post

0 Kudos
Reply
2 Replies
1,032 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

As Mark said, you need apply power to the VBAT pin.

Best Regards,

Robin

0 Kudos
Reply
1,034 Views
mjbcswitzerland
Specialist V

Hi Lucas

Attempted access to RTC registers using VBAT will result in a hard fault if the VBAT is below its threshold (or not present).

See the following: How to detect if VBAT supply is present for RTC to work? 

In the uTasker project the following is used to test VBAT presence in operation to avoid needing to recover from a hard fault when the battery is not present, is removed during operation or its voltage drops below its lower limit. [A DMA read failure is easy to recover from]

            unsigned long ulRegCopy;
            POWER_UP_ATOMIC(6, RTC);                                     // ensure the RTC is powered
            if (DMA_ERROR_OCCURRED == fnConfigDMA_buffer(4, 0, sizeof(ulRegCopy), (void *)RTC_BLOCK, &ulRegCopy, (DMA_DIRECTION_INPUT | DMA_LONG_WORDS | DMA_SINGLE_CYCLE | DMA_FIXED_ADDRESSES | DMA_SW_TRIGGER_WAIT_TERMINATION), 0, 0)) { // configure the transfer, start and wait for termination
                // RTC cannot be accessed - probably due to missing VBAT voltage
                // - avoid RTC access
            }
            else {
                // ulRegCopy has the present RTC_TSR content, meaning that the RTC could be accessed
                //
                fnStartRTC(0);                                           // start the RTC if it isn't yet operating
            }

Regards

Mark


Complete Kinetis solutions, training and support: http://www.utasker.com/kinetis.html
Kinetis K22:
- http://www.utasker.com/kinetis/FRDM-K22F.html
- http://www.utasker.com/kinetis/TWR-K22F120M.html
- http://www.utasker.com/kinetis/BLAZE_K22.html
- http://www.utasker.com/kinetis/tinyK22.html

RTC and time keeping: http://www.utasker.com/docs/uTasker/uTasker_Time.pdf

0 Kudos
Reply