cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 as usb host and pc as client

gurnett
Associate II
Posted on December 23, 2009 at 11:34

STM32 as usb host and pc as client

7 REPLIES 7
picguy
Associate II
Posted on May 17, 2011 at 13:34

USB is host-centric. Most, if not all, USB PC software has the PC as host. The host provides opportunity for you to send stuff to it. Your device can only respond. Your device can ask the PC to poll it every millisecond. If the host’s USB is very busy you may collect data you can’t send. This should not be a problem is the host is mostly dedicated to your application.

Or you can research isochronous transfers for guaranteed bandwidth.

gurnett
Associate II
Posted on May 17, 2011 at 13:34

Looking at a project in which we need the stm32 to send data to the pc immedately when that data (adc) becomes available. We're looking at usb for this. The data is grabbed during a short pulse and then calculated and it is the results that we want to send to the pc. What we don't want is the pc continously asking for the info. As usb is new to me I'm trying to figure out how this would be done. One of the problems we have is that at the start of the pc software start we want to be able to pass data to the stm32. Is usb the way to go or are there more appropiate options, and if so how?

Thanks

Michael

st3
Associate II
Posted on May 17, 2011 at 13:34

Quote:

Most, if not all, USB PC software has the PC as host.

It's not just the software - USB ports on PCs are specifically Host Ports.

As picguy says, this is the way that USB works - you need to work with it, not fight against it!

You might want to start here:

http://www.lvr.com/usb.htm

gurnett
Associate II
Posted on May 17, 2011 at 13:34

The host (pc) usb wont be busy at it only has the data from the stm32 to deal with. I'm more worried what will happen if the pc is polling the usb when the stm32 is working flatout on other tasks. This is why I wanted the the pc no to poll until the stm32 was ready to send. Thanks for the link and the answers so far. I'm sure if I keep reading I'll get the hang of this.

Thanks

Michael

picguy
Associate II
Posted on May 17, 2011 at 13:34

I’m early in the process of writing a custom HID application. So early that what I am to say next is only an educated guess.

The setup: You have just sent data to the host. You will not be ready to send anything else for several milliseconds. But you told (asked, really) the host to accept data every millisecond.

The educated guess: The host asks for data. The STM32 USB engine responds “not now.�? Your code is not bothered. I.e. you remain unaware of the poll and its automated response.

FYI: on another processor (PUC 18F...) using a hardware debugger it appeared that I was able to send data to the host (Win XP) with no application program taking the data. Thus if you want to know if/what data was lost include a sequence number.

chikos33
Associate II
Posted on May 17, 2011 at 13:34

Hi guys,

I think that the you could use the usb without issue foryour application.

In fact, as picguy said, the PC will always ask for data periodically (and you can configure the period lenth of course, min = 1ms).

- When the device has no data to send, it only sends a NAK (negative acknowledge) And this operation is done by hardware (no software needed to monitor the operation). So you risk nothing and your process won't be slowed down.

- If the device has many data to sent within the frame (1 ms), (that means the data sampling frequency is higher than the max host polling frequency), then the device can send all the samples available at that moment to the host in a single packet. And thus no data is lost.

USB is a wonderful protocol, isn't it? :D

jj
Associate II
Posted on May 17, 2011 at 13:34

another processor (PUC 18F...)

Has this opened the door for new poster, ''PUC-guy?''

Seasons Greetings to all...