Commit graph

43 commits

Author SHA1 Message Date
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 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 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 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 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 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 f20568393e Don't try to build some libmaple files.
We can't do these on F2 right now.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-05-31 17:24:17 -04:00
Marti Bolivar bad7e605b5 Fix wrong comment in libmaple/rules.mk.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-05-03 21:50:02 -04:00
Marti Bolivar d10b5a3efa stm32f1: Resurrect DMA support. (sets up breaking change)
Breaking change set up: struct dma_handler_config is no longer part of
the public API in <libmaple/dma.h>. User code which was touching
these was always mistaken; it should be using dma_attach_interrupt()
or dma_detach_interrupt() instead.

Other than that, just move the nonportable bits in <libmaple/dma.h>
and libmaple/dma.c to the appropriate places under
libmaple/stm32f1/. (Ouch. This is almost everything.) Patch the
(new) STM32F1 <series/dma.h> here and there to make everything
compile; this is mostly limited to forward-declaring struct dma_dev
and providing a hack _dma_dev_regs() declaration so inline functions
in the series header can still access a device's registers.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-05-03 14:09:05 -04:00
Marti Bolivar fb13a241b8 libmaple/spi: Fixups, move nonportable bits into libmaple/stm32f1.
Standard family support refactoring: add STM32F1 series spi.h, spi.c,
and move anything that won't port to STM32F2 there.

As part of a general effort to be cleaner, remove the dependency on
libmaple/util.h from libmaple/spi.h by not using BIT(). Also forward
declare struct gpio_dev for spi_gpio_cfg() to remove that include.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
2012-04-11 16:56:57 -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 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 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 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 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 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 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 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 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 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 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 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 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 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
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
Marti Bolivar 6661d006e6 NVIC and SCB refactor 2011-04-05 13:59:33 -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
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
Marti Bolivar 580f0b6965 Maple RET6 edition support 2011-03-16 17:56:54 -04:00
Perry Hung 443953ac94 checkpoint 2011-02-26 22:30:22 -05:00
Marti Bolivar d1a8d832af nzmichaelh's pull request mods compile and upload.
renamed SysTick_Handler back to SysTickHandler since all of our linker magic/lanchon-stm32 depends on that name.  added backup register support in order to test independent watchdog support; it seems to work.  next major test target is DMA support.
2010-12-28 19:06:27 -05:00
Perry Hung 2e79aafb70 Enable USB auto-reset in a hard fault.
Redirect thread-mode execution to a fail routine which throbs the LED to
indicate a hard fault. Because the fail routine runs in thread mode
with interrupts on, USB auto-reset should now work. Test by executing
some bogus instruction (e.g. *(volatile int*)0xf34fdaa = 0;) and check
that the auto-reset continues to work.
2010-09-17 03:49:14 -04:00
bnewbold 7b391d7f76 basic working dac implementation 2010-08-07 20:29:37 -04:00
bnewbold 0f55cc0d89 partial progress on FSMC for SRAM 2010-08-05 21:47:22 -04:00
Perry Hung 2c043efb66 make: Modularize makefiles, add dependency tracking, build-type tracking
Major build system rewrite. New and exciting:

1. Proper dependency tracking. All source files including header files
should be properly tracked and recompiled as necessary when they are
changed.

2. Build-type tracking. If the target changes from 'ram' to 'flash,'
for example, the build system will force a rebuild rather than
incorrectly link modules to a different address.

3. New targets:
   The old 'ram,' 'flash,' and 'jtag' targets have been replaced with
the environment variable MAPLE_TARGET, which controls the link address.
Users can either export it to their environment, or pass MAPLE_TARGET on
the command-line. Once this is set, sketches can be compiled with 'make
sketch,' or simply 'make.'

Note: the default is MAPLE_TARGET='flash.'

The target 'install' now automagically uploads the sketch to the board
using the appropriate method.

The 'run' target has been renamed to 'debug.' It starts an openocd gdb
server.

4. Odds and ends:
  -Verbose and 'quiet' modes. Set V=1 for verbose compilation, the default
   is quiet.
  -Object file sizes and disassembly information is generated and placed
   in build/$(BOARD).sizes and build/$(BOARD).disas, respectively.
  -Parallel make with -j should speed things up if you have multiple
   cores.
2010-06-25 21:23:04 -04:00