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

cross mob
notAnumber
Level 1
Level 1
50 sign-ins 5 questions asked 5 replies posted

Hello!

 

I am trying to implement a simple watchdog timer on my  CY8PROTO-062-4343W PSoC 6 board.

The function that I want is if the program gets stucked somewhere, for example in a while(1) loop it should reset.

I start from the example I found on Infineons GitHub page.

https://github.com/Infineon/Code-Examples-for-the-ModusToolbox-PSoC-6-SDK/blob/mt1.1/CE220060_PSoC6_...

But if I change WDT_DEMO into WDT_RESET_DEMO. And uncomment the while(1) on line 130 I should get a device reset. But I don't.

The program gets stuck in the while(1) loop but the reset won't happend. I added a printf statement do see if I get a reset but it doesn't. 

I also tried to add a if statement with SRSS_SRSS_INTR & SRSS_SRSS_INTR_WDT_MATCH_Msk inside the while(1) to see if I get a interrupt, which I do after approximately 1 second. 

What can be the issue here?

 

 

 

 

0 Likes
1 Solution
Andri-setyabudi
Level 5
Level 5
50 likes received 50 sign-ins 25 solutions authored

Hello, 

Your board will never reset and always execute the instruction inside while because you set the 

Cy_WDT_SetMatch(0);

You need to set the match-value. 
Reset can occur when the counter reaches the match value. 

Warm regards, 

View solution in original post

0 Likes
2 Replies
notAnumber
Level 1
Level 1
50 sign-ins 5 questions asked 5 replies posted

 

 

#include "cy_device_headers.h"
#include "cycfg.h"
#include "cy_retarget_io.h"
#include "cy_wdt.h"
#include "cy_sysint.h"

/* Variable for storing character read from terminal */
uint8_t uart_read_value;

/* WDT Interrupt Number */
#define WDT_IRQ__INTC_NUMBER 				srss_interrupt_IRQn
#define WDT_IRQ__INTC_CORTEXM4_PRIORITY 	7

/* WDT periodic interrupt timing */
#define WDT_INTERRUPT_INTERVAL				1500  //ms

/* Match count =  Desired interrupt interval in seconds x ILO Frequency in Hz */
#define WDT_MATCH_COUNT 					WDT_INTERRUPT_INTERVAL*32000/1000

/* WDT interrupt configuration structure */
const cy_stc_sysint_t WDT_IRQ_cfg = {
	.intrsrc=(IRQn_Type)WDT_IRQ__INTC_NUMBER,
	.intrPriority = WDT_IRQ__INTC_CORTEXM4_PRIORITY
};

/* Function prototypes */
void InitializeWDT(void);

int main(void)
{
    cy_rslt_t result;

	/* Set up the device based on configurator selections */
	init_cycfg_all();

	/* Enable global interrupt */
	__enable_irq();

    /* Initialize retarget-io to use the debug UART port */
    result = cy_retarget_io_init(CYBSP_DEBUG_UART_TX, CYBSP_DEBUG_UART_RX,
                                 CY_RETARGET_IO_BAUDRATE);

    /* retarget-io init failed. Stop program execution */
    if (result != CY_RSLT_SUCCESS)
    {
        CY_ASSERT(0);
    }

	/* Check the reason for device restart */
	if(CY_SYSLIB_RESET_HWWDT == Cy_SysLib_GetResetReason())
	{
		printf("\x1b[2J\x1b[;H");
		printf("A basic WatchDog Timer (WDT) reset has occurred since the last power cycle.");
	}

    /* \x1b[2J\x1b[;H - ANSI ESC sequence for clear screen */
    printf("\x1b[2J\x1b[;H");

    printf("****************** "
           "STARTING THE PROGRAM "
           "****************** \r\n\n");

	/* Initialize WDT */
	InitializeWDT();

	for(;;)
	{
		/* Clear WDT match event */
		Cy_WDT_ClearWatchdog();

		/* Set to 1 to get reset */
		#if 1
		while(1)
		{
			/* Place your application code here. */
			printf("WDT ENABLED: %s", Cy_WDT_IsEnabled()? "true\r\n":"false\r\n");
			CyDelay(500);
		}
		#endif
	}
}

void InitializeWDT()
{

	Cy_SysClk_IloEnable();
	
	Cy_WDT_Unlock();
	
	Cy_WDT_Disable();
	
	Cy_WDT_SetMatch(0);

	Cy_WDT_SetIgnoreBits(0);

	Cy_WDT_Enable();

	Cy_WDT_Lock();
}

 

Here is my full code. 

0 Likes
Andri-setyabudi
Level 5
Level 5
50 likes received 50 sign-ins 25 solutions authored

Hello, 

Your board will never reset and always execute the instruction inside while because you set the 

Cy_WDT_SetMatch(0);

You need to set the match-value. 
Reset can occur when the counter reaches the match value. 

Warm regards, 

0 Likes