Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: USBHost_t36 Buffer parameter handling

Threaded View

  1. #1
    Junior Member
    Join Date
    Oct 2019

    Question USBHost_t36 Buffer parameter handling

    Hello everyone,

    I'm currently working with a Teensy 4.0 and doing USB communication. This is generally working, but now I have a problem which I cannot answer myself. It is about the way the USB library handles buffers. I need to do some sendControlPacket(...) calls and this requires a buffer with the bytes sent. My question is how the library handles the buffer passed. It works with a local static buffer, but what does the library do inside? Does it copy the bytes provided? Does it have memory management or just assume that the address with the buffer just exists when the library gets around to sending the bytes out? From what I've seen the library sends data asynchronously.

    The question came as I experienced a weird behaviour with it. Im doing this and it works:
    uint8_t buf[] = {
         0xB3, // 0xB3
         3, // Length
         2, // Host type
         1, // Reserved
         1 // Reserved
    bool result = hid.sendControlPacket(0x21, 0x09, 0x0300, 2, 5, buf);
    When I wrap this exact code in a function with the declaration
    bool send_b3_packet(USBHIDParser hid_parser);
    it doesn't work anymore. But as soon as I put buf as a parameter like so:
    bool send_b3_packet(USBHIDParser hid_parser, uint8_t* buf);
    it works again.

    My knowledge about C/C++ is okay, but not great and my only guess is that the scope of the function disappears too fast, while the loop scope still exists while the data is read. But this also doesn't seem right. Maybe I'm totally on the wrong path and I just made a error, but any clues are welcome

    Also how would I program a system where I could manage the buffers if I have to provide them from the outside, when I have no way of knowing when I'm good to delete the buffer.

    Thanks in advance!
    Last edited by SkryptX; 11-21-2019 at 04:36 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts