USBVC001: Howto send variable data with const declaration in all function?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Tobias_Gerber
Employee
Employee
He guys,

how can I send "variable data" with all this const declaration?
status_t USBVC001_SendByte(const uint8_t DataByte)
status_t USBVC001_SendData(const char* const DataBuffer, const uint16_t Length)
status_t USBVC001_SendString(const char* const DataString)

Maybe I'm wrong - but standard compiler does allow only constant and can send this into read only area.

Is there any sample - more than send a const "hello world" ?

Thanks for get me out of this gap.
0 Likes
2 Replies
Not applicable
Hi Tobias Gerber,

You can download the USBVC001 example project in the DAVE Project Library.
In the example project, it sends out the value it received.
So, it is the same as sending variable data.


/* Buffer to receive data */
int8_t RxBuffer[100] = { 0 };

/* Receive the byte */
USBVC001_ReceiveByte(&RxBuffer[0]);

/* Send the receive data back to the host */
USBVC001_SendByte(RxBuffer[0]);
0 Likes
Tobias_Gerber
Employee
Employee
Hi Jackson,

this was not the question.
I had a misunderstanding about using const in C. (Internet has some strange interpretations which leads me in a wrong direction)

Code:
...
int a;
const int b = 0815:

a = 1234; // ok
b = a; // wrong, don't change an constant
myfunction ( &a, b); // its ok


myfunction (const int * x, int y)
{
* x = 5; // in function body: every change of x will generate an error - outside it's ok
y = *x; // ok
}

=> const in a function does not include, that outside has to be a const definition.

thanks for helping.

BR Tobias
0 Likes