Commit graph

410 commits

Author SHA1 Message Date
Jan Niehusmann 96e15ee6de
Merge pull request #415 from jannic/features-vector_table
Enable feature "rt" when compiling vector_table example
2022-08-11 19:21:07 +02:00
Jan Niehusmann 0f33d2b8a6 Enable feature "rt" when compiling vector_table example
Without this change, building the vector_table example fails when
building from the rp2040-hal directory:

```
rp2040-hal$ cargo build --release --example vector_table
   Compiling rp2040-hal v0.5.0 (rp2040-hal)
error[E0432]: unresolved import `pac::interrupt`
  --> rp2040-hal/examples/vector_table.rs:30:5
   |
30 | use pac::interrupt;
   |     ^^^^^---------
   |     |    |
   |     |    help: a similar name exists in the module (notice the capitalization): `Interrupt`
   |     no `interrupt` in the root

error: cannot determine resolution for the attribute macro `interrupt`
   --> rp2040-hal/examples/vector_table.rs:148:3
    |
148 | #[interrupt]
    |   ^^^^^^^^^
    |
    = note: import resolution is stuck, try simplifying macro imports
```
2022-08-11 12:09:20 +00:00
Jan Niehusmann d4743061fa Use generic boot loader for rp2040-hal examples
Those examples should be independent of a specific board.
The generic boot loader increases their compatibility.
2022-08-11 11:56:41 +00:00
9names 2bbc52ffce
RAM-based interrupt vector tables (#321)
* Add struct VectorTable to represent an interrupt vector table

* Add member function to VectorTable to initialise based on the current Interrupt Vector Table from VTOR

* Add member function to VectorTable to register an extern "C" function to call on interrupt

* Add example using VectorTable to demonstrate initialisation and interrupt function registration
2022-08-06 14:58:43 +10:00
Jan Niehusmann 575aba4bfe
Merge pull request #408 from jannic/wfi
Use wfi in otherwise empty infinite loops in examples
2022-08-04 16:49:06 +02:00
Jan Niehusmann b636afb7b5 Clear sie_status.suspended / sie_status.resume flags in poll()
usb_device ignores PollResult::Suspend when already suspended,
and PollResult::Resume when not suspended.

This may lead to repeatedly triggered interrupts if for some reason
the Suspend flag gets set while the device is already suspended.

I observed such a situation when a reset was triggered while the device
was suspended.

To make sure that this can't cause interrupt storms, clear the flags
before returning from poll()
2022-08-02 22:17:54 +00:00
Jan Niehusmann 786062aa74 To clear a bit in sie_status, just write that single bit 2022-08-02 22:11:14 +00:00
Jan Niehusmann fb9bac5064
Merge pull request #410 from ithinuel/bump-usb-device-to-0-2-9
bump usb-device to 0.2.9
2022-08-02 21:58:17 +02:00
Jan Niehusmann 1be329a907
Merge pull request #407 from FlorianUekermann/main
Implement NonPwmPinMode for gpio::Disabled
2022-08-02 21:46:18 +02:00
Wilfried Chauveau 60677df099
bump usb-device to 0.2.9 2022-08-02 20:43:00 +01:00
Jan Niehusmann 44019781e2 Use wfi in otherwise empty infinite loops in examples
- Clippy warns about empty loops, https://github.com/rust-lang/rust-clippy/issues/6161
- wfi allows to CPU to save some power

WFI was avoided in examples for fear of ill interactions with debuggers.
However the rp2040 debug port does continue to work, as long as the
relevant clocks are not disabled in SLEEP_EN0/SLEEP_EN1. (By default,
all clocks stay enabled in sleep mode.)

This patch replaces several different workarounds with just calling wfi.
2022-08-01 14:54:03 +00:00
Jan Niehusmann 6dafcc1ac0
Merge pull request #405 from ithinuel/fix-usb-ep0-out
Fix usb missed ep0 out packet and add recommended sync delays
2022-08-01 15:32:45 +02:00
Florian Uekermann 03e791ab31 Implement NonPwmPinMode for gpio::Disabled
Fixes #397
2022-08-01 15:20:54 +02:00
Wilfried Chauveau 5dd095bd45
Add suspend, resume and remote wakeup support. 2022-07-30 20:51:01 +01:00
Wilfried Chauveau fa7c9275b4
Fix missed ep0-data-out transaction
The ep0-out buffer must not be marked as available unless required.
Otherwise, the controller will acknowledge the data-out packet but
won't reflect that in its status registers.

This patch forces the controller to nack the data-out phase until we have
processed the setup packet.
2022-07-30 10:09:20 +01:00
Wilfried Chauveau 067f1396d9
Add the required synchronisation delays
As per 4.1.2.5.1, the access to the DPSRAM should "be considered asynchronous
and not atomic".
It is recommended to write to buffer control register in two steps.
A first one to configure all bits but Available.
Wait clk_sys/clk_usb (typically 125MHz/48MHz).
Then set the available bit (if required).
2022-07-30 10:03:03 +01:00
Jan Niehusmann 6e325ba099
Remove unnecessary cortex_m::interrupt::free in timer.rs (#402)
The only thing accessed by those methods is `&mut self`, which is
guaranteed to be a unique reference. So an interrupt can not
interfere with the correctness of the operation.
2022-07-28 10:26:24 +10:00
9names c7acafda3c
GPIO IRQ example: add check for interrupt source (#401) 2022-07-28 10:14:20 +10:00
Jan Niehusmann c0c72c4db3 Fix handling of duty cycle while PWM channels is disabled
Fixes #390
2022-07-26 08:22:53 +00:00
Jan Niehusmann 32411b8652
Merge pull request #394 from jannic/use-ref-for-clock-to-herz
Implement conversion from Clock to Hertz using reference
2022-07-25 20:38:21 +02:00
Jan Niehusmann 595e0a9974 i2c is driven from system_clock, noch peripheral_clock. Update example accordingly. 2022-07-22 20:34:56 +00:00
Jan Niehusmann f8984a9eac Implement conversion from Clock to Hertz using reference
Implementing `impl From<SystemClock> for Hertz` is a footgun, as
SystemClock is not Copy, so the automatic conversion consumes the
owned clock.

This is visible in the example i2c.rs:

```
    let mut i2c = hal::I2C::i2c1(
        pac.I2C1,
        sda_pin,
        scl_pin, // Try `not_an_scl_pin` here
        400.kHz(),
        &mut pac.RESETS,
        clocks.peripheral_clock,
    );
```

If the user wants to use both `i2c0` and `i2c1` at the same time,
copying from this example won't work:

```
error[E0382]: use of moved value: `clocks.peripheral_clock`
   --> rp2040-hal/examples/i2c.rs:106:9
    |
97  |         clocks.peripheral_clock,
    |         ----------------------- value moved here
...
106 |         clocks.peripheral_clock,
    |         ^^^^^^^^^^^^^^^^^^^^^^^ value used here after move
    |
    = note: move occurs because `clocks.peripheral_clock` has type
`PeripheralClock`, which does not implement the `Copy` trait
```

As getting the frequency from a clock doesn't really need ownership,
changing it to `impl From<&SystemClock> for Hertz` is both more
logical and provides better usability.

This is, however, a breaking change: Code relying on this trait
implementation needs to be changed by adding a `&`.
2022-07-22 20:17:26 +00:00
9names 12387bcf09
Add docs and doc-example for Timer (#386) 2022-07-18 15:35:21 +10:00
Jan Niehusmann 3c4d8f0b43
Merge pull request #372 from 9names/fix_bsp_pins_docs
Add missing open paren in bsp_pins doc macro
2022-07-09 12:40:16 +02:00
Jan Niehusmann 0f5bc072cd
Use ignore instead of text (#378)
While the code block fails to compile, it's still code and not random text. Marking it with `ignore` allows for proper syntax highlighting, for example.

According to https://github.com/rust-lang/rust/issues/97030#issuecomment-1134499264 this is the proper fix, so this closes #374
2022-07-08 20:58:09 +10:00
9names 711694881d
Wrap intrinsics docstring to avoid breakage (#375)
* Wrap code in intrinsics docstring with a text block to fix CI breakage
2022-07-06 19:52:31 +10:00
9names 319c1749fc Fix unmatched parens in bsp_pins doc macro 2022-06-28 22:00:58 +10:00
Jan Niehusmann e5897ca7a4
Fix PIO rx fifo status (#367)
* Implement embedded-hal 1.0.0-alpha.8 traits

* Add comment about missing SPI traits

* Fix doc of rx.is_empty() and add rx.is_full()
2022-06-24 08:24:27 +10:00
Jan Niehusmann 99dfeaf6f2
Implement embedded-hal 1.0.0-alpha.8 traits (#366)
* Implement embedded-hal 1.0.0-alpha.8 traits

* Add comment about missing SPI traits
2022-06-24 08:19:41 +10:00
Hmvp f7cfeec0d7
Add bsp_pin example (#364) 2022-06-23 21:10:58 +10:00
Hmvp 0f114677d5
Explorer base improvements (#363)
* Improve comments

* Expose pins and all pins naming struct.

This allows users to set the interrupts on the button pins and to skip the PicoExplorer struct but still use proper naming

* Use correct interrupt names in timer::alarms macro in HAL
2022-06-23 19:19:32 +10:00
9names 1574a36f7e
Prep for HAL 0.5.0 release (#351)
* Update changelog, readme and version number for HAL 0.5.0 release

* Bump HAL version in BSP deps

* Point ws2812-pio and i2c-pio-rs at hal_0.5.0 branches

* Update changelog with latest commits and release date
2022-06-14 18:04:00 +10:00
9names 9641c0b4a4
Change pio::Tx::write to write u32 instead of <T>* (#352)
* Change pio::Tx::write to write u32 instead of <T>*

* Use i2c-pio branch that supports new SIO FIFO API so the PIO FIFO changes don't break CI
2022-06-13 18:24:05 +10:00
Kasil 9bce594db2
Add accessor for installed pio program offset (#355) 2022-06-05 21:56:46 +10:00
Jan Niehusmann ed7148a1e7
Take possible PIO program length of 32 into account (#350)
Avoid overflow of left-shift operation by special-casing the value 32.

Fixes #349
2022-06-02 07:03:04 +10:00
9names d66b47920e
Merge pull request #311 from Liamolucko/multicore-no-alloc
Remove the `alloc` requirement for `Core::spawn`
2022-06-01 20:52:11 +10:00
Liam Murphy e9534ace04 Add a fence after writing the arguments to the stack
Co-authored-by: Jan Niehusmann <jan@gondor.com>
2022-06-01 17:33:37 +10:00
9names e9f367f26c
Restrict PIO FIFO writes to unsigned integers (#318)
* Change pio::Tx::write to write u32 instead of <T>*

* Add replicated u8/u16 writes to pio::Tx::write

* Switching back to generic version of pio::fifo.write()

* Fix links to make cargo doc happy

Co-authored-by: Jan Niehusmann <jan@gondor.com>

Co-authored-by: Jan Niehusmann <jan@gondor.com>
2022-06-01 06:13:33 +10:00
Liam Murphy 9848f849bd Write core 1 arguments directly to RAM without casting to usize 2022-05-29 19:56:20 +10:00
Christian Maniewski 99b8845d74
Add missing GPIO I2C trait implmentations (#344) 2022-05-25 09:03:29 +10:00
Wilfried Chauveau 38692dfcb9
Add defmt feature (as optional dep) and allow i2c::Error to be formatted (#328) 2022-05-09 19:22:41 +10:00
Liam Murphy 0e5fdcfd9c Fix example 2022-05-08 20:14:40 +10:00
Liam Murphy 3e1e762d20 Add multicore_polyblink example 2022-05-08 18:29:27 +10:00
Liam Murphy c0fafc7694 Make Multicore take SioFifo rather than the whole Sio & make the spawn closure the last argument 2022-05-08 18:24:49 +10:00
Liam Murphy b932663cc9
Merge branch 'main' into multicore-no-alloc 2022-05-03 17:40:22 +10:00
Daniel Bevenius 89371912ad Fix typo in rp2040-hal README.md 2022-04-30 12:52:19 +10:00
mqy 623457a498 fixed typos 2022-04-30 12:51:45 +10:00
Wilfried Chauveau bb07402fc9 Abstract alarms 2022-04-30 11:54:54 +10:00
Wilfried Chauveau 977bc2732a Remove unmaintained implementation async i2c. 2022-04-30 11:46:30 +10:00
9names 3d8f66df78 Provide an unsafe function for resetting all spinlocks 2022-04-30 11:33:22 +10:00