USB CDC hang

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I am new to ASF USB driver and found a problem both using XMEGA ans ARM V71 processor.

It seem that the stack hang when the function "udi_cdc_multi_write_buf" is called (I call "udi_cdc_write_buf" which calls "udi_cdc_multi_write_buf" .)

It probably hang where I have coment "Hang in this loop". 

Thanks for any hints.

 

iram_size_t udi_cdc_multi_write_buf(uint8_t port, const void* buf, iram_size_t size)
{
    irqflags_t flags;
    uint8_t buf_sel;
    uint16_t buf_nb;
    iram_size_t copy_nb;
    uint8_t *ptr_buf = (uint8_t *)buf;

#if UDI_CDC_PORT_NB == 1 // To optimize code
    port = 0;
#endif

    if (9 == udi_cdc_line_coding[port].bDataBits) {
        size *=2;
    }

    // Hang in this loop
udi_cdc_write_buf_loop_wait:
    // Check available space
    if (!udi_cdc_multi_is_tx_ready(port)) {
        if (!udi_cdc_data_running) {
            return size;
        }
        goto udi_cdc_write_buf_loop_wait;
    }

    // Write values
    flags = cpu_irq_save();
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

the latest Atmel Studio Software Package 1.4 has some fairly recent source code for a CDC USB project.  For a long while I thought there were bugs in this code that kept me from properly connecting on our own target board.  I've since come to the conclusion the fault is more likely that our board layout guy did not properly follow the very precise rules for rules for USB lines - this kind of thing can produce very strange problems that are hard to track down.  We used a Beagle USB 480 to be like wireshark to look at the packets going back and forth.

EricKrieg (at) g mail
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I do not think it is the board layout since I am running on SAMV71 Xplained board.

 

The strange thing is that if I remove the check for udi_cdc_data_running, it works unless the data stream is to high.

 

udi_cdc_write_buf_loop_wait:
	// Check available space
	if (!udi_cdc_multi_is_tx_ready(port)) {
//		if (!udi_cdc_data_running) {
			return size;
//		}
		goto udi_cdc_write_buf_loop_wait;
	}

Anybody who know how to solve this issue?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

note that the new studio 7.0 code comes with a lot of changes to usb driver code in the library directory.  It is possible if you port your code onto a project from the 7.0 environment - maybe one of their code fixes will fix your problem.  I had changed some of my usb library driver code to put time outs in infinite loops like the code you show above.  I've rewritten things to not hang - and then downstream code has sometimes allowed retries that can make it work.  We used the total phase beagle USB analyzer to figure out what was going on.  I also added a internal ram logger function so I could tell where the code had been at key points without taking it out of real time mode.  

EricKrieg (at) g mail