Skip to content

Commit 2f63fa7

Browse files
committed
Merge pull request #815 from toyowata/master
Targets: LPC4337 - Fix RTC clock setting issue
2 parents ab46ea6 + 7b62e7d commit 2f63fa7

File tree

1 file changed

+12
-2
lines changed
  • libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX

1 file changed

+12
-2
lines changed

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/rtc_api.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,20 @@
3535
* The RTC may already be running, so we should set it up
3636
* without impacting if it is the case
3737
*/
38+
3839
void rtc_init(void) {
39-
LPC_RTC->CCR = 0x00;
40+
// Return, if already enabled
41+
if (LPC_RTC->CCR & 1)
42+
return;
43+
44+
// Enable 1kHz output of 32kHz oscillator
45+
LPC_CREG->CREG0 &= ~((1 << 3) | (1 << 2));
46+
LPC_CREG->CREG0 |= (0x03 << 6) | (1 << 1) | (1 << 0);
4047

41-
LPC_RTC->CCR |= 1 << 0; // Ensure the RTC is enabled
48+
// Enable RTC
49+
do {
50+
LPC_RTC->CCR |= 1 << 0;
51+
} while ((LPC_RTC->CCR & 1) == 0);
4252
}
4353

4454
void rtc_free(void) {

0 commit comments

Comments
 (0)