MQX4.1: USB CDC stack memory allocation failure

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

MQX4.1: USB CDC stack memory allocation failure

跳至解决方案
841 次查看
huishao2
Contributor IV

Hi-

Does anyone have ever enabled USB CDC device on a MK20DX128VFM5 with 16KB RAM only? I run into memory allocation failure in MAX 4.1 k20d50m BSP usb\device\source\device\dev_main.c:

USB_STATUS _usb_device_init
   (
      /* [IN] the USB device controller to initialize */
      struct usb_dev_if_struct  *usb_if,

      /* [OUT] the USB_USB_dev_initialize state structure */
      _usb_device_handle   *handle,

      /* [IN] number of endpoints to initialize */
      _mqx_uint                 endpoints
   )
{ /* Body */

...

   /* Initialize the USB interface. */

   if (dev_if->DEV_PREINIT != NULL)

   {

      error = dev_if->DEV_PREINIT((_usb_device_handle *) &usb_dev_ptr);

   }

...

}

The function call above ends up with a NULL usb_dev_ptr due to a ~3KB memory allocation failure. Since this model of K20 has only 16KB memory, I just want to know if it is feasible to bring up USB CDC stack on this chip.

Thanks

Hui

Added some more details.

The exact failure place is in  usb\device\source\device\khci\khci_dev_main.c, where 2432 bytes of memory is allocated:

USB_STATUS _usb_dci_usbfs_preinit
(
    /* [IN] the USB device handle */
    _usb_device_handle  *handle_ptr
)
{
    USB_KHCI_DEV_STATE_STRUCT_PTR usb_dev_ptr = (USB_KHCI_DEV_STATE_STRUCT_PTR) USB_mem_alloc_zero(sizeof(USB_KHCI_DEV_STATE_STRUCT));
    KHCI_XD_STRUCT_PTR            xd_ptr;
    SCRATCH_STRUCT_PTR            temp_scratch_ptr;
    _mqx_uint j;

    if (NULL != usb_dev_ptr) {
        /* Allocate MAX_XDS_FOR_TR_CALLS */
        usb_dev_ptr->G.XD_BASE = (XD_STRUCT_PTR) USB_mem_alloc_zero(sizeof(KHCI_XD_STRUCT) * MAX_XDS_FOR_TR_CALLS);

        if (usb_dev_ptr->G.XD_BASE == NULL)
        {
            #if DEV_DEBUG
            printf("2 memalloc failed in _usb_device_init\n");
            #endif

...

0 项奖励
1 解答
606 次查看
huishao2
Contributor IV

I got this resolved by disabling unused components from user_config.h and the code that are used for previous k20 project. Now the memory allocation seems to be OK for the tight 16KB RAM. But my CDC device still doesn't get enumerated on PC, will start a new thread for the question.

在原帖中查看解决方案

0 项奖励
3 回复数
607 次查看
huishao2
Contributor IV

I got this resolved by disabling unused components from user_config.h and the code that are used for previous k20 project. Now the memory allocation seems to be OK for the tight 16KB RAM. But my CDC device still doesn't get enumerated on PC, will start a new thread for the question.

0 项奖励
606 次查看
soledad
NXP Employee
NXP Employee

Hi Hui Shao,

Thank you for share your solution,

Have a nice day!

Regards

Sol

0 项奖励
606 次查看
huishao2
Contributor IV

Hi Sol

Actually my USB device also gets enumerates successfully. The Freescale INF file for Windows had been installed for previous project, that is why Windows doesn't prompt for a new hardware found during USB attachment. It simply shows one more COM port in Device Manager which was overlooked.

Thanks!

Hui

0 项奖励