Hi everyone,
I've found a possible bug in MQX 3.8.1, USB device library.
In the khci_dev_main.c file, in the _usb_dci_usbfs_preinit function, at line 1363 there is a memory allocation call (USB_mem_alloc_zero) returned in the usb_dev_ptr variable. At line 1368 there is a check if the returned value is not null. The instructions between lines 1369 and 1408 are not executed if the memory allocation failed. However the assignments at lines 1410-1412 are executed regardless the value of the usb_dev_ptr variable, even if the memory allocation failed, resulting in an exception.
Many thanks
Teckna
Hello Teckna,
good catch, it has been fixed !! Thank you for your contribution!!
Regards,
MartinK
And that is not all?!?!
There seems to be memory leak in Freescale_MQX_3.8\usb\device\source\device\khci\khci_dev_main.c
Size is 0xA10.
USB_STATUS _usb_dci_usbfs_init
(
/* [IN] the USB device handle */
_usb_device_handle handle
)
{
volatile USB_KHCI_DEV_STATE_STRUCT_PTR usb_dev_ptr = (USB_KHCI_DEV_STATE_STRUCT_PTR)handle;
USB_KHCI_DEV_INIT_STRUCT_PTR param = (USB_KHCI_DEV_INIT_STRUCT_PTR) usb_dev_ptr->G.INIT_PARAM;
volatile USB_MemMapPtr usb_ptr;
KHCI_XD_STRUCT_PTR xd_ptr;
.....
/* Allocate MAX_XDS_FOR_TR_CALLS */
xd_ptr = (KHCI_XD_STRUCT_PTR) USB_mem_alloc_zero(sizeof(KHCI_XD_STRUCT) * MAX_XDS_FOR_TR_CALLS);
if (xd_ptr == NULL)
{
Hello Kari,
We were aware of this problem in code you posted. It was fixed some time ago. Anyway, thanks for reporting.
Regards,
MartinK
Thanks for you reply Martin!
Downloadable installer for Freescale MQX 3.8.1 came out 8/20/12. So for the users of the MQX 3.8.1 this is not so long time ago. Just wondering if there is a centralized document/location on known problems with MQX 3.8.1 that would save us developers lots of time since we could first check if possible unknown feature would be already known and fixed problem.
BTW. As a developer I appreciate that we have access to full source code and there is this forum to share findings and ideas with other developers. All of us have our own challenges.
Thanks,
Kari
Came across a similar issue when porting from 3.7.0 to 3.8.1 - the way the device init is done has changed, newer code has to include a call to _usb_device_driver_install (which the old app code didn't need) and the USB device library was throwing a "bad pointer" error by attempting to access the null pointer. May even be the same piece of code? What version contains the fix?
Moving on - my target board only enumerates if I put a slow hub in between the native PC ports and the target board.
Same behaviour across K20N512 and K60f and two revisions of MQX 370 and 381. MSD example code and own application code has the same problem. Any ideas?
Hello Nick Tyler,
this was fixed after teckna's report which means it's going to be in MQX 4.0. I'll ask about the second paragraph what could be the cause.
Regards,
MartinK
Thanks for the answer. I am going to try to look at the enumeration with my LeCroy, but as it is the very lowest level I don't know what, if anything, I'll find. I am guessing that the Kinetis is somehow "responding" to HS J/K chirps at the electrical level.
PS. Are composite devices going to be in 4.0 as well? All I have ever wanted from the USB engine was the ability to plug in a PC, and have a MSD and a CDC come up, or plug in a HID bootp keyboard or a bulk-endpoint printer and have the target product enumerate them.
Fairly common use-case for embedded product? If it could also do a hub, that would be a bonus.:smileywink:
Hello,
Well, it is class-specific. The hub is transparent for the host application. Handling with HID boot is a bit unhandy, but if you copy the code from the example you can make it work. CDC class installs new devices.
We support more interfaces per configuration.
Regards,
MartinK
Martin,
Not sure what your reply is saying. Sorry. Are you saying that MQX3.8.1 does support Mass Storage and Communication device classes simultaneously? Unless I am mistaken, the ability to do this is what is known as a composite device. Latest FS medical USB stack supports composite devices. AFAIK MQX 3.8.1 does not.
The other "trick" is for the SIE to switch between device and host mode, such as attaching a camera to either a PC (camera is device), or directly to a printer (camera is host).
I have not yet seen any appnote or example code for either of these two requirements. Either MQX to switch between host and device or to simultaneously support MSD and Virtual Serial Port. Perhaps there is one? Or perhaps MQX cannot do either?
Please clarify. Thanks