This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

data dose not received through USB in some cases

Hi to all,

i am developing an product based on the nrf5240 soc and i want to implement an hid device. after receiving some commands from HID i need to gather user presence, like below:

while(counter < MAX_TRY)
{
    //check user presense
    ..
    
    if(canceled == 1)
        return 0;
}

as you can see i stuck the program in a loop to gather user presence. the protocol that i am implementing let host app to cancel the request by sending a cancel command through usb. problem is here that when i am in the above while loop packets from usb did not received and as result i can not receive cancel command.

i expected that usb events like timer events work while i am in a loop like above but it seems that it did not implemented in that way. so can any one give me a advice to solve the problem?? there is any trick to done that (some function that can be called in while loop and let the soft device done her critical jobs like receiving usb packets or etc).

thanks

Parents
  • Hi,

    Have you tried to place this code in your main loop? I'm wondering if maybe your code is called from another interrupt with equal or higher priority than the USB. Thus preventing the USB command from being processed by the app. 

  • Thanks for your answer, actually i have a always loop in main function and as you implied usb packets successfully  delivered in that case.

    but in my case, i had defined "hid_user_ev_handler" function to receive HID packets like below:

    APP_USBD_HID_GENERIC_GLOBAL_DEF(ctap_hid_generic,
                                    FIDO_HID_GENERIC_INTERFACE,
                                    hid_user_ev_handler,
                                    ENDPOINT_LIST(),
                                    fido_reps,
                                    REPORT_IN_QUEUE_SIZE,
                                    REPORT_OUT_MAXSIZE,
                                    APP_USBD_HID_SUBCLASS_NONE,
                                    APP_USBD_HID_PROTO_GENERIC);
    

    and in function "hid_user_ev_handler" after receiving a usb packet i call function "Usb_Proccess_Command"  in below manner to handle the command:

    app_sched_event_put(NULL, 0, Usb_Proccess_Command);
    and in function "Usb_Proccess_Command" i check the user presence with while loop. i expected that as i called function "Usb_Proccess_Command" with "app_sched_event_put", priority of "Usb_Proccess_Command" was lower than "hid_user_ev_handler". am i correct?
    thanks
  • The HID example uses a scheduler from the USB library by default (APP_USBD_CONFIG_EVENT_QUEUE_ENABLE 1) which means the user callback will not be called from an interrupt context, and the app needs to periodically call app_usbd_event_queue_process() to process queued tasks. Also, the app scheduler is not preemptive. I.e., if you have placed your loop in a scheduled task, subsequent tasks will not be processed until your program exits the loop.

Reply
  • The HID example uses a scheduler from the USB library by default (APP_USBD_CONFIG_EVENT_QUEUE_ENABLE 1) which means the user callback will not be called from an interrupt context, and the app needs to periodically call app_usbd_event_queue_process() to process queued tasks. Also, the app scheduler is not preemptive. I.e., if you have placed your loop in a scheduled task, subsequent tasks will not be processed until your program exits the loop.

Children
Related