- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
My host is connected to a PSOC that contains a USBUART.
Upon PSOC boot completion, the PC has a new COM23.
On the PSOC side I used the following code to initialize:
USBUART_1_Start(USBFS_DEVICE, USBUART_1_5V_OPERATION);
while(USBUART_1_GetConfiguration() ==0);
USBUART_1_CDC_Init();
On the PC, COM23 is configured to 115200[baud], 8 (data bits), 1(stop bit).
I succeeded to send a packet to the PSOC and get a reply from the PSOC.
But it seems the rate is quite low.
Example: I sent 28 bytes to the PSOC and got 36 bytes from PSOC.
Expected: (28 + 36) * 8 = 64 bytes = 512 bits
The time required to send + receive should be: ~4.5msec
Actual: The elapsed time till I got a reply was much longer.
Is it possible to improve the performance ?
Thank you,
Zvika
Solved! Go to Solution.
- Labels:
-
PSOC5 LP MCU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Zvika,
There are two RTOS-preferred methods to do what you want to do.
- This method doesn't require an interrupt so is code-simple.
- Lower the UART task priority. This allows other tasks to process more.
- Get rid of CyDelay(100u). It's not needed. Replace it with TaskYIELD(). This task should be activated every so often if the other tasks are not blocking. I see you only have one task scheduled.
- Since UsbUartReadMsg() performs a non-blocking UsbUartRead() then the UsbUartHandleMsg() is executed when the rc == USBUART_TASK_OK and a message is available.
- The second method is to create a RTOS_friendly ISR. The ISR will be attached to the RX_FIFO_NOT_EMPTY. When the ISR executes,
- it sets a Notify to the UsbUartTask() using xTaskNotifyFromISR()
- Replace CyDelay() in UsbUartTask() with xTaskNotifyWait().
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Though COM23 was set to 115k, the actual average transfer speed is several times faster. It is, actually, irrelevant for which speed COM23 is configured - USBUART will operate at its max speed, which is 1000 packets of 64 bytes each per second. This corresponds to the equivalent UART baud rate of 64×8×1000 = 512k. However, since those packets are scheduled at only 1kHz rate, actual round-trip will be over 2ms.
Because of this USBUART packeting, regular UART for small message length can, actually, be faster. But since nowadays computers don't have actual UART, using some USB-UART dongle, like FTDI, you can check how quick your software can ping such dongle with shorted Tx-Rx UART pins.
I recommend to post here your project (File->Create workspace bundle->Minimal), as well as your test results.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
zvivered,
Unfortunately, I am not familiar with RTOS. Hopefully, someone else, proficient in RTOS, can help you further.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I'm quite sure RTOS is not the cause to the problem.
UsbUartTask.c is a while loop that handles incoming requests.
Can tell if it's written properly ?
Will it help if I send a project without RTOS ?
Thank you in advance,
Zvika
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Zvika,
I cannot compile your project.
I'm missing the following:
- FreeRTOSConfig.h
- HostToPsoc.h
- PsocToHost.h
Regardless, I noticed an issue:
- In UsbUartTask.c line 105 you have CyDelay(100u);
In general you should avoid ALL blocking functions in RTOS design (of which CyDelay is a BIG ONE). This CyDelay will eat up 100ms doing nothing and even not letting other tasks to run.
There are RTOS-equivalent calls that are safer to use and lets the RTOS run other tasks until the requested time. An example of a CyDelay()-equivalent task-safe call is vTaskDelay().
Question: Does the "slow-down" appear to occur in the UART Write or Read?
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Len,
Thank you for your reply.
I really appreciate it.
Is it possible to block the task till I get incoming message ?
Currently I can't tell if the "slow-down" appear in the UART Write or Read.
Best regards,
Zvika
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Zvika,
There are two RTOS-preferred methods to do what you want to do.
- This method doesn't require an interrupt so is code-simple.
- Lower the UART task priority. This allows other tasks to process more.
- Get rid of CyDelay(100u). It's not needed. Replace it with TaskYIELD(). This task should be activated every so often if the other tasks are not blocking. I see you only have one task scheduled.
- Since UsbUartReadMsg() performs a non-blocking UsbUartRead() then the UsbUartHandleMsg() is executed when the rc == USBUART_TASK_OK and a message is available.
- The second method is to create a RTOS_friendly ISR. The ISR will be attached to the RX_FIFO_NOT_EMPTY. When the ISR executes,
- it sets a Notify to the UsbUartTask() using xTaskNotifyFromISR()
- Replace CyDelay() in UsbUartTask() with xTaskNotifyWait().
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much !