Commit Graph

1130 Commits

Author SHA1 Message Date
Ross Schlaikjer 4db40e0839 stm32f7: Include i2c_common_v2
With the addition of a define for I2C4, the existing common i2c
functions seem to work out of the box on the F7 (tested on an
STM32F750).
2019-04-04 22:11:20 +00:00
Icenowy Zheng 330d5fd5be gd32: add new chip series f1x0
GD32F1X0 (X can be 3, 5, 7 and 9) is a series of Cortex-M3 MCUs by
GigaDevice, which features pin-to-pin package compatibility with
STM32F030 MCU line. F150 adds USB support to F130, and F170/F190 adds
CAN support.

Currently the code mainly targets GD32F130 and F150 chips. Some register
are different between F130/150 and F170/190, just like the difference
between STM32F1 Performance line and Connectivity line.

From the perspective of registers and memory map, GD32F1X0 seems like a
mixture between STM32F1 and STM32F0 (because it is designed to be
pin-to-pin compatible with F0, but with Cortex-M3 like F1). A bunch of
code are shared between STM32 and GD32, and these code are specially
processed to include the GD32 headers instead of STM32 headers when meet
GD32F1X0.

Signed-off-by: Icenowy Zheng <icenowy@aosc.io>

Reviewed-by: Karl Palsson <karlp@tweak.net.au>
gd32/rcc.[ch] are forks of stm32f1/rcc
gd32/flash.[ch] are forks of stm32f0/flash
No attempts at deduplicating this have been done at this stage.  We can
see where they move in the future.
2019-04-03 12:53:33 +00:00
Mike Szczys 0fd4f74ee3 stm32f1: adc: fixed deprecated/broken example code 2019-02-09 16:47:52 -06:00
Guillaume Revaillot c4c0d14ea4 stm32: exti: stm32g0 have enhanced EXTI_[FR]PR regs instead of EXTIR_PR, use them if defined.
Make exti_get_flag_status and exti_reset_request use EXTI_RPR and EXTI_FPR if present instead of EXTI_PR.

This is less precise than offered by the RPR/FPR registers, but makes
for a consistent experience in the common API.

Reviewed-by: Karl Palsson <karlp@tweak.net.au>
2019-01-31 09:57:46 +00:00
Guillaume Revaillot b98dd8eee0 stm32: exti: exti_select_source: rework and use EXTI_EXTICR.
EXTICR on stm32g0 is in exti registers range. Previous chips used to have that
gpio port exti mux configuration accessible via AFIO_EXTICR or SYSCFG_EXTICR.

Also, the new chip now use 8 bits coded value instead of previously 4 for the
extcr mux selection value (see AFIO/SYSCFG/EXTI_EXTICR_FIELDSIZE)

Let's define two helpers:  EXTICR_SELECTION_REG (to get proper AFIO/SYSCFG/
EXTI_EXTICR register) and EXTICR_SELECTION_FIELDSIZE (to get proper AFIO/SYSCFG/
EXTI_EXTICR_FIELDSIZE value), and use it them exti_select_source to determine
exticr mux selection bits shift and mask.
2019-01-31 09:57:46 +00:00
Guillaume Revaillot 7afd86db30 stm32l[01]: flash common: add flash_unlock_acr, allowing to unlock FLASH_ACR RUN_PD bit.
flash_unlock_acr allows to unlock RUN_PD bit from FLASH_ACR register. Relock is done automatically
when writing 0 to RUN_PD, so no flash_lock_acr method.
2019-01-31 09:35:55 +00:00
Guillaume Revaillot 74f460feac stm32f0: adc: fix doc. 2019-01-25 15:25:11 +01:00
Karl Palsson 72e449f529 stm32f3: rcc: fix typo in PLL clocks for APB1
Reported by jabjoe on irc, fixed by zyp
2019-01-10 14:42:54 +00:00
Patrick Yeon 7e1d3daa11 stm32f0: adc: API call to clear EOS flag 2018-12-06 18:40:30 -08:00
Alfred Klomp 1adc418f9a stm32f42/f43: rcc: add 180 MHz clock options 2018-11-12 21:41:05 +00:00
Alfred Klomp f0e5c73d98 stm32: pll: disable before configuring 2018-11-12 16:49:56 +01:00
Karl Palsson 1883a4311f msp432: whitespace fixups spaces->tabs
whitespace only change.
2018-10-23 21:33:16 +00:00
Dmitry Rezvanov a63d0499de msp432/e4: Add GPIO support 2018-10-23 21:21:54 +00:00
Karl Palsson 2619a4506c stm32f7: use spi v2 peripheral.
F7 indeed has v2 peripheral, not the v1.  Distinguishing figure is the
8/16bit fifo.
2018-10-23 21:21:42 +00:00
mfm f6517f7816 stm32: adc common v2: add circular dma mode
Tested only on the F3 so far.
2018-10-20 11:46:47 +00:00
Karl Palsson bc7e454741 stm32f7: include common dma code
Originally reported at https://github.com/libopencm3/libopencm3/pull/978
2018-10-20 11:40:38 +00:00
Filip Moc 4b16af6e24 stm32: iwdg: correct calculation for all ranges.
The original calculations miscalculated ranges such as
512..639 or 1024..1151 or ... or 32768..32895

Reviewed-by: Karl Palsson <karlp@tweak.net.au>
2018-10-05 23:31:52 +00:00
Jacob Rodgers e2b67d7264 Set PLL source in rcc_clock_setup_pll() for STM32L0 2018-09-29 07:55:16 -07:00
Karl Palsson cccc1267c5 stm32f7: drop toolchain check for m7 support.
the 2014q3 or later toolchains are now readily available, and we should
now just consider this a user problem.  This gets us out of trying to
parse compiler help output and chasing our own tail.

Fixes https://github.com/libopencm3/libopencm3/issues/965
2018-09-10 21:44:16 +00:00
Karl Palsson 9ddafa6284 stm32f7: enable common timers support 2018-09-09 16:38:56 +00:00
Karl Palsson de538c4b80 stm32f7: desig: link common implementation 2018-08-29 09:56:43 +00:00
Clara Casas 889b7de0d7 stm32: adc: Add functions to get and clear flags
This includes adding documentation to the status flags.

Originally tracked at: https://github.com/libopencm3/libopencm3/pull/833

Modified to drop whitespace changes, and simply boolean return.
2018-08-28 22:00:07 +00:00
Daniel Gröber 743513a4b1 stm32: add dma_get_number_of_data
Original discussion at: https://github.com/libopencm3/libopencm3/pull/702
2018-08-28 22:00:01 +00:00
Karl Palsson 08c76f25ec stm32: spi: drop empty spi.c files.
They were originally used to make sure that the doxygen was generated
correctly, but that style is no longer necessary.

There may be more peripherals that can be "cleaned" like this, but let's
do them one step at a time, as we work on that area.
2018-08-27 22:57:41 +00:00
Florian R. Hölzlwimmer f3c620b51b stm32f7: spi: include common code 2018-08-27 22:57:28 +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
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
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
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 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 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 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 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
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 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 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 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