Commit Graph

2250 Commits

Author SHA1 Message Date
Karl Palsson 00e32ccb4c gitignore new generated code 2018-08-27 21:48:16 +00:00
Karl Palsson b7ec3f0b11 tests: usb gadget0: ti: use dummy delay handlers
Not full test coverage, obviously, but at least let it compile until the
delay methods have been implemented.
2018-08-27 15:51:17 +00:00
Karl Palsson 4b3dda2968 tests: usb-gadget0: gitignore generated linker scripts 2018-08-27 15:11:32 +00:00
Karl Palsson 8cf3a20bff tests: usb gadget0: add ti lm4f120xl board
This has failing tests, and doesn't implement (yet) the delay routines,
so it won't even compile without disabling that functionality in the
core gadget0 code.  However, it passes most tests, and it demonstrates
that the changes made to the setup handling earlier haven't broken USB
on this platform.
2018-08-27 15:11:32 +00:00
Karl Palsson 22754f0919 usb: provide lm4fusb driver reference
We provided references for all the others, provide it for the lm4f
driver too.
2018-08-27 15:11:32 +00:00
Karl Palsson 26ab78a710 usb: fix race between setup complete and endpoint nak
See https://github.com/libopencm3/libopencm3/issues/873

Commentary describing this patch originally by zyp:

```
After looking further into it, I've concluded that my preliminary
analysis looks correct. The problem is that setting CNAK before
the SETUP complete event is received causes a race condition. The
SETUP callback is called when the SETUP packet event is received,
which means that setting CNAK from the callback is too early.

Originally the problem was that CNAK was set by ep_read() which is
called by the callback. #672 solved this by moving CNAK out of
ep_read() and calling it after the SETUP complete event is received
instead.

The regression by #785 is caused by the introduction of flow control
calls into the SETUP callback. They also set CNAK.

To solve this properly, I propose changing the event handling code
to only call the SETUP callback after the SETUP complete event is
received. Unfortunately, this implies that the callback can't call
ep_read() itself anymore, because the packet has to be read out of
the FIFO before the SETUP complete event arrives. This implies a
change of the API between the hardware drivers and _usbd_control_setup().
```

L1 (st_usbfs) works and passes tests as before change
F4 (dwc_otg_fs) works and now passes tests. (yay)
LM4f still compiles, and has had the same style of implementation as
st_usbfs, however has not been tested on any hardware.
2018-08-27 15:11:32 +00:00
Karl Palsson 42e43515c6 usb gadget0: ctrl write/read loopback tests
This is based on linux's gadget0 intel loopback tests, and also github
pr: https://github.com/libopencm3/libopencm3/pull/592

Note that this captures the currently broken control loopback issues on
dwc_otg devices.

See https://github.com/libopencm3/libopencm3/issues/873 and all linked
issues.

Current status is passing on f3, f0, and failing on f4.
2018-08-27 15:11:32 +00:00
David Lamparter ebcf197810 usb: make usb_disconnect() weak
usb_disconnect() is board/platform specific for chips that don't have
built-in handling for this.  Allow the application to provide its own
version of usb_disconnect() to handle this.

See https://github.com/libopencm3/libopencm3/pull/924
2018-08-27 15:11:32 +00:00
David Lamparter 343cff4675 usb: make strings "const char * const *"
This allows the pointer table to be in Flash, by using
"static const char * const strings[] = { ... };"

See https://github.com/libopencm3/libopencm3/pull/924
2018-08-27 13:34:52 +00:00
Karl Palsson fa7a908027 doc: msp432/e4: Fix groupings for doxygen
Proper closing tags, an outer grouping, and don't refer to missing
groups.
2018-08-27 13:34:40 +00:00
Karl Palsson 056602b12a doc: msp432/e4: hook up doxygen generation
Just hooks up the target, no changes to the submitted documentation.
2018-08-27 13:34:34 +00:00
Dmitry Rezvanov 2adefd95fe msp432/e4: new target
Basic memory map and system control.

Originally tracked via: https://github.com/libopencm3/libopencm3/pull/946
2018-08-27 13:34:29 +00:00
Karl Palsson 0c91dbf57e cm3: scs: drop (superseded) helper macros for systick
These are superseded by cm3/systick.h and the functions there.

Reported originally under: https://github.com/libopencm3/libopencm3/issues/125
2018-08-21 21:20:57 +00:00
Karl Palsson cfe514913f cm3: scs: drop (superseded) dwt macros
They are all superseded by dwt.h, and the function dwt_enable_cycle_counter

Fixes https://github.com/libopencm3/libopencm3/issues/125

(But only for the cycle count enabling)
2018-08-21 21:20:51 +00:00
Karl Palsson 6fa75afbc6 usb: add USB_REQ_TYPE_OUT to match USB_REQ_TYPE_IN
#defines are free.

Fixes https://github.com/libopencm3/libopencm3/issues/515
2018-08-20 23:53:07 +00:00
Jordi Pakey-Rodriguez 21b23f1ff1 stm32f4: adc: Add VBat sensor enable/disable
Original discussion at: https://github.com/libopencm3/libopencm3/pull/770
2018-08-19 23:26:04 +00:00
Karl Palsson 0787675332 st32l1: adc: there is no adc_chan_vbat on L1x. 2018-08-19 23:26:04 +00:00
Karl Palsson e5b8a164a6 usb: st_usbfs_v2: support disconnect functionality
Originally suggested via https://github.com/libopencm3/libopencm3/pull/628
2018-08-19 23:26:04 +00:00
fenugrec 01f33f47b7 USB: st_usbfs : fix USB_COUNTn_RX buffer size calculation:
Fixes https://github.com/libopencm3/libopencm3/issues/476

Sets USB_COUNTn_RX reg fields : bits <14:10> are NUM_BLOCK; bit 15 is BL_SIZE.
 - When (size <= 62), BL_SIZE must be 0 and NUM_BLOCK set to (size / 2).
 - When (size > 62), BL_SIZE must be 1 and NUM_BLOCK=((size / 32) - 1).

Previous code improperly set NUM_BLOCK and assumed the requested size was set.
Now, we use the next largest legal buffer size. Examples:
size BL_SIZE NUM_BLOCK => Actual bufsize
0    0       0         ??? (illegal !)
1    0       1         2
63   1       1         64
Algo is valid for F102, F103 and F0 devices (USB_FS peripheral).
In addition, the new usb_set_ep_rx_bufsize() function returns the actual
size set.

Tested-by: Karl Palsson <karlp@tweak.net.au>
2018-08-17 00:16:18 +00:00
Karl Palsson 144911a25b stm32: usb gadget0: implement loopback
The loopback functionality was never implemented, not for regular bulk
endpoints.  By adding it, and adding pairs of endpoints, we can easily
catch buffer management problems.  These tests currently fail on
st_usbfs devices.

This did require renumbering the endpoints, as dwc_otg_fs only offers
three endpoints in each direction, and they can't be arbitrary numbers,
unlike on st_usbfs.

See https://github.com/libopencm3/libopencm3/pull/880 and related tickets.
2018-08-17 00:16:13 +00:00
Karl Palsson 0e58ee2f65 stm32: support i2c3 properly
I2C3 is on many parts, but wasn't properly supported with the register
definitions.  Declare them centrally, just depending on the memorymap
defining them. On some parts, the rcc bits were defined, but not the
base registers.

Fixes: https://github.com/libopencm3/libopencm3/issues/820
2018-08-17 00:15:01 +00:00
Karl Palsson b8ede60d9d stm32f3: flash: support basic write/erase operations
Originally filed as https://github.com/libopencm3/libopencm3/pull/627
2018-08-17 00:15:01 +00:00
Karl Palsson 3293913be2 stm32f3: flash: add clear write protect flag
Could actually move to flash_common_f, but they have different names for
the same bit at present.
2018-08-17 00:15:01 +00:00
Karl Palsson d465291f45 tests: use the new auto depends on library
Provided in ea5d3cb7 genlink: provide LIBDEPS for libopencm3 itself
2018-08-17 00:15:01 +00:00
Christian Tacke d14033c744 genlink: provide LIBDEPS for libopencm3 itself
If $(OPENCM3_DIR)/lib/libopencm3_*.a exists, it will be linked in.
If we do that, we should also add it to the deps.
That way a newer *.a will result in a relink.

To use this, you should add a dependency to $(LIBDEPS) where you are
using $(LDFLAGS) and $(LDLIBS) now.

eg, old (wouldn't relink if the library changed)

$(PROJECT).elf: $(OBJS) $(LDSCRIPT)
        @printf "  LD\t$@\n"
        $(Q)$(LD) $(TGT_LDFLAGS) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@

new (will relink when the library changes)

$(PROJECT).elf: $(OBJS) $(LDSCRIPT) $(LIBDEPS)
        @printf "  LD\t$@\n"
        $(Q)$(LD) $(TGT_LDFLAGS) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@

Tested-by:  Karl Palsson <karlp@tweak.net.au>

Originally tracked via: https://github.com/libopencm3/libopencm3/pull/887
2018-08-17 00:15:01 +00:00
Karl Palsson f4bbe7c5bb usb: prevent registering duplicate config callbacks
Originally discussed at https://github.com/libopencm3/libopencm3/pull/722
2018-08-17 00:15:01 +00:00
Christian Tacke c55ec70f49 STM32: USART: Fix baudrate calculation for LPUART1
LPUART1 needs BRR to be 256 times the normal value.

Doing this with 64 bit math would work, but that pulls in quite a lot of
code for every platform, even if they don't have LPUART.

A little bit of maths, thanks to zyp on irc, lets us keep it in 32bit,
provided people don't try and use > 16MBaud on LPUARTs

Originally tracked via https://github.com/libopencm3/libopencm3/pull/888
2018-08-17 00:15:01 +00:00
Karl Palsson 49a8c041ff stm32f3: comparator: fix doxygen and use standard mask/shifts
Convert to standard style of unshifted field values.
2018-08-17 00:15:01 +00:00
Markus Kasten 0d0f59d8ce stm32f3: add comparator register definitions 2018-08-17 00:15:01 +00:00
Karl Palsson 05ce5de4c2 stm32f2/4: link in the specific flash.o files.
We extracted code out to the common files, but they weren't being
linked.  This didn't matter in the past, as they were empty.

Fixes: 46d4103c stm32: flash: move wait_for_last to f2/f4 explicitly.

Fixes: https://github.com/libopencm3/libopencm3/issues/953
2018-08-14 11:19:58 +00:00
Chris Sp 8b1ac585df stm32f4: rcc: typo fix MCO2
Just a small typo I came across while trying to get MCO to work on my board.
The define is not used in any other files as far as I can tell, but of
course applications might break if they use the misspelt variant.
2018-08-07 15:12:58 +00:00
Karl Palsson ddc7ab8c6c stm32l4: flash: don't use misleading names
flash_clear_pgperr_flag is a name used on f247, which is actually most
analogous to the SIZERR bit on l4, (it's a parallelism error)

the bit being cleared originally in this function, PROGERR is a new bit,
and should have it's own name.

Add a function to handle the previously unhandled size/parallelism flag,
and rename the existing one to properly reflect it's new name.
2018-07-29 20:31:17 +00:00
Karl Palsson 659d52b952 stm32f7: flash: drop unimplemented function declaration
flash_art_disable was never implemented, and isn't really a super useful
function anyway, so just drop the decl, rather than implementing it.
2018-07-29 20:31:17 +00:00
Karl Palsson 231f21296f stm32: f247: flash: use common code.
This shows what is _actually_ different for f7.  A couple of option
bits, and a renaming of bit 7 of the status register, from Program
Sequence Error to Erase Sequence Error.

We keep the separate implementation of wait_for_last_operation, to meet
the "suggestions" of the reference manual to insert a DSB instruction.

Keeping the renamed bit/functions also requires us to keep separate
implementations of the flag clearing functions
2018-07-29 20:31:17 +00:00
Karl Palsson 46d4103c1d stm32: flash: move wait_for_last to f2/f4 explicitly.
We're preparing to use all the common code for f2, f4, f7 and large
chunks of l4.  Extract things that we know need to be done differently
there.
2018-07-29 20:31:17 +00:00
Karl Palsson 76d392ee47 stm32: flash: drop common_f234
Move the last few register defines back to their relevant headers, add
doxygen and groups.  While these registers _were_ "common" they were the
_only_ common things, so it's simpler for future work (merging f7 with
f2/4) to move them back separately.
2018-07-29 20:31:17 +00:00
Karl Palsson eafc46ff24 stm32: flash: extract wait_for_last_operation to top level
This then eliminates the misguided attempts at merging f2/4 and f3 flash
support.  Some headers remain.
2018-07-29 20:31:17 +00:00
Karl Palsson c272ea410e stm32: flash: move clear all status flags to single common header
We've got a "f" flash file for common apis now, use it.
2018-07-29 20:31:17 +00:00
Karl Palsson a949b223c3 stm32f3: flash: pgerr is not the same as pgperr
F3's flash interface is actually quite different, don't try and force
sharing code that isn't really related.  The "PGERR" is a very different
bit than the parallelism error that f2/4/7 have.
2018-07-29 20:31:17 +00:00
Karl Palsson b9448bff16 stm32l4: flash: fix page erase for second bank
l4 is pages, not sectors, so update apis to be consistent. (other
families use page/sector as defined in the reference manual)
Make sure that pages on the second bank can also be erased.  Use the
same style in use for f2/4/7 for sector numbers across banks.
2018-07-29 20:31:17 +00:00
Karl Palsson 850931dbcd stm32: flash_unlock_option_bytes is common code.
The keys differ between some familes, but the documentation and
implementation are standard.
2018-07-29 20:31:17 +00:00
Karl Palsson c5a3350a7d stm32l: flash: rename option unlock keys or consistency
Paves the way for using common code.
2018-07-29 20:31:17 +00:00
Karl Palsson 4517ec81fd stm32: flash: remove superfluous locking of option bytes
Comments were not consistent, and this serves no purpose.  There's no
reason to explicitly lock the flash first before unlocking.  These bits
are simply set when the keys are written.
2018-07-29 20:31:17 +00:00
Karl Palsson 7a27795d8c stm32: flash: pull out i/d cache support.
Copied a few times.
2018-07-29 20:31:17 +00:00
Karl Palsson 2bf7eb4a0c stm32: flash: pull set_ws up to common code
All that changes is the size of the field.
2018-07-29 20:31:17 +00:00
Karl Palsson 4840b6bc7e stm32: flash: pull up clear_eop
All the "f" type flash parts have an EOP flag, even if it's in different
bit positions.  Add a header for this common functionality, and move
it's implementation to the existing common file.
2018-07-29 20:31:17 +00:00
Karl Palsson da7ebafcbe stm32: flash: pull lock/unlock up to common_f.
This is a common operation, so definition in _all, and every part except
l0/l1 have the same implementation.  Bring in an _f file too.
2018-07-29 20:31:17 +00:00
Karl Palsson b23dccc7ae stm32: flash: pull up prefetch to _all
Turns out, there's lots of common code for flash.  Pull up prefetch
on/off to start with, as there's only a single bit name different.

Pull up the definitions of common API functions too, starting with
flash_set_ws.  Even if the implementations are different, things that
meant to be the same, should be defined centrally.
2018-07-29 20:31:17 +00:00
Karl Palsson 9dd901ba27 stm32: flash: BSY bit has never been writable.
This has been copied around for years, but has never been a writable bit
on any target.
2018-07-29 20:31:17 +00:00
Karl Palsson 30d88452e6 stm32f4: flash: support discontinuous sectors on banked flash
The sector list is numerically contiguous, but the bits to write are not
contiguous.  Good job ST.

Fixes: https://github.com/libopencm3/libopencm3/pull/934

Don't see any reason to make public definitions of these sorts of magic
numbers, they're completely internal to sector addressing.
2018-07-29 20:31:17 +00:00