Skip to content

Commit ffe9ddf

Browse files
authored
Merge pull request #10268 from cy-vivekp/pr/serial_rts
PSoC6 serial driver: Setup RTS and TX lines on deepsleep entry/exit
2 parents bb0baee + 96b6f99 commit ffe9ddf

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

targets/TARGET_Cypress/TARGET_PSOC6/serial_api.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "cy_scb_uart.h"
3535
#include "cy_sysint.h"
3636
#include "cycfg_pins.h"
37+
#include "cycfg_peripherals.h"
3738

3839
#define UART_OVERSAMPLE 12
3940
#define UART_DEFAULT_BAUDRATE 115200
@@ -127,6 +128,10 @@ static irq_info_t irq_info[NUM_SERIAL_PORTS] = {
127128
{NULL, NULL, 0, unconnected_IRQn}
128129
};
129130

131+
static uint32_t Cy_SCB_UART_GetRtsAcitvePolarity(CySCB_Type const *base)
132+
{
133+
return _FLD2VAL(SCB_UART_FLOW_CTRL_RTS_POLARITY, SCB_UART_FLOW_CTRL(base));
134+
}
130135

131136
/** Routes interrupt to proper SCB block.
132137
*
@@ -398,6 +403,8 @@ static cy_en_syspm_status_t serial_pm_callback(cy_stc_syspm_callback_params_t *c
398403
{
399404
serial_obj_t *obj = (serial_obj_t *) callbackParams->context;
400405
cy_en_syspm_status_t status = CY_SYSPM_FAIL;
406+
GPIO_PRT_Type *port_tx = Cy_GPIO_PortToAddr(CY_PORT(obj->pin_tx));
407+
GPIO_PRT_Type *port_rts = Cy_GPIO_PortToAddr(CY_PORT(obj->pin_rts));
401408

402409
switch (mode) {
403410
case CY_SYSPM_CHECK_READY:
@@ -407,6 +414,17 @@ static cy_en_syspm_status_t serial_pm_callback(cy_stc_syspm_callback_params_t *c
407414
*/
408415
if (Cy_SCB_UART_IsTxComplete(obj->base)) {
409416
if (0 == Cy_SCB_UART_GetNumInRxFifo(obj->base)) {
417+
/* Configure RTS and TX GPIO DR register to drive output (high) */
418+
if(obj->pin_rts != NC) {
419+
uint32_t rts_polarity = Cy_SCB_UART_GetRtsAcitvePolarity(obj->base);
420+
uint32_t rts_value = ((rts_polarity == CY_SCB_UART_ACTIVE_LOW) ? CY_SCB_UART_ACTIVE_HIGH : CY_SCB_UART_ACTIVE_LOW);
421+
Cy_GPIO_Write (port_rts, CY_PIN(obj->pin_rts), rts_value);
422+
Cy_GPIO_SetHSIOM(port_rts, CY_PIN(obj->pin_rts), HSIOM_SEL_GPIO);
423+
}
424+
425+
Cy_GPIO_Write (port_tx, CY_PIN(obj->pin_tx), 1);
426+
Cy_GPIO_SetHSIOM(port_tx, CY_PIN(obj->pin_tx), HSIOM_SEL_GPIO);
427+
410428
/* Disable the UART. The transmitter stops driving the
411429
* lines and the receiver stops receiving data until
412430
* the UART is enabled.
@@ -422,6 +440,13 @@ static cy_en_syspm_status_t serial_pm_callback(cy_stc_syspm_callback_params_t *c
422440
case CY_SYSPM_CHECK_FAIL:
423441
/* Enable the UART to operate */
424442
Cy_SCB_UART_Enable(obj->base);
443+
/* Return SCB control on TX and RTS output pins */
444+
if(obj->pin_rts != NC) {
445+
Cy_GPIO_SetHSIOM(port_rts, CY_PIN(obj->pin_rts), CY_PIN_HSIOM(pinmap_function(obj->pin_rts, PinMap_UART_RTS)));
446+
}
447+
448+
Cy_GPIO_SetHSIOM(port_tx, CY_PIN(obj->pin_tx), CY_PIN_HSIOM(pinmap_function(obj->pin_tx, PinMap_UART_TX)));
449+
425450
status = CY_SYSPM_SUCCESS;
426451
break;
427452

@@ -432,6 +457,13 @@ static cy_en_syspm_status_t serial_pm_callback(cy_stc_syspm_callback_params_t *c
432457
case CY_SYSPM_AFTER_TRANSITION:
433458
/* Enable the UART to operate */
434459
Cy_SCB_UART_Enable(obj->base);
460+
/* Return SCB control on TX and RTS output pins */
461+
if(obj->pin_rts != NC) {
462+
Cy_GPIO_SetHSIOM(port_rts, CY_PIN(obj->pin_rts), CY_PIN_HSIOM(pinmap_function(obj->pin_rts, PinMap_UART_RTS)));
463+
}
464+
465+
Cy_GPIO_SetHSIOM(port_tx, CY_PIN(obj->pin_tx), CY_PIN_HSIOM(pinmap_function(obj->pin_tx, PinMap_UART_TX)));
466+
435467
status = CY_SYSPM_SUCCESS;
436468
break;
437469

0 commit comments

Comments
 (0)