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

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
mostafayasin
Posts: 6
Joined: Sun Oct 21, 2018 12:30 am

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

Post by mostafayasin » Sun Oct 21, 2018 10:36 am

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.

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

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

Post by ulao » Wed Oct 24, 2018 4:03 pm

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.

mostafayasin
Posts: 6
Joined: Sun Oct 21, 2018 12:30 am

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

Post by mostafayasin » Fri Oct 26, 2018 9:12 pm

Thanks ulao, I solved my problem by using another example, I used hid-custom-rq on the vusb examples instead of hid-data .

Post Reply