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

Add Ble Scan to usbd_ble_uart_freertos example

Hi I'm trying to change peripheral usbd_ble_uart_freertos example to central with nus_c
I added the scan and nuc_c module.
When I'm testing the application, before making a connection with the peripheral all USB events are working as expected.
After the connection is established new USB events stop working.

This is the code that is responsible for USB events

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void usb_new_event_isr_handler(app_usbd_internal_evt_t const * const p_event, bool queued)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
UNUSED_PARAMETER(p_event);
UNUSED_PARAMETER(queued);
ASSERT(m_usbd_thread != NULL);
/* Release the semaphore */
vTaskNotifyGiveFromISR(m_usbd_thread, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
static void usbd_thread(void * arg)
{
ret_code_t ret;
static const app_usbd_config_t usbd_config = {
.ev_isr_handler = usb_new_event_isr_handler,
.ev_state_proc = usbd_user_ev_handler
};
UNUSED_PARAMETER(arg);
ret = app_usbd_init(&usbd_config);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

It looks that events are received in usb_new_event_isr_handler function, but usbd_thread keep waiting for the event - stuck in ulTaskNotifyTake

 

Parents
  • Which SDK version are you using? Seems like one of the vTaskNotifyGiveFromISR is being lost making your USBD state machine stuck at wait and unable to create any new usbd events

  • maybe you should let the usbd event queue process to run first before waiting as I see one race condition with first waiting and then processing

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    for (;;)
    {
    while (app_usbd_event_queue_process())
    {
    /* Nothing to do */
    }
    /* Waiting for event */
    UNUSED_RETURN_VALUE(ulTaskNotifyTake(pdTRUE, USB_THREAD_MAX_BLOCK_TIME));
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hi,

    i tried this but it didnt help

  • Hmm, then the problem does not seem to be in the code usbd_isr or the usb thread. Need to understand what your application is doing in the "Connected" event. Can you give me your minimalistic project to be able to reproduce this behaviour? 

Reply
  • Hmm, then the problem does not seem to be in the code usbd_isr or the usb thread. Need to understand what your application is doing in the "Connected" event. Can you give me your minimalistic project to be able to reproduce this behaviour? 

Children
No Data