Skip to content

[BUG] Zephyr UART transport does not works with CDC ACM transport #409

Closed
@gabbla

Description

Describe the bug

Zephyr RTOS provides a transparent API to interact with physical UARTs and USB CDC ACM ones, so in theory one could create an UartTransport with either one.

Using a physical UART with the mentioned transport works fine, however, when switching to a CDC ACM one, the server always returns 16 (kErpcStatus_ReceiveFailed) after receiving an RPC call.
The issue resides in the UartTransport::underlyingReceive function: the logic handles the case in which the uart_receive_buf is not yet filled with the needed bytes, so it waits on a semaphore and only after the get the erpcStatus is marked as success. However, when the uart_receive_buf already has the needed bytes, the erpcStatus is not updated and the read wrongfully fails.

erpc_status_t UartTransport::underlyingReceive(uint8_t *data, uint32_t size)
{
erpc_status_t erpcStatus = kErpcStatus_ReceiveFailed;
if (ring_buf_size_get(&uart_receive_buf) < size)
{
s_transferReceiveRequireBytes = size;
/* wait until the receiving is finished */
#if !ERPC_THREADS_IS(NONE)
(void)m_rxSemaphore.get();
#else
s_isTransferReceiveCompleted = false;
while (!s_isTransferReceiveCompleted)
{
}
#endif
erpcStatus = kErpcStatus_Success;
}
/* read data from buffer */
if (ring_buf_get(&uart_receive_buf, data, size) != size)
{
/* reading error, should not happen */
erpcStatus = kErpcStatus_ReceiveFailed;
}
return erpcStatus;
}

I believe this may fail in other context even with physical UARTs, but I was not able to validate the such statement.

I'm about to open a PR with a proposed solution.

To Reproduce

Simply create an erpc::UartTransport using an USB CDC ACM node instead of a physical UART.

Expected behavior

The UartTransport should works with any kind of UART.

Desktop

The test were conducted with eRPC Version v1.12.0 using the python generated code for the client side and Zephyr v3.6.0-rc2 running on a NUCLEO-H563ZI.

Steps you didn't forgot to do

  • I checked if there is no related issue opened/closed.
  • I checked that there doesn't exist opened PR which is solving this issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions