Sequential control packets without ZLP between?

Status
Not open for further replies.
I am trying to understand where, or if, a ZLP (zero length packet) is sent in the teensy USB stack, as I need to send more than 64 bytes of data as a sequence of non-zero-terminated packets to the control endpoint.

It would seem that the usb_setup() handler in usb_device.c is designed to handle an IN response no longer than 8 bytes. At the very end, I have changed the send: routine to handle a *data pointer of arbitrary size.


Code:
 send:

    if (datalen > setup.wLength) datalen = setup.wLength;
		
	do
	{
		size = datalen;
		if (size > EP0_SIZE) size = EP0_SIZE;
		endpoint0_transmit(data, size);
		data += size;
		datalen -= size;
	} while (!(datalen <= 0 && size < EP0_SIZE));

	return;

//     size = datalen;
//     if (size > EP0_SIZE) size = EP0_SIZE;
//     endpoint0_transmit(data, size);
//     data += size;
//     datalen -= size;
//     if (datalen == 0 && size < EP0_SIZE) return;
// 
// 	// Why two?
//     size = datalen;
//     if (size > EP0_SIZE) size = EP0_SIZE;
//     endpoint0_transmit(data, size);
//     data += size;
//     datalen -= size;
//     if (datalen == 0 && size < EP0_SIZE) return;
// 
//     ep0_tx_ptr = data;
//     ep0_tx_len = datalen;

And as well, have expanded reply_buffer[] in usb_dev.c, to accommodate much more than 8 bytes.

However, I think I am not getting the behavior I am after, which is a sequence of 64 byte packets, terminated by the zero-length-packet.

It appears the message is not actually sent until the USB module is enabled in usb_control()

Code:
        // actually "do" the setup request
        usb_setup();
		
		// unfreeze the USB, now that we're ready
		USB0_CTL = USB_CTL_USBENSOFEN;
        break;

This would lead me to suspect that I am merely overwriting the output buffer in endpoint0_transmit() multiple times, and then sending only the last <= 64 byte chunk.**

I am curious what people feel would be a sensible way to implement >64 byte control responses --ideally in such a way that does not break other functionality, and can be merged back into the teensy core.


**(I could be entirely wrong... I am still trying to familiarize myself with this usb state machine)
 
Status
Not open for further replies.
Back
Top