Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SDK 15.2.0: app_usbd_hid_generic_idle_report_set does not compile: 'ret' undeclared

ret is declared inside a "CRITICAL_REGION" which is a block, so not accessible outside that block to return:

ret_code_t app_usbd_hid_generic_idle_report_set(app_usbd_hid_generic_t const * p_generic, const void * p_buff, size_t size) { app_usbd_class_inst_t const * p_inst = (app_usbd_class_inst_t const *)p_generic; app_usbd_hid_generic_ctx_t * p_generic_ctx = hid_generic_ctx_get(p_generic); nrf_drv_usbd_ep_t ep_addr = app_usbd_hid_epin_addr_get(p_inst); app_usbd_hid_state_flag_clr(&p_generic_ctx->hid_ctx, APP_USBD_HID_STATE_FLAG_TRANS_IN_PROGRESS); NRF_DRV_USBD_TRANSFER_IN(transfer, p_buff, size); CRITICAL_REGION_ENTER(); ret_code_t ret = app_usbd_ep_transfer(ep_addr, &transfer); if (ret == NRF_SUCCESS) { app_usbd_hid_state_flag_set(&p_generic_ctx->hid_ctx, APP_USBD_HID_STATE_FLAG_TRANS_IN_PROGRESS); } CRITICAL_REGION_EXIT(); return ret; }

'ret' undeclared (first use in this function); did you mean 'getc'?
  • PLEASE IGNORE THE ABOVE! I had a different problem and this was not the right fix for me.

  • Yes, a weird set of definitions for CRITICAL_REGION_ENTER() and CRITICAL_REGION_EXIT() mean you must be careful using them:

    1 Both must be placed in the same routine (don't try using CRITICAL_REGION_ENTER() in one routine and expect CRITICAL_REGION_EXIT() to work in a different routine.

    2 Don't include two instances of CRITICAL_REGION_EXIT() in the same routine (e.g. one each in an if/then/else statement).

    3 Don't declare variables after the CRITICAL_REGION_ENTER() and expect them to be in scope after the CRITICAL_REGION_EXIT() call. This is the bug that Denis encountered.

    The reason for all these rules is that the CRITICAL_REGION_ENTER() macro adds a "{" which is balanced by a "}" inserted by the CRITICAL_REGION_EXIT() macro.

    I see that the bug Denis reports in SDK15.2.0 is still present in SDK 16.0.0.

    P.S. Please ignore the other post by me on this topic: I tripped up due to (2) above but my initial fix, posted first, was wrong.

Related