34
34
#include "cy_scb_uart.h"
35
35
#include "cy_sysint.h"
36
36
#include "cycfg_pins.h"
37
+ #include "cycfg_peripherals.h"
37
38
38
39
#define UART_OVERSAMPLE 12
39
40
#define UART_DEFAULT_BAUDRATE 115200
@@ -127,6 +128,10 @@ static irq_info_t irq_info[NUM_SERIAL_PORTS] = {
127
128
{NULL , NULL , 0 , unconnected_IRQn }
128
129
};
129
130
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
+ }
130
135
131
136
/** Routes interrupt to proper SCB block.
132
137
*
@@ -398,6 +403,8 @@ static cy_en_syspm_status_t serial_pm_callback(cy_stc_syspm_callback_params_t *c
398
403
{
399
404
serial_obj_t * obj = (serial_obj_t * ) callbackParams -> context ;
400
405
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 ));
401
408
402
409
switch (mode ) {
403
410
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
407
414
*/
408
415
if (Cy_SCB_UART_IsTxComplete (obj -> base )) {
409
416
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
+
410
428
/* Disable the UART. The transmitter stops driving the
411
429
* lines and the receiver stops receiving data until
412
430
* the UART is enabled.
@@ -422,6 +440,13 @@ static cy_en_syspm_status_t serial_pm_callback(cy_stc_syspm_callback_params_t *c
422
440
case CY_SYSPM_CHECK_FAIL :
423
441
/* Enable the UART to operate */
424
442
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
+
425
450
status = CY_SYSPM_SUCCESS ;
426
451
break ;
427
452
@@ -432,6 +457,13 @@ static cy_en_syspm_status_t serial_pm_callback(cy_stc_syspm_callback_params_t *c
432
457
case CY_SYSPM_AFTER_TRANSITION :
433
458
/* Enable the UART to operate */
434
459
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
+
435
467
status = CY_SYSPM_SUCCESS ;
436
468
break ;
437
469
0 commit comments