MCUXpresso USB Virtual Com Port Class Support

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

MCUXpresso USB Virtual Com Port Class Support

3,021 次查看
gsinde
Contributor III

I am using an MK22FN512 with FreeRTOS and it is running very well. In fact the product is basically done but I would like to now add USB Virtual Serial Port. Up until now, the USB port basically charges the LiOn battery.

Normally, I would go into the pin selection, clock selection, and peripheral selection utilities in MCUXpresso but USB doesn't appear to be like the other peripherals.

Is there a step by step guide to add this peripheral. This sounds like an easy one many people may have  done.

Thanks, Gary

0 项奖励
回复
2 回复数

2,841 次查看
gsinde
Contributor III

I opened an example RTOS / USB project and I will begin from there.

(As I get each step working, I will update this thread)

(My Tool: MCUXpresso IDE v10.3.0 [Build 2200] [2018-12-03])

Step 1) Enable USB pins in MCUXpresso Pin Management GUI

Step 2) Enable USB 48 MHz clock in MCUXpresso Clock Management GUI

0 项奖励
回复

2,841 次查看
gsinde
Contributor III

In order to enable the USB clock and get my code to run, I needed to add this line:

CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcIrc48M, 48000000U);

Otherwise, my code basically just came from the VCOM demo that is included with MCUXpresso. I modified the task to handle my console commands via LPUART0 and USBVCOM through the same command processor and it basically worked as is. The UBS works on complicated call back functions and I tweaked the ISR as follows:

void USB0_IRQHandler(void)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;

USB_DeviceKhciIsrFunction(s_cdcVcom.deviceHandle);

if ((1 == s_cdcVcom.attach) && (1 == s_cdcVcom.startTransactions))
{
if ((0 != s_recvSize) && (0xFFFFFFFF != s_recvSize))
{
uint8_t data = s_currRecvBuf[0];
s_recvSize = 0;

if (ConsoleProcess(data))   // Process one  Byte and look for '/r' aka RETURN
{

// User pressed RETURN
vTaskNotifyGiveFromISR(USBVCOM_TaskToNotify, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
}
}

/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
exception return operation might vector to incorrect interrupt */
#if defined __CORTEX_M && (__CORTEX_M == 4U)
__DSB();
#endif
}

0 项奖励
回复