SAMD21 CDC - How do I know when host port is closed?

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

I have got a full SAMD21 CDC app working fine, though I cannot seem to find a way to know when the CDC host port is closed. That is, it has enumerated as a comport, but data is not currently being read.

 

As soon as the com port has been enumerated and the port is closed:

udi_cdc_is_tx_ready()    will always pass

UDI_CDC_RX_NOTIFY(port) function is called to let me know that it is now operational.

 

When I try to send data via udi_cdc_write_buf, it buffers it 6 times, on the 7th it has obviously run out of buffer space and sits inside the write function waiting for space to become available.

 

My question is, how do I know when there is no more space available to write to these functions?

Last Edited: Tue. Jun 18, 2019 - 01:17 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

within the udc_cdc.c file I created a function to achieve this as a temporary work around:

 

bool usb_cdc_data_available(uint16_t size) {
	uint8_t buf_sel = udi_cdc_tx_buf_sel[0];
	uint16_t buf_nb = udi_cdc_tx_buf_nb[0][buf_sel];
	iram_size_t copy_nb = UDI_CDC_TX_BUFFERS - buf_nb;	//available space
	
	if (copy_nb < size) {
		return false;
	}
	else {
		return true;
	}
}

Since most of the buffer definitions were static, I didn't want to change them and just extended the file instead.

 

If anyone knows the proper way to do this within the API I would much prefer that option.