Bootloader + USB HID device error

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

Bootloader + USB HID device error

2,943 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by szempy on Mon Feb 11 07:57:48 MST 2013
Im using an USB composite device MSC + HID from the AN11232 application note.
And an USB secondary bootloader from the AN10866 application note.

My program is running perfect when i use my project stand alone, but when a make the proper flash size changes and upload the new FW with the bootloader the HID interface isn't working, it appears in the computer management but it has the error : This device cannot start. (Code 10) and it has a yellow warning exclamation mark on it. And everything else is working.

What could be the problem ?
0 Kudos
Reply
10 Replies

2,855 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by szempy on Thu Feb 14 07:41:40 MST 2013

Quote: CodeRedSupport
FAQ now updated for slight text change in drop down in LPCXpresso v5 (you need to select "gdb" rather than "arm-none-eabi-gdb").

Regards,
CodeRedSupport



Thank you.
Is it possible to write somewhere this in so, i don't have to copy and past it to this console ?
0 Kudos
Reply

2,855 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Thu Feb 14 06:39:43 MST 2013

Quote: szempy

Nice, but where is the "select the Console view and in the drop down console selector, pick the "arm-none-eabi-gdb" entry. " ?



FAQ now updated for slight text change in drop down in LPCXpresso v5 (you need to select "gdb" rather than "arm-none-eabi-gdb").

Regards,
CodeRedSupport
0 Kudos
Reply

2,855 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by szempy on Thu Feb 14 04:27:26 MST 2013

Quote: Tsuneo
Surely, my bad. We can't apply source level debug to the bootloaded code.
OK, move to heuristic approach.

In main_hid.c, the Report descriptor, abReportDesc, is declared in this style.
static U8 abReportDesc[] = {
and this declaration causes trouble.

On the other hand, the Device and Configuration descriptors are declared in this style,
static const U8 abDescriptors[] = {
This declaration works fine.

Add "const" to abReportDesc declaration, and try how it goes.
static const U8 abReportDesc[] = {

If it would solve the enumeration problem, it suggests a problem on linker script for the bootloaded code.
- variables with initializer are not initialized well.

Tsuneo



Thank you that fixed the problem
Edit : actually the problem was not that I used the RedLib library, when i switched to the newlib library, everything was working.
I put a printf after this sentence :

           
            *ppbData = abReportDesc;
            printf("\r\n*ppbData : %x &abReportDesc : %x **ppbData : %x abReportDesc[0] : %x\r\n", (unsigned int)*ppbData, (unsigned int)&abReportDesc, **ppbData, abReportDesc[0]);
the Redlib semihost library printed this out without the static in front of the abReportDesc : *ppbData : 10000000 &abReportDesc : 10000000 **ppbData : ff abReportDesc[0] : ff
and the newlib semihost printed out i think just the new lines, but it worked.

When i put the const in under Redlib it printed out the following :
*ppbData : 16678 &abReportDesc : 16678 **ppbData : 6 abReportDesc[0] : 6


Quote: whitecoe
Have you tried this ... ?
http://support.code-red-tech.com/CodeRedWiki/DebugThroughBootloader

HTH!


Nice, but where is the "select the Console view and in the drop down console selector, pick the "arm-none-eabi-gdb" entry. " ?
0 Kudos
Reply

2,855 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by whitecoe on Thu Feb 14 02:18:42 MST 2013

Quote: szempy

How can a place a breakpoint when my bootloader loads the FW ? it jumps to the address 0x10000 and after that i can't see the cod, or am i wrong ?



Have you tried this ... ?
http://support.code-red-tech.com/CodeRedWiki/DebugThroughBootloader

HTH!
0 Kudos
Reply

2,855 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Tsuneo on Wed Feb 13 20:17:10 MST 2013

Quote:
How can a place a breakpoint when my bootloader loads the FW ?

Surely, my bad. We can't apply source level debug to the bootloaded code.
OK, move to heuristic approach.

In main_hid.c, the Report descriptor, abReportDesc, is declared in this style.
static U8 abReportDesc[] = {
and this declaration causes trouble.

On the other hand, the Device and Configuration descriptors are declared in this style,
static const U8 abDescriptors[] = {
This declaration works fine.

Add "const" to abReportDesc declaration, and try how it goes.
static const U8 abReportDesc[] = {

If it would solve the enumeration problem, it suggests a problem on linker script for the bootloaded code.
- variables with initializer are not initialized well.

Tsuneo
0 Kudos
Reply

2,855 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by szempy on Wed Feb 13 05:56:57 MST 2013

Quote: Tsuneo
This is Get_Descriptor( HID_Report ) request.
Failed case returns broken report descriptor.
Maybe, the pointer (address) to the report descriptor is wrong.
This request is processed in this code.

AN11232\software\USBCore\usbcore.c
Line #374
        case HID_REPORT_DESCRIPTOR_TYPE:
          if (SetupPacket.wIndex.WB.L != USB_HID_IF_NUM) {
            return (FALSE);    /* Only Single HID Interface is supported */
          }
          EP0Data.pData = (uint8_t *)HID_ReportDescriptor;   // <---- (1)
          len = HID_ReportDescSize;
          break;


Thank you Tsuneo for your answer, the problem is, that i'm using another usb stack from the Examples folder : RDB1768cmsis2.zip\RDB1768cmsis2_usbstack it looks more understandable for me, but unfortunatly there is something wrong with my LPCXpresso software it gives me a java.lang.NullPointerException when i'm trying to lunch the program.
Any way my function looks like this that handels the HID requests.
static BOOL HIDHandleStdReq(TSetupPacket *pSetup, int *piLen, U8 **ppbData)
{
    U8    bType, bIndex;

    if ((pSetup->bmRequestType == 0x81) &&            // standard IN request for interface
        (pSetup->bRequest == REQ_GET_DESCRIPTOR)) {    // get descriptor
        
        bType = GET_DESC_TYPE(pSetup->wValue);
        bIndex = GET_DESC_INDEX(pSetup->wValue);
        switch (bType) {

        case DESC_HID_REPORT:
            // report
            *ppbData = abReportDesc;
            *piLen = sizeof(abReportDesc);
            break;

        case DESC_HID_HID:
        case DESC_HID_PHYSICAL:
        default:
            // search descriptor space
            return USBGetDescriptor(pSetup->wValue, pSetup->wIndex, piLen, ppbData);
        }
        
        return TRUE;
    }
    return FALSE;
}
you can find this in the RDB1768cmsis2_usb_hid\src\main_hid.c



Quote: Tsuneo

Place a break point at (1), and check the value of EP0Data.pData, after this line.
You'll find HID_ReportDescriptor address on the map file, generated by linker.

OR,
The contents of the report descriptor may be broken.
Read out the address of HID_ReportDescriptor on the debugger.
Its contents should look like
0000: 06 00 ff 09 01 a1 01 19 01 29 40 15 00 26 ff 00
0010: 75 08 95 40 81 00 19 01 29 40 91 00 c0
as the success case.

Tsuneo


How can a place a breakpoint when my bootloader loads the FW ? it jumps to the address 0x10000 and after that i can't see the cod, or am i wrong ?
0 Kudos
Reply

2,855 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Tsuneo on Tue Feb 12 11:38:05 MST 2013

Quote:
Function: 0008 (CONTROL_TRANSFER)
SetupPacket:
0000: 81 06 00 22 00 00 5d 00

This is Get_Descriptor( HID_Report ) request.
Failed case returns broken report descriptor.
Maybe, the pointer (address) to the report descriptor is wrong.
This request is processed in this code.

AN11232\software\USBCore\usbcore.c
Line #374
        case HID_REPORT_DESCRIPTOR_TYPE:
          if (SetupPacket.wIndex.WB.L != USB_HID_IF_NUM) {
            return (FALSE);    /* Only Single HID Interface is supported */
          }
          EP0Data.pData = (uint8_t *)HID_ReportDescriptor;   // <---- (1)
          len = HID_ReportDescSize;
          break;

Place a break point at (1), and check the value of EP0Data.pData, after this line.
You'll find HID_ReportDescriptor address on the map file, generated by linker.

OR,
The contents of the report descriptor may be broken.
Read out the address of HID_ReportDescriptor on the debugger.
Its contents should look like
0000: 06 00 ff 09 01 a1 01 19 01 29 40 15 00 26 ff 00
0010: 75 08 95 40 81 00 19 01 29 40 91 00 c0
as the success case.

Tsuneo
0 Kudos
Reply

2,855 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by stalisman on Tue Feb 12 07:39:32 MST 2013
In your last post you show waht you expected to be sent and what was actually sent.  It might be worth checking what is actually set up in memory prior to the sending of the erroneous descriptor.  It might have been trashed?
0 Kudos
Reply

2,855 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by szempy on Tue Feb 12 00:57:38 MST 2013

Quote: Tsuneo
You need to re-compile your "new" firmware to be loaded, with minor changes.
Did you follow the instruction of "6. User application" section on AN10866_2.pdf?
- Change starting address to 0x0000 2000
- Add NO_CRP macro to the Asm tab


Yep i did that. There is a newer version of the bootloader Revision 3.
I'm using the firmware from address 0x10000.
I took the bootloader and the iap routines from RDB1768cmsis2_usb_bootloader example.


Quote: Tsuneo
It suggests enumeration fails somewhere after the device has returned its device descriptor. If you would try to approach on this facet, take a sniffer logs of enumeration, both in successful and in fail cases. Comparing both logs, and find the first difference of the logs.


I'm getting this :


URB Header (length: 80)
SequenceNumber: 6
Function: 0008 (CONTROL_TRANSFER)
PipeHandle: 897c4290

SetupPacket:
0000: 81 06 00 22 00 00 5d 00
bmRequestType: 81
  DIR: Device-To-Host
  TYPE: Standard
  RECIPIENT: Interface
bRequest: 06 
  GET_DESCRIPTOR
Descriptor Type: 0x0022
  unknown


TransferBuffer: 0x0000001d (29) length
0000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0010: ff ff ff ff ff ff ff ff ff ff ff ff ff

Instead of this :
TransferBuffer: 0x0000001d (29) length
0000: 06 00 ff 09 01 a1 01 19 01 29 40 15 00 26 ff 00
0010: 75 08 95 40 81 00 19 01 29 40 91 00 c0
The header is the same.
Thanx.
0 Kudos
Reply

2,855 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Tsuneo on Mon Feb 11 22:45:36 MST 2013

Quote:
but when a make the proper flash size changes and upload the new FW with the bootloader


You need to re-compile your "new" firmware to be loaded, with minor changes.
Did you follow the instruction of "6. User application" section on AN10866_2.pdf?
- Change starting address to 0x0000 2000
- Add NO_CRP macro to the Asm tab


Quote:
This device cannot start. (Code 10) and it has a yellow warning exclamation mark on it.


It suggests enumeration fails somewhere after the device has returned its device descriptor. If you would try to approach on this facet, take a sniffer logs of enumeration, both in successful and in fail cases. Comparing both logs, and find the first difference of the logs.

Tsuneo
0 Kudos
Reply