UART - Virtual COM bridge causes a system freeze

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

UART - Virtual COM bridge causes a system freeze

934 次查看
embedded_eng_
Contributor III

Hi,

I changed the lpcxpresso55s16_dev_composite_cdc_msc_bm example to bridge the virtual com with UART (Flexcomm 1).

The UART part is based on interrupts.

 

UART to virtual COM: 

UART init:

 

 

#define FLEXCOMM1_PERIPHERAL            USART1
#define FLEXCOMM1_CLOCK_SOURCE    12000000UL
#define FLEXCOMM1_FLEXCOMM_IRQN FLEXCOMM1_IRQn
#define FLEXCOMM1_FLEXCOMM_IRQHANDLER       FLEXCOMM1_IRQHandler



	usart_config_t config;
	USART_GetDefaultConfig(&config);
	config.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE;
	config.enableTx     = true;
	config.enableRx     = true;
	USART_Init(FLEXCOMM1_PERIPHERAL, &config, FLEXCOMM1_CLOCK_SOURCE);
	USART_EnableInterrupts(FLEXCOMM1_PERIPHERAL, kUSART_RxLevelInterruptEnable | kUSART_RxErrorInterruptEnable);
    EnableIRQ(FLEXCOMM1_FLEXCOMM_IRQN);

 

 

 

UART interrupt handler:

 

 

void FLEXCOMM1_IRQHandler(void)
{
    uint8_t data;

    /* If new data arrived. */
    if ((kUSART_RxFifoNotEmptyFlag | kUSART_RxError) & USART_GetStatusFlags(FLEXCOMM1_PERIPHERAL))
    {
        data = USART_ReadByte(FLEXCOMM1_PERIPHERAL);
        send_to_virtual_com(data);
    }
    SDK_ISR_EXIT_BARRIER;
}

 

 

 

The function that actually send the data to the virtual com:

 

 

void send_to_virtual_com(uint8_t byte) {
	if ((1 == g_deviceComposite->cdcVcom.attach) && (1 == g_deviceComposite->cdcVcom.startTransactions)) {
		uint8_t *buf = &byte;
		USB_DeviceCdcAcmSend(g_deviceComposite->cdcVcom.cdcAcmHandle, USB_CDC_VCOM_DIC_BULK_IN_ENDPOINT, buf, 1);

	g_deviceComposite->cdcVcomRecvSize    = 0;
        g_deviceComposite->cdcVcomSendSize    = 0;

    }
}

 

 

 

Virtual COM to UART:

 The following code is part of the infinite loop in main function:

 

 

    if ((1 == g_deviceComposite->cdcVcom.attach) && (1 == g_deviceComposite->cdcVcom.startTransactions))
    {
        /* User Code */
        /* endpoint callback length is USB_CANCELLED_TRANSFER_LENGTH (0xFFFFFFFFU) when transfer is canceled */
        if ((0 != g_deviceComposite->cdcVcomRecvSize) && (USB_CANCELLED_TRANSFER_LENGTH != g_deviceComposite->cdcVcomRecvSize))
        {
            int32_t i;

            /* Copy Buffer to Send Buff */
            for (i = 0; i < g_deviceComposite->cdcVcomRecvSize; i++)
            {
                s_currSendBuf[g_deviceComposite->cdcVcomSendSize++] = s_currRecvBuf[i];
            }
            g_deviceComposite->cdcVcomRecvSize = 0;
        }

        if (g_deviceComposite->cdcVcomSendSize)
        {
            uint32_t size = g_deviceComposite->cdcVcomSendSize;
            g_deviceComposite->cdcVcomSendSize    = 0;
            sendToUart(s_currSendBuf);

            if (error != kStatus_USB_Success)
            {
            }
        }
    }

 

 

 

The function that actually send the data to the UART:

 

 

void sendToUart(uint8_t *buf) {
	USART_WriteBlocking(FLEXCOMM1_PERIPHERAL, buf, (sizeof(buf) / sizeof(buf[0])) - 1);
}

 

 

 

The problem I have is that after ~7000 bytes sent from UART to the virtual COM, the whole system freezes.

 

Maybe someone can help?

标记 (2)
0 项奖励
回复
1 回复

919 次查看
embedded_eng_
Contributor III

I found the problem.

seems that  kUSART_RxErrorInterruptEnable flag caused it.

The bridge works fine without the flag.

0 项奖励
回复