Commit Graph

984 Commits

Author SHA1 Message Date
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 f3df01f14e vf6: use c99 compatible asm syntax.
using __asm__ instead of asm allows compilation under both gnu89 (old
gcc defaults pre 5.x) and also c99 (gcc 5.x+ defaults)
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
Jochen Hoenicke 8b99b56c59 stmfx07: usb: Clean up FIFO read/write macro usage.
Use REBASE(OTG_FIFO(endpoint)) to access the FIFO.
For the receive FIFO do not use the endpoint. There
is only one receive FIFO so giving the endpoint is
a no-op.
Get rid of REBASE_FIFO macro.
2017-03-30 21:48:07 +00:00
Jochen Hoenicke 0c1ff686ad stmfx07: usb: Enable ctrl_out only after done rcvd.
This fixes the problem where the first four bytes were skipped in
the fifo.
2017-03-30 21:48:07 +00:00
Jochen Hoenicke 94f92d54d6 stmfx07: usb: keep better track of rxbcnt
When reading a portion of the packet that is not divisible by 4 and
not equal to rxbcnt the count could get off, since 4 bytes are read
from the fifo in the last step but rxbcnt was only updated by the
number of bytes the caller requested.

We fix this by always subtracting four bytes (the number of bytes
read from the fifo) when we read a word from the fifo.  Care has
to be taken in the last step so that rxbcnt doesn't underflow (it
is an unsigned number).

Note that reading in several small chunks not divisible by 4 doesn't
work as the extra bytes read in the last step are always discarded.
2017-03-30 21:48:07 +00:00
Jochen Hoenicke a4f1568b7d stmfx07: usb: flush txfifo if not empty after SETUP
After a SETUP packet on a control endpoint the transmit FIFO
should usually be empty.  If something bad happened, e.g. PC
and device got out of sync, we want to clear the fifo.
This should fix #668.
2017-03-30 21:48:07 +00:00
Jochen Hoenicke 973efabddb stmfx07: usb: poll DIEPINT before RXFLVL
This is to interrupt for setup sequences on IN packet before
checking for OUT packet received.  This fixes the problem that
usb_control_out stalls because we are not yet in STATUS_OUT phase.
Related to #668.
2017-03-30 21:48:07 +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
Karl Palsson c9c5cb7c9c style: fix some of the easier style bugs
No real changes.
2017-03-30 21:48:07 +00:00
Seven Watt 8a62618a63 stm32l0: add exti to makefile
Tested with a Lora radio application that used three GPIO lines to send
different interrupts from the radio module to the L052. Tested with a
Jeenode Zero Rev1
2017-02-17 09:43:01 +00:00
Dave Hylands 755ce402e2 stm32:desig: Add DFU compatible serial generation
Reviewed-by: Karl Palsson <karlp@tweak.net.au>
Modified to provide better doxygen and consistent api names.
2017-01-10 23:07:00 +00:00
David Sidrane cf80e2bd5e stm32f4: USB support for newer OTG cores
Support for the  conflicting bit definitions for vbus sensing on core id
version 0x2000+

Reviewed-by: Karl Palsson <karlp@tweak.net.au>
2017-01-10 22:32:20 +00:00
Karl Palsson cd9ae5e6d7 eeprom: drop support from linker scripts.
While the NOLOAD variant sometimes worked with some toolchains, the
version in the generator scripts could never work, as neither the
startup code, nor gdb know how to load those sections properly.

Originally added in: eb18cc19cb

The original scripts allowed you to place variables in eeprom space for
reading only.  However, the last toolchain that generated working code
with this linker script was the gcc-arm-none-eabi-4_9-2014q4 release.
Subsequent releases treat the directives differently, and can lose track
of where variables are.  One known symptom is constants getting bad
addresses, so for instance, "printf("asdfad")" will end up passing the
wrong address of the string constant into the eventual _write() call.

This commit removes the problematic directives until a more fully
correct system can be found that more properly follows the linker
script rules.
2016-12-19 11:40:39 +00:00
Karl Palsson 950e064885 stm32l1: flash: avoid duplicate calls to unlock_pecr
Attempts to helpfully unlock PECR when required in unlock_progmem and
unlock_option_bytes actually cause a bus error due to repeated unlocks,
as per ref manual and tedious experience.  The better tested eeprom helper
routines unlock/lock in chunks, but that's not applicable for flash
writing.

Fixes: cf5fb002f6
2016-12-19 11:36:20 +00:00
Karl Palsson 825b51a6a8 usb: dwc_otg: fix missing includes
Went awol merging something :(
(Yes, dwc_otg is theoretically shared with efm and co, but at present
it's still pretty much the stm32 version)

Fixes: 422d708384
2016-11-21 17:27:43 +00:00