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

nrf52840 usb cant work in our board

hi ,

thank for your browse,when i develop my keyborad,there is a problem in the use of usb.

this is my board hw:

and use pca10056 kd,and program the hex of road :

nRF5_SDK_16.0.0_98a08e2\examples\peripheral\usbd_hid_composite\pca10056\blank\arm5_no_packs\_build

the usb work well.

and than i program the same hex to my board,the usb will not work.and my bord can work well if dont use usb.so my problem is

1.if there is some  config need set if use usb is not in the kd ?

2.in the example of nRF5_SDK_16.0.0_98a08e2\examples\peripheral\usbd_hid_composite,i see the callback of APP_USBD_EVT_POWER_DETECTED,so i dont kown how the mcu know the usb is power on ?mybe we can refrence.

  • Hi, 

    could you upload the full schematic?

    Best regards,

    Kaja

  • thank for your reply,i find the erro in my device.and now the other problem is that how can change the input report size?in the project  RF5_SDK_16.0.0_98a08e2\examples\peripheral\usbd_hid_composite,i try to change the size of key_table

    #define APP_USBD_HID_KBD_REPORT_DSC() {                                                    \
            0x05, 0x01,                    /* USAGE_PAGE (Generic Desktop)                   */\
            0x09, 0x06,                    /* USAGE (Keyboard)                               */\
            0xa1, 0x01,                    /* COLLECTION (Application)                       */\
            0x05, 0x07,                    /*   USAGE_PAGE (Keyboard)                        */\
            0x19, 0xe0,                    /*   USAGE_MINIMUM (Keyboard LeftControl)         */\
            0x29, 0xe7,                    /*   USAGE_MAXIMUM (Keyboard Right GUI)           */\
            0x15, 0x00,                    /*   LOGICAL_MINIMUM (0)                          */\
            0x25, 0x01,                    /*   LOGICAL_MAXIMUM (1)                          */\
            0x75, 0x01,                    /*   REPORT_SIZE (1)                              */\
            0x95, 0x08,                    /*   REPORT_COUNT (8)                             */\
            0x81, 0x02,                    /*   INPUT (Data,Var,Abs)                         */\
            0x95, 0x01,                    /*   REPORT_COUNT (1)                             */\
            0x75, 0x08,                    /*   REPORT_SIZE (8)                              */\
            0x81, 0x03,                    /*   INPUT (Cnst,Var,Abs)                         */\
            0x95, 0x05,                    /*   REPORT_COUNT (5)                             */\
            0x75, 0x01,                    /*   REPORT_SIZE (1)                              */\
            0x05, 0x08,                    /*   USAGE_PAGE (LEDs)                            */\
            0x19, 0x01,                    /*   USAGE_MINIMUM (Num Lock)                     */\
            0x29, 0x05,                    /*   USAGE_MAXIMUM (Kana)                         */\
            0x91, 0x02,                    /*   OUTPUT (Data,Var,Abs)                        */\
            0x95, 0x01,                    /*   REPORT_COUNT (1)                             */\
            0x75, 0x03,                    /*   REPORT_SIZE (3)                              */\
            0x91, 0x03,                    /*   OUTPUT (Cnst,Var,Abs)                        */\
            0x95, 0x30+8,                    /*   REPORT_COUNT (56)                             */\
            0x75, 0x01,                    /*   REPORT_SIZE (1)                              */\
            0x15, 0x00,                    /*   LOGICAL_MINIMUM (0)                          */\
            0x25, 0x01,                    /*   LOGICAL_MAXIMUM (1)                        */\
            0x05, 0x07,                    /*   USAGE_PAGE (Keyboard)                        */\
            0x19, 0x04,                    /*   USAGE_MINIMUM (Reserved (no event indicated))*/\
            0x29, 0x34+8,                    /*   USAGE_MAXIMUM (Keyboard 1)         */\
            0x81, 0x02,                    /*   INPUT (Data,Ary,Abs)                         */\
            0xc0                           /* END_COLLECTION                                 */\
    }

    and change the report desc.and the result is fail.the pc cant recive the key code .

  • Do you re-bond when doing changes here?

    Kenneth

  • im sorry i dont what your mean re-bind.and i try to chang point to test the code:

    1.the size of key_table and report_buff in the app_usbd_hid_kbd_internal.h

    typedef struct {
        app_usbd_hid_ctx_t hid_ctx; //!< HID class context.
    
        struct app_usbd_hid_kbd_ctx_internal_s {
            uint8_t modifier;       //!< Keyboard modifier state @ref app_usbd_hid_kbd_modifier_t.
            uint8_t reserved;       //!< Reserved value.
            uint8_t key_table[11];   //!< Keyboard keys table @ref app_usbd_hid_kbd_codes_t.
        } rep;
    
        uint8_t report_buff[13];     //!< Raw report buffer.
        uint8_t leds_state;         //!< Output report LEDs state.
        uint8_t set_repoart;         //!< Set report flag.
    } app_usbd_hid_kbd_ctx_t;

    2.change the report desc

    #define BUFF_LEN  11
    #define APP_USBD_HID_KBD_REPORT_DSC() {                                                    \
            0x05, 0x01,                    /* USAGE_PAGE (Generic Desktop)                   */\
            0x09, 0x06,                    /* USAGE (Keyboard)                               */\
            0xa1, 0x01,                    /* COLLECTION (Application)                       */\
            0x05, 0x07,                    /*   USAGE_PAGE (Keyboard)                        */\
            0x19, 0xe0,                    /*   USAGE_MINIMUM (Keyboard LeftControl)         */\
            0x29, 0xe7,                    /*   USAGE_MAXIMUM (Keyboard Right GUI)           */\
            0x15, 0x00,                    /*   LOGICAL_MINIMUM (0)                          */\
            0x25, 0x01,                    /*   LOGICAL_MAXIMUM (1)                          */\
            0x75, 0x01,                    /*   REPORT_SIZE (1)                              */\
            0x95, 0x08,                    /*   REPORT_COUNT (8)                             */\
            0x81, 0x02,                    /*   INPUT (Data,Var,Abs)                         */\
            0x95, 0x01,                    /*   REPORT_COUNT (1)                             */\
            0x75, 0x08,                    /*   REPORT_SIZE (8)                              */\
            0x81, 0x03,                    /*   INPUT (Cnst,Var,Abs)                         */\
            0x95, 0x05,                    /*   REPORT_COUNT (5)                             */\
            0x75, 0x01,                    /*   REPORT_SIZE (1)                              */\
            0x05, 0x08,                    /*   USAGE_PAGE (LEDs)                            */\
            0x19, 0x01,                    /*   USAGE_MINIMUM (Num Lock)                     */\
            0x29, 0x05,                    /*   USAGE_MAXIMUM (Kana)                         */\
            0x91, 0x02,                    /*   OUTPUT (Data,Var,Abs)                        */\
            0x95, 0x01,                    /*   REPORT_COUNT (1)                             */\
            0x75, 0x03,                    /*   REPORT_SIZE (3)                              */\
            0x91, 0x03,                    /*   OUTPUT (Cnst,Var,Abs)                        */\
    				\
            0x95, BUFF_LEN*8,                   	 /*   REPORT_COUNT (6)                             */\
            0x75, 0x01,                    /*   REPORT_SIZE (8)                              */\
    				\
            0x15, 0x00,                    /*   LOGICAL_MINIMUM (0)                          */\
            0x25, 0x01,                    /*   LOGICAL_MAXIMUM (101)                        */\
    				\
            0x05, 0x07,                    /*   USAGE_PAGE (Keyboard)                        */\
    				\
            0x19, 0x04,                    /*   USAGE_MINIMUM (Reserved (no event indicated))*/\
            0x29, 0x04+BUFF_LEN*8-1,                    /*   USAGE_MAXIMUM (Keyboard Application)         */\
    				\
            0x81, 0x02,                    /*   INPUT (Data,Ary,Abs)                         */\
            0xc0                           /* END_COLLECTION                                 */\
    }

    3.increse my test code

    void kb_transfer_test(app_usbd_hid_kbd_t const * p_kbd)
    {
    	
    		 app_usbd_hid_kbd_ctx_t * p_kbd_ctx   = hid_kbd_ctx_get(p_kbd);
        /*Save destination*/
        app_usbd_hid_access_lock(&p_kbd_ctx->hid_ctx);
       // *destination = press ? key : 0;//
    	
    	//  memset(&p_kbd_ctx->rep.key_table[0],0xff,27);
    	for(uint8_t i=0;i<11;i++)
    	{
    		 p_kbd_ctx->rep.key_table[i]=0xff; 
    	}
    
        app_usbd_hid_access_unlock(&p_kbd_ctx->hid_ctx);
    
        if (app_usbd_hid_trans_required(&p_kbd_ctx->hid_ctx))
        {
            /*New transfer need to be triggered*/
             hid_kbd_transfer_set(p_kbd);
        }
    }
    
    
    
    void kb_transfer_test_realase(app_usbd_hid_kbd_t const * p_kbd)
    {
    	
    		 app_usbd_hid_kbd_ctx_t * p_kbd_ctx   = hid_kbd_ctx_get(p_kbd);
        /*Save destination*/
        app_usbd_hid_access_lock(&p_kbd_ctx->hid_ctx);
       // *destination = press ? key : 0;//
    	
    	  memset(&p_kbd_ctx->rep.key_table[0],0,11);
    
        app_usbd_hid_access_unlock(&p_kbd_ctx->hid_ctx);
    
        if (app_usbd_hid_trans_required(&p_kbd_ctx->hid_ctx))
        {
            /*New transfer need to be triggered*/
             hid_kbd_transfer_set(p_kbd);
        }
    }
    

    and call it in the key callback

    static void bsp_event_callback(bsp_event_t ev)
    {
        switch ((unsigned int)ev)
        {
            case CONCAT_2(BSP_EVENT_KEY_, BTN_MOUSE_X_POS):
                UNUSED_RETURN_VALUE(app_usbd_hid_mouse_x_move(&m_app_hid_mouse, CONFIG_MOUSE_MOVE_STEP));
                UNUSED_RETURN_VALUE(app_timer_start(m_mouse_move_timer, APP_TIMER_TICKS(CONFIG_MOUSE_MOVE_TIME_MS), NULL));
                break;
            case CONCAT_2(BSP_USER_EVENT_RELEASE_, BTN_MOUSE_X_POS):
                UNUSED_RETURN_VALUE(app_timer_stop(m_mouse_move_timer));
                break;
    
            case CONCAT_2(BSP_EVENT_KEY_, BTN_MOUSE_LEFT):
                UNUSED_RETURN_VALUE(app_usbd_hid_mouse_button_state(&m_app_hid_mouse, 0, true));
                break;
            case CONCAT_2(BSP_USER_EVENT_RELEASE_, BTN_MOUSE_LEFT):
                UNUSED_RETURN_VALUE(app_usbd_hid_mouse_button_state(&m_app_hid_mouse, 0, false));
                break;
    
            case CONCAT_2(BSP_EVENT_KEY_, BTN_KBD_SHIFT):
                UNUSED_RETURN_VALUE(app_usbd_hid_kbd_modifier_state_set(&m_app_hid_kbd, APP_USBD_HID_KBD_MODIFIER_LEFT_SHIFT, true));
                break;
            case CONCAT_2(BSP_USER_EVENT_RELEASE_, BTN_KBD_SHIFT):
                UNUSED_RETURN_VALUE(app_usbd_hid_kbd_modifier_state_set(&m_app_hid_kbd, APP_USBD_HID_KBD_MODIFIER_LEFT_SHIFT, false));
                break;
    
            case CONCAT_2(BSP_EVENT_KEY_, BTN_KBD_LETTER):
               // UNUSED_RETURN_VALUE(app_usbd_hid_kbd_key_control(&m_app_hid_kbd, CONFIG_KBD_LETTER, true));
    						kb_transfer_test(  &m_app_hid_kbd);
                break;
            case CONCAT_2(BSP_USER_EVENT_RELEASE_, BTN_KBD_LETTER):
    					  kb_transfer_test_realase( &m_app_hid_kbd);
               // UNUSED_RETURN_VALUE(app_usbd_hid_kbd_key_control(&m_app_hid_kbd, CONFIG_KBD_LETTER, false));
                break;
    
            default:
                return; // no implementation needed
        }
    }
    

    and i find the problem is that :

    1.if the the USAGE_MINIMUM value in the desc id less than 0x04,the pc cant recive the hid code

    2.if the size of key_table big than 12,there is some code will lose when send to pc

  • When you do changes to the HID descriptors you will need to make sure that you pair again with the pc, this to ensure that the pc will do a full discovery of HID descriptors.

    Kenneth

Related