Creating new USB Type

sagreen83

Active member
I've created a new TeensyLC usb type that emulates an off the shelf device. I've completely tested, and that code is working. When I plug the new Teensy device into a host, the host sees the Teensy as the off the shelf device and works as expected. All of the code changes have been made to the files in teensy/avr/cores/teensy3

Now im trying to port the code to a Teensy4.1. I have the code compiling using board = Teensy4.1, usb=mydevice.

Its not working as expected yet, but the first major thing (that needs customized for mydevice) that I see different between LC and 4.1 is this section from usb.c

Code:
static void endpoint0_complete(void)
{
	setup_t setup;

	setup.bothwords = endpoint0_setupdata.bothwords;
	//printf("complete %x %x %x\n", setup.word1, setup.word2, endpoint0_buffer[0]);
#ifdef CDC_STATUS_INTERFACE
	// 0x2021 is CDC_SET_LINE_CODING
	if (setup.wRequestAndType == 0x2021 && setup.wIndex == CDC_STATUS_INTERFACE) {
		memcpy(usb_cdc_line_coding, endpoint0_buffer, 7);
		printf("usb_cdc_line_coding, baud=%u\n", usb_cdc_line_coding[0]);
		if (usb_cdc_line_coding[0] == 134) {
			usb_start_sof_interrupts(NUM_INTERFACE);
			usb_reboot_timer = 80; // TODO: 10 if only 12 Mbit/sec
		}
	}
#endif
.....
#ifdef KEYBOARD_INTERFACE
	if (setup.word1 == 0x02000921 && setup.word2 == ((1 << 16) | KEYBOARD_INTERFACE)) {
		keyboard_leds = endpoint0_buffer[0];
		endpoint0_transmit(NULL, 0, 0);
	}
#endif

The rest of the porting seems to be pretty strait forward, but this seems entirely new. mydevice is probably closest to the KEYBOARD_INTERFACE. Can someone explain what is happening in this section?

usbreset.jpg

I've attached a screenshot of whats happening when I plug in the device. The host receives the descriptor, then goes into a loop of FUNCTION SYNC RESET PIPE AND CLEAR STALL, FUNCTION BULK OR INTERRUPT TRANSFER, and FUNCTION ABORT PIPE. I'm wondering if it has to do with the endpoint0_complete code above.

Thanks,
Scott...
 
Last edited:
Ok, I may have some more data...

This is the sequence of events from a working device...

packetsgood.jpg

This is from the device that is failing...

packetsbad.jpg

The working device in packet 16 receives a FUNCTION GET DESCRIPTOR FROM INTERFACE, the device responds with FUNCTION CONTROL TRANSFER follwed by 2 PnP: Query IDs, then 1.05 seconds later gets a FUNCTION GET DESCRIPTOR FROM DEVICE and the device sends more packets that are the strings related to the manufacturer and product.

The failing device in packet 28 receives a FUNCTION GET DESCRIPTOR FROM INTERFACE, the device responds with FUNCTION CONTROL TRANSFER follwed by 2 PnP: Query IDs, but it seems like the failing device sends an INTERRUPT (packet 34) before waiting for the FUNCTION GET DESCRIPTOR FROM DEVICE.

Its like there is some timeout that I'm missing in the port to Teensy4.1. Any suggestions where I would look in the code for the handshake that is failing?

Scott...
 
Back
Top