797 Commits

Author SHA1 Message Date
Vegard Storheil Eriksen
ef07b970f3 stm32: timer: Remove TIMER_IS_ADVANCED() checks
The ADVANCED_TIMERS define/check was added in 523943a as part of adding L1
support. The runtime checks against TIM1/TIM8 already existed. Since L1
doesn't have TIM1/TIM8, those names are undefined, resulting in a compilation
error until ifdeffed out.

Since I throw out all TIM1/TIM8 checks, there's no references to those names
left, thus no need to keep the ifdef either.

As for the registers themselves, l1/timer.h pulls in common/timer_common_all.h
which defines macros for the superset of all timers, so e.g. TIM_BDTR() is
still available regardless of whether or not the particular chip we're building
for has any timers with a BDTR register.
2017-10-18 20:39:51 +00:00
Karl Palsson
b2079f10af stm32:can: help gcc recognise deliberate fall through
Very new gcc versions add a warning on switch cases that fall through.
While there's an option that accepts any comment as explaining it, it's
easier in our case to just use one of the "blessed" comments.  We can't
use the [[]] attributes for standards code, and the gcc specific
attributes are worse than the comments.  This has no functional change
whatsoever.
2017-10-07 21:06:51 +00:00
Karl Palsson
af7b2190a9 timers: define ADVANCED_TIMERS in a "portable" manner
gcc7.2 complained about the old syntax.  So, be more verbose.

Fixes: https://github.com/libopencm3/libopencm3/issues/826
2017-10-06 15:43:31 +00:00
Adam Heinrich
08dc7dac1c stm32f1: rcc: Fix number of wait states in comment to match the code
Signed-off-by: Adam Heinrich <adam@adamh.cz>
2017-10-02 21:47:06 +00:00
Adam Heinrich
e9a8c5106e stm32f0: rcc: Enable prefetch buffer in rcc_clock_setup_*()
Prefetch buffer makes the code execution from the Flash memory faster.

Signed-off-by: Adam Heinrich <adam@adamh.cz>
2017-10-02 21:47:06 +00:00
Diego Herranz
1b64b1494b stm32f1: doc: Fix gpio cnf parameter
GPIO_CNF_INPUT (non existing) -> GPIO_CNF_INPUT_FLOAT
2017-09-26 09:42:47 +00:00
Amitesh Singh
e3c78b8825 stm32f1:rcc: fix typo in usb prescaler api document
usb scalar value 1.5 is used when clock runs at 72MHz not 64MHz

Reviewed-by: Karl Palsson <karlp@tweak.net.au>
2017-09-01 22:02:28 +00:00
Karl Palsson
b0e050d10d stm32: can: fix can_reset()
Clearly staging branch testers weren't testing.
Also, clearly the separation of RST_ bits and RCC_ bits is a complicated
annoyance.

Fixes: d9615a2eb728 update to modern include apis
2017-08-25 09:44:03 +00:00
Karl Palsson
e11e64330c stm32f0: can: add to build
Added the CAN1 compatibility aliases as has been done for adc and dac to
make code reuse easier.  Only for the magic enums, the raw bit
definitions remain as per the ref mans

Originally suggested as https://github.com/libopencm3/libopencm3/pull/802
2017-07-04 23:24:49 +00:00
Jonathan Halmen
83adad0aed stm32: can: change filter match index to uint8_t
The variable can only be 8bits, and converting pointers resulted in
cases of overwriting nearby variables.
2017-07-04 23:23:29 +00:00
Karl Palsson
5a517f7854 stm32:adcv1: correct documentation for AWD
remove misleading atttempt at describing that the thresholds are
compared before any alignment changes takes place.
2017-06-23 23:17:23 +00:00
Fabián Inostroza
98ff5c23aa stm32: can: Add support for getting the message timestamp.
Provide an optional parameter to receive the timestamp in
2017-06-08 23:01:45 +00:00
Karl Palsson
192c2eacb7 stm32: can: Correct mask/id order in filters
Checked against RM0090r11 and confirmed.

Reported-by: Warren Gay <ve3wwg@gmail.com>
2017-06-08 23:01:45 +00:00
Karl Palsson
bc898d1f92 stm32l0: rcc: Add clock struct setup helper
Based on l1, l4 and friends.
2017-06-08 23:01:45 +00:00
Karl Palsson
ec1d2855b0 stm32l1: rcc: use better naming for flash wait states
More compatible with developments in l0/l4/f7, and just a better choice
of names overall.
2017-06-08 23:01:45 +00:00
Karl Palsson
29c712326f stm32: rcc: extract osc_bypass functions
rcc_osc_bypass_enable and rcc_osc_bypass_disable have been copy/pasted
around for the last time!  There's a compile bit to check for L0/L1, but
otherwise this is just code duplication for no gain.
2017-06-08 23:01:45 +00:00
Karl Palsson
2547bf66d9 stm32l0: flash: use common functionality
Provides all the basic core functionality shared with L1.  No special L0
functionality supported at this point.
2017-06-08 23:01:45 +00:00
Karl Palsson
ce787c0f40 stm32l1: flash: extract common code
Extracted all code that will be common with l0.  Compared with ref mans
for l0 and l4.  No functional change, just moving things getting ready.
2017-06-08 23:01:45 +00:00
Karl Palsson
d9615a2eb7 stm32: can: update to modern includes and apis
No functional change.  But allows automatic functionality on platforms
that support CAN with only makefile changes now.
2017-06-08 23:01:45 +00:00
Matthew Lai
17553da946 stm32f7: pwr: added basic support for pwr (VOS and overdrive) 2017-06-08 23:01:45 +00:00
Karl Palsson
2c0e71b3c7 stm32f7: use DEBUG_FLAGS like other targets
Consistency with other targets wherever possible.
2017-06-08 23:01:45 +00:00
Karl Palsson
6678da39bd stm32: i2c: Support auto speed configuration
For both v1 and v2, support automatic calculation of timing registers
for 100khz and 400khz i2c modes.

Based on work by Chuck in
https://github.com/libopencm3/libopencm3/pull/470 for v1
2017-06-08 23:01:45 +00:00
Karl Palsson
b860319785 make: use std=c99 everywhere by default.
setting "STANDARD_FLAGS=-std=c11" or similar will let you try out
alternate compilation modes.

Fixes https://github.com/libopencm3/libopencm3/issues/773
2017-06-08 23:01:45 +00:00
Matthew Lai
383fafc862 stm32: renamed pwr_common_all to pwr_common_v1, and pwr_common_l01 to pwr_common_v2 2017-03-30 21:48:08 +00:00
Jordi Pakey-Rodriguez
90d8bd6753 stm32f234: flash: Add FLASH_ACR_LATENCY_MASK 2017-03-30 21:48:08 +00:00
Jordi Pakey-Rodriguez
6798cee2a5 stm32f2+: flash: Rename FLASH_ACR_XCE -> FLASH_ACR_XCEN
Match the datasheet register names better.

squish into xcev
2017-03-30 21:48:08 +00:00
Karl Palsson
b40c72828d stm32: i2c: provide "transfer" level helper routines
For both v1 and v2, provide routines to help do arbitrary length
write/read transfers.

Tested with multiple byte writes and reads, for both 100khz and 400khz,
with repeated starts and stop/starts.  However, only tested (presently)
with a single i2c target device, a Sensiron SHT21 sensor.  Extended
testing against eeproms and alternative devices would be useful
2017-03-30 21:48:08 +00:00
Karl Palsson
fb3b5e08f3 stm32: i2c-v2: drop overly restrictive helpers.
* didn't follow naming conventions
* overly restricted to single byte register style commands.

Will be replaced by freeform transfer functions
2017-03-30 21:48:08 +00:00
Karl Palsson
1edcc1b7da stm32: i2c-v2: drop overly specific speed helpers
Will be replaced by generic speed helpers.
2017-03-30 21:48:08 +00:00
Karl Palsson
24225816a1 stm32: i2c-v2: simplify boolean functions
No need to check results and return 1 or 0.  The result itself is
suitable for use directly as a boolean, and a boolean is the intended
outcome.
2017-03-30 21:48:08 +00:00
Karl Palsson
0259102560 stm32f0: drop superfluous intermediate speed helpers
If you're interested in slightly underclocking or midrange speeds,
you're into custom environments.  Drop all the "helpers" for these odd
speeds.  This is not the max speed for any existing f0 part.

Signed-off-by: Karl Palsson <karlp@tweak.net.au>
2017-03-30 21:48:07 +00:00
Sergey Matyukevich
7cacbbfb8d stm32/f0: enable clocking from HSE crystal
The following four new functions enable clocking SoC from HSE crystal:
	rcc_clock_setup_in_hse_8mhz_out_{8,16,32,48}mhz

These functions start HSE as external clock and feed its output to PLL
if higher frequency is needed.

Signed-off-by: Sergey Matyukevich <geomatsi@gmail.com>
Reviewed-by: Karl Palsson <karlp@tweak.net.au>
 -> Dropped 8,16,32Mhz functions as superfluous.
2017-03-30 21:48:07 +00:00
Sergey Matyukevich
ef668edef6 stm32/f0: minor cleanup of HSI clock functions
- add brief descriptions for HSI clock functions
- use rcc_set_pll_source to set PLL source in RCC_CFGR

Signed-off-by: Sergey Matyukevich <geomatsi@gmail.com>
2017-03-30 21:48:07 +00:00
Sergey Matyukevich
1b97ecefff stm32/f0: more clock helper functions
Add two clock helper defines and functions:
- rcc_set_pll_source: select PLL entry clock source
- rcc_set_pllxtpre: HSE divider for PLL input clock

Signed-off-by: Sergey Matyukevich <geomatsi@gmail.com>
2017-03-30 21:48:07 +00:00
Karl Palsson
885d5c6105 stm32: i2c-v2: drop obsolete bit 14 in OAR1
This bit is defined as "maintain at 1" only in v1 peripherals.
Drop this bad carryover from v1 code.
2017-03-30 21:48:07 +00:00
Sergey Matyukevich
59ef83a440 stm32: l0/l4: add i2c support
According to reference manuals both l0 and l4 have "v2" i2c peripheral.
This patch adds i2c support to l0 and l4 using previously unified "v2" i2c
headers and implementation.

No real hardware has been tested so far. Only compilation tests for both
libopencm3 and libopencm3-examples for all stm32 families.

Signed-off-by: Sergey Matyukevich <geomatsi@gmail.com>
2017-03-30 21:48:07 +00:00
Sergey Matyukevich
ef91856ac1 stm32: unify i2c implementations
The f1, f2, f4, l1 chip families have a similar "v1" i2c peripheral on board.
More recent f0, f3, l0, l3 chip families share another "v2" version  of i2c.

This patch unifies headers and implementation for two types of i2c peripherals:

- rename: i2c_common_all.[ch] to i2c_common_v1.[ch]
- remove i2c_common_f24.h: extra I2C blocks are defined in specific headers
- use f3 i2c code as a basis for common "v2" i2c implementation
- add f0 i2c support: use "v2" i2c implementation

Tests:
- tested on a custom f0 board
- compile-tested both libopencm3 and libopencm3-examples for all stm32

Signed-off-by: Sergey Matyukevich <geomatsi@gmail.com>
2017-03-30 21:48:07 +00:00
Sergey Matyukevich
43736cf03f stm32/f0: RTC clock helpers
Add three more RTC clock helper functions:

- rcc_set_rtc_clock_source
  RTC on stm32/f0 can be clocked from the following three
  sources: LSI, LSE (32.768Hz), HSE/32.

- rcc_enable_rtc_clock
- rcc_disable_rtc_clock
  enable/disable clocking RTC module using selected clock source

Signed-off-by: Sergey Matyukevich <geomatsi@gmail.com>
2017-03-30 21:48:07 +00:00
Karl Palsson
d2540e5fc6 stm32f7: rcc: replace magics with existing defines
The defines already existed, use them, rather than the copied constants
from F4 code.
2017-03-30 21:48:07 +00:00
Sync
c285bcb493 stm32f7: rcc: initial clock config for disco board
Add clock config for the 25MHz crystal found on the discovery board.
Verified to work on the STM32F7-Disco.

Reviewed-by: Karl Palsson <karlp@tweak.net.au>
Modified namespaces and types->structs to avoid namespace pollution as
was fixed for other families in:

3a7cbec7: stm32l/stm32f: name space standardization [BREAKING]
2017-03-30 21:48:07 +00:00
Sync
3fc0c9d001 stm32f7: rcc: intial stubs support
Reviewed-by: Karl Palsson <karlp@tweak.net.au>
(Added defines and used them)
2017-03-30 21:48:07 +00:00
Karl Palsson
7ee1d948e9 stm32f0:usart: Correctly allow >8bit words.
Make them 16bit regs, like on other periphs.  This allows proper access
to the "8th" bit.  (0..8 is 9 bits, not 8)

Found and reported in https://github.com/libopencm3/libopencm3/pull/651
2017-03-30 21:48:07 +00:00
Karl Palsson
6dd7b3ecc5 stm32f0:usart: drop redundant type info from doxygen
These are redundant, and provided by compilers and doxygen
interpretation anyway.  Frees up plenty of space on each line for useful
documentation.
2017-03-30 21:48:07 +00:00
Ken Sarkies
808cd44a41 STM32F1: RTC: rtc_awake_from_off() clears CR register incorrectly.
It sets bit 5 (manual says "read only") and clears bit 4 which takes the RTC
out of config mode. The RTC registers are not cleared as a result.
2017-03-30 21:48:07 +00:00
Jonathan Challinger
7f8b32efed stm32f3: include CAN 2017-03-30 21:48:07 +00:00
Karl Palsson
d964dcfca4 stm32:usart: drop usart_get_interrupt_source()
It was never complete, even for F1 family code, and went on to be even
less complete for f0 and f3.  The usefulness of a library function to
check for both the irq being enabled _and_ the status flag is highly
questionable, and caused known user confusion.

The existing, much simpler, and fully functional usart_get_flag() is
a good replacement in almost all sane use cases.

Fixes https://github.com/libopencm3/libopencm3/issues/734
2017-03-30 21:48:07 +00:00
Karl Palsson
f07b58c6d8 stm32:rng: add helper to actually get random numbers
Simplified blocking API, with an async routine if you really need it.
Follows as best as I can understand the reference manual, but testing
those conditions will be difficult.
2017-03-30 21:48:07 +00:00
Karl Palsson
05829037de stm32:rng: add common v1 to l0,l4,f7
This is a common peripheral based on reference manual inspection.
2017-03-30 21:48:07 +00:00
Karl Palsson
2476099f29 stm32:rng: f4 rng peripheral is common with at least f2
Pull it up as common code immediately. Rename to v1, extract to common
with a doxygen marker stubs, add to F2 makefiles.
2017-03-30 21:48:07 +00:00
Sulter
ac45247f60 stm32f4:rng: basic functions with documentation.
Reviewed-by: Karl Palsson <karlp@tweak.net.au>
Removed higher level helpers from this commit, they are not a very
friendly API to use.
2017-03-30 21:48:07 +00:00