PE-generated USB code does not seem to work

cancel
Showing results for 
Search instead for 
Did you mean: 

PE-generated USB code does not seem to work

Jump to solution
781 Views
alexfeinman
Contributor III

Using KDS 3.0 and KSDK 1.2.0 trying to build a barebone USB demo. Tried with FRDM-K22F and TWR-K65F180

Steps:

1. Create a new PE-enabled project, using TWR-K65F180 board.

2. In CPU view right-click USB0 and add KSDK 1.2.0/fsl_usb_device_msd_class

3. Select 115200  and UART2 for debug console when prompted to fix a problem. Enable RAM disk demo option.

4. Generate, build and run.

 

Expected result: USB device enumerates as mass storage

Actual result: USB device fails to enumerate (attempts can be seen via dmesg)

 

On the same board usb device mouse sample from SDK works fine.

Same problem occurs on a FRDM-K22F board. I must be missing something obvious.

 

Note: if using TWR-K65 board, you need to either place it in the elevator or to use the micro usb connector, move 2 resistors. This has been done.

Labels (1)
Tags (1)
0 Kudos
1 Solution
80 Views
isaacavila
NXP Employee
NXP Employee

Hi Alex,

I found the issue you are facing.

Problem here is that device does not enumerate because descriptors can't be sent. See next image:

GetDescriptor Fails.jpgAs you can see, host requests for GetDescritpor but device is sending buffer with invalid data.

PE generated descriptors (usbDsc1.c) and used const modifier for them:

const uint8_t usbDsc1_FS_DeviceDescriptor[]={

  0x12,                                /* Descriptor size: 18 bytes */

  USB_DEVICE_DESCRIPTOR,               /* Descriptor type: Device descriptor */

  0x00,0x02,                           /* USB specification release number: USB 2.0 */

  0x00,                                /* Device class code: 0x00 Class information at interface level */

This forces compiler to save this data in Flash (due const modifier), so, when this data is passed to BDT section, this data is "corrupted".

The problem here is that by default, USB does not have permission to read/write to FLASH due crossbar default configuration (M4AP is 00):

crossbar.png

As you can see, Master 4 Access Protection (USB) is disabled by default (00) so no write/read can be achieved from FLASH. (For more details consult K22 reference manual: http://cache.freescale.com/files/microcontrollers/doc/ref_manual/K22P121M120SF7RM.pdf?fasp=1&WT_TYPE... l)

You can either store these descriptors in RAM (does not declare them as const) and compile again, or leave them as const but enable read access to Master 4 (USB), you can try adding this line in hardware_init function.

  /* Allow read USB from flash */

  FMC_PFAPR |= FMC_PFAPR_M4AP(1);

I tried same code using both solutions (not const descriptors and const descriptors but setting M4AP to 1) and they work well.

GetDescriptor Completed.jpg

I hope this can help you

Best Regards,

Isaac Avila

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

Note: If this post answers your question, please click the Correct Answer button. Thank you!

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

View solution in original post

5 Replies
80 Views
isaacavila
NXP Employee
NXP Employee

Hi Alex,

Could you please attach your project?

There is also a guide in how to create a new USB-PE capable project and use KSDK sample code. It was made for FRDM-K64F but could serve as guidance.

You can check it on:

Creating a New USB project with KSDK and Processor Expert support in KDS

I hope this can help

Best Regards,

Isaac

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

Note: If this post answers your question, please click the Correct Answer button. Thank you!

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

0 Kudos
80 Views
alexfeinman
Contributor III

Isaac,  the project is attached.

I appreciate the write-up you linked, but it's not quite the same. It used SDK as a prebuilt library. That works for me and always did. What doesn't is creating a whole MSD or HID component via PE. PE will import the relevant bits from the SDK, but not configure them correctly, resulting in a code that does not work.

What would be great is if you could tell me why the attached project does not work on FRDM-K22F (or I could generate an identical project for K64 if you prefer)

Thank you

Alex

0 Kudos
81 Views
isaacavila
NXP Employee
NXP Employee

Hi Alex,

I found the issue you are facing.

Problem here is that device does not enumerate because descriptors can't be sent. See next image:

GetDescriptor Fails.jpgAs you can see, host requests for GetDescritpor but device is sending buffer with invalid data.

PE generated descriptors (usbDsc1.c) and used const modifier for them:

const uint8_t usbDsc1_FS_DeviceDescriptor[]={

  0x12,                                /* Descriptor size: 18 bytes */

  USB_DEVICE_DESCRIPTOR,               /* Descriptor type: Device descriptor */

  0x00,0x02,                           /* USB specification release number: USB 2.0 */

  0x00,                                /* Device class code: 0x00 Class information at interface level */

This forces compiler to save this data in Flash (due const modifier), so, when this data is passed to BDT section, this data is "corrupted".

The problem here is that by default, USB does not have permission to read/write to FLASH due crossbar default configuration (M4AP is 00):

crossbar.png

As you can see, Master 4 Access Protection (USB) is disabled by default (00) so no write/read can be achieved from FLASH. (For more details consult K22 reference manual: http://cache.freescale.com/files/microcontrollers/doc/ref_manual/K22P121M120SF7RM.pdf?fasp=1&WT_TYPE... l)

You can either store these descriptors in RAM (does not declare them as const) and compile again, or leave them as const but enable read access to Master 4 (USB), you can try adding this line in hardware_init function.

  /* Allow read USB from flash */

  FMC_PFAPR |= FMC_PFAPR_M4AP(1);

I tried same code using both solutions (not const descriptors and const descriptors but setting M4AP to 1) and they work well.

GetDescriptor Completed.jpg

I hope this can help you

Best Regards,

Isaac Avila

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

Note: If this post answers your question, please click the Correct Answer button. Thank you!

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

View solution in original post

80 Views
alexfeinman
Contributor III

Isaac, that was it. May I suggest a small modification - since this is a PE project, why not solve the problem PE way. Add a new FMC_Init component to the FMC pin and then in the configuration enable Master 4 - USB OTG for readonly access. This way you don't need any manual modifications in PE-generated code (that will be overwritten next time)

pastedImage_0.png

80 Views
isaacavila
NXP Employee
NXP Employee

Hi Alex,

I totally agree with you.

It is better to use a PE component to avoid this patch to be overwritten.

Thanks for your feedback.

Best Regards,

Isaac

0 Kudos