This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C1294NCPDT: The RTC counter would be reset after system reset.

Part Number: TM4C1294NCPDT
Other Parts Discussed in Thread: EK-TM4C1294XL

Hi, TI teams,

I used TI EK-TM4C1294XL board to do a RTC experiment, I enable the RTC as below,

HibernateEnableExpClk(0);

HibernateRTCEnable();

HibernateCounterMode(HIBERNATE_COUNTER_24HR);

I print the RTC time with seconds via UART, the time is counted from "F0C3F000".

Then I press the reset button to reset the system, the RTC time would be reset to "F0C3F000", but I want it to continue counting.

I would to know if the RTC time could be continue counting after system reset? How to config the RTC?

I am looking forward for your reply.

Regards,

eric

  • First, I suggest you upgrade your TivaWare library to the current version 2.1.4.178.

    Yes, the RTC can continue to track time unless both Vdd and Vbat are removed. The simple example in TivaWare fails to check that the hibernate module is already enabled and re-initializes the hibernate module. Changing main() like this avoids re-initializing the hibernation module:

    int
    main(void)
    {
        bool bUpdate;
        uint32_t ui32SysClock, ui32Status, ui32HibernateCount, ui32Len;
        int32_t i32CmdStatus;
    
        //
        // Run from the PLL at 120 MHz.
        //
        ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                               SYSCTL_OSC_MAIN |
                                               SYSCTL_USE_PLL |
                                               SYSCTL_CFG_VCO_480), 120000000);
    
        //
        // Configure the device pins.
        //
        PinoutSet(false, false);
    
        //
        // Enable UART0
        //
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    
        //
        // Initialize the UART for console I/O.
        //
        UARTStdioConfig(0, 115200, ui32SysClock);
    
        //
        // Enable the hibernate module.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);
    
        //
        // Initialize these variables before they are used.
        //
        ui32Status = 0;
        ui32HibernateCount = 0;
    
        //
        // Check to see if Hibernation module is already active, which could mean
        // that the processor is waking from a hibernation.
        //
        if(HibernateIsActive())
        {
            //
            // Read the status bits to see what caused the wake.  Clear the wake
            // source so that the device can be put into hibernation again.
            //
            ui32Status = HibernateIntStatus(0);
            HibernateIntClear(ui32Status);
    
            //
            // Store the common part of the wake information message into a buffer.
            // The wake source will be appended based on the status bits.
            //
            ui32Len = usnprintf(g_pcWakeBuf, sizeof(g_pcWakeBuf),
                                "Wake Due To : ");
    
            //
            // Wake was due to RTC match.
            //
            if(ui32Status & HIBERNATE_INT_RTC_MATCH_0)
            {
                ui32Len = usnprintf(&g_pcWakeBuf[ui32Len],
                                    sizeof(g_pcWakeBuf) - ui32Len, "%s",
                                    g_ppcWakeSource[0]);
            }
    
            //
            // Wake was due to Reset button.
            //
            else if(ui32Status & HIBERNATE_INT_RESET_WAKE)
            {
                ui32Len = usnprintf(&g_pcWakeBuf[ui32Len],
                                    sizeof(g_pcWakeBuf) - ui32Len, "%s",
                                    g_ppcWakeSource[1]);
            }
    
            //
            // Wake was due to the External Wake pin.
            //
            else if(ui32Status & HIBERNATE_INT_PIN_WAKE)
            {
                ui32Len = usnprintf(&g_pcWakeBuf[ui32Len],
                                    sizeof(g_pcWakeBuf) - ui32Len, "%s",
                                    g_ppcWakeSource[2]);
            }
    
            //
            // Wake was due to GPIO wake.
            //
            else if(ui32Status & HIBERNATE_INT_GPIO_WAKE)
            {
                ui32Len = usnprintf(&g_pcWakeBuf[ui32Len],
                                    sizeof(g_pcWakeBuf) - ui32Len, "%s",
                                    g_ppcWakeSource[3]);
            }
    
            //
            // If the wake is due to any of the configured wake sources, then read
            // the first location from the battery-backed memory, as the
            // hibernation count.
            //
            if(ui32Status & (HIBERNATE_INT_PIN_WAKE | HIBERNATE_INT_RTC_MATCH_0 |
                             HIBERNATE_INT_GPIO_WAKE | HIBERNATE_INT_RESET_WAKE))
            {
                HibernateDataGet(&ui32HibernateCount, 1);
            }
        }
        else
        {
            //
            // Configure Hibernate module clock.
            //
            HibernateEnableExpClk(ui32SysClock);
    
            //
            // If the wake was not due to the above sources, then it was a system
            // reset.
            //
            if(!(ui32Status & (HIBERNATE_INT_PIN_WAKE | HIBERNATE_INT_RTC_MATCH_0 |
                               HIBERNATE_INT_GPIO_WAKE | HIBERNATE_INT_RESET_WAKE)))
            {
                //
                // Configure the module clock source.
                //
                HibernateClockConfig(HIBERNATE_OSC_LOWDRIVE);
    
                //
                // Store that this was a system restart not wake from hibernation.
                //
                ui32Len = usnprintf(g_pcWakeBuf, sizeof(g_pcWakeBuf), "%s",
                                    g_ppcWakeSource[4]);
    
                //
                // Set flag to indicate we need a valid date.  Date will then be set
                // in the while(1) loop.
                //
                g_bSetDate = true;
                //
                // Store the hibernation count message into the respective char buffer.
                //
                usnprintf(g_pcHibBuf, sizeof(g_pcHibBuf), "Hibernate count = %u",
                          ui32HibernateCount);
    
                //
                // Enable RTC mode.
                //
                HibernateRTCEnable();
    
                //
                // Configure the hibernate module counter to 24-hour calendar mode.
                //
                HibernateCounterMode(HIBERNATE_COUNTER_24HR);
    
            }
    
        }
    
    
        //
        // Configure GPIOs used as Hibernate wake source.  PK6 is configured as a
        // wake source.  It is available on EK-TM4C1294XL BoosterPack 2 (X7-17)
        // and on the breadboard breakout connector (X11-63).  Short to ground to
        // generate a wake request.
        //
        GPIOPadConfigSet(GPIO_PORTK_BASE, GPIO_PIN_6, GPIO_STRENGTH_2MA,
                         (GPIO_PIN_TYPE_WAKE_LOW | GPIO_PIN_TYPE_STD_WPU));
    
        //
        // Initialize the buttons
        //
        ButtonsInit();
    
        //
        // Initialize the SysTick interrupt to process user buttons.
        //
        SysTickPeriodSet(SysCtlClockGet() / 30);
        SysTickEnable();
        SysTickIntEnable();
        IntMasterEnable();
    
        //
        // Enable processor interrupts.
        //
        IntMasterEnable();
    
        //
        // If hibernation count is very large, it may be that there was already
        // a value in the hibernate memory, so reset the count.
        //
        ui32HibernateCount = (ui32HibernateCount > 10000) ? 0 : ui32HibernateCount;
    
        //
        // Initialize the necessary flags before entering indefinite loop.
        //
        g_bHibernate = false;
    
        //
        // Clear the terminal and print the banner.
        //
        UARTprintf("\033[2J\033[H");
        UARTprintf("%s\n", g_pcWakeBuf);
        UARTprintf("Welcome to the Tiva C Series TM4C1294 LaunchPad!\n");
        UARTprintf("Hibernation Example\n");
        UARTprintf("Type 'help' for a list of commands\n");
        UARTprintf("> ");
        UARTFlushTx(false);
    
        //
        // Set flag that next update is the first ever.
        // This triggers a screen clear on next update.
        //
        g_bFirstUpdate = true;
        g_ui8FirstLine = 5;
    
        //
        // Loop forever.
        //
        while(1)
        {
            //
            // Check the flag which indicates that an invalid time is in hibernate
            // module.  If set then force setting to the default time.
            //
            if(g_bSetDate)
            {
                //
                // Clear the flag.
                //
                g_bSetDate = false;
    
                //
                // Set the date to the default values and commit it to the
                // hibernate module.
                //
                DateTimeDefaultSet();
                DateTimeSet();
            }
    
            //
            // Update the buffer that displays date and time on the main
            // screen.
            //
            bUpdate = DateTimeDisplayGet(g_pcDateTimeBuf,
                                         sizeof(g_pcDateTimeBuf));
    
            //
            // Is a new value of date and time available to be displayed?
            //
            if(bUpdate == true)
            {
                //
                // Check if this is first ever update.
                //
                if(g_bFirstUpdate == false)
                {
                    //
                    // Save current cursor position.
                    //
                    UARTprintf("\033[s");
                }
    
                //
                // Resend the current status and time.
                //
                UARTprintf("\033[%d;1H\033[K", g_ui8FirstLine);
                UARTprintf("The current date and time is: %s\n", g_pcDateTimeBuf);
                UARTprintf("\033[K");
                UARTprintf("%s\n", g_pcHibBuf);
                UARTprintf("\033[K");
                UARTprintf("To Hibernate type 'hib' and press ENTER or press "
                           "USR_SW1\n");
    
                //
                // Check if this is first ever update.
                //
                if(g_bFirstUpdate == false)
                {
                    //
                    // Restore cursor position.
                    //
                    UARTprintf("\033[u");
    
                }
                else
                {
                    UARTprintf(">");
                }
    
                //
                // Flush the TX Buffer.
                //
                UARTFlushTx(false);
    
                //
                // Clear the first update flag.
                //
                g_bFirstUpdate = false;
    
            }
    
            //
            // Check if a carriage return is present in the UART Buffer.
            //
            if(UARTPeek('\r') != -1)
            {
                //
                // A '\r' was detected, so get the line of text from the user.
                //
                UARTgets(g_pcInputBuf,sizeof(g_pcInputBuf));
    
                //
                // Pass the line from the user to the command processor.
                // It will be parsed and valid commands executed.
                //
                i32CmdStatus = CmdLineProcess(g_pcInputBuf);
    
                //
                // Handle the case of bad command.
                //
                if(i32CmdStatus == CMDLINE_BAD_CMD)
                {
                    UARTprintf("Command not recognized!\n");
                }
    
                //
                // Handle the case of too many arguments.
                //
                else if(i32CmdStatus == CMDLINE_TOO_MANY_ARGS)
                {
                    UARTprintf("Too many arguments for command processor!\n");
                }
    
                //
                // Handle the case of too few arguments.
                //
                else if(i32CmdStatus == CMDLINE_TOO_FEW_ARGS)
                {
                    UARTprintf("Too few arguments for command processor!\n");
                }
    
                UARTprintf(">");
            }
    
            //
            // Check if user wants to enter hibernation.
            //
            if(g_bHibernate == true)
            {
                //
                // Increment the hibernation count, and store it in the
                // battery-backed memory.
                //
                ui32HibernateCount++;
                HibernateDataSet(&ui32HibernateCount, 1);
    
                //
                // Yes - Clear the flag.
                //
                g_bHibernate = false;
                AppHibernateEnter();
            }
        }
    }