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

Thread: Question About USB: Debug Message Only Code

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    2

    Question Question About USB: Debug Message Only Code

    Hi there,

    I just had a quick question about a section of the usb_debug_only.c file which can be found in the USB: Debug Message Only code (http://www.pjrc.com/teensy/usb_debug_only.html).

    Code:
    #define ENDPOINT0_SIZE		32
    #define DEBUG_TX_ENDPOINT	3
    #define DEBUG_TX_SIZE		32
    #define DEBUG_TX_BUFFER		EP_DOUBLE_BUFFER
    
    static const uint8_t PROGMEM endpoint_config_table[] = {
    	0,
    	0,
    	1, EP_TYPE_INTERRUPT_IN,  EP_SIZE(DEBUG_TX_SIZE) | DEBUG_TX_BUFFER,
    	0
    };
    Generally with the code, I've been able to find stuff like descriptor field descriptions but I am having trouble finding information about this. I thought it might be an Endpoint descriptor (found here: http://www.beyondlogic.org/usbnutshell/usb5.shtml) but unforunately the fields don't match. So my question is, what is this code and what are these fields that have been filled in? Any help in this regard would be greatly appreciated! Thanks

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    5,098
    Quote Originally Posted by MarkX View Post
    So my question is, what is this code and what are these fields that have been filled in?
    These are the bytes that actually configure the hardware for each endpoint. Each endpoint has 2 registers, UECFG0X and UECFG1X, which define how that endpoint will actually operate. They're documented in the datasheet. For the 32u4 chip, see section 22.18.2 starting on page 281.

  3. #3
    Junior Member
    Join Date
    Jul 2013
    Posts
    2
    Awesome! Thanks for the help. Reading further in the code, I came across this:

    Code:
    // Misc functions to wait for ready and send/receive packets
    static inline void usb_wait_in_ready(void)
    {
    	while (!(UEINTX & (1<<TXINI))) ;
    }
    static inline void usb_send_in(void)
    {
    	UEINTX = ~(1<<TXINI);
    }
    static inline void usb_wait_receive_out(void)
    {
    	while (!(UEINTX & (1<<RXOUTI))) ;
    }
    static inline void usb_ack_out(void)
    {
    	UEINTX = ~(1<<RXOUTI);
    }
    From my understanding, TXINI is high when the host is ready to receive IN packets from the device, so in usb_wait_in_ready( ) we are essentially waiting for the host to get ready to receive. But that brings us to "UEINTX = ~(1<<TXINI);". In this line, why are we not preserving the current contents of UEINTX? To be honest, I don't really understand the use of that function at all, as writing all of the flags in UEINTX to one have no effect (according to the documentation http://www.atmel.com/Images/doc7799.pdf ). Again any help would be greatly appreciated.

Tags for this Thread

Posting Permissions

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