FRDM-MCXN947 Detection of USB_HS Connection

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

FRDM-MCXN947 Detection of USB_HS Connection

1,367 次查看
Doly02
Contributor I

Hello,

in my application on FRDM-MCX947 board that's based on FreeRTOS, I try to detect USB_HS using USB stack. I always have a situation that the first connection after starting the program is not detected by the interrupt (it does not jump to the USB1_HS_IRQHandler) and when disconnecting the USB1_HS_IRQHandler is called, the next connection is also detected, but once in a while it drops out again.

In the main function in the initialization phase, I initialize the USB stack and enable the interrupt:

 

void APP_UsbInit(void)
{
	USB_DeviceClockInit();
    g_msc.speed                      = USB_SPEED_FULL;
    g_msc.attach                     = 0;
    g_msc.deviceHandle               = NULL;

    if (kStatus_USB_Success != USB_DeviceInit(CONTROLLER_ID, USB_DeviceCallback, &g_msc.deviceHandle))
    {
        usb_echo("USB device mass storage init failed\r\n");
        return;
    }
    SDK_DelayAtLeastUs(5000, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);

    USB_DeviceIsrEnable();

}

void USB_DeviceIsrEnable(void)
{
    uint8_t irqNumber;
    uint8_t usbDeviceEhciIrq[] = USBHS_IRQS;
    irqNumber                  = usbDeviceEhciIrq[CONTROLLER_ID - kUSB_ControllerEhci0];

    /* Install isr, set priority, and enable IRQ. */
    DisableIRQ((IRQn_Type)irqNumber);
    NVIC_SetPriority((IRQn_Type)irqNumber, USB_DEVICE_INTERRUPT_PRIORITY);
    EnableIRQ((IRQn_Type)irqNumber);
}

 

Then, if a connected USB is detected, I initialize Mass Storage and switch the program to Mass Storage mode using a semaphore, however, it is probably not invoked on the first connection:

 

void USB1_HS_IRQHandler(void)
{
	BaseType_t xHigherPriorityTaskWoken = pdFALSE;

    if (false == bMscInitialized)
    {
		/* Initialize The Mass Storage Device Application 	*/
		/* @note Initialization SD Card In Device Mode 		*/
        USB_DeviceApplicationInit();
        bMscInitialized = true;
    }
    USB_DeviceEhciIsrFunction(g_msc.deviceHandle);

    /* Free The Mutex For Mass Storage Task */
    xSemaphoreGiveFromISR(g_TaskMutex, &xHigherPriorityTaskWoken);

    /**
     * Switch The Context From ISR To a Higher Priority Task,
     * Without Waiting For The Next Scheduler Tick.
     **/
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}

 

 

I would like to ask if there is anything else to add during initialization to make my detection work properly. Thank you in advance for all your advice.

 

 

标签 (4)
0 项奖励
回复
4 回复数

1,343 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @Doly02 

I recommend that you first run the SDK demo dev_msc_disk_bm to check whether it works well on your side. This will help us determine if the issue is specific to your setup or the configuration.

BR

Alice

0 项奖励
回复

1,330 次查看
Doly02
Contributor I

Hi @Alice_Yang,

I have tried dev_msc_disk_bm, dev_msc_disk_bm_lite and dev_msc_disk_freertos and they all works fine. It looks like it's some configuration issue, my code is based on dev_msc_disk_bm_lite.   

0 项奖励
回复

1,318 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @Doly02 

So, I recommend that you check your modified code. You can try changing one modification at a time to isolate the issue.

 

BR

Alice

0 项奖励
回复

1,303 次查看
Doly02
Contributor I

Dear @Alice_Yang,

Thank you for your helpful thought, I wouldn't have figured it out without you.

0 项奖励
回复