mimxrt1170-evk usb device and usb host on different ports using Azure RTOS

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

mimxrt1170-evk usb device and usb host on different ports using Azure RTOS

733 次查看
Burjak
Contributor III

Need help, have trouble when trying to run it both at the same time.

As I have read, there should be no problem with that. So there is HW setup

 

void board_setup(void)
{
    /* Init board hardware. */
    BOARD_ConfigMPU();
    BOARD_InitBootPins();
    BOARD_InitBootClocks();
    BOARD_InitDebugConsole();

    usb_host_hw_setup();
    usb_device_hw_setup();
}

static void usb_host_interrupt_setup(void)
{
    IRQn_Type irqNumber = USB_OTG2_IRQn;

    /* Clear pending IRQ, set priority, and enable IRQ. */
    NVIC_ClearPendingIRQ(irqNumber);
    NVIC_SetPriority(irqNumber, USB_INTERRUPT_PRIORITY);
    EnableIRQ((IRQn_Type)irqNumber);
}

void usb_host_hw_setup(void)
{
    uint32_t usbClockFreq = 24000000;
    usb_phy_config_struct_t phyConfig = {
        BOARD_USB_PHY_D_CAL,
        BOARD_USB_PHY_TXCAL45DP,
        BOARD_USB_PHY_TXCAL45DM,
    };

    CLOCK_EnableUsbhs1PhyPllClock(kCLOCK_Usbphy480M, usbClockFreq);
    CLOCK_EnableUsbhs1Clock(kCLOCK_Usb480M, usbClockFreq);

    USB_EhciPhyInit(kUSB_ControllerEhci1, BOARD_XTAL0_CLK_HZ, &phyConfig);

    usb_host_interrupt_setup();

    delay_ms(200);
}

static void usb_interrupt_setup(void)
{
    uint8_t irqNumber;

    uint8_t usbDeviceEhciIrq[] = USBHS_IRQS;
    irqNumber                  = usbDeviceEhciIrq[CONTROLLER_ID - kUSB_ControllerEhci0];

    /* Clear pending IRQ, set priority, and enable IRQ. */
    NVIC_ClearPendingIRQ((IRQn_Type)irqNumber);
    NVIC_SetPriority((IRQn_Type)irqNumber, USB_INTERRUPT_PRIORITY);
    EnableIRQ((IRQn_Type)irqNumber);
}

void usb_device_hw_setup(void)
{
    uint32_t usbClockFreq = 24000000;
    usb_phy_config_struct_t phyConfig = {
        BOARD_USB_PHY_D_CAL,
        BOARD_USB_PHY_TXCAL45DP,
        BOARD_USB_PHY_TXCAL45DM,
    };

    CLOCK_EnableUsbhs0PhyPllClock(kCLOCK_Usbphy480M, usbClockFreq);
    CLOCK_EnableUsbhs0Clock(kCLOCK_Usb480M, usbClockFreq);
    USB_EhciPhyInit(CONTROLLER_ID, BOARD_XTAL0_CLK_HZ, &phyConfig);

    usb_interrupt_setup();

    delay_ms(200);
}

void USB_OTG2_IRQHandler(void)
{
    ux_hcd_ehci_interrupt_handler();

    SDK_ISR_EXIT_BARRIER;
}

void USB_OTG1_IRQHandler(void)
{
    USB_DeviceEhciIsrFunction(deviceHandle);
}

 

And azure side

 

void tx_application_define(void *first_unused_memory)
{
	sd_card_t *sdcard = &g_sdcard;
	UINT status;

	TX_THREAD_NOT_USED(first_unused_memory);

	/* Initialize FileX.  */
	fx_system_initialize();

	usbx_host_init(first_unused_memory);

	usbx_device_init(first_unused_memory);

............
}

static int usbx_mem_init(VOID)
{
    return ux_system_initialize((VOID *)usb_memory, USBX_MEMORY_SIZE,
                         usb_memory_cachesafe, USBX_MEMORY_CACHESAFE_SIZE);

}

static void demo_thread_entry(ULONG arg)
{
    FX_MEDIA *fx_media;
    UINT status;

    /* The code below is required for installing the host portion of USBX.  */
    status = ux_host_stack_initialize(usbx_host_change_callback);
    if (status != UX_SUCCESS)
        goto err;

    /* Register the HUB class. */
    status = ux_host_stack_class_register(_ux_system_host_class_hub_name,
                                          _ux_host_class_hub_entry);
    if (status != UX_SUCCESS)
        goto err;

    /* Register storage class. */
    status = ux_host_stack_class_register(_ux_system_host_class_storage_name,
                                          _ux_host_class_storage_entry);
    if (status != UX_SUCCESS)
        goto err;

    status = usbx_host_hcd_register();
    if (status != UX_SUCCESS)
        goto err;

    while (1)
    {
        /* Find the storage class. */
        status = demo_class_storage_get(&fx_media);
        if (status == UX_SUCCESS)
        {
        	int read_media_files_status = 1;
        	read_media_files_status = demo_read_file(fx_media);
            if (read_media_files_status == FX_SUCCESS){
            	update("signed_image.bin", fx_media);
            }
        }

        tx_thread_sleep(4 * TX_TIMER_TICKS_PER_SECOND);
    }

err:
    PRINTF("demo_thread_entry: ERROR(0x%x)\r\n", status);

    while (1)
    {
        tx_thread_sleep(TX_TIMER_TICKS_PER_SECOND);
    }
}

/* Define what the initial system looks like. */
void usbx_host_init(void *first_unused_memory)
{
    TX_THREAD_NOT_USED(first_unused_memory);

    /* Initialize USBX memory. */
    if(usbx_mem_init() != UX_SUCCESS)
        goto err;

    /* Create the main demo thread. */
    tx_thread_create(&tx_demo_thread, "tx demo", demo_thread_entry, 0,
                     (VOID *)demo_stack, DEMO_STACK_SIZE, 20, 20, 1,
                     TX_AUTO_START);

    return;

    err:
        PRINTF("usbx_host_init: ERROR(0x%x)\r\n");

        return;
}

void usb_device_setup(void)
{

    _ux_dcd_nxp_dci_initialize(kUSB_ControllerEhci0, &deviceHandle);

    usb_interrupt_setup();
}

void usbx_device_init(void *first_unused_memory)
{

    UINT status;

    UX_PARAMETER_NOT_USED(first_unused_memory);

    /* Initialize USBX Memory */
//   status = ux_system_initialize((VOID *)usb_device_memory, USBX_MEMORY_SIZE, UX_NULL, 0); // usb_memory
//   if (status != UX_SUCCESS)
//       goto err;

    usb_device_setup();

 /* The code below is required for installing the device portion of USBX. No call back for
	device status change in this example. */
	status = ux_device_stack_initialize(ux_get_hs_framework(),
									 ux_get_hs_framework_length(),
									 ux_get_fs_framework(),
									 ux_get_fs_framework_length(),
									 ux_get_string_framework(),
									 ux_get_string_framework_length(),
									 ux_get_language_framework(),
									 ux_get_language_framework_length(),
									 UX_NULL);
//
    if (status != UX_SUCCESS)
        goto err;
.............
}

 

 

So, I believe there are no errors in HW configuration. I did something wrong while setups azure USB stack. If i comment usbx_device_init like this:

    usbx_host_init(first_unused_memory);
    //usbx_device_init(first_unused_memory);

i will have normal working USB stick on 2nd port on my evaluation board.
If i have uncommented both functions, like this:

    usbx_host_init(first_unused_memory);
    usbx_device_init(first_unused_memory);
 
My audio-device on first port is working, but usb stick on second port is not working. Only shows me product id and manufacturer id. Without filelist. 
 
Any advices?
标签 (1)
0 项奖励
回复
1 回复

695 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Burjak ,

  If you test the two USB interfaces separately, whether it works OK or not, I mean, USB1, not USB2.

   I highly suggest you use the company email to create the question post again, instead of the 3rd part email, then it will have higher support priority.

   In your new post, please also tell me which SDK version you are using, and the MIMXRT1170-EVK version.

 

Best Regards,

Kerry

0 项奖励
回复