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>
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>
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>
Missed one hard-coded structure size.

Signed-off-by: RJ Ryan <rryan@mit.edu>
Merge remote branch 'rryan/usb_fixes'
test-session: Add test case for disabling USB.

This replaces the previously undocumented 'd' option, which tested the
pin mode INPUT_PULLDOWN.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
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>
nvic: Add nvic_sys_reset().

This uses the SCB_AIRCR register to force a system reset.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
rcc: Add RCC_USB to rcc_clk_id/rcc_dev_table.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
build-targets.mk: Tweak for Windows compilation.

Make on Windows doesn't seem to like @echo without a string.
Give it an empty one to keep it happy.
test-fsmc.cpp: Switch to SerialUSB

This messes with timing a little, but makes it faster to test.  The
timing was never perfect anyway, due to incrementing count.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
test-fsmc.cpp: Fixup; wait for user input before running test.
Add Windows support to DFU installation tools.

Tweak Makefile further for cs-make on Windows.  Add Windows support
to support/scripts/reset.py

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
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>
Cosmetics.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
usart: Add usart_rx().

usart_rx() is a nonblocking USART receive.  Add it for symmetry with
usart_tx().
reset.py: Hackishly silence DeprecationWarning.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
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>
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>
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>