Page 1 of 1

Can't copy vaiable "data" to another variable inside "usbFunctionWrite"

Posted: Sun Oct 21, 2018 10:36 am
by mostafayasin
Hello guys,
I tried to copy the whole content of "data" to global array to deal with it as shown in the for loop below :

Code: Select all

volatile static uchar   myData[8];
uchar   usbFunctionWrite(uchar *data, uchar len)
{
    if(bytesRemaining == 0)
        return 1;               /* end of transfer */
    if(len > bytesRemaining)
        len = bytesRemaining;

   currentAddress += len;
    bytesRemaining -= len;

    // copy the whole content of "data"
    uchar i;
    for ( i=0 ; i<len ; i++ ){
       myData[i] = data[i];
    }

    return bytesRemaining == 0; /* return 1 if this was the last chunk */
}

But when trying to send it to the host it seems that my array "myData" is empty and the host prints all zeros, the code below shows how I tried to send it to the host :

Code: Select all

uchar   usbFunctionRead(uchar *data, uchar len)
{
    if(len > bytesRemaining)
        len = bytesRemaining;

    uchar i;
    for ( i=0 ; i<len ; i++ ){
       data[i] = myData[i];
    }

    currentAddress += len;
    bytesRemaining -= len;
    return len;
}

Am I doing something wrongly ?
Thanks for the advice.

Re: Can't copy vaiable "data" to another variable inside "usbFunctionWrite"

Posted: Wed Oct 24, 2018 4:03 pm
by ulao
I'm not sure off hand how the c compiler handles shadow vs one to one copying in c but it is generally better to use memcpy.

Re: Can't copy vaiable "data" to another variable inside "usbFunctionWrite"

Posted: Fri Oct 26, 2018 9:12 pm
by mostafayasin
Thanks ulao, I solved my problem by using another example, I used hid-custom-rq on the vusb examples instead of hid-data .