USB CDC as MQX NIO serial device

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

USB CDC as MQX NIO serial device

Jump to solution
1,913 Views
randyhermes
Contributor III

I would like to use the USB CDC class as a MQX NIO serial device to implement a virtual comm port than can be used with stdio.

I've looked at the virtual comm example.  Although it provides the code for interfacing as virtual comm, it does not use it as a standard device.

I've also looked for documentation on writing NIO devices, but it doesn't appear to exist.

 

Working with MQX for SDK.  SDK v1.2.  KDS 3.0

 

Can anyone point me to example code that implements USB CDC as NIO serial device?

If not, are there any instructions out there that would help?

Thanks

Randy Hermes

Labels (1)
0 Kudos
Reply
1 Solution
1,475 Views
randyhermes
Contributor III

I now have a CDC virtual serial driver that behaves just like the standard SDK uart driver.  You can install it with NIO and use all stdio functions with it.

Ended up with the following:
1. CDC virtual comm driver in USB lib - mostly virtual_com.c with a couple call backs added.

2. SDK - USB_UART_DRV - modified uart driver, uses CDC vc driver.

3. NIO - modified serial_io - added USB_VC type, calls functions in USB_UART_DRV.

Still have some unused code in usb_uart_driver that could be stripped out, but it functions.

Randy

View solution in original post

0 Kudos
Reply
7 Replies
1,475 Views
soledad
NXP Employee
NXP Employee

Hello Randy,

Please check the below thread:

How do I setup the debug console to use the Virtual COM port (USB CDC driver)?

In addition, NIO has locking mechanism and that is why the NIO requests (read, write, open…) together with upper layers (puts, putc, printf) should not be used in the ISR context. If the customers uses legacy USB from the MQX, then the CDC driver is running inside the ISR. With the USB from KSDK, the user can be using NIO drivers from the USB device callbacks as the callbacks are executed from the task context (USB device task).


Have a great day,

Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
1,475 Views
randyhermes
Contributor III

Hi Sol,

Thank you for the link.

Does a good job of explaining how to use CDC for debug console, but doesn't address using CDC as an NIO device.

I'll start with this and look through the code to see how it is working.

BTW - I almost have a usb_vc_uart_driver working.  Right now it receives one character and sends part of a string.

It's a little tough to debug because hitting a breakpoint seeems to kill the USB operation.  I understand why this happens, it just makes debugging slow.

Randy

0 Kudos
Reply
1,476 Views
randyhermes
Contributor III

I now have a CDC virtual serial driver that behaves just like the standard SDK uart driver.  You can install it with NIO and use all stdio functions with it.

Ended up with the following:
1. CDC virtual comm driver in USB lib - mostly virtual_com.c with a couple call backs added.

2. SDK - USB_UART_DRV - modified uart driver, uses CDC vc driver.

3. NIO - modified serial_io - added USB_VC type, calls functions in USB_UART_DRV.

Still have some unused code in usb_uart_driver that could be stripped out, but it functions.

Randy

0 Kudos
Reply
1,475 Views
yorknh
Contributor IV

Hi Randy,

Any chance I could convince you provide the files you modified to get that to work?

Larry

0 Kudos
Reply
1,475 Views
randyhermes
Contributor III

Hi Larry,

This work was done under contract and belongs to the client, so I can't send out the files.

I can give you an overview of what I did.

1.  Took the virtual_serial demo file, added the ability to add callbacks for USB_DEV_EVENT_DATA_RECEIVED and USB_DEV_EVENT_SEND_COMPLETE.

2. Added functions to initialize, and send data.

3. Took a copy of the SDK uart_driver and modified to use the virtual serial interface above.  Added it to the SDK lib.

4. Took MQX nio_serial, added a type for USB_Serial, added section for it in switch(serial_dev_context->module) statement.

Most of the work was in SDK usb_serial_driver.

Took me about 2 weeks to research, change code, make library changes and debug. 

Believe it or not, these short notes should save you 2 or 3 days.

Honestly, I don't understand why Freescale doesn't include this in the SDK/MQX.  Seems like most embedded developers could use it.

Hope this helps.  If you decide to try this on your own, let me know if you run into roadblocks and I'll try to answer your questions.

You should be able to post directly to me.

Randy,

1,475 Views
yorknh
Contributor IV

Hey Randy,

Thanks for the reply. That's annoying about the client, since this is hardly IP that is core to a product, but that's their prerogative. Hopefully Freescale will include it in an upcoming release. I'll have to take this on later, since I have more pressing functionality to address, but thanks again for the guidance.

Larry

0 Kudos
Reply
1,475 Views
randyhermes
Contributor III

Hi Larry,

I need to check with the client and see if they are OK with it.

I'll let you know.

Randy

0 Kudos
Reply