Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MCUXpresso: Ensure the RTC OSC is running at bootup on Kinetis platforms #8872

Merged
merged 1 commit into from
Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,42 @@

#define CRC16
#include "crc.h"
#include "fsl_rtc.h"
#include "fsl_clock_config.h"

// called before main
void mbed_sdk_init()
{
rtc_config_t rtc_basic_config;
uint32_t u32cTPR_counter = 0;

BOARD_BootClockRUN();

CLOCK_EnableClock(kCLOCK_Rtc0);

/* Check if the Rtc oscillator is enabled */
if ((RTC->CR & RTC_CR_OSCE_MASK) == 0u) {
/*Init the RTC with default configuration*/
RTC_GetDefaultConfig(&rtc_basic_config);

/* Setup the 32K RTC OSC */
RTC_Init(RTC, &rtc_basic_config);

/* Enable the RTC 32KHz oscillator */
RTC->CR |= RTC_CR_OSCE_MASK;

/* Start the RTC time counter */
RTC_StartTimer(RTC);

/* Verify TPR register reaches 4096 counts */
while (u32cTPR_counter < 4096) {
u32cTPR_counter = RTC->TPR;
}
/* 32kHz Oscillator is ready. */
RTC_Deinit(RTC);
}

CLOCK_DisableClock(kCLOCK_Rtc0);
}

// Change the NMI pin to an input. This allows NMI pin to
Expand All @@ -34,13 +64,6 @@ void NMI_Handler(void)
gpio_init_in(&gpio, PTA4);
}

// Enable the RTC oscillator if available on the board
void rtc_setup_oscillator(RTC_Type *base)
{
/* Enable the RTC oscillator */
RTC->CR |= RTC_CR_OSCE_MASK;
}

// Provide ethernet devices with a semi-unique MAC address from the UUID
void mbed_mac_address(char *mac)
{
Expand All @@ -55,7 +78,7 @@ void mbed_mac_address(char *mac)

// generate three CRC16's using different slices of the UUID
MAC[0] = crcSlow((const uint8_t *)UID, 8); // most significant half-word
MAC[1] = crcSlow((const uint8_t *)UID, 12);
MAC[1] = crcSlow((const uint8_t *)UID, 12);
MAC[2] = crcSlow((const uint8_t *)UID, 16); // least significant half word

// The network stack expects an array of 6 bytes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,42 @@
* limitations under the License.
*/
#include "gpio_api.h"
#include "fsl_rtc.h"
#include "fsl_clock_config.h"

// called before main
void mbed_sdk_init()
{
rtc_config_t rtc_basic_config;
uint32_t u32cTPR_counter = 0;

BOARD_BootClockRUN();

CLOCK_EnableClock(kCLOCK_Rtc0);

/* Check if the Rtc oscillator is enabled */
if ((RTC->CR & RTC_CR_OSCE_MASK) == 0u) {
/*Init the RTC with default configuration*/
RTC_GetDefaultConfig(&rtc_basic_config);

/* Setup the 32K RTC OSC */
RTC_Init(RTC, &rtc_basic_config);

/* Enable the RTC 32KHz oscillator */
RTC->CR |= RTC_CR_OSCE_MASK;

/* Start the RTC time counter */
RTC_StartTimer(RTC);

/* Verify TPR register reaches 4096 counts */
while (u32cTPR_counter < 4096) {
u32cTPR_counter = RTC->TPR;
}
/* 32kHz Oscillator is ready. */
RTC_Deinit(RTC);
}

CLOCK_DisableClock(kCLOCK_Rtc0);
}

// Change the NMI pin to an input. This allows NMI pin to
Expand All @@ -31,13 +61,6 @@ void NMI_Handler(void)
gpio_init_in(&gpio, PTA4);
}

// Enable the RTC oscillator if available on the board
void rtc_setup_oscillator(RTC_Type *base)
{
/* Enable the RTC oscillator */
RTC->CR |= RTC_CR_OSCE_MASK;
}

// Set the UART clock source
void serial_clock_init(void)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@
#include "fsl_smc.h"
#include "fsl_rcm.h"
#include "fsl_pmc.h"
#include "fsl_rtc.h"
#include "fsl_clock_config.h"

//!< this contains the wakeup source
rcm_reset_source_t kinetisResetSource;

// called before main
void mbed_sdk_init() {
void mbed_sdk_init()
{
rtc_config_t rtc_basic_config;
uint32_t u32cTPR_counter = 0;

SMC_SetPowerModeProtection(SMC, kSMC_AllowPowerModeAll);

// check the power mode source
Expand All @@ -36,6 +41,31 @@ void mbed_sdk_init() {

BOARD_BootClockRUN();

CLOCK_EnableClock(kCLOCK_Rtc0);

/* Check if the Rtc oscillator is enabled */
if ((RTC->CR & RTC_CR_OSCE_MASK) == 0u) {
/*Init the RTC with default configuration*/
RTC_GetDefaultConfig(&rtc_basic_config);

/* Setup the 32K RTC OSC */
RTC_Init(RTC, &rtc_basic_config);

/* Enable the RTC 32KHz oscillator */
RTC->CR |= RTC_CR_OSCE_MASK;

/* Start the RTC time counter */
RTC_StartTimer(RTC);

/* Verify TPR register reaches 4096 counts */
while (u32cTPR_counter < 4096) {
u32cTPR_counter = RTC->TPR;
}
/* 32kHz Oscillator is ready. */
RTC_Deinit(RTC);
}

CLOCK_DisableClock(kCLOCK_Rtc0);
}

// Change the NMI pin to an input. This allows NMI pin to
Expand All @@ -47,13 +77,6 @@ void NMI_Handler(void)
gpio_init_in(&gpio, PTA4);
}

// Enable the RTC oscillator if available on the board
void rtc_setup_oscillator(RTC_Type *base)
{
/* Enable the RTC oscillator */
RTC->CR |= RTC_CR_OSCE_MASK;
}

// Set the UART clock source
void serial_clock_init(void)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,45 @@
*/
#include "gpio_api.h"
#include "pinmap.h"
#include "fsl_rtc.h"
#include "fsl_clock_config.h"

// called before main - implement here if board needs it otherwise, let
// the application override this if necessary
void mbed_sdk_init()
{
rtc_config_t rtc_basic_config;
uint32_t u32cTPR_counter = 0;

BOARD_BootClockRUN();
/* Set the TPM clock source to be IRC48M, do not change as TPM2 is used for the usticker */
CLOCK_SetTpmClock(1U);
}

// Enable the RTC oscillator if available on the board
void rtc_setup_oscillator(RTC_Type *base)
{
/* Enable the RTC oscillator */
RTC->CR |= RTC_CR_OSCE_MASK;
CLOCK_EnableClock(kCLOCK_Rtc0);

/* Check if the Rtc oscillator is enabled */
if ((RTC->CR & RTC_CR_OSCE_MASK) == 0u) {
/*Init the RTC with default configuration*/
RTC_GetDefaultConfig(&rtc_basic_config);

/* Setup the 32K RTC OSC */
RTC_Init(RTC, &rtc_basic_config);

/* Enable the RTC 32KHz oscillator */
RTC->CR |= RTC_CR_OSCE_MASK;

/* Start the RTC time counter */
RTC_StartTimer(RTC);

/* Verify TPR register reaches 4096 counts */
while (u32cTPR_counter < 4096) {
u32cTPR_counter = RTC->TPR;
}
/* 32kHz Oscillator is ready. */
RTC_Deinit(RTC);
}

CLOCK_DisableClock(kCLOCK_Rtc0);
}

// Change the NMI pin to an input. This allows NMI pin to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,45 @@
*/
#include "gpio_api.h"
#include "pinmap.h"
#include "fsl_rtc.h"
#include "fsl_clock_config.h"

// called before main - implement here if board needs it otherwise, let
// the application override this if necessary
void mbed_sdk_init()
{
rtc_config_t rtc_basic_config;
uint32_t u32cTPR_counter = 0;

BOARD_BootClockRUN();
/* Set the TPM clock source to be IRC48M, do not change as TPM2 is used for the usticker */
CLOCK_SetTpmClock(1U);
}

// Enable the RTC oscillator if available on the board
void rtc_setup_oscillator(RTC_Type *base)
{
/* Enable the RTC oscillator */
RTC->CR |= RTC_CR_OSCE_MASK;
CLOCK_EnableClock(kCLOCK_Rtc0);

/* Check if the Rtc oscillator is enabled */
if ((RTC->CR & RTC_CR_OSCE_MASK) == 0u) {
/*Init the RTC with default configuration*/
RTC_GetDefaultConfig(&rtc_basic_config);

/* Setup the 32K RTC OSC */
RTC_Init(RTC, &rtc_basic_config);

/* Enable the RTC 32KHz oscillator */
RTC->CR |= RTC_CR_OSCE_MASK;

/* Start the RTC time counter */
RTC_StartTimer(RTC);

/* Verify TPR register reaches 4096 counts */
while (u32cTPR_counter < 4096) {
u32cTPR_counter = RTC->TPR;
}
/* 32kHz Oscillator is ready. */
RTC_Deinit(RTC);
}

CLOCK_DisableClock(kCLOCK_Rtc0);
}

// Change the NMI pin to an input. This allows NMI pin to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,43 @@
*/
#include "gpio_api.h"
#include "pinmap.h"
#include "fsl_rtc.h"
#include "fsl_clock_config.h"

// called before main - implement here if board needs it otherwise, let
// the application override this if necessary
void mbed_sdk_init()
{
rtc_config_t rtc_basic_config;
uint32_t u32cTPR_counter = 0;

BOARD_BootClockRUN();
}

// Enable the RTC oscillator if available on the board
void rtc_setup_oscillator(RTC_Type *base)
{
/* Enable the RTC oscillator */
RTC->CR |= RTC_CR_OSCE_MASK;
CLOCK_EnableClock(kCLOCK_Rtc0);

/* Check if the Rtc oscillator is enabled */
if ((RTC->CR & RTC_CR_OSCE_MASK) == 0u) {
/*Init the RTC with default configuration*/
RTC_GetDefaultConfig(&rtc_basic_config);

/* Setup the 32K RTC OSC */
RTC_Init(RTC, &rtc_basic_config);

/* Enable the RTC 32KHz oscillator */
RTC->CR |= RTC_CR_OSCE_MASK;

/* Start the RTC time counter */
RTC_StartTimer(RTC);

/* Verify TPR register reaches 4096 counts */
while (u32cTPR_counter < 4096) {
u32cTPR_counter = RTC->TPR;
}
/* 32kHz Oscillator is ready. */
RTC_Deinit(RTC);
}

CLOCK_DisableClock(kCLOCK_Rtc0);
}

// Change the NMI pin to an input. This allows NMI pin to
Expand Down
Loading