Commit graph

605 commits

Author SHA1 Message Date
Marti Bolivar 6715377e27 STM32F2: Add timer support.
Standard series peripheral support patch, containing STM32F2 series
timer.h and timer.c.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:57 -04:00
Marti Bolivar 75421efa8a stm32f2/nvic.h: Add fake NVIC_TIMER6 irq number.
This is necessary to make some timer code portable, but I'm not sure
it's a good idea.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:57 -04:00
Marti Bolivar 8530a332ac libmaple/rcc.h: Fix Doxygen file header.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:57 -04:00
Marti Bolivar cd61bfbaf0 stm32f2/rcc.h: Fix Doxygen file header.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:57 -04:00
Marti Bolivar cbe37fa979 STM32F1: Add support for timers 9 through 14.
This applies to XL-density STM32F1 devices.

In stm32f1/timer.c, add timer_dev's for the new timers, using the
timer_private API. These definitions are conditionally compiled based
on the target density to avoid wasting space on smaller MCUs. Also add
calls to the appropriate timer_private.h dispatch routines within the
IRQ handlers for these timers. We need to change the IRQ handler names
to reflect this eventually, but put that off for now, as it could
break backwards compatibility in some exotic situations where the user
refers to the libmaple IRQ handlers directly.

In stm32f1/timer.h, add register map base pointers and device
declarations for the new timers. timer_dev* declarations are compiled
in only when the target MCU supports them, in keeping with the above
stm32f1/timer.c changes.

In libmaple/timer.c, update the (static) IRQ enable routines to
account for the additional timers. This adds some code that's
unnecessary on smaller STM32F1s, but it's minimal (40 extra bytes on
my machine), so portability and readability win out.

Size change, using GCC version "(Sourcery G++ Lite 2011.03-42) 4.5.2":

Before:

   text	   data	    bss	    dec	    hex	filename
    615	      0	      0	    615	    267	build/home/mbolivar/leaf/libmaple/libmaple/timer.o

After:

   text	   data	    bss	    dec	    hex	filename
    655	      0	      0	    655	    28f	build/home/mbolivar/leaf/libmaple/libmaple/timer.o

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:57 -04:00
Marti Bolivar c8915d3c91 libmaple/timer_private.h: Update to support TIM9-TIM14.
Add DECLARE_RESTRICTED_GENERAL_TIMER(), for declaring general-purpose
timers with limited interrupt support -- that is, for declaring timers
9 through 14. This helps avoid wasting space on pointers to user
handlers for interrupts that don't exist.

Add dispatch_tim_9_12() and dispatch_tim_10_11_13_14(), which are
special purpose dispatch routines for these "restricted" general
purpose timers, which only try to dispatch interrupts supported by
these timers.

Change dispatch_single_irq() to check the logical and of the DIER and
SR registers for the timer whose interrupt it's dispatching. This is
necessary due to increased muxing on the timer IRQ lines caused by the
new timers. See the comment in the patch for more details. This does
add overhead on medium- and high-density STM32F1s, where the extra
check is unnecessary, but it doesn't change dispatch_single_irq()'s
semantics, and keeps the implementation simple, so we'll live with it.

These changes will also work on F2 (and F4 AFAIK), which is why
they're part of the global private timer API, as opposed to
libmaple/stm32f1/timer.c.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:57 -04:00
Marti Bolivar 02545cab4d libmaple/timer_private.h: Add more explanatory comments.
Hopefully these will be helpful when adding timer support for
additional series in the future.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:56 -04:00
Marti Bolivar 16f81ef445 stm32f1/nvic.h: Add nvic_irq_num's for XL-density timers; Doxygen fixup.
This is a backwards-compatible change, but it deprecates some existing
functionality.

XL density STM32F1 devices have additional timers 9 through 14. These
share NVIC lines with timers 1 and 8. This scheme is also used on
e.g. STM32F2, so the corresponding nvic_irq_num enumerators on that
series have names like "NVIC_TIMER1_BRK_TIMER9" instead of
"NVIC_TIMER1_BRK". For portability (and XL-density support), it makes
sense to add these enumerators to the F1 version of nvic_irq_num,
which we do here.

For backwards compatibility, we keep the old enumerators (like
NVIC_TIMER1_BRK) around as aliases to the new ones (like
NVIC_TIMER1_BRK_TIMER9). These old enumerators are now deprecated.

Also fix up the Doxygen @file header.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:56 -04:00
Marti Bolivar 4b4de07958 stm32f2/nvic.h: Fix Doxygen @file directive.
This lets Doxygen pick it up.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:56 -04:00
Marti Bolivar 4c4d704956 stm32f2/rcc: Fix timer rcc_clk_id enumerators.
The timer enumerators are different tokens on F2 than they are on F1.
This is wrong (breaks portability), so fix it, and update the F2
rcc_dev_info table to match.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:56 -04:00
Marti Bolivar dc9a918288 stm32f1/timer.h: Whitespace tweaks.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:56 -04:00
Marti Bolivar 2dd98d25b4 libmaple/timer.h: Minor tweaks.
Comments etc.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:56 -04:00
Marti Bolivar d7b930d055 timer: Fixes, rip out nonportable bits.
Fix copy-paste errors in, and add missing, register bit
definitions. For copy-paste errors that would result in source
incompatibilities with past releases, add some legacy defines.

Add series header and C file for STM32F1 which fills in the missing
API. Much of the F1 timer.c would be repeated on F2, so also add
timer_private.h to hold these.

Support for timers 9 through 14 is still missing.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:56 -04:00
Marti Bolivar 6e2a65e7df Don't conditionally compile rcc_clk_id or nvic_irq_num enumerators.
Whether or not a given peripheral is present on an F1 series MCU
doesn't matter. It doesn't take up any extra space to include these
enumerators, and it's convenient to have them defined so portable
libmaple routines can safely refer to them. This can prevent the need
for special series-specific versions of some functions.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:56 -04:00
Marti Bolivar b545d97c01 libmaple/libmaple_types.h: Add __always_inline.
We need this to ensure inlining when compiled with -Os.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:56 -04:00
Marti Bolivar e8d6ba0cdd libmaple/timer.h: Fixups.
Fix include guard define name, update copyright, fix Doxygen @file.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:56 -04:00
Marti Bolivar b370738ee0 libmaple/dac.h: Fixups.
Assert LeafLabs copyright; fix Doxygen @file, and add missing include.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:56 -04:00
Marti Bolivar 59a7811d05 Deprecate rcc_clk_init().
This function has been with us from the earliest days of libmaple.
It's showing its age, as the API it presents is tied to the
STM32F1. Deprecate it, and provide instructions for how to use newer,
more portable APIs. The new way is more verbose, but we can always add
a portable "just set up the PLL, dammit" convenience function later (a
nice candidate is to extract an interface from setup_clocks() in
boards.cpp).

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:56 -04:00
Marti Bolivar a949744d3c Resurrect ADC support.
Standard refactoring: add series headers for F1 and F2, along with
series adc.c files. There are some issues relating to adc_extsel_event
to hammer out later, but this will do for now.

We also add some new portability interfaces to libmaple/adc.h in order
for Wirish to use the same code to initialize the ADCs at init() time.

As usual, F1 is untested.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:56 -04:00
Marti Bolivar 5f81900107 libmaple/rules.mk: Cosmetics.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:55 -04:00
Marti Bolivar 4dd092d705 Resurrect IWDG support.
This peripheral is identical on F1 and F2.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:55 -04:00
Marti Bolivar 88dc7e263a Resurrect PWR support for F1 and F2.
Just add the missing register bit definitions in new series headers.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:55 -04:00
Marti Bolivar a6644bcec1 Clean up rules.mk files.
Alphabetize targets and remove continuation lines.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:55 -04:00
Marti Bolivar 95f3f3bb0d libmaple/pwr.h: Fix register bits (breaking change).
This is a backwards-incompatible change. It is necessary to fix an
error.

The register bit definitions are given as if they were masks, but
they're actually bit numbers. E.g., PWR_CR_DBP, which should be the
mask for DBP in the power control register PWR_CR, is actually the
number of the bit that should be masked.

Fix this by adding _BIT to the definitions and adding proper
masks. Also add a mask for the PVD level selection bits in
PWR_CSR. Don't add any mask values for particular voltages selected as
these are not portable.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:55 -04:00
Marti Bolivar 918b98426c [UNTESTED] Resurrect FSMC support.
fsmc_sram_init_gpios() is now series-specific, so move its existing
implementation to the F1 backend, and add libmaple/stm32f2/fsmc.c for
the F2 backend.

Delete libmaple/fsmc.c; it is now empty.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:55 -04:00
Marti Bolivar 9cf06a9795 fsmc.h: Use STM32_HAVE_FSMC feature-test macro.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:55 -04:00
Marti Bolivar 5da6d57717 stm32.h: Add STM32_HAVE_FSMC.
This is a feature test macro for the flexible static memory
controller (FSMC) peripheral.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:55 -04:00
Marti Bolivar e59a7442a3 [FIXME] Resurrected, shinier USART support.
FIXME:
- Test F1 support
- Solve problem of duplicated bytes being TXed unless delay is
  inserted after configuration but before first bytes are TXed.

Rip out nonportable bits from top-level interfaces. The USART register
maps are basically the same between F1 and F2, so leave these, but add
register bit definitions which had name changes to the libmaple header
to avoid needless repetition. There are also a few new bits in the F2
USART registers; add definitions for these in the F2 USART header. Add
Doxygen comments for all USART bit definitions.

Deprecate struct usart_dev's max_baud field. This is just bloat that
doesn't bring us much real benefit.

Add new series-specific USART files for F1 and F2:

- libmaple/stm32f[1,2]/usart.c
- libmaple/stm32f[1,2]/include/series/usart.h

These are standard series-specific files, providing register map base
pointers, defining devices, implementing nonportable routines, etc.

We need a portable way to configure the USART GPIOs. To this end, add
usart_async_gpio_cfg() to the top-level USART interface. This function
is implemented in new F1 and F2 USART backends to take the appropriate
action to configure the RX and TX pins for asynchronous full duplex
mode.

USART baud rate calculation is done differently on the different
series. Keep the usart_set_baud_rate() declaration in the top-level
USART header, but move the implementations into the series-specific
usart.c files.

In usart_set_baud_rate(), allow for deriving clock_speed automatically
by letting user tell us to figure out the peripheral clock speed by
mapping the device's rcc_clk_id onto an STM32_PCLK[1,2] value. This
preserves flexibility for users with non-default clock configurations,
but makes things easier on everyone else.

Add private USART files for portable private USART routines:

- libmaple/usart_private.h
- libmaple/usart_private.c

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:55 -04:00
Marti Bolivar 4a88656774 stm32f2: Improve GPIO alternate function support.
Add GPIO_AFRL and GPIO_AFRH bit definitions; these seem to have been
overlooked. Add enum gpio_af to give labels to the various
functions. Add gpio_set_af() convenience routine for configuring a
GPIO's alternate function.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:55 -04:00
Marti Bolivar 63de87bd60 rcc_reconfigure_pll(): Assert that the PLL is disabled.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:55 -04:00
Marti Bolivar 454aab10af RCC: Add rcc_is_clk_on().
This is a convenience function for checking if a clock line is on.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:54 -04:00
Marti Bolivar 2240b54dfa Style change to libmaple/rules.mk.
New style makes for cleaner diffs.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:54 -04:00
Marti Bolivar 53fcafdedf stm32.h: Cleanups.
Fix include guard name. Remove unused STM32_FLASH_WAIT_STATES (which
was superseded by FLASH_SAFE_WAIT_STATES).

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:54 -04:00
Marti Bolivar a0e1657456 Add __weak to <libmaple/libmaple_types.h>.
This is just an alias for __attribute__((weak)).

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:54 -04:00
Marti Bolivar 8513d995ed RCC: Add new mechanism for configuring the main PLL.
The new style for configuring the PLL is to initialize
a (series-specific) struct rcc_pll_cfg, and pass a pointer to it to
rcc_configure_pll(). After that's done, you can use
rcc_turn_on_clk(RCC_CLK_PLL) to turn on the main PLL, and busy-wait
until rcc_is_clk_ready(RCC_CLK_PLL) is true to make sure the new
configuration took effect.

- libmaple/rcc.h:

  -- Add struct rcc_pll_cfg, which specifies a PLL configuration. This
     specifies a PLL source and a void pointer to series-specific PLL
     configuration data.

  -- Add rcc_configure_pll(), which takes a pointer to struct
     rcc_pll_cfg, and configures the main PLL. It's up to each series
     to define this function.

- stm32f1/rcc.h: Add struct stm32f1_rcc_pll_data, to store F1-specific
  PLL configuration state.

- stm32f1/rcc.c: Add an implementation for rcc_configure_pll().

- stm32f2/rcc.h: Add struct stm32f2_rcc_pll_data, to store F2-specific
  PLL configuration data.

- stm32f2/rcc.c: Add an implementation for rcc_configure_pll().

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:54 -04:00
Marti Bolivar 05212074eb stm32f1/rcc.h: Deprecate rcc_clk_init().
We're going to replace this with a more portable mechanism.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:54 -04:00
Marti Bolivar 8af1ff3f56 libmaple/rcc.h: Add rcc_enable_css(), rcc_disable_css().
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:54 -04:00
Marti Bolivar ec6dabfde7 libmaple_types.h: Add __deprecated.
This is a define for __attribute__((deprecated)).

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:54 -04:00
Marti Bolivar f20a281077 RCC: Clean up and sanitize interfaces across F1, F2 series.
Additions:

- rcc_switch_sysclk():

  For changing the clock used as SYSCLK's source.

- enum rcc_clk:

  One for each system and secondary clock source (e.g. HSE,
  LSE). These are defined on a per-series basis in each of the
  <series/rcc.h>.

- rcc_turn_on_clk(),
  rcc_turn_off_clk(),
  rcc_is_clk_ready():

  For turning on system and secondary clock sources, and checking
  whether or not they're ready. Uses enum rcc_clk.

Removals:

- rcc_clk_init(): There's no way to port this to F2. Move it to the F1
  header. This also means we can remove the empty implementation and
  enum rcc_pll_multiplier from the F2 RCC header, where it doesn't
  make any sense.

Also fix up some includes, and rewrite rcc_clk_init() in terms of the
new clock source management functions.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:54 -04:00
Marti Bolivar 32443a2222 Clean up Flash interface; add flash_enable_features().
Make a single function, flash_enable_features(), to control the access
characteristics of Flash memory (i.e. to write to the non-latency bits
of ACR).

In so doing, make everybody pretend to allow instruction and data
caching. On STM32F1, trying to turn these on simply has no
effect. This allows unconditionally trying to turn them on, which will
simplify users' lives.

This has the ancillary benefit of making the stm32f2- and
stm32f1-specific flash.c files unnecessary; delete these.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:54 -04:00
Marti Bolivar 4a4a2dd035 STM32F2 Flash support.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:54 -04:00
Marti Bolivar 8643191193 stm32f2/stm32.h: Add support for STM32F207IG.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:53 -04:00
Marti Bolivar 5447cc100c [UNDO] Rip out a bunch of F1-only bits from libmaple proper
We'll need to bring this functionality back online piecemeal as we add
F2 support.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:53 -04:00
Marti Bolivar f3f82bc87d Initial STM32F2 series/stm32.h.
This still has some FIXMEs, but it's enough to get going.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:53 -04:00
Marti Bolivar 52238ad3f5 Initial STM32F2 GPIO support.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:53 -04:00
Marti Bolivar f3efe9039e Initial STM32F2 RCC support.
Largely untested.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:53 -04:00
Marti Bolivar 9696a3b383 libmaple_types.h: Add offsetof().
Rather than rely on newlib's stddef.h, define our own offsetof() in
terms of GCC's __builtin_offsetof(). Don't override an existing
offsetof() definition, in case the user already has one they prefer.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:53 -04:00
Marti Bolivar 9e8bc1bd40 STM32F2 NVIC support.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:53 -04:00
Marti Bolivar ae88169058 STM32F2: Add vector table and weak ISR definitions.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:53 -04:00
Marti Bolivar ec601e0e23 Add skeleton libmaple/stm32f2/rules.mk.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:53 -04:00
Marti Bolivar 4956f08a8e Make BKP support STM32F1-only.
- libmaple/bkp.h: Mark availability restriction.

- Move libmaple/bkp.c to libmaple/stm32f1; adjust rules.mk files
  accordingly.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:53 -04:00
Marti Bolivar fcb6e1ed28 libmaple/stm32: Add enum stm32_series, STM32_MCU_SERIES.
enum stm32_series gives a tag to each STM32 series, including the ones
we don't yet support.

STM32_MCU_SERIES is a define which the series stm32.h header must
provide, identifying the series of the MCU being targeted.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:52 -04:00
Marti Bolivar 3efa31376b Great renaming: use "series" instead of "family".
This is for greater consistency with the ST application notes, which
refer to migrating "across" series (e.g. F1 to F2), but compatibility
"within" a family (e.g. F1).

So:

- Move libmaple/stm32x/include/family to .../include/series/ and fix
  up includes appropriately.
- Refer to "family" headers as "series" headers in comments.
- Make similar "find and replace"-style changes to build system
  variable names and comments.
- Move support/ld/stm32/family to .../stm32/series.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:52 -04:00
Marti Bolivar 3b8cad1d96 libmaple/flash: Add family-specific FLASH_SAFE_WAIT_STATES.
This is the smallest wait state value that is safe for use when the
MCU is at its fastest rate, not considering overclocking. This
requires moving the FLASH_WAIT_STATE defines above the family include,
so do that, and add the missing #defines (for wait states up to 7).

For the STM32F1, the correct value for FLASH_SAFE_WAIT_STATES is
FLASH_WAIT_STATE_2; say so in the F1-family flash.h.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:52 -04:00
Marti Bolivar 0f334dd868 libmaple/flash.h: Doxygen fixups.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:52 -04:00
Marti Bolivar 7b84b059db Move nonportable bits of libmaple/stm32.h into libmaple/stm32f1.
These go in a new family header, libmaple/stm32f1/include/family/stm32.h.

While we're at it, do some reorganizing.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:52 -04:00
Marti Bolivar d0454eeafe libmaple/nvic.h: Explanatory commenting.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:52 -04:00
Marti Bolivar 7f08784dea stm32f1: License headers, portability markers.
Add license headers to libmaple/stm32f1/isrs_performance.S and
libmaple/stm32f1/vector_table_performance.S. Copyright to Perry
Hung. I was present when Perry wrote these files. Also mark these as
STM32F1 specific (rather than "STM32", say "STM32F1").

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:51 -04:00
Marti Bolivar 72265603db stm32f1/rcc.c: Add cautionary comment.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:51 -04:00
Marti Bolivar 3dd4f375c5 RCC: Break out some portable functionality from stm32f1/.
Portions of rcc_clk_enable(), rcc_reset_dev(), and rcc_set_prescaler()
are portable; break these into static inline helpers in
rcc_private.h. These guts of these are portable, but the arrays of
registers etc. are not.

Also add an extern declaration for rcc_dev_table into
rcc_private.h. This lets us put rcc_dev_clk() into a newly resurrected
libmaple/rcc.c, since that's portable.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:51 -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 0794913537 Move GPIO support for STM32F1 to libmaple/stm32f1.
Make a new family header, libmaple/stm32f1/include/family/gpio.h, and
supporting libmaple/stm32f1/gpio.c.

Beyond registers and devices, these also include anything mentioning
AFIO, which doesn't exist on F2.

Update libmaple/stm32f1/rules.mk for new gpio.c.

Alter gpio_write_bit() to use dev->regs->BSRR only. BRRs are not
present on STM32F2.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:51 -04:00
Marti Bolivar cb8243bc20 libmaple/nvic.c: Cosmetics.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:51 -04:00
Marti Bolivar 996983e54b Move NVIC support for STM32F1 to libmaple/stm32f1.
Backwards-compatible. Only the headers need to change.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:51 -04:00
Marti Bolivar 60f40eb3b6 Move Flash support for STM32F1 to libmaple/stm32f1/.
This is a backwards-compatible change.

The Flash registers on the STM32F2 line are different than on
STM32F1. Therefore, move the register map and bit definitions to new
libmaple/stm32f1/include/family/flash.h.

Move flash_enable_prefetch() from libmaple/flash.c to new
libmaple/stm32f1/flash.c. The remaining pieces of libmaple/flash.c use
a common subset of the Flash registers, so they're's portable to F2,
and that's all we're currently interested in.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:51 -04:00
Marti Bolivar 32b267512f Move RCC support for STM32F1 to libmaple/stm32f1/.
This is a backwards-compatible change.

Modify libmaple/rules.mk to include the family's include
directory. This allows libmaple/include/libmaple/rcc.h to include the
STM32F1 RCC header with #include <family/rcc.h>. We'll use this
convention henceforth to distinguish between top-level and
family-specific headers.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:51 -04:00
Marti Bolivar 198daa7907 libmaple/rules.mk: Reinstate -Werror.
This is OK across all boards now that USB is its own submodule.

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 d70098ba26 Remove "CS3" prefix from libmaple symbol names.
We're no longer even marginally compatible with CS3, so it's
inappropriate to use that prefix in our names.

Rename:
    __cs3_stm32_vector_table -> __stm32_vector_table.
    __cs3_stack              -> __msp_init
    __cs3_reset              -> __exc_reset
    __cs3_start_c            -> start_c

Also add an MIT license header and assert LeafLabs copyright over
wirish/start.S and wirish/start_c.c.  These files are modified from
the original CodeSourcery versions, which were distributed under a
license that permits modifications to be distributed under a different
copyright and licensing terms than the originals.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:52:17 -04:00
Marti Bolivar 926710d872 Remove CS3-style initialization.
Remove libcs3-related bits from support/ld. Break them out into
libmaple proper and Wirish as appropriate: vector table definition and
ISR declarations go into libmaple proper, and startup code goes into
Wirish. Vector table symbols are included into common.inc from an
STM32 family-specific directory under support/ld/stm32.

This is a combination of 5 commits. Individual commit messages follow:

libcs3_stm32_src: Don't depend on cs3.h.

So we can use the existing toolchain.

Move ISR decls/vector table into libmaple proper.

This allows us to configure the vector table on a per-family basis.

- Move
        support/ld/libcs3_stm32_src/stm32_isrs.S
                                    stm32_vector_table.S
  to
        libmaple/stm32f1/isrs_performance.S
                         vector_table_performance.S,
  respectively.

  The directory libmaple/stm32f1/ is intended to hold all
  STM32F1-specific code within libmaple. Obviously, there's a lot of
  work to do before this becomes true.

- support/ld/libcs3_stm32_src/Makefile: Don't try to compile
  stm32_isrs.S and stm32_vector_table.S anymore.

- Add libmaple/stm32f1/rules.mk to include these new files in the
  standard libmaple build.

- support/make/target-config.mk: Add LIBMAPLE_MODULE_FAMILY, which
  selects a directory to use as a family-specific libmaple
  submodule.

- Makefile: Add LIBMAPLE_MODULE_FAMILY to LIBMAPLE_MODULES.

Remove support/ld/libcs3_stm32_src and derived object files.

From support/ld/libcs3_stm32_src, move start.S and start_c.c into
Wirish. Modify wirish/rules.mk accordingly.

Delete support/ld/libcs3_stm32_*_density.a. These are no longer
necessary, as the relevant objects are included in the standard Wirish
build. Remove the GROUP statements from the board linker scripts
accordingly.

Remove SEARCH_DIR(.) from common.inc; it's no longer necessary. Also
fix up some comments that are now out of date.

wirish/start_c.c: Don't use CS3-style memory initialization.

Switch memory initialization to a simpler style of initializing .data
if necessary, then zeroing .bss. Initializing .data is only necessary
during Flash builds, since during RAM builds, LOADADDR(.data) ==
ADDR(.data).

This makes libmaple completely incompatible with the CS3 startup
sequence. Subsequent commits will clean up the namespace to reflect
that fact.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:52:17 -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
Marti Bolivar ef5efb025b usb.h: Mark API unstable.
The USB API is heavily reliant on the ST stack, and additionally
assumes that all USB is the USB FS peripheral.  As such, it's going to
have to change as we go forward.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-21 18:13:00 -04:00
Marti Bolivar 4aebc879dd Oops; actually remove usb_config.h.
usb_config.h was supposed to be removed in
d7afdbe6b41a77938863854a1e719398e6c35094; however, it looks like some
merge conflicts stopped that from happening while I was rebasing.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-18 14:02:25 -04:00
Marti Bolivar 1717afad9e usb_cdcacm.c: Cleanups
Move the callbacks to the bottom of the file, and mark them static.
Replace empty callbacks with NOP_Process in the callback tables.
Remove prototype for nonexistent prep_and_reset().  Other
miscellaneous fixups.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-18 13:30:18 -04:00
Marti Bolivar 6dba382743 usb.h, usb.c: Cleanups
Remove wIstr. This cleans up the control flow. wIstr is still declared
in usb_lib/usb_regs.h, but it's unused throughout the code base.

Remove bIntPackSOF.  Only written, never read.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-18 13:30:18 -04:00
Marti Bolivar 04c2071095 Remove usb_int.h, usb_int.h, usb_int.c.
No longer used.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-18 13:30:18 -04:00
Marti Bolivar 1418bb4ff1 usb: Clean up some globals with new struct usblib_dev.
Add struct usblib_dev (and USBLIB, a pointer to the singleton) to
usb.h.  USBLIB contains the global state which is used by
functionality imported from usb_lib/.

Consolidating global state into USBLIB will make it easier to remove
later.

Initial fields in struct usblib_dev are endpoint interrupt callbacks,
a mask for what to handle in the low-priority USB interrupt, and
device state.  These replace pEpInt_IN, pEpInt_OUT; wInterrupt_Mask;
and bDeviceState, respectively from usb_lib/, so remove their
declarations from usb_lib_globals.h accordingly.  Also remove unused
SaveState declaration from usblib_globals.h. Move bDeviceState into
'state' field in usblib_dev.  Device state type changes from
DEVICE_STATE to usb_dev_state, volatile gets dropped, and enumerators
get a 'USB_' prefix, but it's otherwise the same.

usb_lib/ expects pInformation to point to   Device_Info,
                 pUser_Standard_Requests -> User_Standard_Requests, and
                 pProperty               -> Device_Property.

Alter usb_init_usblib() to reflect these assumptions.  Reorganize
usb_lib_globals.h to make these assumptions more apparent to the
reader.

Modify usb_init_usblib() to take endpoint callbacks as arguments;
update its caller in usb_cdcacm.c.

usb_lib/ defines pInformation, pProperty, and pUser_Standard_Requests
itself (in usb_init.c), but we have our own definitions (in usb.c).
Remove the duplicates from usb.c.  Also remove EPindex and Device_Info
definitions from usb.c. Unused, and anyways already defined in
usb_lib/usb_init.c.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-18 13:30:18 -04:00
Marti Bolivar d7afdbe6b4 Remove usb_config.h.
Move its defines into usb_cdcacm.c and usb.[hc] as appropriate.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-18 13:30:18 -04:00
Marti Bolivar 494f05b236 usb: Disentangle CDC ACM functionality.
Add new usb_cdcacm.h, which provides the virtual serial port API.
This file (and new usb_cdcacm.c) consolidate the VCOM support, which
was previously distributed through descriptors.[hc], usb.[hc],
usb_callbacks.[hc], and usb_config.h.

Add usb_init_usblib() to usb.h, as a way of initializing the USB
peripheral in terms of the data structures required by usb_lib.  This
is used by the new usb_cdcacm_enable().

Create new usb_lib_globals.h, with declarations for the usb_lib global
state which is most used throughout the rest of the libmaple USB stack.

Remove descriptors.c and usb_callbacks.[hc]; they are no longer
necessary.

Update the USB README accordingly.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-18 13:30:18 -04:00
Marti Bolivar fb3c7a1e09 usb.c: Use usb_reg_map.h; replace most of CTR_LP().
This cuts down on some of the uglier dependencies.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-18 13:30:17 -04:00
Marti Bolivar 07bc0c7001 usb: Remove usbPowerOff(), move usbPowerOn() to usb_callbacks.c.
Remove usbPowerOn(), usbPowerOff() prototypes from usb.h.  These
aren't used outside of the USB subsystem, so they don't belong here.

Move usbPowerOn() from usb.c to usb_callbacks.c.  This is the only
place where it's used.  Remove the unused usbPowerOff() (from usb.c)
altogether.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-18 13:30:17 -04:00
Marti Bolivar 51a2d9793b usb: Prepare for moving some files to usb_reg_map.h.
usb_config.h: Remove usb_regs.h dependency; fix includes; add license.

usb_callbacks.h: Change includes to the pieces of usb_lib/ it uses,
which doesn't include usb_regs.h.

descriptors.h: Remove unused usb_lib.h include.

usb.h: Remove unused usb_lib.h include.  Some cosmetic commenting.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-18 13:30:17 -04:00
Marti Bolivar ae3d80d796 Add usb_reg_map.h and usb_reg_map.c.
usb_reg_map.h contains the usual register map and register bit
definitions that libmaple convention requires.  It also contains a
variety of structs and convenience functions for accessing and
manipulating endpoint registers, BTABLE entries, and PMA buffers.

We'll be moving towards usb_reg_map.h instead of usb_lib/usb_regs.h.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-18 13:30:17 -04:00
Marti Bolivar 125f3d9338 usb: Update README file.
Various parts of it are no longer true, and some TODOs are now done.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-18 13:30:17 -04:00
Marti Bolivar e53edd3a7b Remove usb_hardware.c and usb_hardware.h.
These files contain a lot of duplicated and unused code.  Move the
relevant pieces that need to survive into usb.c and usb_callbacks.c.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-18 13:30:17 -04:00
Marti Bolivar 50f68b84c4 usb: Replace duplicated code with nvic.h API.
Replace calls to usbEnbISR()/usbDsbISR() with
nvic_irq_enable()/nvic_irq_disable(). Remove ST-style code. Use
nvic_sys_reset() instead of systemHardReset().  Rename some
conflicting #defines that including nvic.h created.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-18 13:30:17 -04:00
Marti Bolivar 17e67dff76 usb: Cleanups and renames.
Rename setupUSB() and disableUSB() to usb_cdcacm_enable() and
usb_cdcacm_disable(), respectively.

Remove usbSendHello(). This shouldn't exist.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-18 13:30:17 -04:00
Marti Bolivar 545aae4459 usb: Move some board-specific configuration to Wirish.
Create new BOARD_USB_DISC_DEV and BOARD_USB_DISC_BIT board-specific
values.  Use these as arguments to setupUSB() and disableUSB().  This
helps make the USB stack more generic, and goes towards the resolution
of an important FIXME.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-18 13:30:17 -04:00
Marti Bolivar 3b9f0a03bf timer.h: fix timer_oc_set_mode().
timer_oc_set_mode() incorrectly writes to CCMR1 when channel is 2; fix
this.

Thanks to ala42 for the fix.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-10-12 09:22:15 -04:00
Marti Bolivar 2d689be936 usart: Add usart_rx().
usart_rx() is a nonblocking USART receive.  Add it for symmetry with
usart_tx().
2011-10-07 14:38:33 -04:00
David Kiliani 1873871aea Add support for the Olimex STM32 H103 board.
Pin layout and header files for the STM32 H103 prototype board from
Olimex featuring an STM32F103RBT6 chip. This commit contains all
necessary changes to compile with BOARD=olimex_stm32_h103.

Signed-off-by: David Kiliani <mail@davidkiliani.de>
2011-09-27 16:44:53 -04:00
Marti Bolivar 958ead333f rcc: Add RCC_USB to rcc_clk_id/rcc_dev_table.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-09-24 16:02:31 -04:00
Marti Bolivar 04b72e6fdb nvic: Add nvic_sys_reset().
This uses the SCB_AIRCR register to force a system reset.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-09-24 16:02:26 -04:00
Marti Bolivar f3345d6bb0 scb.h: Fix register map and bit definitions.
For the change log: This commit breaks backwards compatibility with
0.0.12.  However, it appears that the previous version was incorrect,
so these changes are necessary.

The SCB register map type (scb_reg_map) appears to be adapted from
versions specified by ARM; these include every possible register, and
do not necessarily apply to the STM32, since some registers are
implementation defined, to the extent that the implementation is
allowed not to feature them at all.  Thus, the current definition
appears to be an overreach, since libmaple is STM32-specific.  We
should thus revise it based on ST's PM0056, where the STM32 SCB is
specified.

However, the ST docs appear to be buggy.  In particular, they appear
to contradict requirements made by ARM v7-M ARM with respect to the
debug fault status register (DFSR), which ARM says must exist, but ST
fails to specify (it does leave a DFSR-sized hole in the SCB memory
layout, conveniently located next to some obvious typos which suggest
that the section was not well-proofread).  We defer to ARM and assume
ST just forgot to document the register, and leave the DFSR field in
struct scb_reg_map, since (based on my reading) its absence would be a
silicon bug.

All of the registers appearing in memory addresses higher than that of
SCB_BFAR are not specified by ST, but the v7-M ARM appears to give
some latitude on this to the implementation.  Leave them in the source
text, but put them in an appropriately-commented #if 0 block so that
users who know they're there can yell at us if they find them missing.
In this block, the Auxiliary Feature Register's field was "ADR"
instead of "AFR" in struct scb_reg_map; fix this.

Register bit definitions have been added which are named based on
PM0056 when possible, and on the November 2010 "Derrata 2010_Q3" issue
of the ARM v7-M Architecture Reference Manual, in the case of the
DFSR.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2011-09-24 16:02:15 -04:00
Marti Bolivar c32adf772e Merge remote branch 'rryan/usb_fixes' 2011-09-20 16:29:46 -04:00
RJ Ryan f549599c72 Missed one hard-coded structure size.
Signed-off-by: RJ Ryan <rryan@mit.edu>
2011-09-18 19:17:54 -04:00
RJ Ryan 8adc7e6127 Fix memory alignment of USB descriptor structures.
A variety of USB descriptor structures have been manually
"unpacked". Instead of using the struct, their members were unpacked
into the struct they were nested in. Additionally sizeof()'s were
commented in favor of manual calculation of structure sizes.

After uncommenting these changes, the USB CDC peripheral stopped
correctly configuring with the host. The root problem with the
structures is that GCC is padding them. By applying
__attribute__((__packed__)), these problems are fixed. I removed all
the instances of the workaround I saw within the USB code.

Signed-off-by: RJ Ryan <rryan@mit.edu>
2011-09-18 15:39:28 -04:00
RJ Ryan c4e0847720 Add a libc abort() implementation.
The STL in particular relies on abort() for entering an error
state. Without an abort() definition, the use of many STL primitives
results in a link error because the default implementation of abort()
uses _kill, _exit, and _getpid -- none of which are present. My
abort() implementation writes an error message to the error USART and
enters the throbbing-LED error state.

Signed-off-by: RJ Ryan <rryan@mit.edu>
2011-09-16 22:14:42 -04:00
RJ Ryan c731833c2d Add an __assert_func assertion handler so that libc does not use its
default implementation. This allows the use of assert() from libc's
assert.h.

Signed-off-by: RJ Ryan <rryan@mit.edu>
2011-09-16 21:31:34 -04:00
Michael Hope b9be2450f0 Added more doxygen file level headers. Documented a few more functions.
Signed-off-by: Michael Hope <michaelh@juju.net.nz>
2011-09-13 19:35:12 +12:00
Marti Bolivar f711c740e0 syscalls.c: Allow environment to specify heap boundaries.
Rename HEAP_START/HEAP_END macros CONFIG_HEAP_START/CONFIG_HEAP_END,
to mark them as build-time configuration options.  Wrap their
definitions with #ifndefs appropriately.
2011-09-12 20:59:12 -04:00
Marti Bolivar f4f8197745 usart.h: Deprecate rx_buf field in usart_dev.
nzmichaelh rightly argues that actual RX buffers should be
heap-allocated, to avoid wastage for unused devices.  Deprecate the
field for 0.0.12, since that's coming out soon.  This will let us get
rid of this field in master immediately after 0.0.12 gets shipped.
2011-09-12 20:11:59 -04:00
Marti Bolivar fc4bd8eb9e [support/ld] Add linker support for reconfigurable heap.
- common_header.inc: Declare EXTERN symbols _lm_heap_start and
  _lm_heap_end.

- common_rom.inc: Check for _lm_heap_start and _lm_heap_end.  If they
  are defined, preserve their values.  Otherwise, _lm_heap_start is
  starts after .bss, and _lm_heap_end is the end of SRAM.

  This allows existing linker scripts to continue using the old heap
  scheme, but allows for customizability elsewhere.

- syscalls.c: Respect the addresses of _lm_heap_start and _lm_heap_end
  as the boundaries of the heap in _sbrk().
2011-09-12 17:25:01 -04:00
Marti Bolivar 3c0a3ee251 syscalls.c: Bugfix _sbrk() implementation.
Fix _sbrk() implementation so it properly rejects negative arguments
which would send the program break below the heap start.  Fix
incorrect check against argument causing heap overflow.  Also set
errno properly to ENOMEM when the call fails.

Beginning and end of the heap are now determined by HEAP_START and
HEAP_END macros.  Their current values seem to work OK for heaps on
the internal SRAM, but they'll need to get generalized for Maple
Native.
2011-09-07 23:34:24 -04:00
Marti Bolivar aa4f3b6645 stm32.h: Add STM32_SRAM_END. 2011-09-07 23:34:24 -04:00
Marti Bolivar aad2377ae3 Update outdated stm32.h usages.
stm32.h has been updated to prefix its definitions.  Update the rest
of libmaple to take this into account.
2011-09-07 23:34:23 -04:00
Marti Bolivar 53f804e335 stm32.h: Remove SRAM_SIZE, prefix all #defines.
Remove SRAM_SIZE define.  This seems like a bad idea given that
bootloader builds drop user code at an offset from the SRAM start
address.

Prefix every #define with "STM32_" to avoid polluting the namespace.
Keep and deprecate the remaining ones (except for aforementioned
SRAM_SIZE), but define them to be the same as their prefixed variant.

Take a little extra care to break libmaple builds which specify PCLK1
and PCLK2 instead of the prefixed versions.  Some libmaple forks make
use of these; they will break in mysterious ways if they don't handle
this change properly.
2011-09-07 23:34:23 -04:00
Marti Bolivar a1772c16e1 syscalls.c: Remove fictitious uart_send() and broken comments.
uart_send() is not part of libmaple, and nm doesn't show it getting
linked in from anywhere else, so I don't believe it exists.  Remove it.

Also remove some commented-out sections from getch(), putch(),
_write(), and fgets().  These either reference uart_send() or use old
libmaple APIs which no longer exist.
2011-09-07 23:34:23 -04:00
Marti Bolivar 28c5b81f6d util.c: Respect stm32.h. 2011-09-07 23:34:23 -04:00
Marti Bolivar 53fede57a9 usart.h: Remove unnecessary local in usart_putc(). 2011-08-30 18:21:38 -04:00
Marti Bolivar 075f073c2c stm32.h: Doxygen tweaks.
For some unfathomable reason, Doxygen happily believes in PCLK2, but
but not PCLK1, so Breathe can't find the docs for PCLK1, and all the
children are unhappy.  As a workaround, move all the Doxgyen crap into
__DOXYGEN_PREDEFINED_HACK sections immediately preceding the actual
definitions.
2011-08-30 01:11:33 -04:00
Marti Bolivar cad3a5422b dma.c: Fix Doxygen syntax for dma_get_irq_cause(). 2011-08-30 00:09:07 -04:00
Marti Bolivar 3887713e69 util.h: Doxygen 2011-08-22 23:29:59 -04:00
Marti Bolivar bada156b62 stm32.h: Doxygen 2011-08-22 23:29:59 -04:00
Marti Bolivar 1d337f535f stm32.h: Doxygen 2011-08-22 23:29:59 -04:00
Marti Bolivar 13ce8aa6fa scb.h: Doxygen 2011-08-22 23:29:59 -04:00
Marti Bolivar 92f87d80de nvic.h: Doxygen 2011-08-22 23:29:59 -04:00
Marti Bolivar 24cf6f17e3 i2c.h: Doxygen 2011-08-22 23:29:58 -04:00
Marti Bolivar f3599645ec gpio.h: Doxygen 2011-08-22 23:29:58 -04:00
Marti Bolivar 86b7cfea48 flash.c: Doxygen 2011-08-22 23:29:58 -04:00
Marti Bolivar b2d244dd6a exti.c: Doxygen improvements. 2011-08-22 23:29:58 -04:00
Marti Bolivar 97e4a6d8a6 rcc: Doxygen improvements. 2011-08-22 23:29:55 -04:00
Marti Bolivar 6bdb5eaef4 dma.h: Doxygen improvements. 2011-08-22 18:08:53 -04:00
Marti Bolivar aa05fa2276 Typos. 2011-08-11 02:56:09 -04:00
Marti Bolivar c075041100 exti.c: Optimize multiplexed IRQ handlers.
Rewrite existing IRQ handlers in terms of new functions
dispatch_single_exti() and dispatch_extis().  dispatch_single_exti()
handles EXTIs which have a dedicated IRQ line, and thus doesn't have
to check EXTI_PR; it is mostly equivalent to the (now removed)
handle_exti().  dispatch_extis() handles multiple EXTIs sharing an IRQ
line.  Using dispatch_extis() instead of calling handle_exti()
multiple times avoids unnecessary I/O to the (volatile) EXTI_BASE->PR
register.

These changes are in the flavor of the timer IRQ optimizations
performed in f5016b15be.
2011-08-03 17:34:03 -04:00
Marti Bolivar 487a60946d exti.c: Cleanups. 2011-08-03 17:34:03 -04:00
Marti Bolivar aee5bceb0f exti.c: Remove enable_irq() and maybe_disable_irq().
These functions incorrectly replicate functionality that is already
accomplished by manipulating EXTI_IMR directly.
2011-08-03 17:34:03 -04:00
Marti Bolivar 5a7ad93ab2 exti.c: Clean up some bit-banding usages. 2011-08-03 17:34:03 -04:00
Marti Bolivar f5935ef477 exti.c: Cleanups.
Add new handle_exti() instead of calling clear_pending() and
dispatch_handler() each time.
2011-08-03 17:34:03 -04:00
Marti Bolivar dab7dd44f2 util.h: Properly parenthesize IS_POWER_OF_TWO(). 2011-08-03 17:34:03 -04:00
Marti Bolivar 4e50d36db8 timer.c: Minor IRQ dispatch tweaks.
Read TIMx_SR before grabbing a pointer to the user handlers instead of
after.  This should shave a couple of cycles off of the time between
IRQ entry and SR read.
2011-07-21 15:22:19 -04:00
Marti Bolivar f5016b15be timer.c: Optimize IRQ dispatch routines.
Remove dispatch_irq() and dispatch_cc_irqs().

For IRQs which handle exactly one timer interrupt, add new
dispatch_single_irq().  The mere fact that the IRQ has been called
suffices to prove that its interrupt enable bit (in TIMx_DIER) and
interrupt flag (in TIMx_SR) are set.  These facts are combined in
dispatch_single_irq(), which only needs to check if the timer_dev
handler is non-null before calling it and clearing the SR flag.

For IRQs which serve multiple timer interrupts, replace the
composition of calls to dispatch_irq() and dispatch_cc_irqs() with
individualized routines.  These eliminate unnecessary timer register
reads/writes, and, in the case of capture/compare interrupts, have a
loop unrolling performed.
2011-07-20 14:02:30 -04:00
Marti Bolivar f362c91d2f timer.c: Fix dispatch_irq() and dispatch_cc_irqs().
Modify them to check whether the relevant interrupts are enabled
before attempting to handle them.
2011-07-19 01:19:38 -04:00
Marti Bolivar f7a4e9c268 timer.c: Fix off-by-one error in NR_GEN_HANDLERS. 2011-07-18 23:59:32 -04:00
Marti Bolivar a6bd904db8 stm32.h: Add license header. 2011-07-18 14:24:59 -04:00
Marti Bolivar 3131e09e38 stm32.h: Trivial comment tweak. 2011-07-18 14:24:33 -04:00
Marti Bolivar 3061d3f600 Add DELAY_US_MULT, for use in generalizing delay_us().
The delay_us() implementation multiplies its specified delay target by
a fixed constant in order to turn it into a busy-loop.  This magic
number doesn't work properly when the clock configuration isn't the
same as a stock LeafLabs board.  Add DELAY_US_MULT to the MCU-specific
configuration in stm32.h in order to allow other chips to use delay_us().
2011-07-18 14:19:04 -04:00
Marti Bolivar 9dde5488a4 Move STM32 config from libmaple.h into stm32.h. 2011-07-18 14:07:17 -04:00
Andrew J Meyer 02d4ea34e5 fixed a bug in usbreceivebytes
bug prevented consecutive SerialUSB.read() calls from returning consecutive bytes
2011-07-01 16:28:40 -04:00
Marti Bolivar 72e45660ab systick.c: Updating systick_uptime_millis before handling user callback.
Thanks to x893 for the suggestion.
2011-06-24 14:45:24 -04:00
Marti Bolivar 8e8975a8f5 Merge branch 'freertos' 2011-06-24 14:38:35 -04:00
Marti Bolivar 55ec285642 Make FreeRTOS changes comply with the coding standard.
Don't modify the core FreeRTOS code; only change source that's
specific to libmaple.
2011-06-24 14:37:54 -04:00
Marti Bolivar 3844dc7467 systick.h: Comment typo 2011-06-21 22:10:11 -04:00
Nis Sarup 496875dc83 FreeRTOS: Added FreeRTOS 7.0.1, including hook in libmaple/systick.c and example blinky. 2011-06-21 17:02:06 +02:00
Marti Bolivar f99e0310fa DMA: Fix non-working DMA interrupts.
libmaple/dma.c defines DMA interrupts __irq_dma_channel[1-7],
consistent with what is specified by support/ld/names.inc.  However,
names.inc is inconsistent with what support/ld/libcs3_stm32_src/
expects.  Specifically, it contradicts the files

- support/ld/libcs3_stm32_src/stm32_isrs.S
- support/ld/libcs3_stm32_src/stm32_vector_table.S

Which use the names __irq_dma1_channel[1-7].

Change names.inc and dma.c to use the correct IRQ names.

The original names.inc/libcs3_stm32_src inconsistency was introduced
in 43d6921658, but dma.c had the correct
names until ec3cf2903f, where they were
renamed for consistency with names.inc.  At that point, DMA interrupts
stopped working.  (This was documented in the commit message).

Thanks to forum user robodude666 for tracking this down.
2011-06-20 15:22:03 -04:00
Marti Bolivar 48d00170f6 rcc.c: Trivial comment tweak. 2011-06-20 15:21:39 -04:00
Marti Bolivar 33f8dc88d8 gpio.h: Fix zero/oh comment mixup. 2011-06-14 15:40:42 -04:00
Marti Bolivar 76b9fd0a7b adc.h: Clarify adc_smp_rate Doxygen comment.
Thanks to gbulmer for the clarifying remarks.
2011-06-11 23:49:18 -04:00
Marti Bolivar cdb8e265bf stm32.h: Don't blindly assume PCLK1 and PCLK2 values.
Put the PCLK1 and PCLK2 within #ifndef guards.  This assumption is
biased towards LeafLabs boards.
2011-06-11 20:05:42 -04:00
Marti Bolivar 450e1c6e17 Keep it 80-column clean.
Go through overlong source code lines and convert as many of them as
appropriate to be 80-column clean.  This mostly affects license
headers.  Overlong lines are determined by running following from the
libmaple base directory:

$ ack-grep --nocolor --nogroup --cpp --cc --ignore-dir=usb -- '.{80}'

Note that this excludes libmaple's usb subdirectory, which is still
full of ST code that doesn't follow the libmaple source code
guidelines.

Contents of ~/.ackrc (these won't matter, but are included for
completeness):

--ignore-dir=docs
--ignore-dir=build
--type-set
ld=.ld
--type-set
rst=.rst
--type-set
txt=.txt
--type-set
mk=.mk
2011-06-07 14:44:39 -04:00
Marti Bolivar 21fd0c693e delay.h: Add missing include. 2011-06-06 17:36:43 -04:00
Marti Bolivar 3e35eb659c flash.h: Add missing include. 2011-06-06 17:36:35 -04:00
Marti Bolivar 3c59176c5e scb.h: Add missing include. 2011-06-06 17:36:26 -04:00
Marti Bolivar ce94285a37 bitband.h: Add missing include. 2011-06-06 17:36:14 -04:00
Marti Bolivar 99d549ee8e i2c.h: Add missing includes.
The missing includes are a bug in general, and prevent usage of i2c.h
from within Maple IDE in particular.
2011-06-06 16:01:01 -04:00
Marti Bolivar bb981bbaae usart.h: Allow the environment to determine USART_RX_BUF_SIZE.
Place the USART_RX_BUF_SIZE #define within an #ifndef to allow users
to pick their own buffer size.

See http://forums.leaflabs.com/topic.php?id=803
2011-05-27 16:11:37 -04:00
Marti Bolivar 484f468629 Tweak some register map base pointers.
Replace

 #define XXX_BASE                        ((xxx_reg_map*)0xDEADBEEF)

with

 #define XXX_BASE                        ((struct xxx_reg_map*)0xDEADBEEF)

for increased GDB-friendliness.
2011-05-26 02:42:06 -04:00
Marti Bolivar aa3487e1cc Moving Doxygen comments from declarations to definitions. 2011-05-23 10:18:39 -04:00
Marti Bolivar 92abff4dff adc.c: Giving adc_dev variables static linkage. 2011-05-23 02:37:04 -04:00
Marti Bolivar 0a12573698 adc: Moving ADC[123] Doxygen comments to definitions 2011-05-23 02:33:34 -04:00
Marti Bolivar de0acc12b2 spi.h: Doxygen 2011-05-20 15:23:18 -04:00
Marti Bolivar 7d647b367e dma: Doxygen 2011-05-20 15:21:40 -04:00
Marti Bolivar 07899c0db3 timer.h: Doxygen 2011-05-20 15:10:37 -04:00
Marti Bolivar 9004de98da usart.h: Doxygen. 2011-05-20 15:10:21 -04:00
Marti Bolivar 7e5f23aae8 i2c.h: Documentation fixes. 2011-05-20 15:05:07 -04:00
Marti Bolivar 9cf0e1006e usart: Moving Doxygen comments to points of definition
In keeping with convention.
2011-05-19 18:45:46 -04:00
Marti Bolivar 178ef4089d timer: Shortening long names.
Various names in timer.h were too unwieldy.  Making these slightly
more bearable.
2011-05-19 18:45:46 -04:00
Marti Bolivar 46dd8e69d9 timer: Moving some Doxygen comments.
From declaration to definition, to keep with convention.
2011-05-19 18:45:46 -04:00
Marti Bolivar 60e5eccf9e timer.h: Naming tweaks.
Renamed timer_reg_map_union -> timer_reg_map.

Named the anonymous timer_type.
2011-05-19 18:45:46 -04:00
Marti Bolivar 36ad4669e9 systick.h: Doxygen comments 2011-05-19 18:45:46 -04:00
Marti Bolivar 36f128a9b1 spi: Comment fixups
Moving SPIn Doxygen comments to point of definition in keeping with
libmaple conventions.
2011-05-19 18:45:45 -04:00
Marti Bolivar 1f8aa6d15d spi.h: Naming anonymous enums.
Named spi_mode, spi_baud_rate, spi_cfg_flag, spi_interrupt.
2011-05-19 18:45:45 -04:00
Marti Bolivar 7a2d8eaf2b scb.h: Comment/line length fixups 2011-05-19 18:45:45 -04:00
Marti Bolivar 4b21718331 ring_buffer.h: Comment fix. 2011-05-19 18:45:45 -04:00
Marti Bolivar 93d7c92027 rcc.h: Better names for the prescaler divider enums.
The various clock divider enums suitable for passing to
rcc_set_prescaler() were badly named.  They have been renamed as
follows:

    * adc_prescaler_divider -> rcc_adc_divider
    * apb1_prescaler_divider -> rcc_apb1_divider
    * apb2_prescaler_divider -> rcc_apb2_divider
    * ahb_prescaler_divider -> rcc_ahb_divider
2011-05-19 18:45:45 -04:00
Marti Bolivar 21b247b46a rcc.h: Naming anonymous rcc_clk_id enum 2011-05-19 18:45:45 -04:00
Marti Bolivar a48528bd0e pwr.h: Whitespace/comment cleanups 2011-05-19 18:45:45 -04:00
Marti Bolivar 2785b06b59 pwr: removing unused device. 2011-05-19 18:45:45 -04:00
Marti Bolivar 20c68e0eda i2c: Renaming, type changes, exposing i2c_init(), documentation.
Changes to struct i2c_dev members:

- uint8 clk_line's type is changing and is being renamed, is now
  rcc_clk_id clk_id
- uint8 ev_nvic_line's type is changing to nvic_irq_num
- uint8 er_nvic_line's type is changing to nvic_irq_num

Previous names were badly typed and inconsistent with the rest of
libmaple.

Exposing i2c_init(), also for consistency.

Adding/editing many Doxygen comments, for documentation and general
housekeeping.
2011-05-19 18:45:45 -04:00
Marti Bolivar 73441c8ea3 i2c.h: fixing type of i2c_dev state member.
It's an i2c_state; calling it one.  Previous uint8 type was broken
since I2C_STATE_ERROR is negative.
2011-05-19 18:45:45 -04:00
Marti Bolivar 4ae5effaa2 iwdg: Doxygen comments 2011-05-19 18:45:45 -04:00
Marti Bolivar ff3938adf6 iwdg: Naming anonymous enum.
Anonymous enum typedefed to iwdg_prescaler is now also enum
iwdg_prescaler, for consistency with the rest of the library.
2011-05-19 18:45:45 -04:00
Marti Bolivar a52f66cb82 gpio: Renaming for consistency.
Gave the anonymous enum typedefed to afio_exti_num the same name;
renamed AFIORemapPeripheral afio_remap_peripheral.
2011-05-19 18:45:45 -04:00
Marti Bolivar cd723c2f0e adc.c: adc_init() doesn't set the RCC's ADC prescaler.
You have to call rcc_set_prescaler() yourself now.  adc_init() never
should have been doing that anyway.
2011-05-19 18:45:45 -04:00
Marti Bolivar 6e96b5b6de delay.h: Adding Doxygen comments for the file and delay_us(). 2011-05-19 15:03:21 -04:00
Marti Bolivar 2e14155e8a bitband.h: Changing "__io" -> "volatile"
For SRAM functions, __io was in error.  Everything else just for
consistency.
2011-05-19 15:03:21 -04:00
Marti Bolivar dad4b59ce0 bkp.h: Adding missing register bit definitions 2011-05-19 15:03:21 -04:00
Marti Bolivar ab285d6f3b adc.h: Putting ADC3_BASE within an #ifdef STM32_HIGH_DENSITY 2011-05-17 16:49:20 -04:00
Marti Bolivar bc47abdbf6 Docs: Various improvements. 2011-05-13 20:10:38 -04:00
Perry Hung c9775ff15c libmaple: Fix warnings in libmaple source files
-Add -Wall, -Werror to libmaple/*
-Fix warnings
2011-05-12 05:00:47 -04:00
Perry Hung 914db021c3 i2c: Various fixes, extensions, documentation.
-Fix clock calculations for fast-mode support
-Add I2C_REMAP option to remap i2c1 (untested)
-Add I2C_BUS_RESET option to reset bus on initialization
-Add optional timeout parameter
-Doxygen comments
-Various cleanup

10-bit slave addressing is untested until I have a device that speaks
such.
2011-05-12 04:07:33 -04:00
Marti Bolivar ff5ae825d6 Converting all files to UNIX newlines.
Committing the results of running the following on the libmaple root
directory:

$ fromdos `grep --exclude-dir='[.]git' -Ilsr $'\r$' .`
2011-05-10 16:41:37 -04:00
Marti Bolivar a00029e132 Finally getting rid of __read() and __write().
This brings util.h down to some bit manipulation macros, failure
routines, and asserts.
2011-05-06 20:19:44 -04:00
Marti Bolivar 6a3f977d85 IWDG include fixup. 2011-05-06 20:17:41 -04:00
Marti Bolivar 5bd9cc6cfd Independent watchdog refactor. 2011-05-06 20:11:57 -04:00
Marti Bolivar 7d7476daaf Doxygen syntax bugfixes. 2011-05-05 04:34:56 -04:00
Marti Bolivar 6c427d285f SPI fixups.
Initial post-review changes based on thread here:

77f707d7b8 (comments)
2011-05-04 17:23:54 -04:00
Marti Bolivar 43b3ba82e6 systick_timer_millis is volatile, not IO-mapped. 2011-05-04 13:31:53 -04:00
Marti Bolivar e7d5f4c167 SerialUSB fixups. 2011-05-04 13:31:53 -04:00
Marti Bolivar c436ffa1bb Native and FSMC cleanups.
Got rid of native_sram.h (and native_sram.cpp), and pushed their
functionality into maple_native.cpp.  Fixed includes in maple_native.h.

Fixed includes in fsmc.h.
2011-05-04 13:29:55 -04:00
Marti Bolivar 7d0445ec14 Adding RCC_SPI3 for high density devices. 2011-04-29 12:02:51 -04:00
Marti Bolivar 77f707d7b8 SPI refactor.
Still a polling driver, but the libmaple proper interface exposes
enough that users enable the various interrupts and define their own
IRQ handlers if they feel like it.

Wirish HardwareSPI interface was largely redone; it's more like the
Arduino implementation now, although there are some differences when I
didn't like their API.  The old methods are still there, but are
deprecated and slated for deletion in 0.1.0.

New board-specific values: BOARD_NR_SPI, BOARD_SPIx_NSS_PIN,
BOARD_SPIx_MOSI_PIN, BOARD_SPIx_MISO_PIN, and BOARD_SPIx_SCK_PIN, for
x from 1 to BOARD_NR_SPI.

Documentation was updated appropriately.
2011-04-28 14:23:30 -04:00
Marti Bolivar ae6500319b Fixing usart_putstr() atrocity. 2011-04-25 22:29:48 -04:00
Marti Bolivar 4941335ab8 Adding rcc_dev_clk(), an accessor for a peripheral's clock line. 2011-04-25 22:08:30 -04:00
Marti Bolivar 2f07cb6f6c Better debug port support.
- gpio.h: afio_mapr_swj_config() renamed afio_cfg_debug_ports()

- [new] wirish_debug.h: disableDebugPorts(), enableDebugPorts()

- Maple, Maple Native, and Maple RET6 PIN_MAPs are now larger by 5,
  have mappings for the extra JTAG/SW pins.

  Documentation was updated appropriately.
2011-04-25 22:03:25 -04:00
Marti Bolivar 000e0e5a98 Adding nonblocking USART transmit, usart_tx().
Other USART transmission functions are still blocking, but are now
implemented in terms of usart_tx().
2011-04-25 18:00:34 -04:00
Marti Bolivar ead6460180 gpio.h whitespace cleanup. 2011-04-25 16:13:09 -04:00
Marti Bolivar 39d4f043f1 I2C fixup.
Added i2c_init() for consistency with rest of libmaple.
2011-04-25 16:12:57 -04:00
Marti Bolivar 61b92e1653 Requiring dac_dev* argument in DAC convenience functions. 2011-04-21 17:24:57 -04:00
Marti Bolivar 7ebf41352a usart.c comment fixes.
License header made 80-column clean.  usart_irq() comment for the
USART_SAFE_INSERT case made easier to understand.
2011-04-15 16:43:57 -04:00
Marti Bolivar ddfd7be79d Making usart.h license header 80-column clean. 2011-04-15 16:42:57 -04:00
Marti Bolivar a962d4f158 i2c cleanups.
Whitespace and column width changes only.
2011-04-14 14:00:47 -04:00
Marti Bolivar 3baf0250ad Reverting some "volatile" -> "__io" changes.
See c57d760676 (commitcomment-338822)
2011-04-12 15:50:18 -04:00
Marti Bolivar dc1b55a694 Making 1c05ac8497 comply with coding standard.
Whitespace corrections only.
2011-04-12 15:41:59 -04:00
Anton Eltchaninov 1c05ac8497 Adding i2c2 and i2c fast mode
Signed-off-by: Anton Eltchaninov <anton.eltchaninov@gmail.com>
2011-04-12 13:21:15 +07:00
Marti Bolivar c57d760676 Changing usages of "volatile" to "__io". 2011-04-12 00:44:05 -04:00
Marti Bolivar 9a95e7b72f Adding guards for negative nvic_irq_num enumerators.
nvic_irq_enable() and nvic_irq_disable() previously didn't protect
against negative arguments.
2011-04-12 00:43:12 -04:00
Marti Bolivar 83f14f36d0 Doxygen bugfixes.
Fixed various Doxygen comment errors.
2011-04-12 00:08:54 -04:00
Marti Bolivar ec3cf2903f DMA checkpoint; dma_attach_interrupt() is broken.
Simple USART receiver to SRAM buffer demo partially working.
Interrupting when buffer is full fails mysteriously.  GDB thinks
we ended up in an STM32 reserved exception.
2011-04-11 20:53:51 -04:00
Marti Bolivar e1a5d8edaf Resolving some FIXMEs. 2011-04-11 20:45:47 -04:00
Marti Bolivar 3403c0b54b Adding delay_us() TODO. 2011-04-11 20:31:39 -04:00
Marti Bolivar f604bb7b27 USART bugfix.
USART refactor commit f6f9a11227 only
worked for USART1.
2011-04-11 15:56:38 -04:00
Marti Bolivar c17e4bdd4a USART fixups.
* usart_enable(): Doxygen comment bugfix.

* usart_disable(): previously, usart_disable() would nuke the
  entire CR1 register just to clear the UE bit.
2011-04-08 18:57:14 -04:00
Marti Bolivar 0004ee5b37 Timer tweaks. 2011-04-07 16:28:14 -04:00
Marti Bolivar 4ba238a7bd Renaming some nvic_irq_num enumerators for better readability. 2011-04-07 15:04:06 -04:00
Marti Bolivar f6f9a11227 USART refactor. 2011-04-07 13:18:36 -04:00
Marti Bolivar f5b41b3457 SysTick refactor.
For the changelog:

* util.h is free of __read(), __write(), etc. macros.

* systick_resume() was renamed systick_enable().
2011-04-05 14:13:35 -04:00
Marti Bolivar 6661d006e6 NVIC and SCB refactor 2011-04-05 13:59:33 -04:00
Marti Bolivar bff2efbb43 ring_buffer.h function comments converted to Doxygen 2011-04-05 13:23:39 -04:00
Marti Bolivar 04ce8168ae ring_buffer tweaks.
Adding basic ring_buffer test (cherry-pick from master).

Changing rb_safe_insert()'s type to match that of rb_push_insert().
(Makes it easier to pass around insertion functions.)
2011-04-05 13:21:06 -04:00
Marti Bolivar 19736152f3 Nitpicks 2011-03-30 03:45:08 -04:00
Marti Bolivar c5e16e9625 Final stm32_pin_info design candidate; ADC3 support on Native.
Added an adc_dev to struct stm32_pin_info.  This was necessary to add
support for the channels on the Native which are only connected to
ADC3, but it does add a bunch of NULLs to the PIN_MAPs.

I don't think any other peripherals need representation on a per-pin
basis.  Each peripheral library will be responsible for keeping track
of related GPIO ports and bits, and we can throw #defines in to
boards/*.h for other things (e.g. BOARD_SPI1_MISO_PIN).

Fleshed out the ADC refactor and brought it more in keeping with the
new design as it evolves.

A couple of other tweaks.  Notably: waitForButtonPress() now takes a
default argument meaning "wait forever".

Removed Maple-specific documentation from core functions in io.h; this
information will need to go into the individual board docs files.
2011-03-25 20:09:30 -04:00
Marti Bolivar 9d2b4e574c Adding /wirish/boards/ for easier porting; shrank PIN_MAPs.
/wirish/boards/ contains xxx.h and xxx.cpp (for xxx=maple,
maple_native, maple_mini, maple_RET6).  The headers contain the
board-specific #defines that used to live in boards.h (except
BOARD_INIT, which was removed).  The CPP files contain the PIN_MAP
definitions that used to live in boards.cpp, and a proper boardInit()
function to replace the old BOARD_INIT macro.  This will make it
easier to add new boards in the future.

struct PinMapping was renamed struct stm32_pin_info, and was moved
into a new wirish_types.h.  Its external interrupt field was moved
into struct gpio_dev, which saves memory by storing an afio_exti_port
per port, rather than one per pin.  Also rearranged the stm32_pin_info
fields to improve packing.  Maple's PIN_MAP is now down to below 500
bytes.
2011-03-24 17:31:47 -04:00
Marti Bolivar a5901fc72e timer_set_dma_burst_length() and TIMER8 comment bugfixes 2011-03-24 08:01:13 -04:00
Marti Bolivar 296b1188bf Initial timer refactor.
Basic PWM works.  Had some problems in testing that might be due to
USART bugs.

HardwareTimer has been removed from the build for now; I will
re-implement it in terms of the new libmaple API, but consider it
deprecated.  Let's come up with something better.

Servo is implemented in terms of HardwareTimer, so it also has been
temporarily removed from the build.

pwmWrite() likely got a little bit less inefficient due to
indirection, but the PIN_MAPs shrank by a pointer per PinMapping.
2011-03-24 07:25:14 -04:00
Marti Bolivar 68b57d9000 Adding license to ring_buffer.h 2011-03-21 14:45:26 -04:00
Marti Bolivar c8c070905c RCC refactor.
Older refactor commit e4807a5010 used
bit-banding in rcc_clk_init() to set RCC_CR_HSEON, which doesn't work
for some reason.  Not going to try to figure out why.
2011-03-21 14:42:46 -04:00
Marti Bolivar 9f3a669ca6 More convenient bit-banding interface 2011-03-21 04:21:55 -04:00
Perry Hung 59f4a8a0df Merge branch 'i2c-wip' into refactor
Conflicts:
	examples/test-fsmc.cpp
	libmaple/rules.mk
	wirish/boards.h
2011-03-21 02:47:53 -04:00
Perry Hung 3568da8fc1 modify gpio interface to expose gpio dev structs 2011-03-21 02:32:39 -04:00
Perry Hung 323627d367 Fix compiler errors after reverting broken commit. 2011-03-21 02:27:45 -04:00
Perry Hung eae720021d Revert "RCC refactor, bugfixes"
This reverts commit e4807a5010.
2011-03-21 02:25:23 -04:00
Marti Bolivar 12aca5b72d Fixing inefficient rb_safe_remove() implementation; thanks, geoffreymbrown! 2011-03-17 09:10:28 -04:00