Issue with disabling RTC in MQX and Kinetis K60.

cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with disabling RTC in MQX and Kinetis K60.

843 Views
Keith4DSmith
Contributor V

I have created a clone of the Kinetis twrk60f120m BSP. I am using CW 10.6 and MQX 4.1.1.

My target does use an RTC, so VBAT is not supplied with power.

Referring to https://community.freescale.com/thread/304195, I did set BSPCFG_ENABLE_RTCDEV to 0.

However in \Freescale\Freescale_MQX_4_1\mqx\source\bsp\<mybsp>\bsp_cm.c in the function __pe_initialize_hardware() is the following

  if ((RTC_CR & RTC_CR_OSCE_MASK) == 0u) { /* Only if the OSCILLATOR is not already enabled */

    /* RTC_CR: SC2P=0,SC4P=0,SC8P=0,SC16P=0 */

    RTC_CR &= (uint32_t)~0x3C00UL;

    /* RTC_CR: OSCE=1 */

    RTC_CR |= (uint32_t)0x0100UL;

    /* RTC_CR: CLKO=0 */

    RTC_CR &= (uint32_t)~0x0200UL;

  }


If the RTC is not operational, as it is on my target, executing the first line, the 'if' results in a kernel exception.


I updated the section of __pe_initialize_hardware() to the following:


#if BSPCFG_ENABLE_RTCDEV

  if ((RTC_CR & RTC_CR_OSCE_MASK) == 0u) { /* Only if the OSCILLATOR is not already enabled */

    /* RTC_CR: SC2P=0,SC4P=0,SC8P=0,SC16P=0 */

    RTC_CR &= (uint32_t)~0x3C00UL;

    /* RTC_CR: OSCE=1 */

    RTC_CR |= (uint32_t)0x0100UL;

    /* RTC_CR: CLKO=0 */

    RTC_CR &= (uint32_t)~0x0200UL;

  }

#endif


Is this the appropriate update to not configure the RTC when VBAT is not powered?


Tags (3)
5 Replies

131 Views
tongjianwu
Contributor III

hi,Keith.

          I ran into the same problem,I just set "BSPCFG_ENABLE_RTCDEV " to '0'.

          It's helpful for me.

          Thanks for your question.

Best Regards

Jianwu

0 Kudos

131 Views
LuisCasado
NXP Employee
NXP Employee

Hi Keith,

Yes, it is correct.

You can't access to RTC registers if VBAT is not powered.

From RM : "During chip power-up, RTC remains powered from the backup power supply (VBAT). All RTC registers are accessible by software and all functions are operational. If enabled, the 32.768 kHz clock can be supplied to the rest of the chip.”

Trying to access to RTC registers without VBAT power applied, you get a Hardware Fault.

Luis

0 Kudos

131 Views
ronnyguardarram
Contributor I

Hi, this has been very helpful. I'm not using MQX only PE and it was working fine until I started messing with the RTC. PE also add in "__low_level_init" something like:

...

  if ((RTC_CR & RTC_CR_OSCE_MASK) == 0u) { /* Only if the OSCILLATOR is not already enabled */

    /* RTC_CR: SC2P=0,SC4P=0,SC8P=0,SC16P=0 */

    RTC_CR &= (uint32_t)~(uint32_t)(

               RTC_CR_SC2P_MASK |

               RTC_CR_SC4P_MASK |

               RTC_CR_SC8P_MASK |

               RTC_CR_SC16P_MASK

              );

    /* RTC_CR: OSCE=1 */

    RTC_CR |= RTC_CR_OSCE_MASK;

    /* RTC_CR: CLKO=0 */

    RTC_CR &= (uint32_t)~(uint32_t)(RTC_CR_CLKO_MASK);

  }

...

An it works fine while I have the RTC battery connected. But as you mention before it does not works if the battery is depleted or removed. If the battery is depleted I must be able to ask the user to replace the RTC battery or at leas show some error message on the LCD. I can probably modify the "if" statement to check first if the battery is present (I don't know how to do that this point). But if later I need that PE generates the source again I will lost all the changes and I need to patch it again. Is there a better way of dealing with RTC battery depleted or disconnected? Once the hardfault interrupt is reached is it possible to keep going with program execution? Any help on this will be highly appreciated.

Thank you very much for your support.

Ronny

0 Kudos

131 Views
Keith4DSmith
Contributor V

Luis - Thank you for the verification about VBAT. I had seen the issue about no power to VBAT and RTC reported here MQX on custom board stuck in dispatch.s and here https://community.freescale.com/thread/302060

However, the problem I was really reporting is that the reference K60 BSP code is not properly coded to support #define BSPCFG_ENABLE_RTCDEV 0

131 Views
RichardR
Contributor IV

Yes, we ran into exactly the same issue with the K65 when not using the RTC.  A fellow developer here has gone through the MQX code and cleaned up the spots where the define for enable/disable of the RTC is not correctly used so that we can use MQX without having the VBAT connected.

0 Kudos