3 Replies Latest reply on Oct 9, 2019 5:07 PM by MoTa_728816

    Sample code: Waking up Deep Sleep by WDT

    KaKo_4074056

      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 !

        • 1. Re: Sample code: Waking up Deep Sleep by WDT
          MoTa_728816

          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

          • 2. Re: Sample code: Waking up Deep Sleep by WDT
            KaKo_4074056

            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

            • 3. Re: Sample code: Waking up Deep Sleep by WDT
              MoTa_728816

              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