717 Commits

Author SHA1 Message Date
Oliver Meier
16cfc6d848 stm32f7: enable fsmc
This uses the existing f4 code as a new shared common base code.
2019-05-19 21:30:48 +00:00
Oliver Meier
4fc7196463 stm32f7: enable existing exti headers 2019-05-19 21:30:38 +00:00
Karl Palsson
e77bc94b8c stm32: adc-v1m: doc cleanups
Try and fix some of the specifics from old f4 source material.
2019-05-10 23:15:42 +00:00
Karl Palsson
13d46e81df stm32l1: adc: use v1-m shared code.
Drops all the l1 copies of this code, and automatically gains all the
following apis that weren't even available before:

void adc_set_clk_prescale(uint32_t prescaler);
void adc_set_resolution(uint32_t adc, uint32_t resolution);
void adc_enable_overrun_interrupt(uint32_t adc);
void adc_disable_overrun_interrupt(uint32_t adc);
bool adc_get_overrun_flag(uint32_t adc);
void adc_clear_overrun_flag(uint32_t adc);
bool adc_awd(uint32_t adc);
void adc_eoc_after_each(uint32_t adc);
void adc_eoc_after_group(uint32_t adc);
void adc_set_dma_continue(uint32_t adc);
void adc_set_dma_terminate(uint32_t adc);
2019-05-10 22:44:30 +00:00
Karl Palsson
8d9b455ac6 stm32: adc-v1m: pull out f4/f7 specifics
Sampling time and sequence length, along with the vbat channel are
specific to the f4/f7, and can't be shared with the l1 and friends.
Pull them out to their own common file.
2019-05-10 22:42:03 +00:00
Karl Palsson
f1340df003 stm32f4: sort makefile objects 2019-05-09 12:00:40 +00:00
Matthew Lai
0a3e1cc0e6 Renamed adc_common_v3 to adc_common_v1_multi 2019-05-09 11:54:19 +00:00
Matthew Lai
6703abf5e3 Added F7 ADC support (almost the same as F4) 2019-05-09 11:54:19 +00:00
vector
5dbdb255d8 STM32F7: dac: include in build.
Based on F4.
2019-05-09 11:34:16 +00:00
Marek Koza
e50ce6a876 stm32l4: Correct memorymap and add the existing CAN library 2019-04-30 20:47:14 +02:00
M J Oldfield
fc8a6aa7a2 stm32: adc-v2: set _only_ the ADC calibration bit
In adc_calibrate_async() we should only set the ADCAL bit and leave the rest alone.

While in the past there were only "rs" bits in this register, this is no
longer the case.

Reviewed-by: Karl Palsson <karlp@tweak.net.au>
2019-04-28 00:11:56 +00:00
Karl Palsson
f5d2d8f109 stm32f7: sort makefile object list alphabetically 2019-04-15 13:12:31 +00:00
Ross Schlaikjer
4fb67d891f stm32f7: enable existing ethernet libraries 2019-04-15 13:11:05 +00:00
Ross Schlaikjer
1290e3129d stm32f7: enable existing CAN library 2019-04-15 13:10:59 +00:00
Ross Schlaikjer
a92a44a7c2 stm32f7: enable existing CRC support 2019-04-15 13:10:37 +00:00
Ross Schlaikjer
0173ecec9c stm32f7: enable existing IWDG support 2019-04-15 13:10:21 +00:00
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
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
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
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
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