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

USB HID and BLE working together ,

When bluetooth only is enabled, the program has no problems.After adding USB, the program crashes。How am I supposed to initialize it, is it a matter of order

<info> app: log_init

int main(void)
{
	log_init();
    ret_code_t err_code;
    timers_init();
    usb_keyboard_init();
    ble_init();

    err_code = app_timer_create(&m_keyboard_scan_timer, APP_TIMER_MODE_REPEATED, keyboard_scan_handler);
    APP_ERROR_CHECK(err_code);   
    err_code = app_timer_start(m_keyboard_scan_timer, APP_TIMER_TICKS(KEYBOARD_SCAN_INTERVAL), NULL);
    APP_ERROR_CHECK(err_code);
    for (;;)
    {
        while (app_usbd_event_queue_process())
        {
            /* Nothing to do */
        }
        idle_state_handle();
    }
}
void ble_init(void)
{
	power_management_init();
	ble_stack_init();
	gap_params_init();
	gatt_init();
	advertising_init();
	services_init();
    conn_params_init();
	advertising_start();
}

<info> app: timers init

<info> CLOCK: Function: nrfx_clock_init, error code: NRF_SUCCESS.

<info> CLOCK: Module enabled.

<info> clock: Function: nrf_drv_clock_init, error code: NRF_SUCCESS.

<info> app: USBD HID composite example started.

<info> app: USB power detected

<error> app: Fatal error

Parents Reply Children
    • I changed the macro definition in sd_config ,

    • NRF_SDH_DISPATCH_MODEL = 0,The original is 1
  • Now my USB can be recognized, and the log also shows that the broadcast starts, but within a few milliseconds the bluetooth broadcast stops, the timer stops working, and the USB is always connected

    • I compiled in VScode and configured the GCC compilation environment

  • Ok. Open your makefile in a text editor and look for the lines starting with CFLAGS += ...

    Add the following line somewhere in between there:

    CFLAGS += -DDEBUG

    Then recompile and flash it again. What does the log say?

  • <info> CLOCK: Function: nrfx_clock_init, error code: NRF_SUCCESS.
    
    <info> CLOCK: Module enabled.
    
    <info> clock: Function: nrf_drv_clock_init, error code: NRF_SUCCESS.
    
    <info> app: USBD HID composite example started.
    
    <debug> nrf_sdh: State request: 0x00000000
    
    <debug> nrf_sdh: State change: 0x00000000
    
    <debug> nrf_sdh: State change: 0x00000001
    
    <debug> nrf_sdh_ble: RAM starts at 0x20002AE8
    
    <info> app: keyboard_scan_handler
    
    <info> app: Fast advertising.
    
    <info> app: keyboard_scan_handler
    
    <info> app: keyboard_scan_handler
    
    <info> app: keyboard_scan_handler
    
    <info> app: keyboard_scan_handler
    
    <info> app: keyboard_scan_handler
    
    <info> app: keyboard_scan_handler
    
    <info> app: keyboard_scan_handler
    
    <info> app: keyboard_scan_handler
    
    <info> app: keyboard_scan_handler
    
    <debug> nrf_sdh_soc: SoC event: 0xA.
    
    <info> app: USB power detected
    
    <debug> nrf_sdh_soc: SoC event: 0x9.
    
    <info> app: USB ready
    
    <debug> USBD: USBD event: SUSPEND
    
    <debug> USBD: USBD event: RESUME
    
    <debug> nrf_sdh_soc: SoC event: 0x0.
    
    <debug> USBD: USBD event: Setup (rt:80 r:06 v:0100 i:0000 l:64 )
    
    <debug> app_usbd_core: SETUP: t: 0x80 r: 0x06
    
    <debug> USBD: Transfer called on endpoint 80, size: 18, mode: FLASH
    
    <debug> USBD: USB DMA process: Starting transfer on EP: 80, size: 18
    
    <debug> USBD: USB DMA process - finishing
    
    <debug> USBD: USB event: DMA ready IN0
    
    <debug> USBD: USBD event: EndpointData: 80
    
    <debug> USBD: USBD event: EndpointData: In finished
    
    <debug> USBD: >> ep0status >>
    
    <debug> USBD: USBD event: Setup (rt:00 r:05 v:000B i:0000 l:0 )
    
    <debug> USBD: USBD event: Setup (rt:80 r:06 v:0100 i:0000 l:18 )
    
    <debug> app_usbd_core: SETUP: t: 0x80 r: 0x06
    
    <debug> USBD: Transfer called on endpoint 80, size: 18, mode: FLASH
    
    <debug> USBD: USB DMA process: Starting transfer on EP: 80, size: 18
    
    <debug> USBD: USB DMA process - finishing
    
    <debug> USBD: USB event: DMA ready IN0
    
    <debug> USBD: USBD event: EndpointData: 80
    
    <debug> USBD: USBD event: EndpointData: In finished
    
    )
    
    <debug> USBD: USB event: DMA ready IN0
    
    <debug> USBD: USBD event: EndpointData: 80
    
    <debug> USBD: USBD event: EndpointData: In finished
    
    <debug> USBD: >> ep0status >>
    
    <debug> USBD: USBD event: Setup (rt:80 r:06 v:0600 i:0000 l:10 )
    
    <debug> app_usbd_core: SETUP: t: 0x80 r: 0x06
    
    <debug> USBD: Setup stalled.
    
    <debug> USBD: USBD event: Setup (rt:80 r:06 v:0100 i:0000 l:18 )
    
    <debug> app_usbd_core: SETUP: t: 0x80 r: 0x06
    
    <debug> USBD: Transfer called on endpoint 80, size: 18, mode: FLASH
    
    : 18
    
    <debug> USBD: USB event: DMA ready IN0
    
    <debug> USBD: USBD event: EndpointData: 80
    
    <debug> USBD: USBD event: EndpointData: In finished
    
    <debug> USBD: >> ep0status >>
    
    <debug> USBD: USBD event: Setup (rt:21 r:09 v:0200 i:0000 l:1 )
    
    <debug> app_usbd_core: SETUP: t: 0x21 r: 0x09
    
    <debug> USBD: USBD event: EndpointData: 0
    
    <debug> USBD: USB DMA process: Starting transfer on EP: 0, size: 1
    
    <debug> USBD: USB DMA process - finishing
    
    <debug> USBD: USB event: DMA ready OUT0
    
    Keyboard_scan_handler, this is one of my timer callback functions, if it's normal, it should be displayed once for 5ms, obviously it's not working properly, and the bluetooth is also dead with the timer

Related