ASF4 - how to setup a control request

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If there is any working example on how to setup control request using USB Host provided with ASF4?

 

I know how to do that in ASF3 framework, but i'm tempted to go with ASF4 due to compactness of code produced

 

anyways, what would be equivalent code to this:

</p>
<p>    req.bmRequestType = USB_REQ_DIR_IN | USB_REQ_TYPE_STANDARD | USB_REQ_RECIP_INTERFACE;<br />
    req.bRequest = USB_REQ_GET_DESCRIPTOR;<br />
    req.wValue = USB_DT_HID_REPORT <<8;<br />
    req.wIndex = (uint16_t)uhi_hid_generic_dev.iface_no;<br />
    req.wLength = sizeof(hid_dsc);<br />
                    <br />
    uhd_setup_request(dev->address, &req, hid_dsc, sizeof(hid_dsc), NULL, uhi_hid_generic_get_descriptor_complete_cb);<br />
 </p>
<p>

 

so far i've tried what i've found in msc examples - and it didn't work, and in driver_example.c provided within framework generated code (using host hid mouse as an example):

</p>
<p>            usb_fill_GetReport_req(req,USB_DT_HID_REPORT,0,(uint8_t)HID_MOUSE_inst.iface,USB_HOST_CORE_0_inst.ctrl_buf_size-USBHC_CTRL_DATA_OFFSET);<br />
            usbhc_request(&USB_HOST_CORE_0_inst,(uint8_t *) req,data);<br />

 

i'm either getting error ERR_DENIED or ERR_NONE, but nothing gets transferred

 

i wish documentation was existing...

 

This topic has a solution.
Last Edited: Thu. May 19, 2022 - 04:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can you say which micro you are talking about. You have posted in the "ASF (8 bit)" section of the site. As only two 8bit micros have USB Host (At90USB647 and AT90USB1287) I have a feeling you are talking about ARM in which case there is a separate "ASF (32bit)" section. I can move you post to the other forum but I need to know whether you really mean AVR8 or ARM (or perhaps this is AVR32-UC3 ?)

 

Moderator.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh, I'm sorry, it's ARM flavored (ATSAMD21 to be exact), but i haven't noticed "AVR-Related" at the end of section - my bad

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

struct usb_req *req = (struct usb_req *)USB_HOST_CORE_0_inst.ctrl_buf;<br />
    req->bmRequestType  = USB_REQT_RECIP_INTERFACE | USB_REQT_TYPE_STANDARD | USB_REQT_DIR_IN;<br />
    req->bRequest       = USB_REQ_GET_DESC;<br />
    req->wValue         = (USB_DT_HID_REPORT << 8);<br />
    req->wIndex         = (uint8_t)HID_MOUSE_inst.iface;<br />
    req->wLength        = 256;<br />
    while (ERR_BUSY==usb_h_control_xfer(USB_HOST_CORE_0_inst.rhfunc.pipe_0, (uint8_t *)req, hid_buffeer, 256, 500));

 

did the job

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

er... it did the job once... 

question on how to do it reliable remains...

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok..

prelude:

</p>
<p>static void USB_HOST_CORE_0_req_cb(struct usbhd_driver *d, struct usb_h_pipe *pipe)<br />
{<br />
    USB_HOST_CORE_0_req_done = true;<br />
}<br />
static struct usbhc_handler USB_HOST_CORE_0_req_h = {NULL, (FUNC_PTR)USB_HOST_CORE_0_req_cb};</p>
<p>

 

then

 

</p>
<p>    usbhc_register_handler(&USB_HOST_CORE_0_inst, USBHC_HDL_REQ, &USB_HOST_CORE_0_req_h);<br />
                volatile uint8_t hid_buffer[256];<br />
                struct usb_req *req = (struct usb_req *)USB_HOST_CORE_0_inst.ctrl_buf;<br />
                req->bmRequestType  = USB_REQT_RECIP_INTERFACE | USB_REQT_TYPE_STANDARD | USB_REQT_DIR_IN;<br />
                req->bRequest       = USB_REQ_GET_DESC;<br />
                req->wValue         = (USB_DT_HID_REPORT << 8);<br />
                req->wIndex         = (uint8_t)HID_MOUSE_inst.iface;<br />
                req->wLength        = 256;<br />
        <br />
                USB_HOST_CORE_0_req_done=false;<br />
                do {<br />
                    usb_h_control_xfer(USB_HOST_CORE_0_inst.rhfunc.pipe_0,(uint8_t *) req, hid_buffer, 256, 500);<br />
                } while (!USB_HOST_CORE_0_req_done);<br />

 

where USB_HOST_CORE_0_req_done flag is updated on USB_REQUEST_DONE call back

buffer is filled in pipe_0.max_pkt_size chunks each time usb_h_control_xfer is called

 

first call just sends request out, remaining ones get your data back - perhaps this is obvious for someone, but for me it was very not intuitive, especially when compared to ASF3 framework behaviour

 

i'm not sure if this is all required, but at least it works now