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.

TM4C123GH6PM: tm4c123gh6pm Hibernate Mode to solve my problem:rest for a while and work for a while.

Part Number: TM4C123GH6PM

/*
 * HibernateTest.c
 *
 *  Created on: 2019年7月26日
 *      Author: Administrator
 */

#include <stdint.h>
#include <stdbool.h>
#include "utils/ustdlib.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"
#include "driverlib/debug.h"
#include "driverlib/hibernate.h"
#include "driverlib/gpio.h"

int main(void)
{
    SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x08);//1000
    //使能低功耗模式
    SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);
    //Enables the Hibernation module for operation
    HibernateEnableExpClk(SysCtlClockGet());
    //Enables GPIO retention(保留) after wake from hibernation.
    HibernateGPIORetentionEnable();
    SysCtlDelay(64000000);
    //低功耗模式下唤醒引脚配置
    //HibernateWakeSet(HIBERNATE_WAKE_PIN);
    HibernateRTCEnable();
    HibernateRTCSet(0);
   // HibernateRTCEnable();
    HibernateRTCMatchSet(0,5);//RTC唤醒时间5s
    HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC);
    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_3, ~GPIO_PIN_3);

    HibernateRequest();
    while(1)
    {
    }
}

my debug port will be locked after this code excuting,so I need to  use LM FlashPro  to unlock ,I am a little scared now,hhh.

could you please teach me how to use Hibernate Mode,or some other advice to save power consumption of my 123gxl.thank you

I read some material about sleep mode and deep mode in datasheet,But ,......,don't understand clearly ,Bob Ralph Cb1 or my other friends

HELP ME.

  • Hi Liguo,

      I don't see you configure the hibernate clock source by calling 

    HibernateClockConfig(HIBERNATE_OSC_LOWDRIVE);

    This may be the reason that your device is locked. The device tries to go into hibernate mode without the 32kHz crystal enabled. Since the RTC clock is not running without a crystal, there is never a RTC wakeup. The device is forever in hibernate. If you want to go into hibernate mode then you need to enable the external 32KHz crystal. See the below snippet of code presented in the Peripheral Driver Library user's guide.. You can also reference the similar example code in <TivaWare_Installation>/examples/boards/dk-tm4c123g/hibernate/hibernate.c

    uint32_t ui32Status;
    uint32_t pui32NVData[64];
    //
    // Need to enable the hibernation peripheral after wake/reset, before using
    // it.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);
    //
    // Wait for the Hibernate module to be ready.
    //
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_HIBERNATE))
    {
    }
    //
    // Enable clocking to the Hibernation module.
    //
    HibernateEnableExpClk(SysCtlClockGet());
    //
    // User-implemented delay here to allow crystal to power up and stabilize.
    //
    //
    // Configure the clock source for Hibernation module and enable the RTC
    // feature.
    //
    HibernateClockConfig(HIBERNATE_OSC_LOWDRIVE);
    HibernateRTCEnable();
    //
    // Set the RTC to 0 or an initial value. The RTC can be set once when the
    // system is initialized after the cold startup and then left to run. Or
    // it can be initialized before every hibernate.
    //
    HibernateRTCSet(0);
    //
    // Set the match 0 register for 30 seconds from now.
    //
    HibernateRTCMatchSet(0, HibernateRTCGet() + 30);
    //
    // Clear any pending status.
    //
    ui32Status = HibernateIntStatus(0);
    HibernateIntClear(ui32Status);
    
    //
    // Save the program state information. The state information is stored in
    // the pui32NVData[] array. It is not necessary to save the full 16 words
    // of data, only as much as is actually needed by the program.
    //
    HibernateDataSet(pui32NVData, 16);
    //
    // Configure to wake on RTC match.
    //
    HibernateWakeSet(HIBERNATE_WAKE_RTC);
    //
    // Request hibernation. The following call may return because it takes a
    // finite amount of time for power to be removed.
    //
    HibernateRequest();
    //
    // Need a loop here to wait for the power to be removed. Power is
    // removed while executing in this loop.
    //
    for(;;)
    {
    }

    Below steps are mentioned in the datasheet to enter the hibernate mode.

  • Good Morning ,Charels.

    I followed your guide and  test corectlly,thank you so much.

    when I read the explanation about HibernateClockConfig(HIBERNATE_OSC_LOWDRIVE);

    and feel puzzeld about this sentence: 

    HIBERNATE_OSC_DISABLE:: This option is used when an externally supplied oscillator

    //! is connected to the XOSC0 pin or to save power when the LFIOSC is used in

    //! devices that have an LFIOSC in the Hibernation module.

    I tried to change HIBERNATE_OSC_LOWDRIVE to HIBERNATE_OSC_DISABLE,as expected, it can't work.

    what it means “when an externally supplied oscillator //! is connected to the XOSC0”?

    I certainly change my clock from  SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

    to  SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN) to Verify my guess

    isn't SYSCTL_USE_OSC|SYSCTL_XTAL_16MHZ represents "an externally supplied oscillator  is connected to the XOSC0 pin"?

    and There has always been a confusion about Interrupt Status function Like HibernateIntStatus(bool bMasked),

     \param bMasked is false to retrieve the raw interrupt status, and true to
    //! retrieve the masked interrupt status.

    what it means raw interrupt status and the masked interrupt status,what's the difference between them?

    Thank you,Charles ,and all my other Friends.

  • Hi Liguo,

      The 16MHz is the "main" crystal connected to the OSC0, not the XOSC0. The main crystal can be the clock source for the entire device. It is also used as the source for the on-chip PLL for which you can select as a clock source running at higher frequency (i.e. 80MHz) The XOSC0 needs to be connected to either a 32kHz crystal or a 32kHz clock. On your launchpad there is the 32kHz crystal connected to the XOSC0 and therefore you need to enable the 32kHz oscillator. If you directly feed an external 32kHz oscillator clock into the XOSC (this may be the case if you have your custom board) then you can bypass or disable the 32kHz oscillator. 

  • Dear Charles:

    thank you for your help.

    now I am confused about when the board goes into hibernate mode,is it after HibernateRequest();I met an example that does't use HibernateRequest()

    but works well too.

    and There has always been a confusion about Interrupt Status function Like HibernateIntStatus(bool bMasked),

     \param bMasked is false to retrieve the raw interrupt status, and true to
    //! retrieve the masked interrupt status.

    what it means raw interrupt status and the masked interrupt status,what's the difference between them?

    Thank you,Charles .

  •  The device goes into hibernate mode after you call HibernateRequest(). I will suggest you read the datasheet for hibernate mode operation. Below is the excerpt from the datasheet.

    The Hibernation module power source is determined dynamically. The supply voltage of the
    Hibernation module is the larger of the main voltage source (VDD) or the battery/auxilliary voltage
    source (VBAT). The Hibernation module also has an independent clock source to maintain a real-time
    clock (RTC) when the system clock is powered down. Hibernate mode can be entered through one
    of two ways:
    ¡ The user initiates hibernation by setting the HIBREQ bit in the Hibernation Control (HIBCTL)
    register
    ¡ Power is arbitrarily removed from VDD while a valid VBAT is applied

    All modules (i.e. Hibernate, SSI, UART, GIO and etc) have the same interrupt architecture. There is an raw interrupt (xxxRIS) and a masked interrupt (xxxMIS). When an interrupt event happens the raw interrupt flag is set. However, do you want to signal the CPU? If your application wants to signal the CPU with an interrupt event then you will need to enable it. To enable the interrupt so that it will signal the CPU you will need to set the xxxIM register. Think of a simple AND gate. The two inputs to the AND gate are the RIS and the IM and the output is the MIS. When you call HibernateIntStatus(false) you are checking the xxxRIS status flags. When you call HibernateIntStatus(true) you are checking the xxxMIS flags. 

      I think you need to read the Peripheral driver library user's guide and it is explained. 

  • Thank you so much,Charles,I will learn to read these dataSheets more.But sometimes I really can't understand what it means,hhh.

  • Hello Mr. Wang,

    Vendor's Charles has given direct & detailed guidance - most excellent - we are glad to note that you have (properly) thanked him.

    His advice regarding a, (perhaps) slower and repeat reading of the MCU Manual - also proves most sound.

    Now w/in this past week - my young team provided advice to you - suggested was  your, 'Finding & Study/Reviewing w/others!'     This will enhance your grasp of English -  as well as your understanding and comfort level - w/these powerful - yet complex MCUs.   You may discover a team member who is 'best' at English - while you (quickly) become the MCU 'expert.'    Our young staff notes that you have (very) broad & wide ranging interests - which (likely) signals that you are NOT Following a standard college Engineering/Programming curriculum.    We don't believe that's optimal - as 'Scattered Learning' - most always - is 'Short-Term Learning' - as you've insufficient time allotted to Each MCU Peripheral...   The MCU manual is deliberately designed into 'Peripheral Sections' - which serves to 'Unify & focus Learning' - and has been proven to strengthen neurological connections.    Skipping often - from the discipline of, "One MCU Peripheral at a time' - may delay your understanding - and be 'too soon' clouded - even forgotten.

    One last point - you have just 'Verified' your own post.   In reality - it was Vendor's Charles post - which (should have) been Verified.   As his post - properly guided - and enabled your issue resolution.    (The not too well known purpose (apparently) of the 'Verify' - is the speeded & eased direction of 'Future Thread Viewers' - to that post - which indeed 'Solved the Issue at hand!    I believe the choice of the word 'Verify' was mistaken - as it has a (near) double meaning:

    • your post can confirm the correctness of another post (which actually resolved) your issue or problem.   Marking your post - which simply 'confirms the correctness of (another's) earlier posting - is a mistake.   (New posters - arriving at your thread - find 'No key content - w/in your Confirming Post - thus confusion reigns!)    
    • the earlier post - which led to the resolution of your issue - is that post (alone) which should be 'Marked by the Green Verify.'
    • my team believes that 'Verify' proves too vague - and should be replaced (sooner rather than later) w/'RESOLVING POST!'    That's a far stronger indicator of proper post marking - and even though 'NIH' - it deserves high consideration.

    Posters - especially those 'outsiders' - who make regular & effort-heavy/detailed forum contributions - should have their successful efforts rewarded!   The present 'Verify' method is seriously flawed - and is quickly & easily corrected...  

  • oh ,Mr Cb1,I don't know why I can't get your reply in time, fortunately,i always review your suggestions.hhh.

    Thank you for your careful remind,I will Correct my mistakes in future.

    and Mr Cb1,your observation is thorouly correct  ,I am trying to quickly master a large number of peripherals,you know ,I

    am running for a competition,which is urgent,I am afraid of I me t a problem i even don't meet  before.

    I will follow your advice and  slow down my learning speed in MCU,to master a peripheral completely at one time.

    But  in recent days ,maybe i will try to learn more basic  peripheral functions in case of Completely unknown.