Commit Graph

490 Commits

Author SHA1 Message Date
pennae
54d31c98fe rp: remove AdcChannel::channel
we're not using it, and actually using it is more trouble than it's
worth. remove the false assurance instead.
2023-08-01 18:31:28 +02:00
pennae
48eac0b146 rp: add AdcChannel trait
this is more general than AdcPin and can also cover the temperature
sensor.
2023-08-01 18:31:28 +02:00
Dario Nieuwenhuis
ef3b1f46a9
Merge pull request #1728 from pennae/rp-gpio-banks
rp: fix qspi gpio interrupts, make qspi gpio optional
2023-08-01 08:18:39 +00:00
pennae
f3ad0c6ade rp: fix qspi gpio interrupts
so far only bank0 interrupts were processed and configured, even if a
qspi pin was given. this is obviously not the right thing to do, so
let's rectify that. the fact that no problems have shown up so far does
suggest that most, if not all, applications don't use this functionality
at all.
2023-07-31 20:02:06 +02:00
Dario Nieuwenhuis
4da9743317
Merge pull request #1690 from Sizurka/rp-flash-ptr-fix
rp: Fix ROM cache ptr() returning the trampoline
2023-07-31 17:26:59 +00:00
pennae
dca1777a2f rp: make QSPI gpio support optional
this will be mostly not useful to anyone since flash is attached to
qspi, and using flash chips that don't use the *entire* qspi interface
will severly slow down the chip. the code overhead is minimal right now,
but if we also fix interrupt support on qspi pins this will
change (adding more code to potentially hot paths, using more memory for
wakers that are never used, and preventing the qspi gpio irq from being
used in software interrupts as RTIC applications may want to do).
2023-07-31 19:13:10 +02:00
pennae
2c6fcdbd3f rp: add gpio::Pin::io() for access to io banks 2023-07-31 18:36:37 +02:00
pennae
e6d4043279 rp: rename gpio::Pin::io to gpio::Pin::gpio
we'll need access to the pin io bank registers for an upcoming fix, and
having both `io` and `io_bank` or similar can get confusing quickly.
rename `io` to `gpio` to avoid this, and also match the type while there.
2023-07-31 18:28:31 +02:00
Derek Hageman
7ed9e29326 rp: add async flash
Implement an async flash mode using the XIP background best effort
read interface.  Only reads are actually async, write and erase remain
blocking.
2023-07-28 16:50:54 -06:00
pennae
cbc8871a0b rp: relocate programs implicitly during load
this removed the RelocatedProgram construction step from pio uses.
there's not all that much to be said for the extra step because the
origin can be set on the input program itself, and the remaining
information exposed by RelocatedProgram can be exposed from
LoadedProgram instead (even though it's already available on the pio_asm
programs, albeit perhaps less convenient). we do lose access to the
relocated instruction iterator, but we also cannot think of anything
this iterator would actually be useful for outside of program loading.
2023-07-28 19:33:02 +02:00
Dario Nieuwenhuis
036e6ae30c
Rename embassy-hal-common to embassy-hal-internal, document it's for internal use only. (#1700) 2023-07-28 13:23:22 +02:00
Dario Nieuwenhuis
0ced8400d0
Merge pull request #1674 from pennae/rp-stack-guards
Rp stack guards
2023-07-28 10:43:54 +00:00
Derek Hageman
a5f2152077 rp: Fix ROM cache ptr() returning the trampoline
Make sure that the ptr() function for ROM functions always returns
the actual ROM pointer.  This allows the use of flash I/O while the
function cache is enabled.
2023-07-26 06:50:43 -06:00
pennae
e9445ec72d rp: allow for MPU-based stack guards on core 0 as well
using these will require some linker script intervention. setting the
core0 stack needs linker intervention anyway (to provide _stack_start),
having it also provide _stack_end for the guard to use is not that much
of a stretch.
2023-07-21 18:51:35 +02:00
pennae
4d6b3c57b1 rp: fix multicore stack guard setup
the region field of the register is four bits wide followed by the valid
bit that causes the rnr update we rely on for the rasr write. 0x08 is
just a bit short to reach the valid bit, and since rp2040 has only 8
regions it (at best) doesn't do anything at all.
2023-07-20 16:08:59 +02:00
pennae
a3d4ae85b0 rp: disable adc hardware on Adc drop
the adc constantly pulls a small but significant amount of current while
the hardware is enabled. this can have quite an effect on sleeping
devices that also use the adc.
2023-07-20 15:48:59 +02:00
Alex Ferro
e4ad1aa542 Embassy-rp I2C: Fix 1664
Change embassy-rp i2c.rs impl of embedded_hal_async::i2c::I2c::transaction
to only do the call to setup() for address once per call to transactions.
Calling setup multiple times results in I2C transactions being skipped
on the bus, even across calls to transaction() or devices.
2023-07-16 19:59:35 -06:00
Ben Simms
460cdc9e0f
Check intrstatus before signalling suspended 2023-07-13 19:29:09 +01:00
Henrik Berg
ff2daaff67 RP: Watchdog scratch set/get with index: usize. 2023-07-12 16:41:35 +02:00
Henrik Berg
6d402fe393 RP: Don't reset RTC in Clock::init. Updated example. 2023-07-12 15:16:56 +02:00
Henrik Berg
466a391b52 RP: Add save/restore to Rtc. Example use. 2023-07-12 14:22:48 +02:00
Henrik Berg
a93714327e RP: Rename Rtc to match STM32 impl. Remove setting RTC in new(). 2023-07-12 14:22:48 +02:00
Henrik Berg
029b156563 RP: Add scratchN registers to watchdog. Add Clone and Debug to DateTime 2023-07-12 14:22:48 +02:00
Dario Nieuwenhuis
91c1d17f16 rp/gpio: fix is_set_high/is_set_low, expand tests. 2023-07-11 12:40:07 +02:00
Dario Nieuwenhuis
b0da6318f3
Merge pull request #1623 from pennae/rp-adc
rp/adc: rewrite the module
2023-07-07 15:52:48 +00:00
pennae
972cdd4265 rp/adc: rewrite the module
- don't require an irq binding for blocking-only adc
- abstract adc pins into an AnyPin like interface, erasing the actual
  peripheral type at runtime.
- add pull-up/pull-down functions for adc pins
- add a test (mostly a copy of the example, to be honest)
- configure adc pads according to datasheet
- report conversion errors (although they seem exceedingly rare?)
- drop embedded-hal interfaces. embedded-hal channels can do neither
  AnyPin nor pullup/pulldown without encoding both into the type
2023-07-07 17:46:35 +02:00
pennae
4b63829110 rp/pio: use bind_interrupts for irqs
closes #1338
2023-07-07 16:27:10 +02:00
Dario Nieuwenhuis
d137286981 Release embassy-time v0.1.2 2023-07-06 01:29:44 +02:00
Dario Nieuwenhuis
a101d9078d update embedded-hal crates. 2023-07-04 19:59:36 +02:00
Dario Nieuwenhuis
ce889900d6 Update rp-pac. 2023-06-29 02:09:51 +02:00
Dario Nieuwenhuis
a2d1e7f02c rp/usb: add TODO: implement VBUS detection. 2023-06-27 04:29:01 +02:00
Dietrich Beck
23c51a1874 disable pull-up and down resistors for rp adc blocking_read 2023-06-22 23:02:16 +02:00
Dario Nieuwenhuis
837ebe405f rp: update rp-pac. 2023-06-16 01:41:07 +02:00
Dario Nieuwenhuis
98c821ac39 Remove embassy-cortex-m crate, move stuff to embassy-hal-common. 2023-06-09 16:44:20 +02:00
Dario Nieuwenhuis
dc8e34420f Remove executor dep+reexports from HALs.
Closes #1547
2023-06-09 16:29:45 +02:00
Dario Nieuwenhuis
8c93805ab5 Add rt feature to HALs, cfg out interrupt handling when not set. 2023-06-08 18:57:03 +02:00
Dario Nieuwenhuis
5c2f02c735 Reexport NVIC_PRIO_BITS at HAL root.
This allows using RTIC with `#[rtic::app(device = embassy_nrf, ...)]`
2023-06-08 18:07:49 +02:00
Dario Nieuwenhuis
921780e6bf Make interrupt module more standard.
- Move typelevel interrupts to a special-purpose mod: `embassy_xx::interrupt::typelevel`.
- Reexport the PAC interrupt enum in `embassy_xx::interrupt`.

This has a few advantages:
- The `embassy_xx::interrupt` module is now more "standard".
  - It works with `cortex-m` functions for manipulating interrupts, for example.
  - It works with RTIC.
- the interrupt enum allows holding value that can be "any interrupt at runtime", this can't be done with typelevel irqs.
- When "const-generics on enums" is stable, we can remove the typelevel interrupts without disruptive changes to `embassy_xx::interrupt`.
2023-06-08 18:00:48 +02:00
Dario Nieuwenhuis
4f03dff577 rp: add run-from-ram feature. 2023-06-06 00:06:32 +02:00
Dario Nieuwenhuis
162d485304 rp/flash: centralize USE_BOOT2 in a single const. 2023-06-05 23:41:26 +02:00
Dario Nieuwenhuis
70e1b976d8 rp/flash: fix missing clobbers, do not clobber frame pointer (r7). 2023-06-05 23:40:34 +02:00
Dario Nieuwenhuis
adf053a935 rp/flash: unify FLASH_BASE const. 2023-06-05 22:55:15 +02:00
Dario Nieuwenhuis
5ee26a5dd1 rp/dma: fix use-after-free read. 2023-06-05 22:28:14 +02:00
ExplodingWaffle
a4b8fc420a Replace Into<bool> for Level with From<Level> for bool 2023-06-05 01:37:56 +01:00
Dario Nieuwenhuis
dd5ce985bd rp/spi: enable rxdmae/txdmae only once at init.
see https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_spi/spi.c#L27-L28
2023-06-02 04:05:25 +02:00
Dario Nieuwenhuis
fa7510968a rp/spi: start rx dma first. 2023-06-02 03:44:49 +02:00
Dario Nieuwenhuis
404aa29289 cortex-m: remove owned interrupts. 2023-06-01 03:25:19 +02:00
Dario Nieuwenhuis
1d8321b821 Use make_static! from static-cell v1.1 2023-06-01 01:42:34 +02:00
Dario Nieuwenhuis
1a31b03976 ci: fix nrf, rp tests. 2023-05-29 22:01:19 +02:00
Alpha3__0
dc28a42fd2 Fix return definition 2023-05-25 11:55:05 -07:00
Alpha3__0
0d80a95e54 Implement eh 0.2.* serial::Write for Uart/UartTx 2023-05-25 11:33:29 -07:00
Dario Nieuwenhuis
9f7392474b Update Rust nightly. 2023-05-19 17:12:39 +02:00
bors[bot]
4b303949bf
Merge #1465
1465: rp: continue clock rework r=Dirbaio a=pennae

vastly reduce the code size of initial clock config (over 700 bytes saved!), at the cost of about 48 bytes of ram used to store the frequencies of all clocks in the system. also stop exporting unstable pac items for clock config, fix a few settings that were out of spec, and add missing features (most notably gpin source information).

Co-authored-by: pennae <github@quasiparticle.net>
2023-05-17 22:20:44 +00:00
pennae
fc746a88b5 rp/clocks: comment out all gpin handling for now
gpin clock sources aren't going to be very useful during cold boot and
thus require runtime clock reconfig. once we get there we can use this
for reference. or maybe we can't, only time will tell.
2023-05-17 23:25:49 +02:00
pennae
1e029a9e66 rp/clocks: remove superfluous clock actions
the rtc doesn't have to be disabled since it's always clocked from ref,
and the watchdog doesn't need to be configured twice.
2023-05-17 21:36:19 +02:00
pennae
053d5629ba rp/clocks: require GpinPin for gpin config
we'll take static ownership of an entire pin (not just a limited
reference), otherwise we cannot at all guarantee that the pin will not
be reused for something else while still in use. in theory we could
limit the liftime of this use, but that would require attaching
lifetimes to ClockConfig (and subsequently the main config), passing
those through init(), and returning an object that undoes the gpin
configuration on drop. that's a lot unnecessary support code while we
don't have runtime clock reconfig.
2023-05-17 21:36:19 +02:00
pennae
1b3d9a0aef rp/clocks: compactify pll setup
we don't need to preserve existing bits of the pll pwr register, so
let's only write and save a few instructions.
2023-05-17 21:36:19 +02:00
pennae
f79d8cb2d3 rp/clocks: store clock frequencies in ram
don't recalculate clock frequencies every time they are asked for. while
this is not very often in practice it does consume a bunch of flash
space that cannot be optimized away, and was pulled in unconditionally
previously. while we technically only need the configured rosc, xosc and
gpin frequencies it is easier to store all frequencies (and much cheaper
at runtime too).
2023-05-17 21:36:19 +02:00
pennae
0d4ab559a7 rp/clocks: fix comments and rosc defaults
if rosc really does run at 140MHz in high at div=1 then these values
were not correct and would've exceeded the chip spec. the HIL test
device seems to run fast (150MHz) so they're still not quite correct,
but rosc has high variance anyway so it's probably fine.
2023-05-17 21:36:19 +02:00
pennae
1379eb4e70 rp/clocks: handle fractional gpout dividers 2023-05-17 21:36:19 +02:00
pennae
f97b591831 rp/clocks: don't expose unstable pac items
exposing pac items kind of undermines the unstable-pac feature. directly
exposing register structure is also pretty inconvenient since the clock
switching code takes care of the src/aux difference in behavior, so a
user needn't really be forced to write down decomposed register values.
2023-05-17 21:36:19 +02:00
pennae
d97a771479 rp/clocks: remove unsupported xosc config input
the datasheet says that the xosc may be run by feeding a square wave
into the XIN pin of the chip, but requires that the oscillator be set to
pass through XIN in that case. it does not mention how, the xosc
peripheral does not seem to have any config bits that could be set to
this effect, and pico-sdk seems to have no (or at least no special)
handling for this configuration at all. it can thus be assumed to either
be not supported even by the reference sdk or to not need different
handling.
2023-05-17 19:29:26 +02:00
pennae
5bbed31513 rp/clocks: provide fbdiv, not vco_freq
solvers usually output fbdiv directly, using vco_freq to get back to
fbdiv is not all that necessary or useful. both vco_freq and fbdiv have
hidden constraints, but vco_freq is a lot less accurate because the
fbdiv value resulting from the division may be off by almost a full
ref_freq's worth of frequency.

also fixes the usb pll config, which ran the pll vco way out of (below)
spec.
2023-05-17 19:28:51 +02:00
pennae
d3494a4bdf rp/clocks: reset all plls at once
we might not configure both, so we should put the others into reset
state. leaving them fully as is might leave them running, which might
not be the goal for runtime reconfig (when it comes around). this now
mirrors how we reset all clock-using peripherals and only unreset those
that are properly clocked.
2023-05-17 18:35:58 +02:00
pennae
2f2860b096 rp/clocks: always reconfigure pll
this is only really useful for runtime *re*configuration, which we don't
currently support. even runtime reconfig probably won't need it, unless
we keep taking the sledgehammer approach of reconfiguring everything all
the time.
2023-05-17 14:45:42 +02:00
pennae
e1e87fef25 rp/clocks: always inline configure_pll
this is always advantageous, except *maybe* in O0. nothing really works
as expected in O0, so we may as well always inline for constant propagation.
2023-05-17 14:45:35 +02:00
kalkyl
a4772c15c0 rp: Add system reset fn via watchdog 2023-05-17 00:16:36 +02:00
kalkyl
ab63f3832f rp: Read flash unique id and jedec id 2023-05-16 11:21:17 +02:00
Dario Nieuwenhuis
56c3a949af rp/multicore: ensure stack is 8-byte aligned. 2023-05-16 01:42:35 +02:00
Dario Nieuwenhuis
0c18a13cc0 rp/multicore: fix undefined behavior in multicore spawn.
It is UB to pass `entry` to core1 as `&mut`, because core0 keeps
an aliasing pointer to that memory region, and actually writes to
it (when `spawn_core1` returns, the stack frame gets deallocated and the memory
gets reused). This violates noalias requirements.

Added the fence just in case, een though it works without.
2023-05-16 01:21:28 +02:00
pennae
14a5d03af2 rp: remove take!, add bind_interrupts! 2023-05-15 15:24:56 +02:00
Dario Nieuwenhuis
2fcdfc4876 rp: don't use SetConfig trait in PWM and PIO.
It was intended to allow changing baudrate on shared spi/i2c. There's no
advantage in using it for PWM or PIO, and makes it less usable because you have to
have `embassy-embedded-hal` as a dep to use it.
2023-05-13 02:13:26 +02:00
Dario Nieuwenhuis
3edd81a94e rp/watchdog: fix overflow if period is longer than 4294 seconds. 2023-05-13 00:33:00 +02:00
Caleb Jamison
9d971e5b15
Merge branch 'master' into master 2023-05-09 17:55:27 -04:00
Caleb Jamison
5cfe1a1fb4 Dirbaio comments round 2 2023-05-09 17:45:24 -04:00
bors[bot]
856b944eaf
Merge #1439
1439: rp: use rp2040-boot2 to provide the boot2 blob r=Dirbaio a=pennae

we're currently shipping an old boot2 that runs the flash at half speed. use the more recent version instead, and allow user to choose between the different supported boot2 versions for different flash chips if they need that.

Co-authored-by: pennae <github@quasiparticle.net>
2023-05-09 16:39:13 +00:00
pennae
0e3cd87a32 rp: use rp2040-boot2 to provide the boot2 blob
we're currently shipping an old boot2 that runs the flash at half speed.
use the more recent version instead, and allow user to choose between
the different supported boot2 versions for different flash chips if they
need that.
2023-05-09 18:36:17 +02:00
Caleb Jamison
6bea078487 Remove patches, bump rp-pac version 2023-05-09 12:20:23 -04:00
Caleb Jamison
5015c845c5 Improve gpout example, clk_gpout_freq 2023-05-09 12:10:24 -04:00
Caleb Jamison
c1eaad41f3 Gpout cleanup, basic Gpin support
Requires rp-pac #3
2023-05-09 11:46:25 -04:00
Caleb Jamison
14eecf2fc4 Address Dirbaio comments
Gpout still incomplete.
2023-05-08 19:13:50 -04:00
Dirk Stolle
0584312ef0 Fix some typos 2023-05-08 23:25:01 +02:00
bors[bot]
d0703f83db
Merge #1435
1435: Added example for multi priority executors rp2040 r=Dirbaio a=fakusb

I added an example for multiple priorities of tasks on rp2040 by adjusting [examples/nrf52840/src/bin/multiprio.rs](https://github.com/embassy-rs/embassy/blob/master/examples/nrf52840/src/bin/multiprio.rs) .

This needs https://github.com/embassy-rs/rp-pac/pull/2 , and this commit also adds the 6 new interrupt handlers for software interrupts to embassy-rs.

We might need to change the git path for rp-pac in [embassy-rp/Cargo.toml](https://github.com/embassy-rs/embassy/compare/master...fakusb:rp2040-multiprio-executor?expand=1#diff-47463ea358745927ecdb686f52feab816fde5d402a9628a136c116f34a802ab0)

Closes #1413

Co-authored-by: Fabian Kunze <fkunze@fkunze.de>
2023-05-08 16:59:07 +00:00
Fabian Kunze
2910b09cba bumped rp-pac version 2023-05-08 17:55:53 +02:00
Caleb Jamison
59132514cf Add missing functions, Cleanup, Gpout example 2023-05-08 09:45:54 -04:00
Caleb Jamison
1a96eae22c rp clock configuration 2023-05-08 09:45:54 -04:00
Fabian Kunze
fb2d5b484a changed relative cargo.toml dependency to github revision 2023-05-07 01:24:59 +02:00
Fabian Kunze
87795cbca8 added example multi priority executors rp2040 2023-05-07 01:00:13 +02:00
pennae
db9b8eb88f rp/pio: make sure gpio() asserts are compiled out
we'll have to touch pio one way or other if the number of gpio pins ever
increases. may as well make sure an assert never fires until that happens.
2023-05-06 21:14:00 +02:00
pennae
b38d496d51 rp/pio: allow wrap-around program loading
execution wraps around after the end of instruction memory and wrapping
works with this, so we may as well allow program loading across this
boundary. could be useful for reusing chunks of instruction memory.
2023-05-06 21:08:20 +02:00
pennae
374c7513f9 rp/pio: mark exec_instr as unsafe
because it most definitely is.
2023-05-06 17:24:06 +02:00
pennae
bdcea84ca1 rp/pio: add sm batch operations
sometimes state machines need to be started, restarted, or synchronized
at exactly the same time. the current interface does not allow this but
the hardware does, so let's expose that.
2023-05-06 17:23:41 +02:00
pennae
8e4d65e163 rp/pio: configure state machines with Config struct
the many individual sets aren't very efficient, and almost no checks
were done to ensure that the configuration written to the hardware was
actually valid. this adresses both of these.
2023-05-06 17:23:41 +02:00
pennae
2873cb93ee rp/pio: mark pio_instr_util unsafe
none of these are safe. the x/y functions mangle the fifos, the set
functions require the state machine to be stopped to be in any way safe,
the out functions do both of those things at once. only the jump
instruction is marginally safe, but running this on an active program is
bound to cause problems.
2023-05-06 11:52:25 +02:00
pennae
37b460637d rp/pio: add set-pin-{values,dirs} convenience functions
these are needed a lot during state machine setup, it makes sense to
provide convenience functions for them.
2023-05-06 11:52:25 +02:00
pennae
41ec4170a5 rp/pio: add load_program, use_program
programs contain information we could pull from them directly and use to
validate other configuration of the state machine instead of asking the
user to pull them out and hand them to us bit by bit. unfortunately
programs do not specify how many in or out bits they use, so we can only
handle side-set and wrapping jumps like this. it's still something though.
2023-05-06 11:44:04 +02:00
pennae
5f7ef8bed0 rp/pio: only clear diag bits if they're set
otherwise we may lose a bit being raised after it was read, but before
it was cleared.
2023-05-05 19:08:16 +02:00
pennae
ed843b519b rp/pio: tighten variance of particle structs
all of these exist in 1:1 correspondence to their parent hal objects, so
let's make all of their lifetimes invariant.
2023-05-05 19:08:16 +02:00
pennae
09f078a1cc rp/pio: remove critical section in IrqFuture::poll
there's nothing this critical section protects against. both read and
write-to-clear are atomic and don't interfere with other irq futures,
only potentially with setting/clearing an irq flag from an arm core.
neither have ever been synchronized, and both have the same observable
effects under atomic writes and critical sections. (for both setting and
clearing an irq flag observable differences could only happen if the
set/clear happened after the poll read, but before the write. if it's a
clear we observe the same effects as sequencing the clear entirely after
the poll, and if it's a set we observe the same effects as sequencing
the set entirely before the poll)
2023-05-05 19:08:16 +02:00
pennae
8ebe6e5f20 rp/pio: drop Pio prefix from almost all names
it's only any good for PioPin because there it follows a pattern of gpio
pin alternate functions being named like that, everything else can just
as well be referred to as `pio::Thing`
2023-05-05 19:08:16 +02:00