This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problems with USB VCOM on Cortex-M0+ and USB RL

Hello Forum! I am working on a FRDM-KL25Z dev board and hopign to have it come up as a virtual com port on a windows machine and then interact with the incoming data inside the ARM. I didn't see a straightforward example of doing a VCOM port on this processor so I started out with the USB HID example for the tower system with the same processor (Keil\ARM\Boards\Freescale\XTWR-KL25Z48M\RL\USB\Device\HID) and then copied the usb_config.c and usbd_user_cdc.c from another example (Keil\ARM\Boards\Keil\MCBSTR9\RL\USB\Device\CDC). The project compiles, I load it on the target, and then I see the virtual com port on my system (after installing the driver). I have stripped out the code from usbd_user_cdc.c to remove UART functionality. The problem I am having is when I try to open the virtual com port on the windows side. I tried 9600 baud, which seemed to be the default rate in the demo. I tried Putty and RealTerm, both applications hang when I try to open the specific com port. I was wondering if you folks had an idea what I was doing wrong or how I can begin to troubleshoot this. I have debugging access and it seems that USB works enough to identify its self on my system. I also included the CM1 usb library. I added some relevant code below. (I verified usb_config.c with the wizard and it seems to make sense) Thank you in advance!

I had to put the files on pastebin to meet the 7000 character limit

usb_config.c: http://pastebin.com/4vtczSUB
usbd_user_cdc.c: http://pastebin.com/RrSrH3ML
usbd_MKL25Z4.c: http://pastebin.com/D9WGuqnD

Parents
  • Hi,
    same problem on Freescale’s Board TWR-K60N512. There is no example how to use CDC. So I tried to convert one of other examples (HID - which worked), into CDC.
    Basically I removed usbd_user_hid.c , KBD.c files from project.
    Copied usbd_user_cdc.c and usb_config.c from c:\Keil\ARM\Boards\Keil\MCB2300\RL\USB\Device\CDC\
    to project folder and added those 2 files.
    After that I modified USBD_Demo.c and usbd_user_cdc.c.
    On Windows 7 Professional 64 bit, I used :
    mcb2300-vcom.inf, mcb2300-vcom_x86.cat, mcb2300-vcom_amd64.cat files from placed in c:\Keil\ARM\Boards\Keil\MCB2300\RL\USB\Device\CDC\ to install drivers.
    (Or its modifications, basically all text in mcb2300-vcom.inf and usb_config.c were set to “Keil”,and PID, VID changed to corresponding values in usb_config.c).
    Everything is compiling, and running. But when I am trying open virtual serial port on my Windows application Putty, usbd_cdc_ser_initport(U32 baudrate, U32 databits, U32 parity, U32 stopbits) is called – with proper parameter values (set in Putty). After that Putty
    (same with other similar applications), disappears or is locked. So it does not work at all.
    I have installed USBlyzer and all communication looks very similar.

    CODE:
    *USB_Demo.c

    #include <RTL.h>
    #include <rl_usb.h>
    #include "LED.h"
    OS_TID task_id_write;
    U64 write_stack [1200/8];
    __task void writeTask (void);
    
    __task void init (void) {
      os_tsk_prio_self(1);
      usbd_init();
      usbd_connect(__TRUE);
      os_tsk_prio_self(1);
      task_id_write = os_tsk_create_user (writeTask, 1, &write_stack, sizeof (write_stack));
      while (!usbd_configured()){};
       LED_Val(0x0);
      while (1) {
        usbd_vcom_serial2usb();
        usbd_vcom_chkserstate();
        usbd_vcom_usb2serial();
        os_tsk_pass ();
      }
    }
    
    /* buffer type                                                                */
    typedef struct __SER_BUF_T {
      unsigned int wrIdx;
      unsigned int rdIdx;
      unsigned char data[128];
    } SER_BUF_T;
    
    extern unsigned long         ser_txRestart;    /* NZ if TX restart is required       */
    extern unsigned short        ser_lineState;    /* ((msr << 8) | (lsr))               */
    extern volatile SER_BUF_T    ser_out;          /* Serial data buffers                */
    extern volatile SER_BUF_T    ser_in;
    
    #define SER_BUF_SIZE (128)              /* serial buffer in bytes (power 2)   */
    #define SER_BUF_MASK (SER_BUF_SIZE-1ul) /* buffer size mask                   */
    
    /* Buffer read / write macros                                                 */
    #define SER_BUF_RESET(serBuf)      (serBuf.rdIdx = serBuf.wrIdx = 0)
    #define SER_BUF_WR(serBuf, dataIn) (serBuf.data[SER_BUF_MASK & serBuf.wrIdx++] = (dataIn))
    #define SER_BUF_RD(serBuf, dataOut) serBuf.rdIdx++; dataOut = serBuf.data[SER_BUF_MASK & (serBuf.rdIdx-1)];
    #define SER_BUF_EMPTY(serBuf)      (serBuf.rdIdx == serBuf.wrIdx)
    #define SER_BUF_FULL(serBuf)       ((SER_BUF_MASK & serBuf.rdIdx) == (SER_BUF_MASK & (serBuf.wrIdx+1)))
    #define SER_BUF_COUNT(serBuf)      (SER_BUF_MASK & (serBuf.wrIdx - serBuf.rdIdx))
    
    __task void writeTask (void)
    {
            SER_BUF_RESET(ser_in);
            while(1)
            {
      SER_BUF_WR(ser_in, 'a');
      os_tsk_pass ();
    
            }
    }
    
    int main (void) {
      LED_Init();
      LED_Val(0xFF);
      os_sys_init(init);                    /* Init RTX and start 'init'          */
    }
    


    By the way I can see in USBlyzer characters ('a') which I want to sent to PC Host, just after I connect the device to USB.

Reply
  • Hi,
    same problem on Freescale’s Board TWR-K60N512. There is no example how to use CDC. So I tried to convert one of other examples (HID - which worked), into CDC.
    Basically I removed usbd_user_hid.c , KBD.c files from project.
    Copied usbd_user_cdc.c and usb_config.c from c:\Keil\ARM\Boards\Keil\MCB2300\RL\USB\Device\CDC\
    to project folder and added those 2 files.
    After that I modified USBD_Demo.c and usbd_user_cdc.c.
    On Windows 7 Professional 64 bit, I used :
    mcb2300-vcom.inf, mcb2300-vcom_x86.cat, mcb2300-vcom_amd64.cat files from placed in c:\Keil\ARM\Boards\Keil\MCB2300\RL\USB\Device\CDC\ to install drivers.
    (Or its modifications, basically all text in mcb2300-vcom.inf and usb_config.c were set to “Keil”,and PID, VID changed to corresponding values in usb_config.c).
    Everything is compiling, and running. But when I am trying open virtual serial port on my Windows application Putty, usbd_cdc_ser_initport(U32 baudrate, U32 databits, U32 parity, U32 stopbits) is called – with proper parameter values (set in Putty). After that Putty
    (same with other similar applications), disappears or is locked. So it does not work at all.
    I have installed USBlyzer and all communication looks very similar.

    CODE:
    *USB_Demo.c

    #include <RTL.h>
    #include <rl_usb.h>
    #include "LED.h"
    OS_TID task_id_write;
    U64 write_stack [1200/8];
    __task void writeTask (void);
    
    __task void init (void) {
      os_tsk_prio_self(1);
      usbd_init();
      usbd_connect(__TRUE);
      os_tsk_prio_self(1);
      task_id_write = os_tsk_create_user (writeTask, 1, &write_stack, sizeof (write_stack));
      while (!usbd_configured()){};
       LED_Val(0x0);
      while (1) {
        usbd_vcom_serial2usb();
        usbd_vcom_chkserstate();
        usbd_vcom_usb2serial();
        os_tsk_pass ();
      }
    }
    
    /* buffer type                                                                */
    typedef struct __SER_BUF_T {
      unsigned int wrIdx;
      unsigned int rdIdx;
      unsigned char data[128];
    } SER_BUF_T;
    
    extern unsigned long         ser_txRestart;    /* NZ if TX restart is required       */
    extern unsigned short        ser_lineState;    /* ((msr << 8) | (lsr))               */
    extern volatile SER_BUF_T    ser_out;          /* Serial data buffers                */
    extern volatile SER_BUF_T    ser_in;
    
    #define SER_BUF_SIZE (128)              /* serial buffer in bytes (power 2)   */
    #define SER_BUF_MASK (SER_BUF_SIZE-1ul) /* buffer size mask                   */
    
    /* Buffer read / write macros                                                 */
    #define SER_BUF_RESET(serBuf)      (serBuf.rdIdx = serBuf.wrIdx = 0)
    #define SER_BUF_WR(serBuf, dataIn) (serBuf.data[SER_BUF_MASK & serBuf.wrIdx++] = (dataIn))
    #define SER_BUF_RD(serBuf, dataOut) serBuf.rdIdx++; dataOut = serBuf.data[SER_BUF_MASK & (serBuf.rdIdx-1)];
    #define SER_BUF_EMPTY(serBuf)      (serBuf.rdIdx == serBuf.wrIdx)
    #define SER_BUF_FULL(serBuf)       ((SER_BUF_MASK & serBuf.rdIdx) == (SER_BUF_MASK & (serBuf.wrIdx+1)))
    #define SER_BUF_COUNT(serBuf)      (SER_BUF_MASK & (serBuf.wrIdx - serBuf.rdIdx))
    
    __task void writeTask (void)
    {
            SER_BUF_RESET(ser_in);
            while(1)
            {
      SER_BUF_WR(ser_in, 'a');
      os_tsk_pass ();
    
            }
    }
    
    int main (void) {
      LED_Init();
      LED_Val(0xFF);
      os_sys_init(init);                    /* Init RTX and start 'init'          */
    }
    


    By the way I can see in USBlyzer characters ('a') which I want to sent to PC Host, just after I connect the device to USB.

Children