Sample code: Waking up Deep Sleep by WDT

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
KaKo_4074056
Level 4
Level 4
Distributor - Marubun (Japan)
First like given First solution authored 25 replies posted

Hi Experts,

I want sample code that wakes up from Deep Sleep by WDT on CY8CKIT-147. Do you have this sample code? I referred to a sample code on PSoC4200M, but it doesn't work on PSoC4100PS.

Thanks !

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I tried with 4200M sample but it did not come back from DeepSleep.

After a few hours of code juggling, I found that if I place CySysWdtUnmaskInterrupt()

before CySysPmDeepSleep(), my CY8CKIT-147 could come back from DeepSleep like below.

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

        CySysWdtUnmaskInterrupt() ;
     
        CySysPmDeepSleep() ;
     
        CySysWdtMaskInterrupt() ;

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

Schematic

001-schematic.JPG

Global Signal (WDT) config

003-GlobalSignal-WDT.JPG

Pin assignment

002-pin-assignment.JPG

main.c

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

#include "project.h"

#include "stdio.h"

#define LED_ON  (1u)

#define LED_OFF (0u)

#define STR_LENGTH 64

char str[STR_LENGTH + 1] ; /* print buffer */

void print(char *str)

{

    UART_UartPutString(str) ;

}

void clear_wdt_intr(void)

{

    CySysWdtClearInterrupt() ;

}

void enable_wdt_reset(void)

{

    CySysWdtEnable() ;  

}

void disable_wdt_reset(void)

{

    CySysWdtDisable() ;

}

void init_hardware(void)

{

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

    LED_Write(LED_OFF) ; /* turn LED OFF */

    wdt_isr_ClearPending() ;

    wdt_isr_StartEx(clear_wdt_intr) ;

}

void splash(void)

{

    snprintf(str, STR_LENGTH, "WDT Wake-up test (%s %s)\n", __DATE__, __TIME__) ;

    print(str) ;

    while(UART_SpiUartGetTxBufferSize())

        ;

}

int main(void)

{

    init_hardware() ;

  

    splash() ;

  

    for(;;)

    {

        LED_Write(LED_ON) ;

        CyDelay(1000) ;

        print("Entering Deep Sleep ... \n") ;

        while(UART_SpiUartGetTxBufferSize())

            ;

        UART_Stop() ;

        LED_Write(LED_OFF) ;

      

        CySysWdtUnmaskInterrupt() ;

      

        CySysPmDeepSleep() ;

      

        CySysWdtMaskInterrupt() ;

      

        UART_Start() ;

        print("Woke-up!\n") ;

        while(UART_SpiUartGetTxBufferSize())

            ;

        LED_Write(LED_ON) ;

        CyDelay(1000) ;

    }

}

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

Serial Output (TeraTerm)

000-TeraTerm.JPG

moto

View solution in original post

0 Likes
3 Replies
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I tried with 4200M sample but it did not come back from DeepSleep.

After a few hours of code juggling, I found that if I place CySysWdtUnmaskInterrupt()

before CySysPmDeepSleep(), my CY8CKIT-147 could come back from DeepSleep like below.

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

        CySysWdtUnmaskInterrupt() ;
     
        CySysPmDeepSleep() ;
     
        CySysWdtMaskInterrupt() ;

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

Schematic

001-schematic.JPG

Global Signal (WDT) config

003-GlobalSignal-WDT.JPG

Pin assignment

002-pin-assignment.JPG

main.c

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

#include "project.h"

#include "stdio.h"

#define LED_ON  (1u)

#define LED_OFF (0u)

#define STR_LENGTH 64

char str[STR_LENGTH + 1] ; /* print buffer */

void print(char *str)

{

    UART_UartPutString(str) ;

}

void clear_wdt_intr(void)

{

    CySysWdtClearInterrupt() ;

}

void enable_wdt_reset(void)

{

    CySysWdtEnable() ;  

}

void disable_wdt_reset(void)

{

    CySysWdtDisable() ;

}

void init_hardware(void)

{

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

    LED_Write(LED_OFF) ; /* turn LED OFF */

    wdt_isr_ClearPending() ;

    wdt_isr_StartEx(clear_wdt_intr) ;

}

void splash(void)

{

    snprintf(str, STR_LENGTH, "WDT Wake-up test (%s %s)\n", __DATE__, __TIME__) ;

    print(str) ;

    while(UART_SpiUartGetTxBufferSize())

        ;

}

int main(void)

{

    init_hardware() ;

  

    splash() ;

  

    for(;;)

    {

        LED_Write(LED_ON) ;

        CyDelay(1000) ;

        print("Entering Deep Sleep ... \n") ;

        while(UART_SpiUartGetTxBufferSize())

            ;

        UART_Stop() ;

        LED_Write(LED_OFF) ;

      

        CySysWdtUnmaskInterrupt() ;

      

        CySysPmDeepSleep() ;

      

        CySysWdtMaskInterrupt() ;

      

        UART_Start() ;

        print("Woke-up!\n") ;

        while(UART_SpiUartGetTxBufferSize())

            ;

        LED_Write(LED_ON) ;

        CyDelay(1000) ;

    }

}

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

Serial Output (TeraTerm)

000-TeraTerm.JPG

moto

0 Likes
KaKo_4074056
Level 4
Level 4
Distributor - Marubun (Japan)
First like given First solution authored 25 replies posted

Hi moto,

Thank you! It looks like that your code works in my environment. Why does the device not wake up from Deep Sleep if I call CySysPmDeepSleep without CySysWdtUnmaskInterrupt? Please let me know if you have any idea.

Best Regareds

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

As far as I studied, both 4200M and 4100PS wakes up from DeepSleep via WIC.

But for the WDT, there is a register called SRSS and in the Architecture TRM

Chapter 12. Watchdog Timer  > 12.3 How It Works there is a description

002-WDT_PIG.JPG

At the step 4.  it is required to set WDT_MATCH bit in SRSS_INTR_MASK,

which is what the CySysWdtUnmaskInterrupt()  call is doing.

My best guess is that this step was not required for 4200M or

the bit was set by default for 4200M (and may be other older PSoC 4s)

moto

0 Likes