Commit graph

115 commits

Author SHA1 Message Date
Marti Bolivar 0fca062e2d libmaple/usb/stm32f1/usb.c: cosmetics.
Whitespace and comments.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2013-04-30 09:22:31 -04:00
Marti Bolivar 07b56b89fb libmaple/usb/stm32f1/usb.c: fix build error.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2013-04-29 10:19:42 -04:00
Marti Bolivar 58794b59d4 Merge remote-tracking branch 'wesen/bug/usb-resume' 2013-04-26 12:49:55 -04:00
Manuel Odendahl 5315e3a239 Preserve previous usb state when suspending / restore on resume
Signed-off-by: Manuel Odendahl <wesen@ruinwesen.com>
2013-04-26 11:12:03 +02:00
Marti Bolivar 13635d539f usb_cdcacm: Reset transmitting flag in usbReset().
Thanks to Manuel Odenahl for the fix.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2013-04-15 15:01:58 -04:00
Marti Bolivar 048e70fc41 usb_cdcacm: Make USB lib globals weak symbols.
This allows users to override them.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2013-01-18 18:18:30 -05:00
Marti Bolivar 964279b9bf Merge branch 'bug/usb-full-ep'
This resolves issues related to sending full (64B) packets via USB
2.0. In this case, some hosts continue to expect more data. Add
infrastructure for sending 0-byte packets to signal end of
transmission, and use it in SerialUSB.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2013-01-18 18:12:21 -05:00
Marti Bolivar 0dbf94bf31 usb_cdcacm.c: Fixups for usb_cdcacm_tx().
- Check if we're transmitting (instead of how many bytes are left
  untransmitted) before bailing, in case we're transmitting a
  zero-length packet.

- Set transmitting=1 before setting the endpoint valid to avoid races
  with the USB interrupt.

- Eliminate some duplicated code.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2013-01-17 18:08:39 -05:00
Marti Bolivar d12a5b14e1 usb_reg_map.c: Fix incorrect function name call.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2013-01-17 17:48:13 -05:00
Marti Bolivar 9e14f40c20 usb_reg_map.h: Fix incorrect register bit definitions.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2013-01-17 17:47:27 -05:00
Manuel Odendahl 7446068400 Handle sending 0 byte packets.
Added a flag to see if we are currently waiting on an interrupt to acknowledge the sending of the current
IN packet.
Added a method usb_cdcacm_is_transmitting() to check for that flag.

Signed-off-by: Manuel Odendahl <wesen@ruinwesen.com>
2013-01-17 21:17:00 +01:00
Manuel Odendahl 699f97fdcb Move endpoint definitions to include files (they are now needed outside in usb_serial.cpp)
Signed-off-by: Manuel Odendahl <wesen@ruinwesen.com>
2013-01-17 21:11:10 +01:00
Manuel Odendahl b3287225c5 Rename misleading ptr function
Signed-off-by: Manuel Odendahl <wesen@ruinwesen.com>
2013-01-17 21:09:07 +01:00
Manuel Odendahl c95edd391e Refactor setting a USB EP rx count
Signed-off-by: Manuel Odendahl <wesen@ruinwesen.com>
2013-01-17 20:52:34 +01:00
Manuel Odendahl e0748ce668 Rename USB_EP_EP_KIND to USB_EP_EP_KIND_DBL_BUF
Signed-off-by: Manuel Odendahl <wesen@ruinwesen.com>
2013-01-17 20:52:25 +01:00
Manuel Odendahl 0c8ab1f655 Add double buffering routines
Signed-off-by: Manuel Odendahl <wesen@ruinwesen.com>
2013-01-17 20:51:58 +01:00
Manuel Odendahl 8e14e7ff77 usb_cdcacm.c: reenable the endpoint if an empty bulk transfer was received.
It is possible to receive empty bulk transfers. This would lead to the endpoint never being reenabled as this was handled by the read routine. This caused the USB to hang.

Signed-off-by: Manuel Odendahl <wesen@ruinwesen.com>
2012-11-08 20:53:32 +01:00
Marti Bolivar 36b24f9cce usb_cdcacm.c: Fix up descriptor definitions.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-08-04 18:43:50 -04:00
Marti Bolivar cf6e56ed4e Move contents of usb_descriptors.h to <libmaple/usb.h>.
These form and name of structs etc. is basically determined by the USB
spec and the libmaple style guide, so there's little reason for them
to change, and less reason for them to stay hidden.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-08-04 18:43:46 -04:00
Marti Bolivar 5ac380615e Prep usb_descriptors.h for removal.
Just change names and things to fit the libmaple style. Its contents
will move to the top-level <libmaple/usb.h> header next.

This API is still unstable, but we need to expose pieces of it in
order to get the Maple-specific pieces of usb_cdcacm.c into Wirish.

Adjust uses of the API appropriately.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-08-04 18:43:45 -04:00
Marti Bolivar 7f2b5d0112 usb_cdcacm: Remove unused/redundant variables.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-08-04 18:43:40 -04:00
Marti Bolivar a97e9c14ed usb_cdcacm: Expose line coding state.
This was already supported, so just move the line coding structure to
the header and add some functions for accessing the current values.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-08-04 01:47:22 -04:00
Marti Bolivar b642f7b095 usb_cdcacm: Set endpoint to NAK before checking byte count.
Fixes an (admittedly very unlikely) race condition.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-08-04 00:33:32 -04:00
Marti Bolivar 6788dff2e0 Add FIXME for usb_get_ep_tx_count().
We definitely need to mask out the high bits, as RM0008 doesn't
specify that they read as zero. Calling this function seems to crash
the board, though. I'm not sure why, especially since
usb_set_ep_tx_count(), used by usb_cdcacm.c, seems to work.

Confusing.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-08-04 00:18:14 -04:00
Marti Bolivar b0a9e6fda2 usb_cdcacm: various fixups.
Mark internal state static. Properly reset the RX/TX state on USB
reset. Choose better names for countTx and newBytes.

Move the exposed configuration back into the .c; this information is
not beneficial to hooks.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-08-04 00:18:01 -04:00
Marti Bolivar fa1b298b78 usb_cdcacm: Improve write speed.
Actually fill the TX buffer in the packet memory area, so we can send
more bytes per transaction. Using the test-session benchmark, we're
now clocking in the high 700KB/sec range via PySerial. With screen,
rate is now about 550 KB/sec.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-08-03 23:15:43 -04:00
Marti Bolivar c1e57e08bf usb_cdcacm: Cosmetics
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-08-03 23:13:32 -04:00
Marti Bolivar d63d5c7fb9 usb_cdcacm: minor fixups.
Rename USB_Line_Coding to usb_line_coding, and rename its fields to
match the spec to aid searches. Alter the line_coding global to match,
fixing an incorrect comment and avoiding magic numbers.

Other minor fixups and comment improvements.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-08-03 22:53:31 -04:00
Marti Bolivar 69cb5c65cb usb_cdcacm: Rename "notification" -> "management".
This keeps things in line with the specification, helping readability.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-08-01 13:42:08 -04:00
Marti Bolivar 0cc911c4ae Move CDC ACM config. descriptor into usb_cdcacm.c.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-07-31 18:02:29 -04:00
Marti Bolivar 365f45679b Move bootloader reset signal detection to Wirish.
Use usb_cdcacm hooks to move the DTR edge and "1EAF" magic packet
detection to usb_serial.cpp. We'll later be able to extend this system
to support Leonardo-style reset signalling.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-07-31 15:04:49 -04:00
Marti Bolivar ef1cc46487 usb_cdcacm: Add usb_cdcacm_peek().
We need this so the bootloader reset signal detector can look ahead in
the byte stream without stealing bytes from the user when "1EAF" isn't
received.

While we're doing this, take the time to fix a bunch of RX-related
code (dead code removal, adding volatile, etc.)

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-07-31 15:04:49 -04:00
Marti Bolivar 572633d61e usb_cdacm: Use config instead of magic numbers.
Sigh.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-07-31 15:04:49 -04:00
Marti Bolivar 496e0566fa usb_cdcacm: Add hook system.
Provide hooks so users can reach into the CDC ACM callbacks with their
own code. We'll use this to move the bootloader reset signals to
Wirish.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-07-31 15:04:49 -04:00
Marti Bolivar 84468115ec usb_cdcacm: Expose some internal configuration and values.
Mark the API as unstable so people don't rely on these too hard. (This
header is not part of the official libmaple docs). We'll need some of
this configuration elsewhere later, and it doesn't make much sense to
expose it piecemeal.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-07-31 15:04:49 -04:00
Marti Bolivar e629303f0d usb_cdcacm.c: Add another verification TODO.
Not sure what the comment above the new TODO is supposed to mean, but
it looks like something that should be checked.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-07-31 15:04:49 -04:00
Marti Bolivar 4e90c4028c usb_cdcacm.c: Resolve TODO and improve comments.
The disc pin code was copy-pasted when the CDC ACM pieces were
extracted from the rest of the USB code, and I didn't really
understand what was going on when I moved it over. Having checked the
spec, the comments can be safely improved.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-07-31 15:04:49 -04:00
Marti Bolivar 50ee2097b3 Doxygen hacks and fixups.
- Shut Doxygen up in various places
- Fix some genuine docs bugs
- Ignore sources we're not responsible for

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-28 17:29:43 -04:00
Marti Bolivar 8796a81efc Slightly improve and generify the USB infrastructure.
The good news is that <libmaple/usb.h> and <libmaple/usb_cdcacm.h> did
turn out generic enough in what they specify to go on unchanged.

However, we can't just go on assuming that there's USB just because
we're on an F1. Now that there's value line in the tree, we need to be
more careful (value line F1s don't have USB peripherals). To that end,
make all the F1 board-includes/*.mk files specify what line their MCU
is with an MCU_F1_LINE variable. Use that to hack
libmaple/usb/rules.mk so we only try to build the USB module under
appropriate circumstances.

While we're at it, add a vector_symbols.inc for value line MCUs under
support/ld/. We need this to get the target-config.mk modifications
implied by the addition of MCU_F1_LINE. We'll fix up some other
performance-line-isms under libmaple/stm32f1 in a separate commit.

Also in libmaple/usb/:

- Move everything into a new stm32f1 directory. Due to aforementioned
  rules.mk hacks, there is no immediate need for an stm32f2
  directory (USB support doesn't exist there).

- Update the README for style and content.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-03 22:40:39 -04:00
Marti Bolivar 306e19cb9f Fix a bunch of Doxygen file-level comments.
Fix @file in many places. Also fix up the descriptions where it's
appropriate. This standardizes the @file formatting across the library
to explicitly include any parent directories up to the repository
root.

Besides being nice, this will hopefully let us manage Doxygen's XML
output so as to make extracting series-specific pieces via Breathe in
the leaflabs-docs repo possible.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-05-08 16:22:41 -04:00
Marti Bolivar 3c9e9a49bb libmaple: Add build infrastructure for private headers.
libmaple/rules.mk: Add LIBMAPLE_PRIVATE_INCLUDES, a place for storing
headers which should be commonly available throughout libmaple, but
not made public. Currently, this is just the libmaple directory.

Add LIBMAPLE_PRIVATE_INCLUDES to the target flags in the STM32F1 and
USB submodules.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:51 -04:00
Marti Bolivar 04760fa17b Make USB its own submodule.
Add libmaple/usb/rules.mk, which compiles the USB FS device firmware
submodule. Move the logic for compiling the USB stack from
libmaple/rules.mk into libmaple/usb/rules.mk.

Move libmaple/usb/usb_cdacm.h to libmaple/include/libmaple/. Its API
is sufficiently general that we'll be able to port it over to USB
OTG (either FS or HS) eventually, and that lets us include it from
Wirish using the new style for libmaple headers.

Fix the includes for public libmaple headers within libmaple/usb.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:51 -04:00
Marti Bolivar f4604a8263 usb_cdcacm.c: Fix warning for non-LeafLabs boards.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:51 -04:00
Marti Bolivar 954f9e5065 Move public headers to include directories; related cleanups.
Move libmaple/*.h to (new) libmaple/include/libmaple/. The new
accepted way to include a libmaple header foo.h is with:

    #include <libmaple/foo.h>

This is more polite in terms of the include namespace. It also allows
us to e.g. implement the Arduino SPI library at all (which has header
SPI.h; providing it was previously impossible on case-insensitive
filesystems due to libmaple's spi.h).

Similarly for Wirish.

The old include style (#include "header.h") is now deprecated.

libmaple/*.h:

- Change include guard #defines from _FOO_H_ to _LIBMAPLE_FOO_H_.
- Add license headers where they're missing
- Add conditional extern "C" { ... } blocks where they're missing
  (they aren't always necessary, but we might was well do it against
  the future, while we're at it.).
- Change includes from #include "foo.h" to #include <libmaple/foo.h>.
- Move includes after extern "C".
- Remove extra trailing newlines

Note that this doesn't include the headers under libmaple/usb/ or
libmaple/usb/usb_lib. These will get fixed later.

libmaple/*.c:

- Change includes from #include "foo.h" to #include <libmaple/foo.h>.

Makefile:

- Add I$(LIBMAPLE_PATH)/include/libmaple to GLOBAL_FLAGS.  This allows
  for users (including Wirish) to migrate their code, but should go
  away ASAP, since it slows down compilation.

Wirish:

- Move wirish/**/*.h to (new) wirish/include/wirish/.  This ignores
  the USB headers, which, as usual, are getting handled after
  everything else.

- Similarly generify wirish/boards/ structure. For each supported
  board "foo", move wirish/boards/foo.h and wirish/boards/foo.cpp to
  wirish/boards/foo/include/board/board.h and
  wirish/boards/foo/board.cpp, respectively. Also remove the #ifdef
  hacks around the .cpp files.

- wirish/rules.mk: put wirish/boards/foo/include in the include path
  (and add wirish/boards/foo/board.cpp to the list of sources to be
  compiled). This allows saying:

      #include <board/board.h>

  instead of the hack currently in place. We can allow the user to
  override this setting later to make adding custom board definitions
  easier.

- Disable -Werror in libmaple/rules.mk, as the current USB warnings
  don't let the olimex_stm32_h103 board compile. We can re-enable
  -Werror once we've moved the board-specific bits out of libmaple
  proper.

libraries, examples:

- Update includes accordingly.
- Miscellaneous cosmetic fixups.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:50 -04:00
Marti Bolivar 7c1a00a836 usb_descriptors.h: Remove usbVcomDescriptor[...] values.
These are CDC ACM-specific.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-21 19:21:08 -04:00
Marti Bolivar a83a6c2aed usb_descriptors.h: Whitespace and column cleanups.
Untabify, make (mostly) 80-column clean.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-21 19:19:03 -04:00
Marti Bolivar 824001c923 usb: Rename descriptors.h -> usb_descriptors.h.
Modify its include guard, and the files that include it, appropriately.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-21 18:17:09 -04:00
Marti Bolivar 061fae7206 usb.h: Move to libmaple/.
Apart from having an unstable API, usb.h is now a fairly good citizen
of libmaple, so move it to live with the rest of the libmaple headers.

Its device struct is still "struct usblib_dev".  Leave that there; the
asymmetry with the rest of the library is a good reminder that the API
isn't really on equal footing with the rest of the library.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-21 18:13:06 -04:00
Marti Bolivar 9be44ebd86 USB: API cleanups.
Modify usb.h functions (changing their names in some cases) to also
take a usblib_dev* argument, to fit in better with the rest of
libmaple.

Store an rcc_clk_id in struct usblib_dev for the same reason.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-21 18:13:05 -04:00
Marti Bolivar d21d68fd36 USB: API cleanups.
Remove usbSuspend(), usbResumeInit(), usbResume(), the USB
low-priority IRQ, and usbWaitReset() from usb.h.  Also remove
RESUME_STATE since it was only there for usbResume().

These functions don't need to be seen by anybody except for usb.c and
usb_cdcacm.c, so move them there (altering their names to fit with
libmaple style guidelines) and mark them static.

Clean up includes in usb.c while we're there.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-21 18:13:05 -04:00