简体   繁体   中英

argument of type “uint8_t” is incompatible with parameter of type “uint8_t *”

I am trying to compile a USB HID example code on Keil for a STM32F4-Discovery. This code allows me to send and receive message to and from a software called "USB HID Demonstrator".

But I have a problem in the USBD_HID_DataOut function. The line:

USB_OTG_ReadPacket((USB_OTG_CORE_HANDLE*)pdev, *Buffer, HID_OUT_PACKET);

Gives me an error:

error #167: argument of type "uint8_t" is incompatible with parameter of type "uint8_t *"

When I suppress the * of Buffer , the code compiles but doesn't seem to work (the buffer values received don't match what is expected but I'm perhaps mistaken about that) and actually the second argument of USB_OTG_ReadPacket must be a pointer so I don't understand why this error occurs.

The Buffer variable is defined as follow: uint8_t Buffer[6];

So is there a problem with the compiler? Do I have to deal with special issues copying this project code into Keil since it was first created for Atollic?

Or is there simply a mistake in the link?

It doesn't make sense to pass *Buffer , because that means the same as Buffer[0] . Why would you write *Buffer instead of Buffer[0] in the first place? Buffer isn't even declared as a pointer, so why would you dereference it? (You can, but it just doesn't look right.)

If the function expects a pointer, than passing Buffer is correct, since it means the same as &Buffer[0] .

Try to clarify your question. What is it you want to pass to the function? Do you want to pass it the first uint8_t element in the Buffer array? In that case, you want to pass Buffer[0] or *Buffer (both mean the same thing.) Or do you want to pass a pointer to the array? In that case, pass Buffer or &Buffer[0] (both are equivalent.)

If you look in the file usbd_hid_core.c.bak at the same line, you can see that there, the author is calling the function correctly:

USB_OTG_ReadPacket((USB_OTG_CORE_HANDLE*)pdev, Buffer, HID_OUT_PACKET);

Since it's declared as an array, you just need to pass the variable name for the reasons Nikos C. mentioned. See this Daniweb thread post for more information on passing pointers to functions.

If you are not receiving the expected values, you will need to debug the flow of that information. I suggest adding Buffer to a Watch window and stepping through your program to see what the value in your Buffer actually is and if it is changing at some unexpected point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM