Commit Graph

393 Commits

Author SHA1 Message Date
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