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.

RE: TM4C123GH6PM:Hibernate mode problems

Hello,Mr Cb1

      first thing,Thank you very much.your encouragement  really inspired me greatly

      Mr Cb1,what if my english become so native like you in future,so i can understand your careful suggestions thoroughly , hhh.

      the day after tomorrow ,the contest will be held,and i can only use tm4c or C2000 now(just some basic functions),really anxious now.

    

     I made mistakes between PF0 and PF4,so i need to unlock PF0 tomorrow (it's so late now(24:00))

 Dear Mr Cb1,I have another question about hibernate, Could you help me out,  my board always get tripped in  _HibernateWriteComplete() in  HibernateEnableExpClk(uint32_t ui32HibClk) ,and it cannot awake by RTC Counter,i can only use ROM_SysCtlReset() to get it into reset. below is code.

And thank all my other friends helpped me.

/*
 * hibernateCBC.c
 *
 *通过按键进入休眠,再次按键跳出休眠,或者5秒后自动走出休眠
 *  Created on: 2019年8月4日
 *      Author: Administrator
 */
#include <stdint.h>
#include <stdbool.h>
#include <time.h>
#include "inc/hw_memmap.h"
#include "inc/hw_ints.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/hibernate.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/rom.h"
#include "driverlib/uart.h"
#include "utils/ustdlib.h"
#include "drivers/buttons.h"
#include "inc/hw_hibernate.h"
#include "driverlib/pin_map.h"
#include "driverlib/timer.h"
#include "driverlib/interrupt.h"
#include "utils/uartstdio.h"

//void HibernateHandler(void);
void Timer0A_Init(void);
void Timer0A_ISR(void);

static volatile bool bSelectPressed = 0;


#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif


void
ConfigureUART(void)
{
    //
    // Enable the GPIO Peripheral used by the UART.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    //
    // Enable UART0
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Configure GPIO Pins for UART mode.
    //
    /*ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
    ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);*/

    //
    // Use the internal 16MHz oscillator as the UART clock source.
    //
    UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);

    //
    // Initialize the UART for console I/O.
    //
    UARTStdioConfig(0, 115200, 16000000);
}


int
main(void)
{

    uint32_t ui32Status = 0;
    uint32_t ui32HibernateCount = 0;

    ROM_FPULazyStackingEnable();

    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    ConfigureUART();

    ButtonsInit();
    Timer0A_Init();

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);
    while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_HIBERNATE)) ;
    SysCtlDelay(SysCtlClockGet()/3);    //延时1秒使能振荡器
    HibernateEnableExpClk(SysCtlClockGet());
    HibernateClockConfig(HIBERNATE_OSC_LOWDRIVE);
    if(HibernateIsActive())     //休眠模式的时钟是否使能
    {
        ui32Status = HibernateIntStatus(0);      //清除中断状态,即便暂时没有使能中断
        HibernateIntClear(ui32Status);

        if(ui32Status & HIBERNATE_INT_PIN_WAKE)
        {
             UARTprintf("button awake\n");
        }

        else if(ui32Status & HIBERNATE_INT_RTC_MATCH_0)
        {
            UARTprintf("timeout awake\n");
        }
        else
        {
            UARTprintf("Reset awake\n");
        }

        if(ui32Status & (HIBERNATE_INT_PIN_WAKE | HIBERNATE_INT_RTC_MATCH_0))
        {
            HibernateDataGet(&ui32HibernateCount, 1);
        }
    }


    /*if(!(ui32Status & (HIBERNATE_INT_PIN_WAKE | HIBERNATE_INT_RTC_MATCH_0)))
    {

        HibernateClockConfig(HIBERNATE_OSC_LOWDRIVE);


        UARTprintf("Reset awake\n");

    }*/



    bSelectPressed = 0;

    while(!bSelectPressed)
    {
         SysCtlDelay(SysCtlClockGet()/30);   //wait 100ms
    }

    UARTprintf("Release the Button\n");

    while(bSelectPressed)
    {
    }

    //ui32HibernateCount = (ui32HibernateCount > 10000) ? 0 : ui32HibernateCount;

    ui32HibernateCount++;
    HibernateDataSet(&ui32HibernateCount, 1);

    UARTprintf("Intcnt:%d",ui32HibernateCount);

    HibernateRTCEnable();
    HibernateRTCSet(0);
    HibernateRTCMatchSet(0, 5);

    HibernateIntEnable(HIBERNATE_INT_PIN_WAKE |HIBERNATE_INT_RTC_MATCH_0);
    HibernateIntClear(HIBERNATE_INT_PIN_WAKE | HIBERNATE_INT_RTC_MATCH_0);
    //HibernateIntRegister(HibernateHandler);

    HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC);

    /*IntPrioritySet(HIBERNATE_INT_PIN_WAKE,0x20);
    IntPrioritySet(HIBERNATE_INT_RTC_MATCH_0,0x40);
    IntPrioritySet(TIMER_TIMA_TIMEOUT,0x60);
*/
    UARTprintf("Select to Hib");
    UARTprintf("Wake in 5 s,");
    UARTprintf("or press Select");
    UARTprintf("for immed. wake.\n");

    HibernateRequest();

    SysCtlDelay(SysCtlClockGet()/3);

    bSelectPressed = 0;
    while(!bSelectPressed)
    {
    }
    ROM_SysCtlReset();  //SysCtlReset()   软件复位

    while(1)
    {
    }
}

/*void HibernateHandler(void)
{
    uint32_t ui32Status;

    ui32Status = HibernateIntStatus(1);
    HibernateIntClear(ui32Status);

}*/

void Timer0A_Init(void)
{
        uint32_t ui32Period,SysPeriod,TimerFrequency;

        TimerFrequency = 100;

        SysPeriod = SysCtlClockGet();
        SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
        TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);   //设置时钟的类型为周期型的

        ui32Period =SysPeriod/ TimerFrequency;   //配置时钟的频率,10ms计数一次
        TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period - 1);

        IntMasterEnable();   //开主中断
        IntEnable(INT_TIMER0A);    //使能TIMER0A中断
        TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
        TimerEnable(TIMER0_BASE, TIMER_A);
}

void Timer0A_ISR(void)
{

    TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    uint8_t ui8Data, ui8Delta;
    //
    // Get buttons status using button debouncer driver
    //
    ui8Data = ButtonsPoll(&ui8Delta, 0);

    //
    // See if the select button was just pressed.
    //
    if(BUTTON_PRESSED(SELECT_BUTTON, ui8Data, ui8Delta))
    {
        //
        // Set a flag to indicate that the select button was just pressed.
        //
        bSelectPressed = 1;
    }

    //
    // Else, see if the select button was just released.
    //
    if(BUTTON_RELEASED(SELECT_BUTTON, ui8Data, ui8Delta))
    {
        //
        // Clear the button pressed flag.
        //
        bSelectPressed = 0;
    }
}



  • My friend,

    Such a 'contest' - which 'SO limits the designer's, 'Range of Solutions' - is outside of my group's experience & understanding.    Being relatively small - we must - most always - fully & properly, 'SURVEY a Broad Field of Solutions' - and not seize (too often prematurely) upon one which - although flashing brightly - may not prove best!   (when the 'glare' is turned down - and reality arrives...)

    We employ ARM Cortex MCUs (M0, M0+, M3, M4 & M7) from 4 vendors - we've almost 'zero' experience w/'4C123's hibernate.   (And the young college students who most recently 'mastered hibernate' - have been denied their past, 'well-earned, 'Verify' - and 'VOW Not to return here!')    And will 'Set social-media ON FIRE' - w/their disenchantment...

    They (have) noted that your 'Contest Concentration' leads to broad & diverging, 'Topics du jour!'   (i.e. you 'jump' from subject to subject - which is NOT how most effective college level courses are presented - and may not properly 'penetrate' into your long-term memory & full understanding...)   Might you visit & speak w/one of your instructors - and adopt the more, 'Normal/Customary' means of MCU review & study.    Often that's by MCU Peripheral - and this vendor's MCU manuals (even though (now) labeled 'OTHER' (how very reassuring/quaint that) are (superbly) broken down into JUST such, 'MCU Peripheral Sections.'   And (somehow) the MCU Peripherals 'retained their names' - perhaps just escaping the (none too impressive)  'other'  (i.e. 'LIKE-less') designation - at least for now...

  • Mr Cb1,your suggestions are really Instructive and must lead me to a more efficient way in future MCU learning,

    I am responsible for software in my contest team,so i only know something about MCU now,my teammates are responsible for hardware part,so i need to learn more about tm4c in case of something unknow.but as you see,something strange happend in my code ,it shows my understanding about this board is not very deep,so i need to solve my problems one by one.

    when i finish my contest  on 11 Aug,i will read your guide more carefully,as you said ,i need to know both software and hardware.and i will cheer up .

    Mr Cb1,i can only type these words at one time.(you know my english is not satisfactory,so i can't spend too much time on typing now)

    i have invite Bob to help see my code,hope he can help me out tonight.,see you later.

  • I am not sure what you are trying to do with the Hibernation module here. Are you trying to reduce power? Look at the examples in section 15.3 (starting on page 315) of C:\ti\TivaWare_C_Series-2.1.4.178\docs\SW-TM4C-DRL-UG-2.1.4.178.pdf

  • Dear Bob,thank you putting my messy questions into order.

    i spend much time on hibernate,i want to show my effort in power saving in contest and i don,t want to give this question up.

    it always goes into infinite  loop(writecomplete()  or intdefaulthandler()),

    and i also don,t know why  PF0 is always high when work as comp output port.

    dear bob,it,s 00:47 in China ,sleep is calling me .see you later.