Commit graph

605 commits

Author SHA1 Message Date
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 c6aa996912 <libmaple/scb.h>: Add FIXME to check for F2 compatibility.
Signed-off-by: Marti Bolivar <mbolivar@lozenge.(none)>
2012-07-13 03:04:27 -04:00
Marti Bolivar fcdfeb495b <libmaple/scb.h>: Don't use BIT().
Also, assert copyright LeafLabs 2012.

Signed-off-by: Marti Bolivar <mbolivar@lozenge.(none)>
2012-07-13 02:59:58 -04:00
Marti Bolivar f006ea136d <libmaple/scb.h>: Assert LeafLabs copyright.
Signed-off-by: Marti Bolivar <mbolivar@lozenge.(none)>
2012-07-13 02:58:33 -04:00
Marti Bolivar b49510cef2 ADC: Doxygen fixups
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-29 20:46:20 -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 11c79ef89f Cosmetics.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-28 16:27:40 -04:00
Marti Bolivar 139ea7c353 Bring back and fix up util.c functionality.
Rip out the existing nonportable pieces, and shove them under
wirish/stm32f1, using weak symbols so users who only want libmaple
proper don't end up with build errors. Add stubbed-out (and only
partially functional) definitions for F2 targets under wirish/stm32f2.

The behavior on F103 targets is the same as it was before (though the
assertion framework has always been broken and badly needs
replacement, that awaits another commit). We additionally now skip
re-enabling USB on F1 targets without USB, to make things work on
value line MCUs.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-26 18:03:40 -04:00
Marti Bolivar cf940181c6 util.c: Fix Doxygen header.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-26 16:59:03 -04:00
Marti Bolivar e05eb6c7cc Bring back throb().
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-26 16:50:31 -04:00
Marti Bolivar cad21184bb stm32f1: gpio.h: Add another hack mode macro.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-26 16:50:31 -04:00
Marti Bolivar c8fb008d34 libmaple/util.c: Add FIXMEs.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-26 16:50:30 -04:00
Marti Bolivar 05e78fe0f5 I2C: Move CCR/TRISE config helper back to libmaple/i2c.c.
We can implement it in terms of _i2c_bus_clk() instead of hard-coding
STM32_PCLK1.

This might be overkill, since I2C peripherals are slow and thus likely
to be on APB1 for all STM32 devices (that is the case for F2/F4, for
instance), but if we're going to have _i2c_bus_clk(), we might as well
respect it.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 15:07:08 -04:00
Marti Bolivar d9d78c6bd3 <libmaple/i2c.h>: Add I2C_CCR_DUTY bit value definitions.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 15:07:08 -04:00
Marti Bolivar 75b42a51a2 libmaple/stm32f1/i2c.c: Add Doxygen file header.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:10 -04:00
Marti Bolivar 0a54c3e336 i2c_dev: deprecate .gpio_port.
This won't work on F2, which at times has SDA and SCL on different
ports (e.g. I2C3 SDA on PC9, SCL on PA8). Add .sda_port and .scl_port
replacements, which are used when the now-deprecated .gpio_port is
null. Use them correctly everywhere, with some new i2c_private.h
helper functionality.

Sigh. The F1 I2C code tries too hard to guess what you wanted; it's
not porting well at all.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:10 -04:00
Marti Bolivar 8ab24a8903 STM32F1: i2c_config_gpios(): Do afio_remap() if we should.
This should help avoid surprising some users.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:10 -04:00
Marti Bolivar 52341e8ede I2C: Move nonportable CCR/TRISE configuration.
Do this via new private _i2c_set_ccr_trise().

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:10 -04:00
Marti Bolivar ae675749e0 I2C: Deprecate I2C_REMAP flag.
This is ad-hoc and nonportable. If you really want I2C mapped
elsewhere, then mess with the I2C device fields and call afio_remap()
yourself. (This is also cleaner for F2).

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:10 -04:00
Marti Bolivar 56a593e8a5 I2C: Move F1-only errata workarounds out of libmaple/i2c.c.
The IRQ priority hack is unnecessary on targets with properly
functioning I2C IRQ handlers, so we shouldn't use it unless we have
to. Add a mechanism so a series header can provide such a hack if
necessary.  Have the F1 series header use this mechanism.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:10 -04:00
Marti Bolivar 88d2a4083d libmaple/i2c.c: Cosmetics.
Move private API to bottom of file.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:10 -04:00
Marti Bolivar 6d3f82b03f libmaple/i2c.c: Keep authorship straight.
I'm going to be moving a lot of code around without changing it soon,
so git blame will be unreliable.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:10 -04:00
Marti Bolivar 0bb2b3a282 I2C: Add i2c_config_gpios(), i2c_master_release_bus().
These are necessary to pull out some calls to gpio_set_mode().

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:10 -04:00
Marti Bolivar c00e9aea44 <libmaple/i2c.h>: Fix Doxygen.
Existing Doxygen was commenting I2C_IRQ_ERROR instead of
i2c_enable_irq(), as desired.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:10 -04:00
Marti Bolivar ec096b7f7f libmaple/i2c.h: Better comments.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:10 -04:00
Marti Bolivar 6335da211b libmaple/i2c.c: Replace throb() with ASSERT(0).
Calling throb() directly like that breaks the abstraction.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 209e31185c I2C: I don't think 10-bit addressing works.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 385b4e0814 <libmaple/i2c.h>: Move low-level routines to end of file.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 449b7ceb76 I2C: Fix Doxygen F1-isms.
I'm not sure these functions should even exist in their present form,,
but I don't understand the code well enough to make a real fix. For
now, just replace references to RM0008 with "chip reference manual".

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 7aa5dd2d48 i2c_set_input_clk(): fix an F1-ism.
i2c_set_input_clk()'s documentation says that the maximum peripheral
clock frequency is 36 MHz, but that's a hard-coded magic number. The
actual limit is the device's APB frequency or 46 MHz, whichever is
lower (F2 and F4 share the 46 MHz limit).

Fix the documentation to reflect that fact, and add an internal
series-provided function to get the maximum clock frequency for a
device. To help users porting to F2, have i2c_set_input_clk()
assert-check that the provided frequency is less than that maximum
value and the hard 46 MHz limit.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 3e67141436 Move i2c_dev and i2c_state into new i2c_common.h.
This is necessary to add series-specific infrastructure to clean up
some F1-isms in <libmaple/i2c.h>'s inline functions.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 040595b919 libmaple/i2c.h: Cosmetics.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 7c81947272 I2C: Restore on F1, refactoring prep for F2.
Bring back <libmaple/i2c.h> support on STM32F1 with a view towards how
it'll be implemented on STM32F2. There are still many F1-isms in
libmaple/i2c.c and <libmaple/i2c.h>, to be dealt with subsequently.

Move device declarations and base pointer definitions to a new F1
<series/i2c.h>. The register maps and bit definitions themselves are
identical on both series, so leave them in the libmaple header.

Add i2c_private.h, which contains:

- I2C_DEV(), a convenience macro for defining an i2c_dev, and
- declarations for the event and error IRQ handlers.

The IRQ handlers are large, and I2C is slow anyway, so I see no reason
to make them inline in the private header (as we do for some other
peripherals). We just expose the existing ones that were formerly
static in libmaple/i2c.c, but prefix the names with underscore.

Move the device declarations and IRQ handlers into new
stm32f1/i2c.c. These use the i2c_private.h API.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 413853aa44 libmaple/i2c.c: Cosmetics.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar ec40c9ddc9 <libmaple/i2c.h>: Cosmetics.
Put CCR definitions after SR2, to keep them in register map order.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 2e32d86142 <libmaple/i2c.h>: Cosmetics.
Reorder register bit definitions by descending bit number, for
consistency with the rest of the library.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 38fdbf8d10 <libmaple/i2c.h>: Add missing register bit defns.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 74f4437188 libmaple/i2c.h: Assert LeafLabs copyright.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 4efec065ff Fix I2C_CR2_FREQ bit definition.
The existing value clobbers the entire register.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar aac8e2ba2c libmaple/i2c.h: Cosmetics.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar 2031b7a50a libmaple/i2c.h: Don't use BIT().
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-22 14:06:09 -04:00
Marti Bolivar f7826ab473 <libmaple/dma.h>: Assert LeafLabs copyright.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-21 23:17:24 -04:00
Marti Bolivar 26cf9b2209 Implement DMA tube API on STM32F2.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-15 17:41:37 -04:00
Marti Bolivar 205f3f7eb7 Implement DMA tube API on STM32F1.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-15 17:41:37 -04:00
Marti Bolivar 2026ef2c36 DMA: prep for F2 with new "tube" API.
To prepare for STM32F2/F4 DMA support, introduce a new libmaple DMA
API, and move some code around to make priority level and interrupt
handling more generic.

The new API is based on a new set of types (dma_tube, struct
dma_tube_reg_map, enum dma_request_src, enum dma_cfg_flags, and struct
dma_tube_config).

The central abstraction is the dma_tube type. STM32F2/F4 use DMA
streams to control dataflow, and STM32F1 uses channels. dma_tube
stands for whichever is appropriate for the current target. Dealing
with tubes allows for configuring and using DMA with opaque tube
values in the same source, instead of (as with ST's firmware)
requiring two separate codebases.

The new API is also more user-friendly, as it doesn't require knowing
which DMA address registers to set and which configuration register
flags go along with them. It now suffices to specify the source and
destination for the DMA transfer, along with their sizes. This avoids
confusion (e.g. for memory-to-memory transfers, data flows from the
peripheral address register to the memory register, which might be
surprising on F2, which has two memory address registers).

The old API (based on enum dma_mode_flags and dma_setup_transfer()) is
still available on F1, but deprecate it.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-15 17:41:34 -04:00
Marti Bolivar f7e7cf0930 Add stm32_private.h.
This will hold STM32-related things that I'm not sure are well-thought
out enough to go into <libmaple/stm32.h>. Currently, it contains an
accessor routine that tells you the purpose of the memory block
containing an address.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-12 16:04:02 -04:00
Marti Bolivar b95f3e56b5 Build libmaple/dma.c on STM32F1.
F2 doesn't work yet.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-12 16:02:13 -04:00
Marti Bolivar 78f2bb290b enum spi_mode: Add more descriptive enumerators, documentation.
Instead of requiring everyone to figure it out for themselves, add
enumerators specifying the idle logic level and what clock edge
triggers data capture. Yes, it's easy enough to figure it out. It's
also convenient to have these.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-07 21:47:46 -04:00
Marti Bolivar d71254f8f9 Bring back <libmaple/spi.h>.
Add a spi_private.h with a SPI_DEV(), for convenience. Use it in the
F1 and F2 implementations. We could probably unify these with an
STM32_HAVE_SPI(n) macro, but we'll leave that for the future.

Most everything from F1 is portable; F2 has some additional bit
definitions and a spi_get_af() routine, but that's about it.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-07 21:46:25 -04:00
Marti Bolivar d14105d11e Move syscalls.c into Wirish.
libmaple takes orders, it doesn't give them.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-07 19:15:05 -04:00
Marti Bolivar 3365fc03e0 libmaple/timer.h: Capitalization fix
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-07 19:15:05 -04:00
Marti Bolivar 3cdab05f52 libmaple/timer.h: Lose BIT().
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-07 19:15:05 -04:00
Marti Bolivar 89f991bf6a libmaple/timer.h: Move deprecated bits to bottom.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-07 19:15:05 -04:00
Marti Bolivar d1f279a85c struct timer_dev: Don't touch ->handlers!
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-07 19:15:05 -04:00
Marti Bolivar 4e05eee606 libmaple/timer.h: Nuke useless comment.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-07 19:15:05 -04:00
Marti Bolivar 5c48a50f85 libmaple/timer.h: Doxygen beautification and fixups
Make the Doxygen comments nicer to look at. Some of the docstrings are
out-of-date since F2 support was added, so update them.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-07 19:15:04 -04:00
Marti Bolivar 47d3326f3a Move timer_dev definitions into libmaple/timer.c.
The addition of STM32_HAVE_TIMER() allows us to avoid some
repetition. There's still an issue with names on F1 preventing us from
moving the IRQ handlers to libmaple/timer.c, but once that's resolved,
we'll be able to remove even more.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-07 19:15:04 -04:00
Marti Bolivar 29518f6e34 Tweak some timer_private APIs.
The current versions of DELARE_*_TIMER() don't play well with cscope,
which is a bad sign. Fix that.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-07 19:15:04 -04:00
Marti Bolivar db3efddaa9 series/timer.h: Remove silly duplicate declarations.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-07 19:15:04 -04:00
Marti Bolivar 2cc3749c19 stm32.h: Soften "missing MCU" errors into warnings.
It's not important whether the MCU is specified. What's important is
that <libmaple/stm32.h> gets everything it needs -- which it now
ensures that it does. Requiring people to do things on a per-MCU basis
hurts hackability and is just asking for trouble.

On the other hand, it's nice to provide a clue as to why
<libmaple/stm32.h> might be giving #errors, so do leave the
warnings. People can always hack the header to shut them up if they
want.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-07 03:38:29 -04:00
Marti Bolivar 6f91cfc425 Bring back libmaple/dac.h.
Minor variations on F2: DMA underrun interrupts, and a status register
to hold the notification bits.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-04 00:20:21 -04:00
Marti Bolivar 19aebdf425 stm32.h: Add STM32_HAVE_DAC feature-test.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-04 00:17:01 -04:00
Marti Bolivar 8558b62e06 STM32F1: gpio.h: Add hack mode macro, for F2 compatibility.
I'm sure we can work the compatible subset of F1/F2 GPIO functionality
into the F1 gpio.h interface in a clean way. This is not that clean
way, but I'm short on time.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-04 00:17:01 -04:00
Marti Bolivar 3cc2ff5f50 STM32F2: Add EXTI support.
Add series headers to keep the base pointers, and (on F2) use SYSCFG
to tell exti_do_select() where the EXTI control registers are. No
surprises.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-03 22:45:41 -04:00
Marti Bolivar 647c4b1027 STM32F2: Add SYSCFG support.
Turn it on at init() time on F2.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-03 22:44:43 -04:00
Marti Bolivar aeb6ae44b8 STM32F1: gpio.h: Cosmetics.
Those ugly Doxygen comments have been bothering me since forever. Fix
them up and throw some M-x align around.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-03 22:40:40 -04:00
Marti Bolivar 9557be1f25 Bring back EXTI on F1, with deprecations for gpio.h on F1.
Tested on Maple Mini with examples/mini-exti-test. Changes to Wirish
are minor: use the new EXTI types exti_num and exti_cfg (see below) in
place of now-deprecated variants in ext_interrupts.cpp.

The way I originally did libmaple/exti.h was stupid, and fixing it
turned out to be a little disruptive.

libmaple/exti.h depends on libmaple/gpio.h (for AFIO), but that's a
classic case of exposed implementation detail. So invert the
dependency: make gpio.h depend on exti.h. Do this by adding exti_num
and exti_cfg to exti.h; these respectively replace afio_exti_num and
afio_exti_port. The afio_* variants are now deprecated. (Throw in a
typedef and some macros at the bottom of the F1 series/gpio.h for
backwards compatibility).

Make exti_attach_interrupt() and exti_detach_interrupt() take
exti_num/exti_cfg arguments instead of the afio_* variants.

Make the EXTI dispatch routines __always_inline to defeat GCC -Os.

Many renames throughout libmaple/stm32f1/ to stop using the deprecated
names. Also move the previously F1-only gpio_exti_port() function into
the public libmaple header. Reimplementing it in terms of rcc_clk_ids
lets us deprecate the gpio_dev->exti_port field, which will save space
in the future.

While we're there, I notice that struct gpio_dev is defined once per
series. That's dumb, as it misses the entire point of having device
structs: they contain what's portable. So put the F1 version (which
has the extra EXTI port field) into libmaple/gpio.h, and add the
necessary exti_ports to libmaple/stm32f2/gpio.c. Sigh. We'll get rid
of it eventually, at least.

Clean up some other mistakes in gpio.h files as well (mostly removing
util.h dependency). Sorry for the messy commit.

For portability, add a new series-specific exti function,
exti_select(). The F1 version in (new) libmaple/stm32f1/exti.c uses
AFIO and some new private functionality in libmaple/exti.c and (new)
libmaple/exti_private.h to make this convenient.  We'll be able to do
the SYSCFG equivalent on F2 without any trouble.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-03 22:40:40 -04:00
Marti Bolivar 6b5c8417ef <libmaple/bitband.h>: Doxygen
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-03 22:40:40 -04:00
Marti Bolivar 1c5a7ecb98 libmaple/dac.c: Copyright.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-03 22:40:40 -04:00
Marti Bolivar 0b93e882bf libmaple/dac.c: Generalize comment about PA4/PA5.
Seems like this is true on F2 as well!

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-03 22:40:39 -04:00
Marti Bolivar 44aa07d181 Add ISRs and vector table for F1 value line.
Now libmaple/stm32f1/rules.mk tries to pull in ISRs and a vector table
on a per-line basis. Move isrs_performance.S and
vector_table_performance.S to (new) libmaple/stm32f1/performance, and
rename them.

Add corresponding files for value line under (new)
libmaple/stm32f1/value. This helps clean up some
performance-line-isms, and allows implementing e.g. the CEC interrupt,
which is used by something else on performance line.

Untested (I don't have access to a value line MCU); hopefully this
works.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-03 22:40:39 -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 a9381eb090 libmaple_types.h: Add __unused.
We'll need this soon.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-03 22:40:38 -04:00
Marti Bolivar 9ee2f6c79d F2: Add usart_get_af().
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-03 02:23:27 -04:00
Marti Bolivar 97b01c0b98 Globally switch style for GPIO config routines.
Stupidly, spi_gpio_cfg() didn't take a spi_dev* argument on F1,
because it doesn't matter there. On F2, where we need to set an
alternate function when configuring GPIOs for SPI, we need to know the
dev.

We can't add break backwards compatibility, so we need a new
function. However, we've since added a bunch of foo_gpio_cfg()
routines, and we don't want confusing asymmetry in the names. So a
global style change is needed. (Fortunately, the new functions weren't
part of a release, so it's no problem to change their names).

Change all foo_gpio_cfg() routines to foo_config_gpios() (or
foo_config_gpio(), if there's only one GPIO to configure). For
backwards compatibility, make spi_gpio_cfg() on F1 an __always_inline
call to spi_config_gpios().

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-03 02:15:22 -04:00
Marti Bolivar cd494c17d9 STM32F2: Add timer_get_af().
Pull some code out of the F2 pinMode() into a utility function. This
feels generally useful enough to be exposed to the users (it will, for
example, make it easier to implement input capture in a clean way).

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-03 00:04:01 -04:00
Marti Bolivar 49794bbbee Add timer_has_cc_channel().
This is a convenience function for deciding whether a timer supports a
particular capture/compare channel. It's necessary because of those
nuisance "general purpose" timers that only have a subset of the
channels.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-02 20:36:36 -04:00
Marti Bolivar 8c7d91af97 Sort the rcc_clk_id enumerators semi-alphabetically.
Only semi-alphabetically because peripherals are kept together (so the
UARTs sort as if they were USARTs). Advantages:

- It lets us play numeric comparison and lookup-table hacks, as we now
  have the property that the rcc_clk_ids for a given peripheral are a
  contiguous range of integers.

- It will hopefully let the compiler emit faster/smaller code for
  switches over a dev->clk_id.

- It's better intuitively.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-02 20:31:52 -04:00
Marti Bolivar ec5a2f8309 Oops; don't break the build on F1.
That was dumb.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-02 19:39:47 -04:00
Marti Bolivar b07c06d3e3 libmaple/adc.h: Fixup for Doxygen.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-01 16:36:20 -04:00
Marti Bolivar feae1d4478 libmaple/stm32.h: Add STM32_TIMER_MASK, STM32_HAVE_TIMER.
Feature-test macros for dealing with the fact that timer support has
holes. STM32_TIMER_MASK is a bitmask where bit n is set when TIMERn is
present. STM32_HAVE_TIMER(n) just tests whether bit n is set in
STM32_TIMER_MASK.

This is necessary because e.g. the STM32F100RB has timers 1-4, 6, 7,
and 15-17.  Because of this, the usual STM32_NR_whatever won't work,
and we use a bitmask instead.

For F1 performance line (F103s), STM32_TIMER_MASK can be derived from
the density. For F1 value line, I'm not as sure, so just add it for
the single MCU we support (the STM32F100RB). Same story for F2: add it
for the STM32F207IC. We can fix this up later if necessary.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-01 03:05:56 -04:00
Marti Bolivar 9a2ed4a661 stm32f2/usart.c: Change some FIXMEs to TODOs.
I think these are probably unchanged, but we need to make sure.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-01 01:29:54 -04:00
Marti Bolivar d2c4bd6564 Bring back HardwareSerial.
To make this happen, we need to have <board/board.h> tell us whether
or not it's got each of the USARTs. Do that with BOARD_HAVE_USARTn,
for n = 1,...,6. This lets us define HardwareSerial instances only
when appropriate, and gets rid of some board-specific hacks we'd
accumulated.

The new <libmaple/usart.h> now has a convenience function for
determining the bus rate by using the appropriate STM32_PCLKx macro,
so we can shave a uint32 per instance, which is nice given that
they're all going to be in memory. This changes the constructor
arguments, but the API only specifies the semantics of the predefined
instances, so this is still backwards-compatible. (We should look into
storing the instances in Flash -- they don't change, after all.)

We don't actually need struct usart_dev's definition in
HardwareSerial.h, so replace it with a forward declaration and include
<libmaple/usart.h> it in HardwareSerial.cpp instead.

Assert some copyrights.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-06-01 01:28:51 -04:00
Marti Bolivar 714569afdb stm32f2/gpio.c: Fix some bugs.
Make gpioh.regs actually point to GPIOH_BASE. Properly AND out flag
bits in gpio_set_modef().

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-05-31 18:44:26 -04:00
Marti Bolivar 3e6269316d <libmaple/gpio.h>: Fix gpio_write_bit().
It's exactly wrong -- val=0 makes the pin high, and val=1 makes it
low.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-05-31 18:43:18 -04:00
Marti Bolivar 766cda51fa libmaple/usart_private.c: Add missing include.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-05-31 17:24:41 -04:00
Marti Bolivar 47b17f5b98 STM32F1: Fix nvic_irq_disable_all() on some MCUs.
The current implementation only disables the first 64 IRQ lines. This
covers all the chips we currently support, but it'll be a nasty
surprise if anyone decides to add e.g. connectivity line MCUs (which
have more IRQs) in the future.  We already have the infrastructure to
fix it in a clean way, so we might as well do it now.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-05-31 17:24:18 -04:00
Marti Bolivar 0bc34d060c nvic.h: Doxygen: nvic_irq_num is target dependent.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-05-31 17:24:18 -04:00
Marti Bolivar fc3fb928fa libmaple/nvic.h: Doxygen tweak.s
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-05-31 17:24:18 -04:00
Marti Bolivar 1fb5934180 libmaple/nvic.h: Fix typo.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-05-31 17:24:18 -04:00
Marti Bolivar daee14b0b6 stm32f1/rcc.c: Move Doyxgen.
This is a workaround for Breathe.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-05-31 17:24:17 -04:00
Marti Bolivar 94f362e925 series/rcc.h: Lose BIT().
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-05-31 17:24:17 -04:00
Marti Bolivar ef217b7434 libmaple/rcc.c: Fix typo.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-05-31 17:24:17 -04:00
Marti Bolivar 8f8ab2e354 libmaple/rcc.h: Doxygen.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-05-31 17:24:17 -04:00
Marti Bolivar 1cf0366934 stm32f2/rcc.h: Remove a TODO.
That never worked out.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-05-31 17:24:17 -04:00