Keil Logo

second USB CDC hangs

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Read-Only
Author
Tonino Reinbergen
Posted
8-Apr-2011 14:33 GMT
Toolset
ARM
New! second USB CDC hangs

Greetings,

From the sample program provided by Keil, and through the use of various websites especially http://www.keil.com/forum/15274/ I've created a program that is able to sniff out data from the USB2Serial Converter.
It then detects whether the information is usable and if so it stores it's data.

The problem I'm facing is that I can send the data perfectly through one Virtual Com Port. However when I want to review the data that has been 'sniffed' out by sending the sniffed data through the second virtual com port, the device hangs after two requests. These request are being made in the endpoint 5 event in USBUSER.c. During the first two requests it does send its information.
I have described the end points in the USB descriptor file as described by Tsuneo Chinzei on the before mentioned page of Keil.

I had to include the End point in the USB CDC in the USBCORE.c file to be accepted on the PC, else it would just say that the device is not responding when trying to connect to that COM port.

The code below will handle the storage, and reading of the sniffed data.
*RefData will be the pointer to the sniffed data
Value will indicate what will be read
ReadWrite will indicate whether or not the data ought to be stored or read
Position will determine which position it will take in the database.
The Program ain't complete, but the main goal will be to sniff out GPS data provided by a novatel device.

void ReferenceDatabase(char Value, unsigned char *RefData, char ReadWrite, char Position) {
        static TDatabaseData ReferenceDatabase[40];
        static char PassCounter=0;

        switch(ReadWrite) {
        case(WRITE_):
          if (PhotoPosition){
             if( PassCounter>39 )PassCounter=0;
               memcpy(ReferenceDatabase[PassCounter].Latitude,  RefData,sizeof(double));
              RefData+= 8;
              memcpy(ReferenceDatabase[PassCounter].Longitude, RefData,sizeof(double));
              RefData+= 8;
              memcpy(ReferenceDatabase[PassCounter].Height,    RefData,sizeof(double));
              RefData+= 8;
              memcpy(ReferenceDatabase[PassCounter].Bearing,   RefData,sizeof(double));
              PassCounter++;
              }
           else {
              LastPosition = CurrentPosition;
              memcpy(CurrentPosition.Latitude,  RefData, sizeof(double));
              RefData+= 8;
              memcpy(CurrentPosition.Longitude, RefData, sizeof(double));
              RefData+= 8;
              memcpy(CurrentPosition.Height,      RefData, sizeof(double));
              RefData+= 8;
              memcpy(CurrentPosition.Bearing,   RefData, sizeof(double));
              PassCounter++;
              }
        break;
        case(READ_):
            switch(Value){
               case(BEARING_):
                USB_WriteEP(CDC_DEP_IN1, &ReferenceDatabase[Position].Bearing[0], 8);
                break;
               case(HEIGHT_):
                USB_WriteEP(CDC_DEP_IN1, &ReferenceDatabase[Position].Height[0], 8);
                break;
               case(LONGITUDE_):
                 USB_WriteEP(CDC_DEP_IN1, &ReferenceDatabase[Position].Longitude[0], 8);
                break;
               case(LATITUDE_):
                USB_WriteEP(CDC_DEP_IN1, &ReferenceDatabase[Position].Latitude[0], 8);
                break;
                }
             break;
           }
}

This can be done when I write the reference to this function from the Main, however when referred to from the USB endpoint the device hangs after two requests.

This is the INF file written to work under windows XP and windows 7

;
; Keil - An ARM Company  Communication Device Class driver installation file
; (C)2007-2008 Copyright
;

[Version]
Signature="$Windows NT$"
Class=Ports
ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318}
Provider=%Keil%
DriverVer=01/06/07
; CatalogFile=mcb2300-vcom.cat

[Manufacturer]
%Keil%=DeviceList,ntamd64

;-----------------------------------------------------------------------------
;   Device List
;-----------------------------------------------------------------------------


[DeviceList]
%DESCRIPTION%=MCB2300USB, USB\VID_c251&PID_1705
%COMPOSITE%  =MCB2300USB, USB\VID_FF00&PID_0300&MI_00, USB\VID_FF00&PID_0300&MI_02

[DeviceList.ntamd64]
%DESCRIPTION%=MCB2300USB, USB\VID_c251&PID_1705
%COMPOSITE%  =MCB2300USB, USB\VID_FF00&PID_0300&MI_00, USB\VID_FF00&PID_0300&MI_02

;------------------------------------------------------------------------------
;  Windows 2000/XP Sections
;------------------------------------------------------------------------------


[SourceDisksFiles]
;;; blank space

[SourceDisksNames]
;;; blank space


[DestinationDirs]
FakeModemCopyFileSection=12
DefaultDestDir=12

[MCB2300USB]
include=mdmcpq.inf
CopyFiles=FakeModemCopyFileSection
AddReg=MCB2300USB.AddReg

[MCB2300USB.AddReg]
HKR,,DevLoader,,*ntkern
HKR,,NTMPDriver,,usbser.sys
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"

[MCB2300USB.Services]
;;add removed MCB2300USB.NT.Services for testing
;;include=mdmcpq.inf
AddService=usbser, 0x00000002, DriverService


;;[MCB2300USB.nt.HW]
;;include=mdmcpq.inf
;;AddReg=LowerFilterAddReg

[DriverService]
DisplayName=%DRIVER.SVC%
ServiceType=1
StartType=3
ErrorControl=1
ServiceBinary=%12%\usbser.sys


;------------------------------------------------------------------------------
;  String Definitions
;------------------------------------------------------------------------------

[Strings]
Keil       ="Keil - An ARM Company"
DRIVER.SVC ="MCB2300 USB VCom Driver"
DESCRIPTION="MCB2300 USB VCom Port"
COMPOSITE ="MCB2300 CDC-CDC COM Port"

As may be obvious or not from the code written, I'm no pro at programming, however I fail to understand why the device would hang.
If requested I am able to send the whole Program, or provide more information as to what is the goal of this program or whatever information is needed

Hope someone can and is willing to help me with this problem

With kind regards
Tonino Reinbergen

Read-Only
Author
Tsuneo Chinzei
Posted
9-Apr-2011 06:06 GMT
Toolset
ARM
New! RE: second USB CDC hangs

What is the detailed OS version (XP/Vista/7, x86/x64) and Service Pack version?
Also, what is your MCU?

Tsuneo

Read-Only
Author
Tonino Reinbergen
Posted
10-Apr-2011 00:39 GMT
Toolset
ARM
New! RE: second USB CDC hangs

I have programmed it for the lpc2368 on a mcb2300 experimental board.
The os is a 64bit windows 7 professional. Haven't installed any service packs on the system.
I have had problems with the original *.inf file from the keil cdc example. However from several sites I have been able to rewrite it to make it suitable for a 64bit os

Kind regards
Tonino Reinbergen

Read-Only
Author
Tonino Reinbergen
Posted
11-Apr-2011 09:53 GMT
Toolset
ARM
New! RE: second USB CDC hangs

My apologies, the service pack version is service pack 1.
The OS is Windows 7 dutch version.

I haven't modified much from the original CDC example.

A better description of what is going wrong:

When I communicate with the device (the MCB2300 board from Keil) I use endpoint 1 and endpoint 2 for the serial2USB conversion, as was provided in the original example.
From the forum thread as stated in my first post, I have used your example to realize a USB IAD with two USB CDC's.
The only thing I've modified is added a piece in the USBcore.c file, namely the part in the USB CDC parts where it uses an if statement:

if ((SetupPacket.wIndex.WB.L == USB_CDC_CIF_NUM0)  ||       /* IF number correct? */
    (SetupPacket.wIndex.WB.L == USB_CDC_DIF_NUM0)  ||
    (SetupPacket.wIndex.WB.L == USB_CDC_CIF_NUM1)  ||
    (SetupPacket.wIndex.WB.L == USB_CDC_DIF_NUM1)) {

The problem that is occuring is not that it cannot communicate through the serial2USB. Neither is the problem occuring when I duplicate the endpoint 1/2 to endpoint 4/5.
However it cannot convert endpoint 5 data to the serial port. But can convert serial port data to endpoint 5.

My problem is that I am not able to call upon the USB endpoint without it hanging with my own code. The Main idea is that while the normal converter is working my program will have to sniff out certain data, and send it through Endpoint 5 to the pc.
But endpoint 5 will also be used to send a 'database' to the device.

It will be used as an device that determines whether or not the current location (received through the serial port from a Novatel GPS device) has been photographed yet by referring its current position with the positions stored in its memory.

But now after asking information from the second VCOM it hangs after the third try.
It always sends its information twice.

I hope one of you may have a solution or is willing to help me.

With Kind Regards
Tonino Reinbergen

Read-Only
Author
Tonino Reinbergen
Posted
11-Apr-2011 11:24 GMT
Toolset
ARM
New! RE: second USB CDC hangs

I think I may have found the solution...
In the original example the USB_ReadEP is being used to determine whether or not there is useful information and writes that to a buffer. I didn't think it were necessary because I don't want the information, but just use it a trigger to indicate that it has to send its information. However by using it and just asking whether the amount of bytes is higher than zero I was able to keep on requesting information without it hanging...

Next Thread | Thread List | Previous Thread Start a Thread | Settings

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.