[SOLVED]usbFunctionSetup to read/write memory

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
maxi
Rank 3
Rank 3
Posts: 122
Joined: Fri Jul 24, 2009 6:13 pm

[SOLVED]usbFunctionSetup to read/write memory

Post by maxi » Sun Aug 09, 2009 12:17 am

I have been trying to read the contents of a specific memory location on an active device using only usbFunctionSetup.
The address is specified by wIndex in usb_control_msg on a simple endpoint 0 in request (based on custom-class example).
All I want is a single uchar value returned in the buffer.

Code: Select all

usbMsgLen_t usbFunctionSetup(uchar data[8])
{
   usbRequest_t *rq = (void *)data;
   switch(rq->bRequest)
   {
   case GET_ADDRESS_VALUE:      
      usbMsgPtr = (uchar *)((unsigned int)rq->wIndex.word);
      return 1;
   }
   return 0;
}


All I get returned in my buffer is zero, even when I know the value is not. I'm sure this must be possible as the CDC-IO example has something like this via telnet.
It is most likely my mis-understaning of usbMsgPtr as my knowledge of C-style casting is a little vague..

Would someone please tell me if or how I could make this work, I'd also like to be able to set values if that's possible.

Thanks in advance.
Last edited by maxi on Mon Aug 10, 2009 1:04 am, edited 1 time in total.

spiky
Posts: 18
Joined: Mon Jul 27, 2009 4:27 pm

Re: usbFunctionSetup to read memory location

Post by spiky » Sun Aug 09, 2009 6:20 am

I dont have an answer but i propose an alternative.

How about creating a global array ? Pass that array to usbMsgPtr. In your Main loop or elsewhere , you can modify that array. Is there any particular reason you wish to read from a specific location ?

maxi
Rank 3
Rank 3
Posts: 122
Joined: Fri Jul 24, 2009 6:13 pm

Re: usbFunctionSetup to read memory location

Post by maxi » Sun Aug 09, 2009 1:49 pm

Basically what I am trying to implement is a means of reading/altering the contents of certain registers; timers, pre-scalers, adc status etc.
I realise that I could simply set up a switch case with a whole bunch of different request id's, however my idea was, if I could read/write the contents
of a specific location I could theoretically change the value of any register. Bitwise operations could be performed in a two-step process.

The idea came from the CDC-IO example which allows you to read/write the registers via Telnet. I have studied the source code and I think accessing the memory is not such a problem, I'm just not sure how to pass this correctly to usbMsgPtr.

maxi
Rank 3
Rank 3
Posts: 122
Joined: Fri Jul 24, 2009 6:13 pm

Re: usbFunctionSetup to read memory location

Post by maxi » Mon Aug 10, 2009 12:02 am

Problem solved! once again just a silly oversight on my part. I have been using the IO addresses from the data sheet not realising that in memory they are offset by 0x20 because of the reigsters. The following code works if anyone is interested.

Code: Select all

usbMsgLen_t usbFunctionSetup(uchar data[8])
{
   usbRequest_t *rq = (void *)data;
   switch(rq->bRequest)
   {
   case GET_ADDRESS_VALUE:
      usbMsgPtr = (uchar *)((unsigned int)rq->wIndex.word);
      return 1;

   case SET_ADDRESS_VALUE:
      *(uchar *)((unsigned int)rq->wIndex.word) = rq->wValue.bytes[0];
      return 1;
   }
    return 0;
}

Post Reply