www.Walzer.cn - Tech & Management Blog

Focus on mobile dev
本博客文章,未在标题中写明转载的, 均为原创.
所谓高手,也就是熟悉别人制定的游戏规则、并且能在规则内跳舞的人。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Q&A: Four problems on USB Serial KITL

Posted on 2006-02-05 11:45  Walzer  阅读(2367)  评论(1编辑  收藏  举报
Q1:What are the differences between PlatformBuilder for Wince5.0 and PlatformBuilder for WindowsMobile(Magneto) ?
     When i use PlatformBuiler for WinCE5.0, open the dialog box of "Target Device Connectivity Options",  I select Ethernet for Download and USB for Transport, Kdstub for Debugger,  then I click "Attach Device". BEFOR DOING ANYTHING, the PB output these lines in the debug window:
(CoreCon)  10:09:20 04/12/2005  Failed to connect debug message service! Please check the transport settings.
(CoreCon)  10:09:20 04/12/2005  Transport service failed to connect
(CoreCon)  10:09:20 04/12/2005  Warning:  One or more services failed to connect.  Make sure that the service is properly configured
    Note that if working normally, the PB must jump out a downloading window and wait for bootme message form the target.
    But I install the Magneto in Tools Only mode, and use the PlatformBuiler Beta for Windows Mobile. The problem above fixed up. So what's the differences between these two PBs?

A1
:很想说两个PB其实没什么区别的. 但现在发现唯一的一点区别在于, 在bootloader没有对target的USB CLIENT模块初始化时, PB for WinCE5.0就不肯Attach了, 而PB for WindowsMobile5.0就可以ATTACH, 但在DOWNLOAD结束后就傻掉不工作了. 这么看来还是前者要更stabile一点.


----------------------------------------------------------

Q2: I can only initialize the USB serial function one time after open the PB, and failed from the second time except i close then re-open the PB.
    I got the source code of USB serial Kitl from Intel. After the hardware init, it polls the usb interrupt status registers. Only if I download and run the image first time after i open the PB, this polling process can be successful. Otherwise it will poll for ever after sending the usb descriptors(PC can recognise it). Maybe it can't get the connected flag in modemStatus and break out from the spin, but it did died at copying usb client interrupt status registers from the hardware register to a volatile parameter. How to fix it?
 
A2仍然不清楚为什么会这样. 其实前面做的代码一点问题也没有,操作顺序有误而已。仔细看了INTEL BSP的USER GUIDE,按照GUIDE里面的顺序操作就OK了。在按照INTEL的说明操作后, 这事情就无法重现了. 似乎这两者之间不应该有关系……

下面是两个要点:

Attaching Device:
1.From the PB Connectivity options kernel service map page, set "Download" to Ethernet, "Transport" to Ethernet, and "Debugger" to KdStub. In the Core Service Setting, set "Download Image" to Always. Click apply button.

2. Start downloading the image by clicking the Attach Device icon.

3. If you are using USB KITL for the first time, PC will ask you to install a USB driver for this device. Use the attachment of this mail, which are wceusbsh.inf and wceusbsh.sys.
8. After the image was successfully downloaded to the target, click on Detach Device icon. Note that don't power off the target device now !

4. From the PB Connectivity options kernel service map page, set "Download" to Ethernet, "Transport" to USB, and "Debugger" to KdStub. Then Form the Core Settings page, select "Never (Jump to Image only)" option for download setting and leave the KITL settings to the defaults. Click the Apply button.

5. Connect the USB Cable to the target device.

6. Attach the device by clicking on Attach Device icon again.

Why should we attach device twice?  (personal opinion by Walzer)
When the first time we attach device, the program runs into kitl initialization, and init usb module. Before this, the usb module isn't valid yet, so we can't set "Transport" to USB, instead set it to Ethernet which has been initialized in the eboot.
At the second time attaching, the USB module is ready, and we set Transport to USB, everything works well except the kitl speed is as low as tranditional serial, hehe

--------------------------------------------------------------------------------------

Q3:In the function ProcessAdminMsg (private\winceos\coreos\nk\kitl\edbgprot.c), i can't get pHdr->Cmd = 9 (KITL_CMD_TRAN_CONFIG) and proceed StartKitl.
    The function StartKitl(TRUE) invoke KITLConnectToDesktop, which invoke KitlSendFrame then KITLPollResponse. I have implemented ethernet KITL successfully, and catch the frames sended the received. In USB serial KITL connecting , i send the same frame to the PC (except i change the device name to "USBDevice"). These two frame is described below:
 
Ethernet:
[0]-[41] DLC_HEADER + IPV4_HEADER + UDP_HEADER. 
[42]-[45]  0x45, 0x44, 0x42, 0x47 'EDBG'
[46] 0xFF (KITL_SVC_ADMIN)
[47] 0x0    (Flags)
[48] 0x0    (SeqNum)
[49] 0x9    (Cmd-KITL_CMD_TRAN_CONFIG)
[50]-[51] 0x20, 0x0 (wLen)
[52]-[53] 0x41, 0x0 (wCPUId = ARMV4I)
[54]-65] 'XXXXXXXX7223' (device name)
[66]-..    0x00...
 
USB serial
[0]-[9] serial header
[10]-[13] 0x45, 0x44, 0x42, 0x47 ('EDBG')
[14] 0xFF (service=KITL_SVC_ADMIN)
[15] 0x0 (flags)
[16] 0x0 (SeqNum)
[17] 0x9 (Cmd=KITL_CMD_TRAN_CONFIG)
[18]-[19]  0x14, 0x00, (wLen)
[20]-[21]  0x41, 0x00 (wCPUId = KITL_CPU_ARMV4I)
[22]-[30]  'USBDevice'
[31]-...  0x00...
 
And then runs the function KITLPollResponse -> KITLPollData -> HandleRecvInterrupt - > Kitl.pfnRecv & ProcessRecvFrame -> ProcessAdminMsg.
The message I got from PC is described as follow:
Ethernet:
[42]-[45]  45 44 42 47  ;'EDBG'
[46]-[48]  ff 00 00 ;service=KITL_SVC_ADMIN, flags=0, seqnum=0
[49] 09  ;pHdr->Cmd=KITL_CMD_TRAN_CONFIG
... 
00000000: 6b 49 54 4c aa 02 20 00 09 29 45 44 42 47 ff 00    ;
00000010: 00 06 01 50 50 53 48 00 47 00 2c ff 6d 09 f8 cf       ;
00000020: 03 00 90 ff 6d 09 00 ff 00 00
'kITL'=6b,49,54,4c.
packetType=OAL_KITL_SERIAL_PACKET (aa)
'EDBG' = 45,44,42,47
service = KITL_SVC_ADMIN (ff)
flags=0, SeqNum=0,
pHdr->Cmd = KITL_CMD_SVC_CONFIG (06)
 
That's the differences. And if i get Cmd=KITL_CMD_SVC_CONFIG, and the KITLPollResponse will spin forever and never get KITLGlobalState |= KITL_ST_DESKTOP_CONNECTED.  What should I do now? I send the same frame but the PB returns the different frame....so puzzled..
 
A3:Ditto,按照上面INTEL GUIDE的步骤操作, 先初始化硬件, 然后第二次ATTACH, 就能收到cmd=9的packet了.

---------------------------------------------------------------------------------------------

Q4:I am quite sure that will be a problem in the near future if i pass down the 3 problems above.  In the function StartKitl,  below KITLConnectToDesktop, there are three subfucntions.
        if (Kitl.dwBootFlags & KITL_FL_DBGMSG)
            SetKernelCommDev (KERNEL_SVC_DBGMSG, KERNEL_COMM_ETHER);
        if (Kitl.dwBootFlags & KITL_FL_PPSH)
            SetKernelCommDev (KERNEL_SVC_PPSH, KERNEL_COMM_ETHER);
        if (Kitl.dwBootFlags & KITL_FL_KDBG)
            SetKernelCommDev (KERNEL_SVC_KDBG, KERNEL_COMM_ETHER);
This codes are in the private directory so i mustn't modify it. But I do use KERNEL_COMM_SERIAL for the usb serial kitl, instead of KERNEL_COMM_ETHER. Even if I change it to KERNEL_COMM_SERIAL, the function SetKernelCommDev doesn't recognise it.
    // only support KERNEL_COMM_ETHER
    if (KERNEL_COMM_ETHER != CommDevice) {
        return FALSE;
    }
I serach this function in the DOCUMENTATION OF WINCE,  Microsoft says "this function is obsolete and should not be used". OMG,how to deal with this?

A4:That's not a problem. 虽然这个文件叫ethdbg.c, 虽然在第二个参数一定要赋成KERNEL_COMM_ETHER, 但实际上进到SetKernelCommDev里面看, 只是在开头判断是否为KERNEL_COMM_ETHER, 并不带到该函数后面的运行里. 所以不论是usb serial kitl或者是tranditional serial kitl, 在这个地方都是过得去的. 我们要做的就是IGNORE.