How to set internal oscillator for K21 tower board.

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

How to set internal oscillator for K21 tower board.

Jump to solution
845 Views
sudhanshumehta
Contributor IV

Hi Team,

I want to use internal oscillator for K21 tower board.

Do you have any reference.

Thanks

Sudhanshu

0 Kudos
1 Solution
674 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi sudhanshu mehta

Please put below line into user_config.h to disable 32khz reference osclillator.

#define BSPCFG_ENABLE_RTCDEV   0

Don't forget to rebuild all libraries.

This macro is disabled by default.

From low level driver level, this is controlled by RTC_CR register.  bit 8 OSCE

pastedImage_1.png

In mqx, low level driver is _rtc_init.,  this function is controlled by the macro BSPCFG_ENABLE_RTCDEV.

 

/*FUNCTION****************************************************************
*
* Function Name    : _rtc_init
* Returned Value   : MQX error code
* Comments         :
*    This function (re)initializes/clears/enables RTC module.
*
*END*********************************************************************/
int32_t _rtc_init
(
    /* [IN] param identifying init operations */
    void* param
)
{ /* Body */
    int32_t       result = MQX_OK;
    RTC_MemMapPtr rtc    = RTC_BASE_PTR;

 

    _int_disable();
    /* Check if the time is invalid */
    if (rtc->SR & RTC_SR_TIF_MASK)
    {
        rtc->SR &= ~RTC_SR_TCE_MASK;    /* disable rtc timer - enable write access */
        rtc->TAR = 0xFFFFFFFF;          /* e2574: RTC: Writing RTC_TAR[TAR] = 0 does not disable RTC alarm */

 

        /* if TIF reading TSR return zero and we must set TSR to one */
        rtc->TSR = 1;                   /* this clear SR flags TIF, TOF */
        rtc->SR |= RTC_SR_TCE_MASK;
        /* Update alarm time & alarm period */

 

        alarm_time = 0;
        alarm_period = 0;
    } /* End if*/
    _int_enable();

 

    /* Check if RTC counter or OSC for RTC is not started */
    if( !(rtc->SR & RTC_SR_TCE_MASK) || !(rtc->CR & RTC_CR_OSCE_MASK) )
    {
        rtc->CR |= RTC_CR_OSCE_MASK;
        /* recommended 125 ms delay for oscillator start */
        _time_delay(125);
        rtc->SR |= RTC_SR_TCE_MASK;
    } /* End if */

 

    return result;
} /* Endbody */

 

If this post is helpful, please mark correct , thank you!

 

Have a nice day!

Regards

Daniel

View solution in original post

0 Kudos
4 Replies
673 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi  sudhanshu mehta

I assume you are using MQX, please refer to the attached document -How to change Default Clcok Settings in  Kinetis BSPs.

TWR-K21F120M is supported in MQX4.2, please refer to clock settings

Freescale_MQX_4_2\mqx\source\bsp\twrk21f120m\bsp_cm.c

If this post is helpful, please mark correct or helpful, thank you.


Have a nice day,
Daniel

0 Kudos
673 Views
sudhanshumehta
Contributor IV

Hi Daniel,

I thank you for your reply. Attached document is for mqx 3.8. there are many functions given in this document which are not available in bsp_cm.h/c file. 

yes I am using MQX 4.2

I just want to disable 32khz reference oscillator but i have 8mhz crystal on my board. 

Any other example you have?

Thanks

Sudhanshu

0 Kudos
675 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi sudhanshu mehta

Please put below line into user_config.h to disable 32khz reference osclillator.

#define BSPCFG_ENABLE_RTCDEV   0

Don't forget to rebuild all libraries.

This macro is disabled by default.

From low level driver level, this is controlled by RTC_CR register.  bit 8 OSCE

pastedImage_1.png

In mqx, low level driver is _rtc_init.,  this function is controlled by the macro BSPCFG_ENABLE_RTCDEV.

 

/*FUNCTION****************************************************************
*
* Function Name    : _rtc_init
* Returned Value   : MQX error code
* Comments         :
*    This function (re)initializes/clears/enables RTC module.
*
*END*********************************************************************/
int32_t _rtc_init
(
    /* [IN] param identifying init operations */
    void* param
)
{ /* Body */
    int32_t       result = MQX_OK;
    RTC_MemMapPtr rtc    = RTC_BASE_PTR;

 

    _int_disable();
    /* Check if the time is invalid */
    if (rtc->SR & RTC_SR_TIF_MASK)
    {
        rtc->SR &= ~RTC_SR_TCE_MASK;    /* disable rtc timer - enable write access */
        rtc->TAR = 0xFFFFFFFF;          /* e2574: RTC: Writing RTC_TAR[TAR] = 0 does not disable RTC alarm */

 

        /* if TIF reading TSR return zero and we must set TSR to one */
        rtc->TSR = 1;                   /* this clear SR flags TIF, TOF */
        rtc->SR |= RTC_SR_TCE_MASK;
        /* Update alarm time & alarm period */

 

        alarm_time = 0;
        alarm_period = 0;
    } /* End if*/
    _int_enable();

 

    /* Check if RTC counter or OSC for RTC is not started */
    if( !(rtc->SR & RTC_SR_TCE_MASK) || !(rtc->CR & RTC_CR_OSCE_MASK) )
    {
        rtc->CR |= RTC_CR_OSCE_MASK;
        /* recommended 125 ms delay for oscillator start */
        _time_delay(125);
        rtc->SR |= RTC_SR_TCE_MASK;
    } /* End if */

 

    return result;
} /* Endbody */

 

If this post is helpful, please mark correct , thank you!

 

Have a nice day!

Regards

Daniel

0 Kudos
673 Views
sudhanshumehta
Contributor IV

this is correct answer.. worked for me. I thank you Daniel Chen.. :-) Thanks

0 Kudos