IMXRT UART communication on Zephyr with ISR

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

IMXRT UART communication on Zephyr with ISR

570 Views
srinivasa2005
Contributor II

Hi 

I am using IMXRT1064 EVK to communicate with GSM module over UART using ISR on Zephyr OS. 

uart_fifo_read always reading 4 bytes from the buffer and post that it returns number of bytes is 0. this API works well if the response is less than  4 bytes. If the response is more than 4 bytes, I am not getting the complete data from the FIFO.
 
1. Do we need to change the FIFO size? If we need to change, where is the place to update?
2. CTS and RTS to be enabled? if to enable,  there is no option on IMXRT1064 EVK UART pinouts.
 
Here is UART config 
struct uart_config cfg;
 
    cfg.baudrate = p_baudrate;
    cfg.data_bits = UART_CFG_DATA_BITS_8;
    cfg.parity = UART_CFG_PARITY_NONE;
    cfg.stop_bits = UART_CFG_STOP_BITS_1;
    cfg.flow_ctrl = UART_CFG_FLOW_CTRL_NONE;
 
Here is the Callback to read the FIFO 
/*void NXPUart::UartCb(const struct device* dev, void* user_data)
{
    NXPUart* instance = static_cast<NXPUart*>(user_data);
    auto& logger = Logger::GetInstance();

    if (!instance->uart_dev_)
    {
        logger.Error("UART device not initialized");
        return;
    }

    uint8_t buffer[UART_FIFO_SIZE];
    std::lock_guard<std::mutex> lock(instance->data_mutex_);
    int total_bytes_read = 0;

    while (uart_irq_update(dev) && uart_irq_is_pending(dev))
    {
        // Check if RX IRQ is ready
        if (uart_irq_rx_ready(dev))
        {
            int l_num_bytes_read = 0;
            do
            {
                // Read data in chunks into the buffer
                l_num_bytes_read = uart_fifo_read(dev, buffer, UART_FIFO_SIZE);
                total_bytes_read += l_num_bytes_read;

                if (l_num_bytes_read > 0)
                {
                    // Insert the chunk of data into accumulated_data_
                    instance->accumulated_data_.insert(instance->accumulated_data_.end(), buffer, buffer + l_num_bytes_read);
                    logger.Info("Received chunk: %s", std::string(buffer, buffer + l_num_bytes_read).c_str());
                }

            } while (l_num_bytes_read > 0);

            // Debug: Check accumulated data
            logger.Info("Accumulated Data so far: %s", std::string(instance->accumulated_data_.begin(), instance->accumulated_data_.end()).c_str());

            // Check if accumulated data contains a complete response
            if (instance->is_complete_response_callback_)
            {
                bool is_complete = instance->is_complete_response_callback_(instance->accumulated_data_);

                if (is_complete)
                {
                    // If response is complete, process the accumulated data
                    if (instance->data_received_callback_)
                    {
                        instance->data_received_callback_(
                            instance->accumulated_data_.data(),
                            instance->accumulated_data_.size()
                        );
                    }

                    // Clear the accumulated data after processing the complete response
                    instance->accumulated_data_.clear();
                }
            }
        }
0 Kudos
Reply
1 Reply

529 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

The RXFIFO size is 4 ( 32 data words).  It is a fixed value, a hardware attribute, not configurable.

Hardware control may be helpful, you can use another LPUART instance to have it available on the EVK, CTS and RTS are available on the RT1064 EVK pins over LPUART3.

Best regards,
Omar

0 Kudos
Reply