lpcopen_3_02 code not according to LPC1857 UM10430 v3.0

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

lpcopen_3_02 code not according to LPC1857 UM10430 v3.0

1,068 Views
billsheng
Contributor II

On LPC1857 UM10430 v3.0 36.2 there have following remarks:

"

Remark: After initializing the 32 kHz oscillator, wait for 2 sec before writing to the RTC
registers (see Section 36.7.1).
Remark: Only write to the RTC registers when the 32 kHz oscillator is running. Repeated
writes to the RTC registers without the 32 kHz clock can stall the CPU. To confirm that the
32 kHz clock is running, read the Alarm timer counter register (DOWNCOUNTER, see
Table 787), which counts down from a preset value using the 1024 Hz clock signal derived
from the 32 kHz oscillator.

"

On LPC1857 UM10430 v3.0 34.2 there have following remark:

"

Remark: Only write to the Alarm timer registers when the 32 kHz oscillator is running.
Repeated writes to the Alarm timer registers without the 32 kHz clock can stall the CPU.
To confirm that the 32 kHz clock is running, read the Alarm timer counter register
(DOWNCOUNTER, see Table 787), which counts down from a preset value using the
1024 Hz clock signal derived from the 32 kHz oscillator.

"

The code in NXP\lpcopen_3_02_keil_iar_mcb1857\LPC43xx_18xx\chip_43xx_18xx\src\rtc_18xx_43xx.c  

/* Initialize the RTC peripheral */
void Chip_RTC_Init(LPC_RTC_T *pRTC)
{
Chip_Clock_RTCEnable();

/* 2-Second delay after enabling RTC clock */
LPC_ATIMER->DOWNCOUNTER = 2048;
while (LPC_ATIMER->DOWNCOUNTER);

/* Disable RTC */
Chip_RTC_Enable(pRTC, DISABLE);

/* Disable Calibration */
Chip_RTC_CalibCounterCmd(pRTC, DISABLE);

/* Reset RTC Clock */
Chip_RTC_ResetClockTickCounter(pRTC);

/* Clear counter increment and alarm interrupt */
pRTC->ILR = RTC_IRL_RTCCIF | RTC_IRL_RTCALF;
while (pRTC->ILR != 0) {}

/* Clear all register to be default */
pRTC->CIIR = 0x00;
pRTC->AMR = 0xFF;
pRTC->CALIBRATION = 0x00;
}

The code in Red color part, actually could not work as expected.

Following are the debug message for the timing:

"

(14:26:55.35) RTC: Start check downcounter with 2048
(14:26:55.41) RTC: End to check downcounter

"

It's only 60ms, not 2 second as expectation.

So the driver could not work on some MCU which has potencial internal RTC issue.

What's the correct code to cover this internal RTC remarks from user guide?

Labels (2)
Tags (1)
0 Kudos
4 Replies

795 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Bill,

    Thank you for your interest in NXP LPC product, I would like to provide service for you.

   I think this problem is related to the Alarm timer. I already reproduced your problem on my side, it seems the first time after reset, the alarm timer is not precise, because the DOWNCOUNTER already works, the write has no influence.

   I test it with the following code, it can get 2S now:

     Board_LED_Set(2, 1);
         Board_LED_Set(2, 0);
         LPC_CREG->CREG0 &= ~((1 << 3) | (1 << 2));     /* Reset 32Khz oscillator */
         LPC_CREG->CREG0 &= ~((1 << 0) | (1 << 1)); //disable 32Khz oscillator.
         Chip_Clock_RTCEnable();
         DEBUGOUT(" begin1 Downcounter=%x ; PresetCount=%x; enable=%x \n",LPC_ATIMER->DOWNCOUNTER,LPC_ATIMER->PRESET,LPC_ATIMER->ENABLE);
         LPC_ATIMER->PRESET=0;
         LPC_ATIMER->DOWNCOUNTER=0;
         DEBUGOUT("Downcounter=%x ; PresetCount=%x; enable=%x \n",LPC_ATIMER->DOWNCOUNTER,LPC_ATIMER->PRESET,LPC_ATIMER->ENABLE);
             Chip_ATIMER_Init(LPC_ATIMER, PresetCount);
         //LPC_ATIMER->DOWNCOUNTER=2048;
             DEBUGOUT("Downcounter=%x ; PresetCount=%x; enable=%x \n",LPC_ATIMER->DOWNCOUNTER,LPC_ATIMER->PRESET,LPC_ATIMER->ENABLE);
        while (LPC_ATIMER->DOWNCOUNTER);
         DEBUGOUT("Downcounter=%x ; PresetCount=%x; enable=%x \n",LPC_ATIMER->DOWNCOUNTER,LPC_ATIMER->PRESET,LPC_ATIMER->ENABLE);
         Board_LED_Set(2, 1);
         DEBUGSTR("\n End1");   //kerry add end

         Board_LED_Set(2, 1);
         Board_LED_Set(2, 0);
         //LPC_ATIMER->DOWNCOUNTER = 2048;
         DEBUGOUT("begin2 Downcounter=%x ; PresetCount=%x; enable=%x \n",LPC_ATIMER->DOWNCOUNTER,LPC_ATIMER->PRESET,LPC_ATIMER->ENABLE);
         Chip_Clock_RTCEnable();
         DEBUGOUT("Downcounter=%x ; PresetCount=%x; enable=%x \n",LPC_ATIMER->DOWNCOUNTER,LPC_ATIMER->PRESET,LPC_ATIMER->ENABLE);
         Chip_ATIMER_Init(LPC_ATIMER, PresetCount);
            //LPC_ATIMER->DOWNCOUNTER=2048;
      while (LPC_ATIMER->DOWNCOUNTER);
         DEBUGOUT("Downcounter=%x ; PresetCount=%x; enable=%x \n",LPC_ATIMER->DOWNCOUNTER,LPC_ATIMER->PRESET,LPC_ATIMER->ENABLE);
         Board_LED_Set(2, 1);
         DEBUGSTR("\n End2 ========================================\n");   //kerry add end‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The above code will get two times 2Seconds.

We can check the LED2 pin, this is the oscilloscope wave about the LED2 pin in MCB1857:

pastedImage_1.png

This is the printf data after just reset:

Begin1 begin1 Downcounter=6a3 ; PresetCount=800; enable=0
Downcounter=69e ; PresetCount=800; enable=0
Downcounter=0 ; PresetCount=0; enable=0
Downcounter=0 ; PresetCount=800; enable=0

 End1begin2 Downcounter=7fd ; PresetCount=800; enable=0
Downcounter=7f9 ; PresetCount=800; enable=0
Downcounter=0 ; PresetCount=800; enable=0

 End2 ========================================

but, even I can get the 2S now, I think there still have problems with the alarm timer, I am still working on it, and I need to check it with our according department.

After I get the updated information, I will let you know.

Please wait patiently.

You also can do the alarm timer test on your side, any updated information, please kindly let me know!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

795 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Bill,

   It's strange that, I have received your updated information in the email, but the post I can't see it.

This your updated information:

================================================================================

Hi Kerry,

 

Thanks for your efforts on this issue.

 

The headche problem we had that RTC module could not work as expected.

You could see following picture on the real device.

https://community.nxp.com/servlet/JiveServlet/downloadImage/2-975375-207887/RTCErrorWithDebugInfo.PN...

 

We made following work around.

"

               Chip_Clock_RTCEnable();

                for (waitMS = 0; waitMS < 2000; waitMS++)

                {

                LPC_RTC->CCR = value | (1uL << 4); // Disable calibration

                if ((LPC_RTC->CCR & 0x1FuL) == (value | (1uL << 4)))

                {

                                LPC_RTC->CALIBRATION = 0;      // Disable calibration

                                return(true); // Leave if it is done

                }

                            _BusyWaitMicroSeconds(1000uL); // Wait 1 millisecond

                }

 

"

From the testing, the leave time after RTC ready is around 1700ms.

But it's ugly that we have to disable calibration always in the loop.

We tested that move this disable calibration after delay 3.2 seconds, RTC could not work either.

 

It's appreciated that NXP could help us confirm the work around would not cause other problem.

========================================================================================

Actually, I have test the official RTC code, even the first time atimer is not precise, but the RTC still works OK.

It seems on your side, your RTC problem is caused the 2S time is not enough which is caused by the atimer.

Another suggestion, I think you still can refer to the lpcopen code

void Chip_RTC_Init(LPC_RTC_T *pRTC)
{
//    Chip_Clock_RTCEnable();

    /* 2-Second delay after enabling RTC clock */
//    LPC_ATIMER->DOWNCOUNTER = 2048;  //just add another 2S delay here
//    while (LPC_ATIMER->DOWNCOUNTER);

    /* Disable RTC */
    Chip_RTC_Enable(pRTC, DISABLE);

    /* Disable Calibration */
    Chip_RTC_CalibCounterCmd(pRTC, DISABLE);

    /* Reset RTC Clock */
    Chip_RTC_ResetClockTickCounter(pRTC);

    /* Clear counter increment and alarm interrupt */
    pRTC->ILR = RTC_IRL_RTCCIF | RTC_IRL_RTCALF;
    while (pRTC->ILR != 0) {}

    /* Clear all register to be default */
    pRTC->CIIR = 0x00;
    pRTC->AMR = 0xFF;
    pRTC->CALIBRATION = 0x00;
}

From my test, I find the first time 2S is not precise, because the altimer is running after reset, but the second 2S is precise.

So, I think, you also can add two altimer code, just make sure, before the RTC is enabled, there more than 2S.


Chip_ATIMER_Init(LPC_ATIMER, PresetCount);
while (LPC_ATIMER->DOWNCOUNTER);
You can try it on your side, whether it works ok on your side?


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

795 Views
billsheng
Contributor II

Hi Kerry,

It seems that someone blocked my comments to be posted.

I could just see that "正在审批".

We found that the RTC module not work problem could not be reproduced on every MCU.

On some specific manufacturing date, the possibility is quite high, e.g. the MCU label production date is 1725.

Which should be the 25 weeks' of 2017, the failed cases in our production found around 45%(52/112).

There is a quick way to reproduce it on some specific MCU samples.

a. Plug off external power  adapter, disconnect the MCU with RTC battery/capacitor.

(make the RTC module has no power, everything back to default)

b. Connect MCU with RTC battery/capacitor.

c. Plug in external power  adapter.

If you have detail question, you could also contact me via my office mail: bill.sheng@mt.com

About your following comments

"

Actually, I have test the official RTC code, even the first time atimer is not precise, but the RTC still works OK.

It seems on your side, your RTC problem is caused the 2S time is not enough which is caused by the atimer.

Another suggestion, I think you still can refer to the lpcopen code

"

We tested the lpcopen code on those failed MCU samples, it could not work.

It's not a simple 2s time wait there.

That's why the user manual had those remarks.

It seems that there have difference on the internal RTC with different MCU.

Best regards,

Bill

0 Kudos

795 Views
billsheng
Contributor II

Hi Kerry,

Thanks for your efforts on this issue.

The headache problem we had that RTC module could not work as expected.

You could see following picture on the real device.

RTCErrorWithDebugInfo.PNG

We made following work around.

"

               Chip_Clock_RTCEnable();

                for (waitMS = 0; waitMS < 2000; waitMS++)

                {

                LPC_RTC->CCR = value | (1uL << 4); // Disable calibration

                if ((LPC_RTC->CCR & 0x1FuL) == (value | (1uL << 4)))

                {

                                LPC_RTC->CALIBRATION = 0;      // Disable calibration

                                return(true); // Leave if it is done

                }

                            _BusyWaitMicroSeconds(1000uL); // Wait 1 millisecond

                }

"

From the testing, the leave time after RTC ready is around 1700ms.

We tested on the failed 5pcs MCU samples, which found RTC not work problem, it could fix the issue.

But it's ugly that we have to disable calibration always in the loop.

We tested that move this disable calibration after delay 3.2 seconds, RTC could not work either.

It's appreciated that NXP could help us confirm the work around would not cause other problem.

0 Kudos