Skip to content

Commit f7c6e55

Browse files
mmahadevan108bulislaw
authored andcommitted
MCUXpresso: Enable RTC on LPC54114 and LPC546XX
Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent a17cf07 commit f7c6e55

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC/rtc_api.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
*/
1616
#include "rtc_api.h"
1717

18-
#if DEVICE_RTC
18+
#if DEVICE_RTC || DEVICE_LOWPOWERTIMER
1919

2020
#include "pinmap.h"
2121
#include "fsl_rtc.h"
2222
#include "PeripheralPins.h"
2323

2424
extern void rtc_setup_oscillator(void);
2525

26+
static bool rtc_time_set = false;
27+
2628
void rtc_init(void)
2729
{
2830
rtc_setup_oscillator();
@@ -34,7 +36,10 @@ void rtc_init(void)
3436

3537
void rtc_free(void)
3638
{
37-
RTC_Deinit(RTC);
39+
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
40+
/* Gate the module clock */
41+
CLOCK_DisableClock(kCLOCK_Rtc);
42+
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
3843
}
3944

4045
/*
@@ -43,8 +48,19 @@ void rtc_free(void)
4348
*/
4449
int rtc_isenabled(void)
4550
{
51+
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
52+
/* Enable the RTC peripheral clock */
4653
CLOCK_EnableClock(kCLOCK_Rtc);
47-
return (int)((RTC->CTRL & RTC_CTRL_RTC_EN_MASK) >> RTC_CTRL_RTC_EN_SHIFT);
54+
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
55+
56+
const bool rtc_init_done = ((RTC->CTRL & RTC_CTRL_RTC_EN_MASK) >> RTC_CTRL_RTC_EN_SHIFT);
57+
58+
/* If RTC is not initialized, then disable the clock gate on exit. */
59+
if(!rtc_init_done) {
60+
rtc_free();
61+
}
62+
63+
return (rtc_init_done & rtc_time_set);
4864
}
4965

5066
time_t rtc_read(void)
@@ -57,6 +73,8 @@ void rtc_write(time_t t)
5773
RTC_StopTimer(RTC);
5874
RTC->COUNT = t;
5975
RTC_StartTimer(RTC);
76+
77+
rtc_time_set = true;
6078
}
6179

6280
#endif

targets/targets.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@
766766
"macros": ["CPU_LPC54114J256BD64_cm4", "FSL_RTOS_MBED"],
767767
"inherits": ["Target"],
768768
"detect_code": ["1054"],
769-
"device_has": ["USTICKER", "ANALOGIN", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "FLASH"],
769+
"device_has": ["USTICKER", "RTC", "ANALOGIN", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "FLASH"],
770770
"release_versions": ["2", "5"],
771771
"device_name" : "LPC54114J256BD64"
772772
},
@@ -777,7 +777,7 @@
777777
"is_disk_virtual": true,
778778
"macros": ["CPU_LPC54628J512ET180", "FSL_RTOS_MBED"],
779779
"inherits": ["Target"],
780-
"device_has": ["USTICKER", "ANALOGIN", "EMAC", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "FLASH", "TRNG"],
780+
"device_has": ["USTICKER", "RTC", "ANALOGIN", "EMAC", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "FLASH", "TRNG"],
781781
"features": ["LWIP"],
782782
"device_name" : "LPC54628J512ET180",
783783
"overrides": {

0 commit comments

Comments
 (0)