DFU Upload only working when MAX_BLOCK_SIZE is not a multiple of CONTROL_MAX_PACKET_SIZE

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

DFU Upload only working when MAX_BLOCK_SIZE is not a multiple of CONTROL_MAX_PACKET_SIZE

Jump to solution
1,532 Views
gabrielharrison
Contributor III

Hi,

We are using the DFU class in USB 4.1.1 library successfully to update our device but have had to create a work-around for this issue.

The device is a MK60F15. We have used the bare-metal example code to initialize the USB-FS module.

I have found that if the DFU packet size (MAX_BLOCK_SIZE in usb_descriptor.h) is a multiple of USB packet size the upload hangs at the end of the first block. I've created a temporary work-around by setting MAX_BLOCK_SIZE to 499 but this then causes a bit of a headache within the code that burns each block to flash.

I think the issue is probably that a Zero Length Packet is not sent at the end of the final block but haven't managed to find the relevant bit of code in the stack. I'm also not entirely sure if the issue is at the Windows App end of the Kinetis MCU end.

Any help would be much appreciated,

Gabriel

Message was edited by: Gabriel Harrison

Labels (2)
0 Kudos
Reply
1 Solution
1,317 Views
gabrielharrison
Contributor III

Hi,

I have managed to get to the bottom of this issue but would appreciate a little more advice. The cause of the issue is the Windows DFU Demo not the firmware.

If the block size is a multiple of the USB packet size, after the last block packet, a zero length packet is expected (as set up in USB_Bus_Token_Cpl_Handler() [lines 1608 - 1645]) but is never sent

I have proved this by temporarily changing the 'flag' parameter of the call to _usb_device_init_endpoint() to FALSE.

I am not a C# developer but think that the Demo app needs to configure the use of ZLP with WinUsb_SetPipePolicy() has anyone done this?

Is there a more up-to-date version the the demo app?

Thank you,

Gabriel

View solution in original post

0 Kudos
Reply
7 Replies
1,318 Views
gabrielharrison
Contributor III

Hi,

I have managed to get to the bottom of this issue but would appreciate a little more advice. The cause of the issue is the Windows DFU Demo not the firmware.

If the block size is a multiple of the USB packet size, after the last block packet, a zero length packet is expected (as set up in USB_Bus_Token_Cpl_Handler() [lines 1608 - 1645]) but is never sent

I have proved this by temporarily changing the 'flag' parameter of the call to _usb_device_init_endpoint() to FALSE.

I am not a C# developer but think that the Demo app needs to configure the use of ZLP with WinUsb_SetPipePolicy() has anyone done this?

Is there a more up-to-date version the the demo app?

Thank you,

Gabriel

0 Kudos
Reply
1,317 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Gabriel,

Which device did you run the USB stack 4.1.1 on? Would you please help to clarify? Thanks for your patience!


Have a great day,
Kan

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

0 Kudos
Reply
1,317 Views
gabrielharrison
Contributor III

Hi,

Sorry, yes that would be useful!

I'm running it on a MK60F15 by using the MK60F15 bare-metal example code to initialize the USB-FS module.

Gabriel

0 Kudos
Reply
1,317 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Gabriel,

Thanks for  the information! Would you please tell us if there is any other changes you applied to the USB stack 4.1.1 besides MAX_BLOCK_SIZE? It would be better  if you pass your project for a review, and Thanks for your patience!


Have a great day,
Kan

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

0 Kudos
Reply
1,317 Views
gabrielharrison
Contributor III

Hi,

The change I have made to the stack are:

- Global upgrade of wBlockNum & Final_Block from uint_8 to uint_16 to allow block sizes > 255 (usb_descriptior.c, usb_descriptior.h, usb_dfu.c)

- Upgraded wTransferSize to use both bytes (usb_descriptior.c)

- Increase USB_OUT_PKT_SIZE to 4096 (user_config.h)

- Change MAX_BLOCK_SIZE to 499 (usb_descriptior.h)

Regards,

Gabriel

0 Kudos
Reply
1,317 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Gabriel,

I have checked with an expert for DFU application, and he told me USB_OUT_PKT_SIZE can be 64 bytes at max according to the USB spec. so maybe you can try reduce it and see  if it makes any difference.

Hope that helps,


Have a great day,
Kan

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

0 Kudos
Reply
1,317 Views
gabrielharrison
Contributor III

Thanks,

I've updated USB_OUT_PKT_SIZE although something is still not happy as it's getting stuck in USB_DFU_DNBUSY.

I'm on vacation for a week and will pick this up again when I get back. It could be that this was the fix for this question but I can't tell quick yet.

Regards,

Gabriel

0 Kudos
Reply