Hi all:
One of my ongoing projects requires hibernation, and then wake up through reset pin. Because the MCU used is TM4C123, I first perform functional verification on the TM4C123 red lanuchpad.
And refer to the reference routine of hibernation in dk-tm4c123g in tivaware. But my program couldn't hibernate. I used LED flicker to indicate if the program was hibernating. The LED kept flickering after the program
was running, so it didn't go into hibernation. My code is as follows. What tips can help me solve this problem? Thank you very much.
void
SysTickWait(uint32_t ui32Ticks)
{
ui32Ticks += g_ui32SysTickCount;
while(g_ui32SysTickCount <= ui32Ticks)
{
}
}
//*****************************************************************************
//
//! \addtogroup example_list
//! <h1>Blinky (blinky)</h1>
//!
//! A very simple example that blinks the on-board LED using direct register
//! access.
//
//*****************************************************************************
void SysTickHandler(void)
{
//
// Increment the tick counter.
//
g_ui32SysTickCount++;
}
int
main(void)
{
volatile uint32_t ui32Loop, k;
uint32_t ui32Status = 0;
uint32_t ui32HibernateCount = 0;
//
// Enable lazy stacking for interrupt handlers. This allows floating-point
// instructions to be used within interrupt handlers, but at the expense of
// extra stack usage.
//
ROM_FPULazyStackingEnable();
//
// Set the clocking to run directly from the crystal.
//
ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
//
// Enable the GPIO port that is used for the on-board LED.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
//
// Check if the peripheral access is enabled.
//
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOF))
{
}
//
// Enable the GPIO pin for the LED (PF3). Set the direction as output, and
// enable the GPIO pin for digital function.
//
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3);
//
// Set up systick to generate interrupts at 100 Hz.
//
ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100);
ROM_SysTickIntEnable();
ROM_SysTickEnable();
//
// Enable the Hibernation module.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);
if(HibernateIsActive())
{
//
// Read the status bits to see what caused the wake.
//
ui32Status = HibernateIntStatus(0);
HibernateIntClear(ui32Status);
//
// Wake was due to the push button.
//
if(ui32Status & HIBERNATE_INT_PIN_WAKE)
{
}
//
// Wake was due to RTC match
//
else if(ui32Status & HIBERNATE_INT_RTC_MATCH_0)
{
}
//
// Wake is due to neither button nor RTC, so it must have been a hard
// reset.
//
else
{
}
}
HibernateEnableExpClk(ROM_SysCtlClockGet());
if(!(ui32Status & (HIBERNATE_INT_PIN_WAKE | HIBERNATE_INT_RTC_MATCH_0)))
{
//
// Configure the module clock source.
//
HibernateClockConfig(HIBERNATE_OSC_LOWDRIVE);
//
// Wait a couple of seconds in case we need to break in with the
// debugger.
//
SysTickWait(3 * 100);
//
// Allow time for the crystal to power up. This line is separated from
// the above to make it clear this is still needed, even if the above
// delay is removed.
//
SysTickWait(15);
}
ui32HibernateCount = (ui32HibernateCount > 10000) ? 0 : ui32HibernateCount;
ui32HibernateCount++;
HibernateDataSet(&ui32HibernateCount, 1);
//
// Loop forever.
//
while(1)
{
// LED flash loop 10 times
for(k = 0; k < 10; k++)
{
//
// Turn on the LED.
//
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_PIN_3);
//
// Delay for a bit.
//
for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++)
{
}
//
// Turn off the LED.
//
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0x0);
//
// Delay for a bit.
//
for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++)
{
}
}
// start hibernate
HibernateWakeSet(HIBERNATE_WAKE_RESET);
HibernateRequest();
SysTickWait(100);
}
}