Announcements

Ever wondered how you could shape the future in collaboration with others? Join us at OktoberTech Asia Pacific and get inspired. Click here to sign up FREE of charge.

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

PSoC™ 6 Forum Discussions

YSJE_3566666
Level 4
50 questions asked 25 replies posted 100 sign-ins
Level 4

Hello,
I'm testing UART(P5.0, P5.1) on CY8CKIT-062-WIFI-BT.

When I execute soft reset through NVIC_SystemReset(), UART Tx(P5.1) goes low for a while.
For this reason, the PC terminal utility receives 1 byte (0x00).
Is there any way to keep the UART Tx line high even after soft reset?

Thanks and Regards,
YS

0 Likes
1 Solution
PandaS
Moderator
Moderator 100 sign-ins 25 solutions authored 10 likes received
Moderator

Hi @YSJE_3566666 ,

I tried using PDL for UART initialization. It still works. I have a weak pull up (10k Ohm) connected to Pin 9_1(Tx Pin) this time. Please, take a look at my code and output.

 

#include "cy_pdl.h"
#include "cy_retarget_io.h"
#include "cyhal.h"
#include "cybsp.h"

#define UART_PORT       P9_0_PORT
#define UART_RX_NUM     P9_0_NUM
#define UART_TX_NUM     P9_1_NUM

/* Assign divider type and number for UART */
#define UART_CLK_DIV_TYPE     (CY_SYSCLK_DIV_8_BIT)
#define UART_CLK_DIV_NUMBER   (0U)


#define GPIO_INTERRUPT_PRIORITY (7u)

/*******************************************************************************
* Function Prototypes
********************************************************************************/
static void gpio_interrupt_handler(void *handler_arg, cyhal_gpio_event_t event);


/*******************************************************************************
* Global Variables
********************************************************************************/
volatile bool gpio_intr_flag = false;


/*******************************************************************************
* Function Name: main
********************************************************************************/
int main(void)
{
    cy_rslt_t result;
    //uint32_t count = 0;


    /* Initialize the device and board peripherals */
    result = cybsp_init();
    
    /* Board init failed. Stop program execution */
    if (result != CY_RSLT_SUCCESS)
    {
        CY_ASSERT(0);
    }

    cy_stc_scb_uart_context_t contextVCOM;

        cy_stc_scb_uart_config_t VCOM = {

    	    .uartMode                   = CY_SCB_UART_STANDARD,
    	    .enableMutliProcessorMode   = false,
    	    .smartCardRetryOnNack       = false,
    	    .irdaInvertRx               = false,
    	    .irdaEnableLowPowerReceiver = false,
    	    .oversample                 = 12UL,
    	    .enableMsbFirst             = false,
    	    .dataWidth                  = 8UL,
    	    .parity                     = CY_SCB_UART_PARITY_NONE,
    	    .stopBits                   = CY_SCB_UART_STOP_BITS_1,
    	    .enableInputFilter          = false,
    	    .breakWidth                 = 11UL,
    	    .dropOnFrameError           = false,
    	    .dropOnParityError          = false,
    	    .receiverAddress            = 0UL,
    	    .receiverAddressMask        = 0UL,
    	    .acceptAddrInFifo           = false,
    	    .enableCts                  = false,
    	    .ctsPolarity                = CY_SCB_UART_ACTIVE_LOW,
    	    .rtsRxFifoLevel             = 0UL,
    	    .rtsPolarity                = CY_SCB_UART_ACTIVE_LOW,
    	    .rxFifoTriggerLevel  = 0UL,
    	    .rxFifoIntEnableMask = 0UL,
    	    .txFifoTriggerLevel  = 0UL,
    	    .txFifoIntEnableMask = 0UL,
        };

        cy_en_scb_uart_status_t UART_STATUS = CY_SCB_UART_SUCCESS;
        UART_STATUS = Cy_SCB_UART_Init(SCB2, &VCOM, &contextVCOM);

        while(UART_STATUS != CY_SCB_UART_SUCCESS){};

    	/* Connect SCB2 UART function to pins */
        if(P9_0_GPIO == Cy_GPIO_GetHSIOM(P9_0_PORT, P9_0_NUM))
        {
        	Cy_GPIO_SetHSIOM(UART_PORT, UART_RX_NUM, P9_0_SCB2_UART_RX);
        }
        if(P9_1_GPIO == Cy_GPIO_GetHSIOM(P9_1_PORT, P9_1_NUM))
        {
        	Cy_GPIO_SetHSIOM(UART_PORT, UART_TX_NUM, P9_1_SCB2_UART_TX);
        }


    	/* Configure pins for UART operation */
    	Cy_GPIO_SetDrivemode(UART_PORT, UART_RX_NUM, CY_GPIO_DM_HIGHZ);
    	Cy_GPIO_SetDrivemode(UART_PORT, UART_TX_NUM, CY_GPIO_DM_STRONG_IN_OFF);

    	/* Connect assigned divider to be a clock source for UART */
    	Cy_SysClk_PeriphAssignDivider(PCLK_SCB2_CLOCK, UART_CLK_DIV_TYPE, UART_CLK_DIV_NUMBER);

    	Cy_SysClk_PeriphSetDivider   (UART_CLK_DIV_TYPE, UART_CLK_DIV_NUMBER, 71UL);
    	Cy_SysClk_PeriphEnableDivider(UART_CLK_DIV_TYPE, UART_CLK_DIV_NUMBER);

        Cy_SCB_UART_Enable(SCB2);





    /* Initialize the user LED */
    result = cyhal_gpio_init(CYBSP_USER_LED, CYHAL_GPIO_DIR_OUTPUT,
                    CYHAL_GPIO_DRIVE_STRONG, CYBSP_LED_STATE_OFF);

    /* Initialize the user button */
    result = cyhal_gpio_init(CYBSP_USER_BTN, CYHAL_GPIO_DIR_INPUT,
                    CYHAL_GPIO_DRIVE_PULLUP, CYBSP_BTN_OFF);

    /* Configure GPIO interrupt */
    cyhal_gpio_register_callback(CYBSP_USER_BTN, 
                                 gpio_interrupt_handler, NULL);
    cyhal_gpio_enable_event(CYBSP_USER_BTN, CYHAL_GPIO_IRQ_FALL, 
                                 GPIO_INTERRUPT_PRIORITY, true);

    /* Enable global interrupts */
    __enable_irq();

    /* \x1b[2J\x1b[;H - ANSI ESC sequence for clear screen */
    Cy_SCB_UART_PutString(SCB2, "\r\n");
    Cy_SCB_UART_PutString(SCB2,"**************** PSoC 6 MCU: GPIO Interrupt *****************\r\n");

    for (;;)
    {

    }
}


/*******************************************************************************
* Function Name: gpio_interrupt_handler
********************************************************************************
* Summary:
*   GPIO interrupt handler.
*
* Parameters:
*  void *handler_arg (unused)
*  cyhal_gpio_irq_event_t (unused)
*
*******************************************************************************/
static void gpio_interrupt_handler(void *handler_arg, cyhal_gpio_irq_event_t event)
{
    gpio_intr_flag = true;
    NVIC_SystemReset();
}

 

PandaS_0-1657461598149.png

 

Thankyou and Warm Regards

Sobhit

View solution in original post

0 Likes
6 Replies
PandaS
Moderator
Moderator 100 sign-ins 25 solutions authored 10 likes received
Moderator

Hi @YSJE_3566666 ,

I replicated your issue at my end. I created a user button press - software reset.

PandaS_1-1656946366008.png

PandaS_2-1656946389138.png

0x00 byte is being captured as you said.

This is the output / the problem which you face because of the GPIO being pulled to low.

 

After a small hardware trick:

PandaS_0-1656946136418.png

Saleae Output - Not being pulled to low

PandaS_3-1656946410998.png

No more "0" in the terminal.

This is after adding a weak external pull up resistor of 10K Ohm at P5.1. And the GPIO was configured to strong drive.

Do this at your end and do let us know if you have further queries.

 Warm Regards

Sobhit

0 Likes
YSJE_3566666
Level 4
50 questions asked 25 replies posted 100 sign-ins
Level 4

Hi, Sobhit.
Thanks for your kind reply.

I added 10k ohm at P5.1 and sometimes 0xFF is captured.

1.JPG

When I use the oscilloscope on P5.1, it measures low for 4us after reset.
I think this affects 0xff. I attached my main.c.

 

#include "cy_pdl.h"
#include "cybsp.h"

cy_stc_scb_uart_context_t UART_context; /* UART context variable */
cy_stc_sysint_t SCB5Uart_INT_config = {
.intrsrc=scb_5_interrupt_IRQn,
.intrPriority = 6u
};
bool scb5_interrupt_flag = false;
char_t charReceived;

void SCB5_UART_Handler(void);

int main(void)
{
cy_rslt_t result;

Cy_GPIO_SetDrivemode(P5_1_PORT, P5_1_NUM, CY_GPIO_DM_STRONG);
Cy_GPIO_Write(P5_1_PORT, P5_1_NUM, 1);

/* Initialize the device and board peripherals */
result = cybsp_init() ;
if (result != CY_RSLT_SUCCESS)
{
CY_ASSERT(0);
}
__enable_irq();

/*********** Set GPIO Configuration ***********/
Cy_GPIO_SetDrivemode(P1_1_PORT, P1_1_NUM, CY_GPIO_DM_STRONG); /* P1_1 Green LED */
Cy_GPIO_Write(P1_1_PORT, P1_1_NUM, 1);


/*********** Set UART Configuration ***********/
/* UART Initialization */
Cy_SCB_UART_Init(SCB5, &scb_5_config, &UART_context);
Cy_SCB_UART_Enable(SCB5);

/* UART Interrupt Initialization */
Cy_SysInt_Init(&SCB5Uart_INT_config, &SCB5_UART_Handler);
//SCB5->INTR_RX_MASK = SCB_INTR_RX_MASK_NOT_EMPTY_Msk;

Cy_SCB_SetRxInterruptMask(SCB5, SCB_INTR_RX_MASK_NOT_EMPTY_Msk);
NVIC_ClearPendingIRQ(SCB5Uart_INT_config.intrSrc);
NVIC_EnableIRQ(SCB5Uart_INT_config.intrSrc);

Cy_SysLib_Delay(100);
Cy_SCB_WriteString(SCB5, "*");
//Cy_SCB_WriteString(SCB5, "***** Start *****\r\n");

for (;;)
{
if (true == scb5_interrupt_flag)
{
charReceived = Cy_SCB_UART_Get(SCB5);
if(charReceived == '0') /* If a 0 is received turn the LED off */
{
Cy_GPIO_Write(P1_1_PORT, P1_1_NUM, 1);

//Cy_SCB_WriteString(SCB5, "***** NVIC_SystemReset *****\r\n");

//Cy_SysLib_Delay(100);

Cy_GPIO_SetDrivemode(P5_1_PORT, P5_1_NUM, CY_GPIO_DM_STRONG);
Cy_GPIO_Write(P5_1_PORT, P5_1_NUM, 1);

NVIC_SystemReset();
}
else if (charReceived == '1') /* If a 1 is received turn the LED on */
{
Cy_GPIO_Write(P1_1_PORT, P1_1_NUM, 0);
}
Cy_SCB_UART_Put(SCB5, charReceived);
scb5_interrupt_flag = false;

Cy_SCB_SetRxInterruptMask(SCB5, SCB_INTR_RX_MASK_NOT_EMPTY_Msk);
}

}
}

void SCB5_UART_Handler(void)
{
NVIC_ClearPendingIRQ(SCB5Uart_INT_config.intrSrc);
uint32_t rxintMask=Cy_SCB_GetRxInterruptStatusMasked(SCB5);
Cy_SCB_ClearRxInterrupt(SCB5, rxintMask);

scb5_interrupt_flag = true;
}

 

Thanks and Regards,
YS

0 Likes
PandaS
Moderator
Moderator 100 sign-ins 25 solutions authored 10 likes received
Moderator

Hi @YSJE_3566666 ,

You don't need to do the gpio strong drive configuration explicitly. I want you to remove these lines - Cy_GPIO_SetDrivemode(P5_1_PORT, P5_1_NUM, CY_GPIO_DM_STRONG); and Cy_GPIO_Write(P5_1_PORT, P5_1_NUM, 1);

Please follow the code snippet attached below: (Check the interrupt ISR where software reset is done / no reconfiguration is required for UART Pin)

 

#include "cy_pdl.h"
#include "cy_retarget_io.h"
#include "cyhal.h"
#include "cybsp.h"

#define GPIO_INTERRUPT_PRIORITY (7u)

/*******************************************************************************
* Function Prototypes
********************************************************************************/
static void gpio_interrupt_handler(void *handler_arg, cyhal_gpio_event_t event);


/*******************************************************************************
* Global Variables
********************************************************************************/
volatile bool gpio_intr_flag = false;


/*******************************************************************************
* Function Name: main
********************************************************************************/
int main(void)
{
    cy_rslt_t result;
    uint32_t count = 0;


    /* Initialize the device and board peripherals */
    result = cybsp_init();
    
    /* Board init failed. Stop program execution */
    if (result != CY_RSLT_SUCCESS)
    {
        CY_ASSERT(0);
    }

    /* 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);

    /* Initialize the user LED */
    result = cyhal_gpio_init(CYBSP_USER_LED, CYHAL_GPIO_DIR_OUTPUT,
                    CYHAL_GPIO_DRIVE_STRONG, CYBSP_LED_STATE_OFF);

    /* Initialize the user button */
    result = cyhal_gpio_init(CYBSP_USER_BTN, CYHAL_GPIO_DIR_INPUT,
                    CYHAL_GPIO_DRIVE_PULLUP, CYBSP_BTN_OFF);

    /* Configure GPIO interrupt */
    cyhal_gpio_register_callback(CYBSP_USER_BTN, 
                                 gpio_interrupt_handler, NULL);
    cyhal_gpio_enable_event(CYBSP_USER_BTN, CYHAL_GPIO_IRQ_FALL, 
                                 GPIO_INTERRUPT_PRIORITY, true);

    /* Enable global interrupts */
    __enable_irq();

    /* \x1b[2J\x1b[;H - ANSI ESC sequence for clear screen */
    printf("\r\n");
    printf("**************** PSoC 6 MCU: GPIO Interrupt *****************\r\n");

    for (;;)
    {
    }
}


/*******************************************************************************
* Function Name: gpio_interrupt_handler
********************************************************************************
* Summary:
*   GPIO interrupt handler.
*
* Parameters:
*  void *handler_arg (unused)
*  cyhal_gpio_irq_event_t (unused)
*
*******************************************************************************/
static void gpio_interrupt_handler(void *handler_arg, cyhal_gpio_irq_event_t event)
{
    gpio_intr_flag = true;
    NVIC_SystemReset();
}

/* [] END OF FILE */

 

0 Likes
YSJE_3566666
Level 4
50 questions asked 25 replies posted 100 sign-ins
Level 4

Hi, Sobhit.
Thank you for your support.

I removed Cy_GPIO_SetDrivemode and Cy_GPIO_Write as you mentioned.
And I found the following.

When I use PDL, GPIO is observed as low in the function below during initialization (cybsp_init()).
- in the cy_gpio.c
- Cy_GPIO_SetDrivemode(base, pinNum, config->driveMode);

But when I use HAL Driver(cy_retarget_io_init()), no low is observed.
Should I use the HAL driver for UART initialization?

Thanks and Regards,
YS

0 Likes
PandaS
Moderator
Moderator 100 sign-ins 25 solutions authored 10 likes received
Moderator

Hi @YSJE_3566666 ,

Did you try the 2nd code example and did it work? Do let us know if you are still facing the issue.

Warm Regards

Sobhit

0 Likes
PandaS
Moderator
Moderator 100 sign-ins 25 solutions authored 10 likes received
Moderator

Hi @YSJE_3566666 ,

I tried using PDL for UART initialization. It still works. I have a weak pull up (10k Ohm) connected to Pin 9_1(Tx Pin) this time. Please, take a look at my code and output.

 

#include "cy_pdl.h"
#include "cy_retarget_io.h"
#include "cyhal.h"
#include "cybsp.h"

#define UART_PORT       P9_0_PORT
#define UART_RX_NUM     P9_0_NUM
#define UART_TX_NUM     P9_1_NUM

/* Assign divider type and number for UART */
#define UART_CLK_DIV_TYPE     (CY_SYSCLK_DIV_8_BIT)
#define UART_CLK_DIV_NUMBER   (0U)


#define GPIO_INTERRUPT_PRIORITY (7u)

/*******************************************************************************
* Function Prototypes
********************************************************************************/
static void gpio_interrupt_handler(void *handler_arg, cyhal_gpio_event_t event);


/*******************************************************************************
* Global Variables
********************************************************************************/
volatile bool gpio_intr_flag = false;


/*******************************************************************************
* Function Name: main
********************************************************************************/
int main(void)
{
    cy_rslt_t result;
    //uint32_t count = 0;


    /* Initialize the device and board peripherals */
    result = cybsp_init();
    
    /* Board init failed. Stop program execution */
    if (result != CY_RSLT_SUCCESS)
    {
        CY_ASSERT(0);
    }

    cy_stc_scb_uart_context_t contextVCOM;

        cy_stc_scb_uart_config_t VCOM = {

    	    .uartMode                   = CY_SCB_UART_STANDARD,
    	    .enableMutliProcessorMode   = false,
    	    .smartCardRetryOnNack       = false,
    	    .irdaInvertRx               = false,
    	    .irdaEnableLowPowerReceiver = false,
    	    .oversample                 = 12UL,
    	    .enableMsbFirst             = false,
    	    .dataWidth                  = 8UL,
    	    .parity                     = CY_SCB_UART_PARITY_NONE,
    	    .stopBits                   = CY_SCB_UART_STOP_BITS_1,
    	    .enableInputFilter          = false,
    	    .breakWidth                 = 11UL,
    	    .dropOnFrameError           = false,
    	    .dropOnParityError          = false,
    	    .receiverAddress            = 0UL,
    	    .receiverAddressMask        = 0UL,
    	    .acceptAddrInFifo           = false,
    	    .enableCts                  = false,
    	    .ctsPolarity                = CY_SCB_UART_ACTIVE_LOW,
    	    .rtsRxFifoLevel             = 0UL,
    	    .rtsPolarity                = CY_SCB_UART_ACTIVE_LOW,
    	    .rxFifoTriggerLevel  = 0UL,
    	    .rxFifoIntEnableMask = 0UL,
    	    .txFifoTriggerLevel  = 0UL,
    	    .txFifoIntEnableMask = 0UL,
        };

        cy_en_scb_uart_status_t UART_STATUS = CY_SCB_UART_SUCCESS;
        UART_STATUS = Cy_SCB_UART_Init(SCB2, &VCOM, &contextVCOM);

        while(UART_STATUS != CY_SCB_UART_SUCCESS){};

    	/* Connect SCB2 UART function to pins */
        if(P9_0_GPIO == Cy_GPIO_GetHSIOM(P9_0_PORT, P9_0_NUM))
        {
        	Cy_GPIO_SetHSIOM(UART_PORT, UART_RX_NUM, P9_0_SCB2_UART_RX);
        }
        if(P9_1_GPIO == Cy_GPIO_GetHSIOM(P9_1_PORT, P9_1_NUM))
        {
        	Cy_GPIO_SetHSIOM(UART_PORT, UART_TX_NUM, P9_1_SCB2_UART_TX);
        }


    	/* Configure pins for UART operation */
    	Cy_GPIO_SetDrivemode(UART_PORT, UART_RX_NUM, CY_GPIO_DM_HIGHZ);
    	Cy_GPIO_SetDrivemode(UART_PORT, UART_TX_NUM, CY_GPIO_DM_STRONG_IN_OFF);

    	/* Connect assigned divider to be a clock source for UART */
    	Cy_SysClk_PeriphAssignDivider(PCLK_SCB2_CLOCK, UART_CLK_DIV_TYPE, UART_CLK_DIV_NUMBER);

    	Cy_SysClk_PeriphSetDivider   (UART_CLK_DIV_TYPE, UART_CLK_DIV_NUMBER, 71UL);
    	Cy_SysClk_PeriphEnableDivider(UART_CLK_DIV_TYPE, UART_CLK_DIV_NUMBER);

        Cy_SCB_UART_Enable(SCB2);





    /* Initialize the user LED */
    result = cyhal_gpio_init(CYBSP_USER_LED, CYHAL_GPIO_DIR_OUTPUT,
                    CYHAL_GPIO_DRIVE_STRONG, CYBSP_LED_STATE_OFF);

    /* Initialize the user button */
    result = cyhal_gpio_init(CYBSP_USER_BTN, CYHAL_GPIO_DIR_INPUT,
                    CYHAL_GPIO_DRIVE_PULLUP, CYBSP_BTN_OFF);

    /* Configure GPIO interrupt */
    cyhal_gpio_register_callback(CYBSP_USER_BTN, 
                                 gpio_interrupt_handler, NULL);
    cyhal_gpio_enable_event(CYBSP_USER_BTN, CYHAL_GPIO_IRQ_FALL, 
                                 GPIO_INTERRUPT_PRIORITY, true);

    /* Enable global interrupts */
    __enable_irq();

    /* \x1b[2J\x1b[;H - ANSI ESC sequence for clear screen */
    Cy_SCB_UART_PutString(SCB2, "\r\n");
    Cy_SCB_UART_PutString(SCB2,"**************** PSoC 6 MCU: GPIO Interrupt *****************\r\n");

    for (;;)
    {

    }
}


/*******************************************************************************
* Function Name: gpio_interrupt_handler
********************************************************************************
* Summary:
*   GPIO interrupt handler.
*
* Parameters:
*  void *handler_arg (unused)
*  cyhal_gpio_irq_event_t (unused)
*
*******************************************************************************/
static void gpio_interrupt_handler(void *handler_arg, cyhal_gpio_irq_event_t event)
{
    gpio_intr_flag = true;
    NVIC_SystemReset();
}

 

PandaS_0-1657461598149.png

 

Thankyou and Warm Regards

Sobhit

0 Likes