类型“uint8_t”的参数与“uint8_t *”类型的参数不兼容。

时间:2022-11-07 16:29:15

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".

我正在试图为一个stm32f4发现在Keil上编译一个USB HID示例代码。这段代码允许我发送和接收来自一个名为“USB HID演示者”的软件的消息。

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

但是在USBD_HID_DataOut函数中有一个问题。线:

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

USB_OTG_ReadPacket(pdev(USB_OTG_CORE_HANDLE *)*缓冲区,HID_OUT_PACKET);

Gives me an error:

给了我一个错误:

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

错误#167:类型“uint8_t”的参数与“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.

当我抑制缓冲区的*时,代码会编译,但似乎不起作用(接收的缓冲区值与预期的不匹配,但我可能弄错了),实际上,USB_OTG_ReadPacket的第二个参数必须是一个指针,所以我不理解为什么会出现这个错误。

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

缓冲变量的定义如下:[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?

那么编译器有问题吗?我是否需要处理特殊问题,将这个项目代码复制到Keil中,因为它最初是为Atollic创建的?

Or is there simply a mistake in the link?

或者只是链接上有一个错误?

2 个解决方案

#1


5  

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.)

传递*缓冲区是没有意义的,因为这意味着与缓冲区[0]相同。首先,为什么要写*缓冲区,而不是缓冲区[0]?缓冲区甚至没有被声明为一个指针,那么您为什么要取消它呢?(你可以,但它看起来不太对。)

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

如果函数期望一个指针,那么传递缓冲区是正确的,因为它的意思是相同的和缓冲区[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.)

试着澄清你的问题。你想传递给函数的是什么?您想要将它传递给缓冲区数组中的第一个uint8_t元素吗?在这种情况下,您希望传递缓冲区[0]或*缓冲区(两者都是相同的内容)。还是要传递一个指向数组的指针?在这种情况下,传递缓冲区或缓冲区[0](两者都是等效的)。

#2


1  

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:

如果您查看文件usbd_hid_core.c。在同一行,你可以看到,作者正确地调用了函数:

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

USB_OTG_ReadPacket((USB_OTG_CORE_HANDLE *)pdev缓冲区,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.

因为它被声明为一个数组,所以您只需要传递变量名,就像Nikos c提到的原因一样。有关传递指针到函数的更多信息,请参见这个Daniweb thread post。

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.

如果您没有收到预期值,您将需要调试该信息的流。我建议在一个表窗口中添加缓冲区,并通过程序来查看缓冲区中的值实际上是什么,如果它在某个意外点发生变化。

#1


5  

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.)

传递*缓冲区是没有意义的,因为这意味着与缓冲区[0]相同。首先,为什么要写*缓冲区,而不是缓冲区[0]?缓冲区甚至没有被声明为一个指针,那么您为什么要取消它呢?(你可以,但它看起来不太对。)

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

如果函数期望一个指针,那么传递缓冲区是正确的,因为它的意思是相同的和缓冲区[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.)

试着澄清你的问题。你想传递给函数的是什么?您想要将它传递给缓冲区数组中的第一个uint8_t元素吗?在这种情况下,您希望传递缓冲区[0]或*缓冲区(两者都是相同的内容)。还是要传递一个指向数组的指针?在这种情况下,传递缓冲区或缓冲区[0](两者都是等效的)。

#2


1  

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:

如果您查看文件usbd_hid_core.c。在同一行,你可以看到,作者正确地调用了函数:

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

USB_OTG_ReadPacket((USB_OTG_CORE_HANDLE *)pdev缓冲区,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.

因为它被声明为一个数组,所以您只需要传递变量名,就像Nikos c提到的原因一样。有关传递指针到函数的更多信息,请参见这个Daniweb thread post。

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.

如果您没有收到预期值,您将需要调试该信息的流。我建议在一个表窗口中添加缓冲区,并通过程序来查看缓冲区中的值实际上是什么,如果它在某个意外点发生变化。