I use Keil uVision to bulid a target there is no errors and warings.But Rebulid got 4 warinings,like: Warning C280: "ad_ ptr" unreferenced local variable
Oh, thanks. But how to deal with the warnings, like <unreferenced local varible"size"> What does it mean?
"... <unreferenced local varible"size"> What does it mean?"
That you are nor referencing local variable "size".
"... But how to deal with the warnings, ..."
Reference "size".
#include <Nordic\reg24lu1.h> #include "hal_nrf.h" #include "cklf.h" #include "cpu.h" #include "hal_usb.h" #include "hal_usb_hid.h" #include "usb_api.h" #include "nordic_common.h" static hal_usb_dev_req_resp_t device_req_cb(hal_usb_device_req* req, uint8_t** data_ptr, uint16_t* size) reentrant; static void suspend_cb(uint8_t allow_remote_wu) reentrant; static void resume_cb() reentrant; static void reset_cb() reentrant; static uint8_t ep_1_in_cb(uint8_t *adr_ptr, uint8_t* size) reentrant; static uint8_t ep_2_in_cb(uint8_t *adr_ptr, uint8_t* size) reentrant; bool ep1_sent, ep2_sent; volatile usb_state_t usb_state; void usb_init(void) { hal_usb_init(true, device_req_cb, reset_cb, resume_cb, suspend_cb); hal_usb_endpoint_config(0x81, 32, ep_1_in_cb); hal_usb_endpoint_config(0x82, 32, ep_2_in_cb); ep1_sent = true; ep2_sent = true; usb_state = USB_AWAKE; } void usb_wakeup(void) { hal_usb_wakeup(); usb_state = USB_AWAKE; } usb_state_t usb_get_state() { return usb_state; } void usb_wait_for_configuration(void) { volatile hal_usb_state_t usb_hal_state; do { usb_hal_state = hal_usb_get_state(); } while(usb_hal_state != CONFIGURED); } void usb_send_packet(uint8_t* in_data, uint8_t ep_num, uint8_t size) { if(ep_num == USB_EP_MOUSE) { while(!ep1_sent) ; ep1_sent = false; } else if(ep_num == USB_EP_KEYBOARD) { while(!ep2_sent) ; ep2_sent = false; } hal_usb_send_data(0x80 | ep_num, in_data, size); } static hal_usb_dev_req_resp_t device_req_cb(hal_usb_device_req* req, uint8_t** data_ptr, uint16_t* size) reentrant { hal_usb_dev_req_resp_t retval; if( hal_usb_hid_device_req_proc(req, data_ptr, size, &retval) == true ) { // The request was processed with the result stored in the retval variable return retval; } else { // The request was *not* processed by the HID subsystem return STALL; } return STALL; } static void suspend_cb(uint8_t allow_remote_wu) reentrant { USBSLP = 1; // Disable USB clock (auto clear) if (allow_remote_wu == 1) { // Enable wake-up on USB and USBWU (bit3:0=1010) // Enable MCU_WU (bit5:4=10 ) on RTC WUCONF = (BIT_5 | BIT_3 | BIT_1); usb_state = USB_REM_WU_ENABLE; } else { // Enable wake-up on USB and USBWU (bit3:0=1010) WUCONF = (BIT_3 | BIT_1); usb_state = USB_REM_WU_DISABLE; } } static void resume_cb() reentrant { ep1_sent = true; ep2_sent = true; usb_state = USB_AWAKE; } static void reset_cb() reentrant { ep1_sent = true; ep2_sent = true; usb_state = USB_AWAKE; } static uint8_t ep_1_in_cb(uint8_t *adr_ptr, uint8_t* size) reentrant { ep1_sent = true; return 0x60; // NAK } static uint8_t ep_2_in_cb(uint8_t *adr_ptr, uint8_t* size) reentrant { ep2_sent = true; return 0x60; // NAK } /** @} */
warning C280:'adr_ptr':unreferenced local variable warning C280:'size': unreferenced local variable warning C280:'adr_ptr':unreferenced local variable warning C280:'size': unreferenced local variable
Yes. Unused variables are unreferenced. So you get a warning. So your choices are: 1) Make use of them. 2) Remove them (if global or local) 3) Remove name of unused function parameter,keeping just the type as place holder - or adjust the function to take fewer parameters.
"So your choices are:"
Or, like I said,
4) Reference them. For example, the following works for many compilers.
static uint8_t ep_1_in_cb(uint8_t *adr_ptr, uint8_t* size) reentrant { (void)adr_ptr; (void)size; /* Reference unused parms */ ep1_sent = true; return 0x60; // NAK }
I included your alternative in my "use them".
But the important thing is that this is not Keil-specific. It is the same for just about all C/C++ compilers.
That's not quite the same as just referencing them.
"Use them" implies putting them to some functional use - whereas Dan's suggestion just references them without actually doing anything with them at all.
And there's the problem: some compilers will give a warning along the lines of "code has no effect" for such references...
:-(
BTW: Is it just me, or does the ARM compiler not warn about unused parameters?
It (4) works for many compilers but for C251 it just yields another warning.
The alternative (3) to just mention the type without a name also just yields another warning.
Whatever steps you try to avoid, finally you will have to #pragma warning disable _some_ warning, which looks very ugly in the code to do it locally.
Keil also has
__attribute__((unused)) variable