expiomegat
Member
This is my first post so I apologize if it's in the wrong section.
I am trying to write a bare metal usb device driver on the Teensy3.1. I have been following Kevin Cuzner's approach http://kevincuzner.com/2014/12/12/teensy-3-1-bare-metal-writing-a-usb-driver/. Right now I am using visual studio with a makefile and the arm eabi M4 compilers (also thanks in part to work by Kevin Cuzner http://kevincuzner.com/2014/04/28/teensy-3-1-bare-metal/). At this point, I have the teensy working as a simple USB device functioning on endpoint 0 and responding to all the control and setup requests. This includes the device, configuration, interface, string, and endpoint descriptors. The device is successfully sets and returns a current configuration. I will post the descriptors below. Now, I am trying to add a BULK IN endpoint at endpoint 1. I am specifying the new endpoint 1 as a bulk IN endpoint under interface 1 in the configuration descriptor. I have also added a relevant handler in the teensy software, under the switch statement.
I have been using microsoft's message analyzer to debug the usb traffic. I am currently using the WinUSB driver on the host side, along with a c# app and ms .net device library to send and recieve low level pipe transfers (i.e. control and setup requests and bulk/interrupt transfers to various endpoints).
Here is a summary/my understanding of the code
So, my problem...
I am able to send and recieve requests to endpoint 0 (the default device control endpoint) in the vs app. However, when I try to send a BULK IN transfer request to endpoint 1, it seems like the USB IRQ is not firing. I have ommited alot of the code but below is the relevant section. Also, I have used PyUSB and a different driver (forget the name, but part of the package) to try a BULK IN transfer request on endpoint 1 and had the same issue. In message analyzer, once the packet times out the sniffer shows what looks like a legitimate request to endpoint 1 (I will also post this below)
But, when the switch is called 'switch (endpoint)', it value is never endpoint 1. When I send a BULK IN request on endpoint 1 through the vs app, the request times out, and I never receive a TOKDNE interrupt for endpoint 1. I have tested back to this point by the small 'SetPin(D13)' in the switch statement, which turns on the Teensy LED when that endpoint is addressed.
I will post code more code but wanted to try to narrow it down to the relevant sections. Sorry if this is a little vague, I'm not sure where to start. Thanks for any ideas/assistance
This is from querying my device descriptor and configuration descriptor in the vs app. But, when I send a BULK IN request to endpoint 1, the stat register is never endpoint 1
Device Descriptor
Edit - Realized I was missing some of the device descriptor, added below
[0x12] 18
[0x01] 1
[0x00] 0
[0x02] 2
[0xFF] 255
[0x02] 2
[0x00] 0
[0x40] 64
[0xC0] 192
[0x16] 22
[0xDC] 220
[0x27] 39
[0x01] 1
[0x00] 0
[0x01] 1
[0x02] 2
[0x00] 0
[0x01] 1
Configuration Descriptor
[0x09] 9
[0x02] 2
[0x19] 25
[0x00] 0
[0x01] 1
[0x01] 1
[0x00] 0
[0x80] 128
[0xFA] 250
[0x09] 9
[0x04] 4
[0x00] 0
[0x00] 0
[0x01] 1
[0xFF] 255
[0xFF] 255
[0x00] 0
[0x00] 0
[0x07] 7
[0x05] 5
[0x81] 129
[0x02] 2
[0x40] 64
[0x00] 0
[0x0A] 10
Edit:
Here is the message analyzer log showing the canceled bulk in transfer request due to timeout in the vs app (approx 30 seconds). The address 0x81 should correspond to endpoint 1 IN
Name Value:Bit Offset Bit Length Type
TransferData: (BinaryValue)
UrbPtr: 18446708890892172592 (UInt64)
DeviceInstance: 6 (Int32)
EndpointAddress 0x81 (Byte)
Type: Bulk(2) (UsbTransferType)
Direction: In(1) (UsbDirection)
LengthCompleted: 0 (UInt32)
LengthRequested: 64 (UInt32)
NtStatus: STATUS_CANCELLED(3221225760) (NTSTATUS)
Status: USBD_STATUS_CANCELED(3221291008) (UsbdStatus)
I am trying to write a bare metal usb device driver on the Teensy3.1. I have been following Kevin Cuzner's approach http://kevincuzner.com/2014/12/12/teensy-3-1-bare-metal-writing-a-usb-driver/. Right now I am using visual studio with a makefile and the arm eabi M4 compilers (also thanks in part to work by Kevin Cuzner http://kevincuzner.com/2014/04/28/teensy-3-1-bare-metal/). At this point, I have the teensy working as a simple USB device functioning on endpoint 0 and responding to all the control and setup requests. This includes the device, configuration, interface, string, and endpoint descriptors. The device is successfully sets and returns a current configuration. I will post the descriptors below. Now, I am trying to add a BULK IN endpoint at endpoint 1. I am specifying the new endpoint 1 as a bulk IN endpoint under interface 1 in the configuration descriptor. I have also added a relevant handler in the teensy software, under the switch statement.
I have been using microsoft's message analyzer to debug the usb traffic. I am currently using the WinUSB driver on the host side, along with a c# app and ms .net device library to send and recieve low level pipe transfers (i.e. control and setup requests and bulk/interrupt transfers to various endpoints).
Here is a summary/my understanding of the code
- When a packet is recieved, an interrupt is fired by the USB module and the USBOTG_IRQHandler() is called
- The USB0_ISTAT (pg. 983) reg tells us what kind of USB packet was recieved
- If USB_ISTAT_USBRST_MASK
- I am enabling the USB0_ENDPT0 and USB0_ENDPT1 register on reset for rx,tx, and handshaking (when the device is plugged in).
- If USB_ISTAT_TOKDNE_MASK (we are handling a new USB token)
- The USB0_STAT register should contain the target endpoint index in high nibble for the current packet (pg. 988)
- The token is processed though a switch statement on the endpoint index to the correct endpoint handler
- If USB_ISTAT_USBRST_MASK
So, my problem...
I am able to send and recieve requests to endpoint 0 (the default device control endpoint) in the vs app. However, when I try to send a BULK IN transfer request to endpoint 1, it seems like the USB IRQ is not firing. I have ommited alot of the code but below is the relevant section. Also, I have used PyUSB and a different driver (forget the name, but part of the package) to try a BULK IN transfer request on endpoint 1 and had the same issue. In message analyzer, once the packet times out the sniffer shows what looks like a legitimate request to endpoint 1 (I will also post this below)
But, when the switch is called 'switch (endpoint)', it value is never endpoint 1. When I send a BULK IN request on endpoint 1 through the vs app, the request times out, and I never receive a TOKDNE interrupt for endpoint 1. I have tested back to this point by the small 'SetPin(D13)' in the switch statement, which turns on the Teensy LED when that endpoint is addressed.
I will post code more code but wanted to try to narrow it down to the relevant sections. Sorry if this is a little vague, I'm not sure where to start. Thanks for any ideas/assistance
Code:
void USBOTG_IRQHandler(void)
{
uint8_t status;
uint8_t stat, endpoint;
status = USB0_ISTAT;
if (status & USB_ISTAT_USBRST_MASK)
{
//handle USB reset
... ....
//initialize endpoint0 to 0x0d (41.5.23)
//transmit, recieve, and handshake
USB0_ENDPT0 = USB_ENDPT_EPRXEN_MASK | USB_ENDPT_EPTXEN_MASK | USB_ENDPT_EPHSHK_MASK;
//same for endpoint 1
USB0_ENDPT1 = USB_ENDPT_EPRXEN_MASK | USB_ENDPT_EPTXEN_MASK | USB_ENDPT_EPHSHK_MASK;
... ...
}
... ...
if (status & USB_ISTAT_TOKDNE_MASK)
{
//handle completion of current token being processed
//45.5.13, page 987 describes the STAT register
//The stat register contains:
// D7-D4: The endpoint. This also allows the processor to figure out which BDT was updated
// D3: TX (0 = The most recent was a recieve operation)
// D2: ODD (1 = The most recent was a transmit operation)
// D1-0: zero
stat = USB0_STAT;
endpoint = (stat & USB_STAT_ENDP_MASK) >> USB_STAT_ENDP_SHIFT;
switch (endpoint)
{
case 0x0u:
usb_endp0_handler(stat);
break;
case 0x1u:
SetPin(D13);
usb_endp1_handler(stat);
break;
default:
STALL_ENDPT(0);
}
USB0_ISTAT = USB_ISTAT_TOKDNE_MASK;
}
... ...
}
This is from querying my device descriptor and configuration descriptor in the vs app. But, when I send a BULK IN request to endpoint 1, the stat register is never endpoint 1
Device Descriptor
Edit - Realized I was missing some of the device descriptor, added below
[0x12] 18
[0x01] 1
[0x00] 0
[0x02] 2
[0xFF] 255
[0x02] 2
[0x00] 0
[0x40] 64
[0xC0] 192
[0x16] 22
[0xDC] 220
[0x27] 39
[0x01] 1
[0x00] 0
[0x01] 1
[0x02] 2
[0x00] 0
[0x01] 1
Configuration Descriptor
[0x09] 9
[0x02] 2
[0x19] 25
[0x00] 0
[0x01] 1
[0x01] 1
[0x00] 0
[0x80] 128
[0xFA] 250
[0x09] 9
[0x04] 4
[0x00] 0
[0x00] 0
[0x01] 1
[0xFF] 255
[0xFF] 255
[0x00] 0
[0x00] 0
[0x07] 7
[0x05] 5
[0x81] 129
[0x02] 2
[0x40] 64
[0x00] 0
[0x0A] 10
Edit:
Here is the message analyzer log showing the canceled bulk in transfer request due to timeout in the vs app (approx 30 seconds). The address 0x81 should correspond to endpoint 1 IN
Name Value:Bit Offset Bit Length Type
TransferData: (BinaryValue)
UrbPtr: 18446708890892172592 (UInt64)
DeviceInstance: 6 (Int32)
EndpointAddress 0x81 (Byte)
Type: Bulk(2) (UsbTransferType)
Direction: In(1) (UsbDirection)
LengthCompleted: 0 (UInt32)
LengthRequested: 64 (UInt32)
NtStatus: STATUS_CANCELLED(3221225760) (NTSTATUS)
Status: USBD_STATUS_CANCELED(3221291008) (UsbdStatus)
Last edited: