fixing macro parenthesization and RCC_APB1ENR (thanks, x893)
Correct bcdDFUVersion and wDetachTimeOut in DFU functional descriptor

The firmware matches pretty much the DFU 1.1 specification.

This is a follow up of 95e1150ddcbb6e0e4c4e2ff9f85a0e6d9d620407
which only changed the separately defined u8_usbFunctionalDescriptor
but not the one included in the configuration descriptor. And which
also got it wrong (0.1).

(Ideally the code should be cleaned up to only specify this in one place)

Also fix the detach timeout which was set to 64 seconds. I believe
the intended value was 255 ms like stated in the comment. Since the
Maple devices are not detached (transition between run-time mode and
DFU mode, issued over the DFU interface), this is not used anyway.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Acked-by: Marti Bolivar <mbolivar@leaflabs.com>
Bump the bcdDevice to 2.01 now that the DFU descriptor is fixed

To let DFU programmers such as dfu-util know that they can trust
the DFU functional descriptor on this device.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Acked-by: Marti Bolivar <mbolivar@leaflabs.com>
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Add a CREDITS file.

It's about time we had one of these, and I don't want to imply that
the previous two commits for DFU compliance were mine. So credit their
author, Tormod Volden, in the single entry.

We can add more people as we go.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Use Unix newlines.

Comitting the results of:

$ find . -name '*.c' -o -name '*.s' -o -name '*.h' -o -name '*.ld' | xargs fromdos

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Remove trailing whitespace from source files.

Command used:

$ ack --files-with-matches '[ \t]+$' | xargs sed -i -E 's/[ \t]+$//'

`ack' is also known as `ack-grep' on some systems and in some package
managers (e.g. Ubuntu's).

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Reduce poll timeout after page flash from 511 ms to 32 ms

32 ms is the value used in ST's DFU IAP example for STM32.

For DFU-compliant programming tools like dfu-util this change
should speed up flashing more than ten times.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Run astyle on top-level sources.

The sources have ugly whitespace. Run astyle on them, ignoring those
in usb_lib/. Astyle version 2.01 (2.01-1 on Ubuntu 12.04) options were:

--indent=spaces=4
--style=java
--indent-namespaces
--pad-oper
--pad-header
--unpad-paren
--align-pointer=name
--indent-preprocessor
--lineend=linux

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Update README.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Fix endian mix-up in usb_core

USB uses little endian, as does ARM, so there should not be any byte
swapping. Bytes were swapped back and forth inconsistently and would
break word access of u16_u8 union types. It seems like this has gone
unnoticed for long because the word values are mostly used for comparing
against zero.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Add DFU_UPLOAD support

The DFU_UPLOAD support allows copying the contents of the flash or RAM
memory of the Maple to the computer.

Note that we use the wValue (BlockNum in the DFU standard) to calculate
the target address. We therefore rely on the host program (for instance
dfu-util) to set (increase) wValue for each block.

This use of wValue is not mandated by the DFU standard, which only says
wValue should be incremented by the host "to provide useful context" to
the device, but this implementation allows random access of memory
locations.

On the other hand the DFU_DNLOAD code does not make use of BlockNum but
simply increases its memory pointer for each block received. Maybe this
was done because reading out wValue was broken due to endian mix-up?

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
dfu.c: whitespace.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Merge branch 'dfu-upload'
Fixing DFU bugs that makes it compiable with -Os
Typo
Fixes
Fixing Makefile
Merge pull request #9 from Gregwar/dfu-fix

Fixing dfu.c to allow compiling with -Os
Merge branch 'master' into mini-boot

Conflicts:
	dfu.c
	hardware.c
	hardware.h
	main.c
	usb.c