How to build a new virtual com project in MCUXpresso 11.1.1?

cancel
Showing results for 
Search instead for 
Did you mean: 

How to build a new virtual com project in MCUXpresso 11.1.1?

309 Views
baldurthorgilss
Contributor III

#MKL46Z #USB #virtual_com #MCUXpresso

In spite of having searched quite a lot for documentation I find it surprisingly cumbersome to create a new USB project for MKL46Z with MCUXpresso. I used MCUXpresso 10 and the best advice I found was to copy an example. I managed to do this but had hoped for a faster way. 

When I upgraded to MCUXpresso 11.1.1 I found a virtual_com item under folder utilities - which gave me hope that here would be a fast way to do a virtual com project (my most frequent use of the usb). None of the material I find mention this. I tried to make a new project. It builds fine but no device gets detected when run. Looking into the code it seems like one is supposed to call the function USB_VcomInit in virtual_com.c but this induces errors that I can't fix.

Hopefully I am just not finding the right documentation. I would be happy for any help.

Best regards

Baldur

Labels (1)
3 Replies

186 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello baldurthorgilsson‌,

As you mention, the best way to start with a CDC example but if you add the utilities vitual_com the APIs to init the VCOM will be added to the project.

In the utilities folder your USB files will be added.

pastedImage_1.png

Let me know if this helps you.

Best Regards,

Alexis Andalon

0 Kudos

186 Views
baldurthorgilss
Contributor III

Hi Alexis 

And thank you so much for replying.

When I run my USB-virtual_com based project i hear the port come in (sound in windows) but it fails immediately (sound again) with the following error in device manager:

USBERROR.png

My utility folder looks very similar to yours (you have extra: fsl_console, fsl_io filesfsl_log and fsl_str files that I think has nothing to do with the USB). My main function looks like this, I have boldfaced the call to what I think is the main entrance of the USB interface in the virtual_com.c file in the utilities folder created by checking the virtual_com utility:

int main(void) {
/* Init board hardware. */
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();

printf("Hello World\n");
//B_APPInit();
USB_VcomInit();

/* Force the counter to be placed into memory. */
volatile static int i = 0 ;
/* Enter an infinite loop, just incrementing a counter. */
while(1) {
i++ ;
/* 'Dummy' NOP to allow source level single stepping of
tight while() loop */
__asm volatile ("nop");
}
return 0 ;
}

Stopping simulation, unplugging USB port and plugging again leads to same error, the virtual comport never appear properly under Ports in Device manager.

Since my post I have found an interesting example: "hello_world_virtual_com" under demo_apps in SDK import wizard. As the name implies is seems to use the virtual_com utility, at least the files and directories look very much like my USB-virtual_com based project. To my surprise when debugging this project the port fails exactly the same way as my project. But when stopping simulation, unplugging the USB connector and plugging it in again the port comes in under Ports in Device manager.

I have analyzed (eclipse compare files) USB files in both these projects and the most important files are exactly the same (usb_device_descriptor.c/.h, virtual_com.c/.h, usb_device_config.h). I found some minor difference in clock_config.c/.h.

I thought I could import the clock from the "hello_world_virtual_com" project into mine with import mex file, but it did not work I am not convinced that the small difference matters for USB, I have the 48MHz clock.

In contrast to these two examples, the example "dev_cdc_vcom_bm" under usb_examples in SDK import wizard has no problems, I can debug it and the above mentioned error never appears. (this is the example I have built on (copied from) when creating a new USB project with the recommended method of building new USB project from an example)

The error I get in the two first mentioned projects (Device descriptor request failed) directs my interest to the USB_DeviceCallback function in the virtual_com.c file. If I compare this function in "hello_world_virtual_com" or my own USB project (these two are equal) on one side to this function in dev_cdc_vcom_bm on the other side, there is a big difference. The latter seems to respond to much more cases in the switch function. 

So to summarize:

  • My USB project: port never come in under Ports in Device manager
  • hello_world_virtual_com: port comes in when rebooted, not during debugging
  • dev_cdc_vcom_bm: port always works fine (but is cumbersome transform to a new project)

Could the problem be that the USB_DeviceCallback  does not serve some device descriptor request?

I would be happy for any comment.

Best regards,

Baldur

0 Kudos

186 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello baldurthorgilsson‌,

I have tested this and as you mention I present the same behavior as you mention, comparing the code example and this library it looks different implementation and the content descriptor is different. Looking at newer SDK it looks like this feature is not supported in the MCUXpresso yet, so I will suggest using the example project as a base to implement the VCOM.

Sorry for the inconvenience this may cause you.

Best Regards,

Alexis Andalon