Commit Graph

27 Commits

Author SHA1 Message Date
Karl Palsson 26ab78a710 usb: fix race between setup complete and endpoint nak
See https://github.com/libopencm3/libopencm3/issues/873

Commentary describing this patch originally by zyp:

```
After looking further into it, I've concluded that my preliminary
analysis looks correct. The problem is that setting CNAK before
the SETUP complete event is received causes a race condition. The
SETUP callback is called when the SETUP packet event is received,
which means that setting CNAK from the callback is too early.

Originally the problem was that CNAK was set by ep_read() which is
called by the callback. #672 solved this by moving CNAK out of
ep_read() and calling it after the SETUP complete event is received
instead.

The regression by #785 is caused by the introduction of flow control
calls into the SETUP callback. They also set CNAK.

To solve this properly, I propose changing the event handling code
to only call the SETUP callback after the SETUP complete event is
received. Unfortunately, this implies that the callback can't call
ep_read() itself anymore, because the packet has to be read out of
the FIFO before the SETUP complete event arrives. This implies a
change of the API between the hardware drivers and _usbd_control_setup().
```

L1 (st_usbfs) works and passes tests as before change
F4 (dwc_otg_fs) works and now passes tests. (yay)
LM4f still compiles, and has had the same style of implementation as
st_usbfs, however has not been tested on any hardware.
2018-08-27 15:11:32 +00:00
Karl Palsson 54b117c5a5 usb: Use enumerated return codes
The enum usbd_request_return_codes has been available for some time.  It
should be used internally, not just by users of this code.
2018-03-02 22:42:05 +00:00
Vegard Storheil Eriksen 58f2ee34fa usb: Ensure control events are handled in order
Use EP0 OUT flow control to NAK OUT packets when we're not yet expecting
any. This prevents the status OUT event from arriving while the control
state machine is still expecting the data IN completion event.
2017-06-08 23:01:45 +00:00
Jochen Hoenicke 8b99b56c59 stmfx07: usb: Clean up FIFO read/write macro usage.
Use REBASE(OTG_FIFO(endpoint)) to access the FIFO.
For the receive FIFO do not use the endpoint. There
is only one receive FIFO so giving the endpoint is
a no-op.
Get rid of REBASE_FIFO macro.
2017-03-30 21:48:07 +00:00
Piotr Esden-Tempski b1049f9a6f [Style] Stylefix sweep over the whole codebase. 2015-12-14 22:57:15 +01:00
Karl Palsson 3ed12b6fd9 usb: short control IN might need a ZLP
Control transfers can transfer less than was requested by the host in the
wLength field.  if this short transfer is a multiple of the endpoint's packet
size, a zero length packet must be sent.

Adds tests for a range of control transfer IN requests, and properly supports
this in the core.  Based heavily on work by Kuldeep Dhaka.

See https://github.com/libopencm3/libopencm3/pull/505
and https://github.com/libopencm3/libopencm3/pull/194 for original discussion.

Tested with stm32f4, stm32f103 and stm32l053.
2015-10-11 18:43:11 +00:00
Alexandru Gagniuc 0819a49411 usb_control: Mark the control pipe as IDLE after a STALL
After a STALL handshake is transmitted, a control pipe becomes idle. Not
marking the pipe as idle did not affect the STM32 family. Since it
distinguishes between OUT and SETUP tokens, it calls the setup handler
on a SETUP token, regardless of the state of the pipe.

Other families, such as LM4F do not distinguish in software between IN and
SETUP tokens, and need to decide which handler to call based on the state
of the pipe. On these chips, SETUP transactions will not be handled
properly after a transfer was STALLED, as the state machine of the pipe is
b0rked. Unb0rk it.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
2013-07-07 17:04:38 -07:00
Piotr Esden-Tempski 39fa9e4c58 Stile fixes run, 80 char boundry. 2013-06-12 21:07:35 -07:00
Piotr Esden-Tempski 34de1e776e Changed to use stdint types. 2013-06-12 19:11:22 -07:00
Piotr Esden-Tempski 7df63fcae0 First coarse run to fix coding style in locm3.
Added --terse and --mailback options to the make stylecheck target. It
also does continue even if it enounters a possible error.

We decided on two exceptions from the linux kernel coding standard:
- Empty wait while loops may end with ; on the same line.
- All blocks after while, if, for have to be in brackets even if they
  only contain one statement. Otherwise it is easy to introduce an
  error.

Checkpatch needs to be adapted to reflect those changes.
2013-06-12 18:22:56 -07:00
Ken Sarkies 1374d2622b Place generic USB header and source files into the documentation tree. 2013-04-19 10:26:01 +09:30
Jeff Ciesielski db35fbb7ba Merge branch 'master' of git://github.com/libopencm3/libopencm3 into upstream-merge 2012-11-13 13:13:40 -08:00
Andrey Smirnov c5c4db0196 Extend control hook framework
This commits adds a new error code that can be return from a
registered control callback: USBD_REQ_NEXT_CALLBACK. This return code
signifies that the callback is done processing the data successfully,
but user would like to have all matching callbacks down the callback
chain to be executed too.

This change allows for example to intercept standard requests like
GET_DESCRIPTOR, do some small action upon receiving of one, but still
have the standard callback executed and do it's job. This way user
doesn't have to re-implement standard GET_DESCRIPTOR functionality if
they want to intercept that request to do some small thing.
2012-11-07 10:33:51 -08:00
Jason Kotzin 34beeae925 USB core updated for reentrance based on Christian Cier-Zniewski's branch 2012-09-13 10:43:35 -07:00
Jason Kotzin 4958fae906 fixing usb and alignment issue 2012-09-13 10:43:26 -07:00
Piotr Esden-Tempski 43561de329 License change of the library to LGPL, version 3 or later.
Agreed to by all the significant contributors to the library.
2012-03-02 14:44:49 -08:00
Uwe Hermann 3e9b9cb345 usb: Coding-style fixes. 2011-11-17 00:12:43 +01:00
Uwe Hermann 8f251e8a9d Some more file/path restructuring.
All #includes now explicitly use the "<libopencm3/stm32/rcc.h>" format.
If you want to get rid of the "libopencm3" prefix in your local project you
can add a respective -I entry in your Makefile (not recommended though).

All .ld files and .a libs are installed in $(TOOLCHAIN_DIR)/lib
directly (as before), but are now renamed to avoid potential
conflicts now or in the future. Examples:

  libopencm3_lpc13xx.a
  libopencm3_lpc13xx.ld
  libopencm3_stm32.a
  libopencm3_stm32.ld
2010-12-31 18:18:39 +01:00
Uwe Hermann 18790a2454 More renames for libopenstm32 -> libopencm3. 2010-12-30 13:19:25 +01:00
Uwe Hermann b5727a6c73 USB: Cosmetics and coding-style fixes. 2010-12-29 18:00:32 +01:00
Uwe Hermann c39eb69e4d Replace uint8_t with u8 et al, fix whitespace. 2010-12-29 17:28:06 +01:00
Uwe Hermann 34fd228bf9 Move generic USB stuff to a subdir, dedupe .h files.
Adapt examples and the lib code accordingly.
2010-12-29 17:02:36 +01:00
Uwe Hermann f062777930 More whitespace fixes. 2010-12-29 16:43:26 +01:00
Gareth McMullin 7f002110dc Improved dispatching of user control callbacks.
Only cdc_acm example is updated.
2010-11-06 12:21:46 +13:00
Gareth McMullin 87960830f4 Fixed HALT condition handling and data toggle. 2010-11-04 16:49:03 +13:00
Martin Mueller d6eacce827 add standard request 2010-11-04 00:44:47 +01:00
Uwe Hermann 6e090ccee1 Initial USB device stack for STM32.
Patch provided by Gareth McMullin <gareth@blacksphere.co.nz>,
thanks a lot!
2010-11-02 02:02:21 +01:00