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

PSoC™ 6

mvpablo
Level 2
10 sign-ins 5 replies posted 5 questions asked
Level 2

Hi Community

I would like to get some help and guidance on how  to send a string message (characters array) via UART from an Arduino UNO to a PSCO 6 CY8CKIT-062S2-43012.

I'm using ModusToolbox 2.3 on macOS 10.15.7

For testing on PSoC 6, I'm using the basic Hello World example provided by Cypress and I add the code and libraries from there 

 

IMG_7639.jpg

The arduino code is pretty simple and I have already tested on an arduino to arduino UART communication. this is a dummy code example here:

 

 

char str[4];
void setup() {
  Serial.begin(9600);
}
void loop() {
  int bytesSent = Serial.write("hello");
  delay(1000);// wait for a second
}

 

 

 

But I have limited knowledge on how to configure the pins on the PSOC 6 and use the HAL.  I'm totally new to hardware configuration

 

I use printf for debugging  which I configure with retarget on the ports defined by the BSP for UART debugging

 

 

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

 

 

 

But as I see from the documentation, those pins are also assigned to the arduino header pins for UART TX RX

 

Screenshot 2021-08-31 at 09.43.25.png

 

Screenshot 2021-08-31 at 09.44.50.png

Please correct me if I'm wrong but I assume that I need to free those arduino pins from the serial terminal debugging in order to use them for incoming UART communication from the arduino

Question 1:  How can I change the retarget i/o pins so I can still do printf to serial terminal for debugging?

I found this article that suggest to change the pins on the init function (cy_retarget_io_init( P6_1, P6_0, 9600 );)  but it  didn't work and I cannot print info on the serial terminal for debugging.  I also tried this  but doesn't match the code structure in PSoC 6 with modustoolbox

Question 2: Where can I find an easy to use example code to receive UART data on the PSOC 6?

I found an article here, but it doesn't provide information on how to keep debugging with printf while receiving data via UART in the PSOC.  I want at least to print the data on serial terminal when it arrives to the  PSoC.

All the examples for the board are for UART TX and RX to a serial terminal. 

I also read this and  this  but those post are quite old and don't offer any details to solve my issue

Also in the SCB documentation the examples use the pins that my PSoC board is using for UART serial term debugging

 

@brandiware I see that you are working on something similar. Any luck ?

 

thanks

 

0 Likes
1 Solution
mvpablo
Level 2
10 sign-ins 5 replies posted 5 questions asked
Level 2

thank you to the authors of this post. I managed to implement the solution.

Attached is the source code. assume that the uart is initialized from the main and also the uart_task is created from the main. 

the wiring is from PSoC to UNO,  see also images

A0 -> Tx

A1 -> Rx

GND -> GND

IMG_7709 copy.jpgIMG_7710 copy.jpg

 

 

 

 

 

View solution in original post

0 Likes
3 Replies
Ekta
Moderator
Moderator 250 sign-ins First question asked 500 replies posted
Moderator

Hello @mvpablo ,

1.  How can I change the retarget i/o pins so I can still do printf to serial terminal for debugging?

Ans: I noticed you are using a CY8CKIT-062S2-43012. Fot this board there is only one set of UART  RX and TX pins (P5_0 and P5_1) that are hardwired to kitprog which act as a USB-UART bridge (which is finally connected to you PC that has the serial terminal running)

Ekta_0-1630507736119.png

Therefore, even when you successfully change the pins used for debugging there would not be any output reflected on the serial terminal since the new set of pins are not harwired to kitprog.

You can refer to the CY8CKIT-062S2-43012 Pioneer kit guide (section 2.2.2 USB-UART Bridge) for more details: https://www.cypress.com/file/487006/download

In this case we would recommend you to use the pins P5_1 and P5_0 for debugging and use a different set of pins for communication with Arduino.

2. You can refer to the pinouts section of PSOC 62 datasheet: https://www.cypress.com/file/460816/download

Ekta_1-1630508406100.png

There are different (serial communication blocks) SCBs which can be configured as UART and each have a set of pins associated with it. You can use any other SCB apart from the one used for debugging  for connection to arduino.

Best Regards
Ekta

 

 

0 Likes
mvpablo
Level 2
10 sign-ins 5 replies posted 5 questions asked
Level 2

Special thanks to the authors of this post  and the source code provided, I used it  to get my app to work:

 

SCB and free pins:

my first question was, which SCB and pins to work with? Since I don't know how to find free pins, I decided to give it a try with the SCB1 and pins A0 y A1 of the example. 

 

 

#define UART_SCB SCB1
#define UART_PORT       P10_0_PORT
#define UART_RX_NUM     P10_0_NUM
#define UART_TX_NUM     P10_1_NUM
#define UART_RX_PIN     P10_0_SCB1_UART_RX
#define UART_TX_PIN     P10_1_SCB1_UART_TX

 

 

 

init the UART 

I used the same code as the example and I modified it to add a callback function to process the UART events

 

 

void initUART() {
  // https://cypresssemiconductorco.github.io/psoc6pdl/pdl_api_reference_manual/html/group__group__scb__uart.html


  /* Populate configuration structure */
  const cy_stc_scb_uart_config_t uartConfig = {
      .uartMode                   = CY_SCB_UART_STANDARD,
      .enableMutliProcessorMode   = false,
      .smartCardRetryOnNack       = false,
      .irdaInvertRx               = false,
      .irdaEnableLowPowerReceiver = false,
      .oversample                 = UART_OVERSAMPLE,
      .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,
  };

  /* Configure UART to operate */
  (void) Cy_SCB_UART_Init(UART_SCB, &uartConfig, &uartContext);

  /* Assign pins for UART on SCBx */

  /* Connect SCB UART function to pins */
  Cy_GPIO_SetHSIOM(UART_PORT, UART_RX_NUM, UART_RX_PIN);
  Cy_GPIO_SetHSIOM(UART_PORT, UART_TX_NUM, UART_TX_PIN);
  /* 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);

  /* Assign divider type and number for UART */

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


  // set baud
  Cy_SysClk_PeriphSetDivider   (UART_CLK_DIV_TYPE, UART_CLK_DIV_NUMBER, UART_DIVISION);
  Cy_SysClk_PeriphEnableDivider(UART_CLK_DIV_TYPE, UART_CLK_DIV_NUMBER);

  /* Populate configuration structure (code specific for CM4) */
  cy_stc_sysint_t uartIntrConfig =
  {
      .intrsrc=UART_INTR_NUM,
      .intrPriority = UART_INTR_PRIORITY,
  };
  /* Hook interrupt service routine and enable interrupt */
  (void) Cy_SysInt_Init(&uartIntrConfig, &UART_Isr);
  NVIC_EnableIRQ(UART_INTR_NUM);

  /* Enable UART to operate */
  Cy_SCB_UART_Enable(UART_SCB);

  /*register a callback to process UART events */
  Cy_SCB_UART_RegisterCallback(UART_SCB, uart_callback_handler, &uartContext);
}

void UART_Isr() {
  Cy_SCB_UART_Interrupt(UART_SCB, &uartContext);
}

 

 

 

Process UART events

In the callback handler,  whenever  the Rx is done, one can do whatever with the data. But since this is a function inside an ISR, it needs to be something fast. So I just send the buffer to a queue, but since we are inside an ISR, we need to use the function xQueueSendFromISR

 

 

 

void uart_callback_handler(uint32_t event)
{
    switch(event)
    {
        case CY_SCB_UART_TRANSMIT_DONE_EVENT: {
        	counter ++;
        	break;
        }

        case CY_SCB_UART_RECEIVE_DONE_EVENT: {
        	BaseType_t xHigherPriorityTaskWoken = pdFALSE;
            if( xQueueSendFromISR( task_handler,
            		( void * ) rxBuffer,
					&xHigherPriorityTaskWoken ) != pdPASS ) {
              CY_ASSERT_L3(!0);
            }
            portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
        	break;
        }

        case CY_SCB_UART_TRANSMIT_IN_FIFO_EVENT:{
        	break;
        }

        case CY_SCB_UART_RECEIVE_ERR_EVENT:{
        	break;
        }

        case CY_SCB_UART_TRANSMIT_ERR_EVENT:{
        	break;
        }

        case CY_SCB_UART_RB_FULL_EVENT:{
        	break;
        }

        default:{
        	break;
        }
    }

}

 

 

 

UART freeRTOS task

then I have a tasks with the receive operation

 

 

void uart_task(void *pvParameters) {

  /* To avoid compiler warnings */
  (void)pvParameters;

  while (true) {

	/* Start receive operation (do not check status) */
	(void) Cy_SCB_UART_Receive(UART_SCB, rxBuffer, sizeof(rxBuffer), &uartContext);


  }
}

 

 

 

Arduino to PSoC wiring

CY8CKIT-062S2-43012 Arduino UNO
P10_0/A0 Tx
P10_1/A1 Rx
GND GND 

 

 

 

 

IMG_7710 copy.jpgIMG_7709 copy.jpg 

this is just my simple approach that for now it works. 

Now, I need to make PSOC read buffer chunks of bytes until the end of line character.  ANY IDEAS?

thanks

0 Likes
mvpablo
Level 2
10 sign-ins 5 replies posted 5 questions asked
Level 2

thank you to the authors of this post. I managed to implement the solution.

Attached is the source code. assume that the uart is initialized from the main and also the uart_task is created from the main. 

the wiring is from PSoC to UNO,  see also images

A0 -> Tx

A1 -> Rx

GND -> GND

IMG_7709 copy.jpgIMG_7710 copy.jpg

 

 

 

 

 

0 Likes
Top labels