368 Commits

Author SHA1 Message Date
Dániel Buga
0d9f43db29
Rewrite RNG (#3829) 2025-07-21 15:10:35 +00:00
Dániel Buga
da9a933e7e
Panic in exception handler (#3838) 2025-07-21 11:43:14 +00:00
Dániel Buga
8c64b09ba7
Allow configuring longer WDT periods (#3816)
* Clean up with new PAC

* Allow configuring longer WDT periods

* Enable WDT after updating timeout
2025-07-17 14:50:26 +00:00
Dániel Buga
f9419afcc2
Update PAC (#3802) 2025-07-17 12:23:51 +00:00
Simon Neuenhausen
3d6e522cbc
Allow splitting control over modem clocks. (#3687)
* Minimal architecture for split RCC.

* Removed critical section.

* Add all modem clock controllers and adjust esp-ieee802154.

* Fixed incorrect cfg.

* Fixed unstable attribute usage.

* Replaced AtomicU8 with Cell<u8>

* Reverted example channel back to 15

* Added unstable attribute to ModemClockController impls.

* Remember to actually increase the ref count.

* Experimentally removed RadioClockController

* Merged ref counters and made decrease panic if zero is reached.

* Removed RADIO_CLK peripheral.

* Removed RADIO_CLK again.

* Revert "Removed RADIO_CLK again."

This reverts commit 6da2d2834850068aa21bc52b141de2cfd8154acc.

* Removed RADIO_CLK without reformatting the files.

* Applied changes to examples and hil-tests.

* Fixed OS adapter for C2 and H2

* Adjusted docs and used unwrap!

* Fixed comments.

* Added changelog.

* Fixed esp-wifi for esp32h2.

* Changed comment for PHY_CLOCK_REF_COUNTER.

* Fixed lint for esp32c2.

* Update esp-hal/src/clock/mod.rs

Co-authored-by: Dániel Buga <bugadani@gmail.com>

* Update esp-hal/src/clock/mod.rs

Co-authored-by: Dániel Buga <bugadani@gmail.com>

* Removed unnecessary comments and made init_radio_clocks unstable.

* Update esp-hal/src/clock/mod.rs

Co-authored-by: Dániel Buga <bugadani@gmail.com>

* Fixed lint.

* Removed clocks_ll functions for chips that don't have those peripherals.

* fmt

* Changed modem clock controller stealing.

* Added lifetime

* fixed peripheral stealing again

* Made modem_clock_controller not const.

* Used type alias instead of function for peripheral stealing.

* fmt

* Adjusted remaining comments.

* Added note about coex.

* fmt

* misc

* Revert "misc"

This reverts commit d8740421e0dff84af605160939e246f2308a48e1.

* Regenerated esp metadata

---------

Co-authored-by: Dániel Buga <bugadani@gmail.com>
2025-07-08 17:23:55 +00:00
Dániel Buga
692a768b3a
Introduce esp-metadata-generated (#3754)
* Move macros to new crate

* Generate a single file

* Pre-generate esp-metadata-generated

* Move saving code to xtask

* Format with both rustfmt and prettyplease

* Fix doc build

* Unhide macros

* Fix doc string

* Update semver-check baseline
2025-07-07 15:37:05 +00:00
Dániel Buga
583be70559
Allow hooking into the executor (#3737)
* Allow hooking into the executor

* Attempt to test that the callback API is not dysfunctional
2025-07-03 09:17:34 +00:00
Dániel Buga
517b5ccbe2
Make cargo xfmt respect the format config (#3739)
* Make cargo xfmt respect the format config

* Make sure comments and doc code have the same width
2025-07-03 08:18:02 +00:00
Björn Quentin
cc2083fd1a
Introduce esp-rom-sys crate (#3688)
* Move ROM function definitions to esp-hal-rom crate

* Patch ESP32 ROM-functions, use it in esp-storage

* Allow placing additional code in IRAM

* esp-storage depends on esp-hal-rom

* Move ROM function wrappers from esp-hal to esp-hal-rom

* Make bootloader-support crate use CRC ROM function

* Minor polishing

* changelogs

* Make CI green

* Define (some) spiflash ROM functions in esp-hal-rom

* Lint

* Avoid duplicate definition of `__assert_func`

* Rename to `esp-rom-sys`

* Mention versioning this crate in the README

* Fixes

* Check self-version

* Docs

* Clippy

* Check if version bump is allowed

* Unconditionally place spiflash ROM function patches (if present) in rwtext

* Cleanup

* Change how unacceptable version bump requests are detected

* Initial version 0.1.0

* Docs

* Use correct version

* Force esp-rom-sys bumps to patch

* Fix
2025-07-01 13:05:01 +00:00
Gabriel Hansson
9eadaa147f
Adjust ESP32-S2 and ESP32-S3 memory region lengths to reflect those defined in ESP-IDF (#3709)
* fix(esp-hal/ld): adjust esp32s2 SRAM size from 188K to 184K

* fix(esp-hal/ld): extend esp32s2 heap size from 130.5K to 136K

* fix(esp-hal/ld): reduce esp32s3 SRAM size with 1K

* docs(changelog): add esp-rs#3709 entry
2025-07-01 08:17:41 +00:00
Benedikt
c71cbcd2c3
RMT: Refactor driver internals (less macros, type-erased channels) (#3505)
* RMT: Move some methods from (Tx|Rx)ChannelInternal to ChannelInternal

Adds a new `ChannelInternal` trait implemented on `Channel`s, which
bundles some methods that conceptually make sense for both rx and tx
channels (whether the implementation is exactly the same is
chip-specific).
This avoids a small amount of code duplication.

* RMT: Define input/output signals via a const array

Allowing a default implementation of the getter functions in the ChannelInternal
trait, and more importantly, paving the way for type-erased channels
(where it will become necessary to map Channel number to signal at runtime).

The array is indexed by ch_index, i.e. the index of the channel among
channels of the same type (for devices with separate rx/tx channels).

* RMT: move some `Sized` bounds from methods to trait

To avoid repetition. There's no downside, since the trait is only
implemented for a single type anyway, which is Sized.

These traits are user-visible, but since they can't be implemented by users,
and this only makes the bounds stricter, it should require not changes
to user code.

* RMT: Use composition with ConstChannelAccess, reduces macro usage

instead of an extension trait implemened via the impl_*_channel macros.
This reduces macro usage, making the code easier to reason about, and it also
paves the way for type-erased channels by adding a second implementation
of RawChannelAccess.

This touches many lines, but is a fairly mechanical change that should
be easier to review by ignoring whitespace changes.

Previously, channel architecture was as follows:

- `Channel` is parameterized by a const generic `CHANNEL: u8` number
- low-level hardware operations are implemented via the
  *ChannelInternal traits directly on `Channel`. This is done via the
  `impl_*x_channel` macros to account for the different channel
  capabilities (rx/tx only or rx+tx)

This PR changes this to:

- `Channel` contains an `Raw: RawChannelAccess<Dir=Rx|Tx>` where `Rx`
  and `Tx` are ZSTs used as markers for a channel configured for a given
  direction.
- low-level operations are implemented on the `Raw` type, depending on
  a bound on RawChannelAccess::Dir
- the `Raw` types can only be constructed safely from the
  `ChannelCreator`, which ensures that only valid combinations of channel
  number and `Dir=Rx|Tx` can exist.
- currently, the only implementation of `RawChannelAccess` is
  `ConstChannelAccess`, which has a `CHANNEL: u8` const generic
  parameter, just as `Channel` did before. Thus, the compiler should be
  able to inline and const-propagate code just as before.

These new types are user-visible. Thus, if code directly names `Channel`
types, it needs to be adapted. If it just uses a method chain such as
`rmt.channelX.configure(...).transmit(...)`, no changes should be
required.

* RMT: rm (Rx|Tx)ChannelCreatorAsync, use mode generic on (Rx|Tx)ChannelCreator

this de-duplicates some code,
and may be useful to implement user code (e.g. setup functions) that is
independent of DriverMode

* RMT: Rewrite pending_interrupt_for_channel using indexed PAC accessors

This deduplicates some code. I've also changed the return type
(usize -> u8) for better consistency, since channel indices are generally
typed as u8.

* RMT: add DynChannelAccess as basis for type-erased channels

Channels can now be `degrade`d to their type-erased variants.

* RMT: Move around some code

The channel definition used to be somewhere in the middle of channel
implementation. There's no change to the code other than its location.

* RMT: slightly more readable subsclicing

* RMT: Move some chip-specific code to a cfg_if! switch

There's no reason for these to reside in separate modules, and this
restructuring meshes well with moving the Rmt definition to a macro as
well, which will be done next.

* RMT: Declare Rmt struct via macro to avoid repetition

Reduces boilerplate at the cost of a somewhat complex macro.

* RMT: Move RmtState

Which was previously in the middle of channel implementation, but
conceptually is more global to the module, thus more natural define
earlier.

* RMT: explicity mark a few private functions in submodule as pub(super)

* RMT: use DynChannelAccess::conjure to simplify async_interrupt_handler

If the compiler decides to unroll the loops, the resulting code should
be essentially the same. Otherwise, it should be more compact. In any
case, from a developer point of view, this is much more concise and
removes one chip-specific case.

* RMT: Use type-erased channels for some HIL tests

* RMT: don't reset clock divider in start_tx

This seems to fix flaky loopback tests where tx/rx pulse code length
differs by 1.

This matches IDF, which also doesn't reset channels on each transmit
operation, but only once on channel creation, and when a sync_manager is
used (which the Rust driver doesn't support, and which would also need
to be handled differently anyway).

* RMT: implement degrade() even if the channel is already type-erased

This makes wrapping channels in custom structs slightly more convenient
since it allows taking any channel and type-erasing it in that structs
constructor.

* RMT: rename (Rx|Tx)ChannelCreator methods to avoid trait disambiguation problems

For devices with channels that support both Rx and Tx, Rust cannot
disambiguate the trait at the call site (because it doesn't look at the
argument types to do so).

Renaming the methods avoids that. The alternative is to use
fully-qualified names to call the trait methods (i.e. left-side
turbofish), or to import the traits only in a limited scope. Both are
much more verbose than the _rx/_tx suffixes to method names.

* RMT: add basic async HIL test

* RMT: remove overcomplicated WithMode trait from tests

according to a suggestion by @bugadani

---------

Co-authored-by: Scott Mabin <scott@mabez.dev>
2025-06-24 12:11:05 +00:00
Dániel Buga
581eec517e
Do not enable static_cell/nightly (#3676) 2025-06-23 09:43:11 +00:00
Dániel Buga
2438d03b21
Simplify generated code to save on build time, yeet a few dependencies (#3643)
* Reduce use of iter::chain

* Cache all symbols

* Trim xtensa-lx-rt deps

* Remove unused dep

* Replace chrono with jiff

* Yeet minijinja

* Save a bit on toml_edit

* Disable some default features

* Disable regex log filters

* Reduce xtensa-lx-rt build script

* Remove unnecessary dependencies

* Remove darling

* Update embedded-test

* lol

* Clean up

* Only validate loaded config once

* fmt

* Changelog
2025-06-17 20:35:00 +00:00
Dániel Buga
8cf0fc7153
Test -Zstack-protector (#3636)
* Test -Zstack-protector

* Pass config as inline TOML to cargo

* Try to fix failing test
2025-06-16 12:05:21 +00:00
Dániel Buga
3e6b85bf30
Update i2c/spi instance info (#3627)
* Add instances to drivers

* Move AnyI2c

* Move AnySpi and DataMode

* Generate new semver baseline
2025-06-13 13:56:52 +00:00
Björn Quentin
45248100f4
Simple ota example (#3629)
* Fix esp-bootloader-esp-idf

* Use OTA enabled partition table for examples

* Add simple OTA example

* CHANGELOG.md

* Create a dummy `ota_image` in CI

* mkdir

* Remove unnecessary details from CHANGELOG

* Make non-Window's users life easier

* Test ROM function in esp-bootloader-esp-idf

* Fix
2025-06-13 13:42:09 +00:00
Dániel Buga
c15fc6773e
Esp32: ensure wifi data comes before bss (#3635)
* Place wifi data before bss

* Minor fixes

* Changelog

* Fix the stack guard's address
2025-06-13 08:28:29 +00:00
Dániel Buga
793b01beaa
Move timer instance config into driver metadata (#3626)
* Remove timg_timer1 symbol

* Ensure instances exist

* Rename timers to timergroup

* Remove unnecessary cfg
2025-06-12 14:49:04 +00:00
Gabriel Hansson
1b5a85e7d6
chore: remove unused esp-build dependency listings (#3625) 2025-06-12 13:42:26 +00:00
Dániel Buga
2b6cece356
Lower the probability of a lockup (#3589) 2025-06-05 11:43:44 +00:00
Dániel Buga
4894220e29
Add multi-core critical section test (#3585) 2025-06-05 11:04:38 +00:00
Dániel Buga
6ab240d7ff
Fix i2c hanging after cancelling a transaction (#3572)
* Add failing test

* Reset FSM when cancelling a transaction

* Refactor clear_bus_blocking to avoid duplicating the logic

* Extract timeout from ClearBusFuture

* Clear bus immediately when cancelling an async transfer
2025-06-02 12:12:03 +00:00
Dániel Buga
946cbf842e
Fix duration_since_epoch (#3582) 2025-06-02 11:12:44 +00:00
Dániel Buga
d3a303c4be
Use the I2C future on ESP32, add sw timeout for S2 (#3571) 2025-05-30 13:19:01 +00:00
Kirill Mikhailov
59cfe438fe
change common test pins for esp32 (#3573) 2025-05-29 16:36:16 +00:00
Dániel Buga
f5305a6686
Add i2c blocking timeout test, unwrap results (#3567)
* Add blocking timeout test

* Don't ignore return values
2025-05-29 10:51:49 +00:00
Dániel Buga
6a49e9e0cd
Parametrize I2C tests a bit better (#3566) 2025-05-28 10:52:18 +00:00
Björn Quentin
7e2f1b1d31
Include uninit in noinit section (#3558)
* Include `uninit` in noinit section

* CHANGELOG.md

* Include `defmt` in flip-link test
2025-05-27 13:06:36 +00:00
Juraj Sadel
c6437c7a44
Update examples and qa-test to new bootloader (#3541) 2025-05-26 10:37:41 +00:00
Björn Quentin
51e23fe14d
Fix ESP32 PSRAM (in combination with esp-storage) (#3524)
* Fix ESP32 PSRAM (in combination with esp-storage)

* CHANGELOG.md

* Cleanup

* Add test
2025-05-23 14:28:18 +00:00
Kirill Mikhailov
c53e0bf788
UART: Adding HW and SW flow control config option (#3435)
* Add HW and SW flow control option

* Fmt + warnings

* changelog entry

wrong unstable macro

* address reviews

* get away with using 1 pin only

* unnecessary function call

* Address reviews + use "byte" instead of misleading "character" (at_cmd)
2025-05-21 10:36:07 +00:00
Benedikt
fe25980e53
RMT: Minor cleanups, simplify address calculations, extend HIL test (#3477)
* RMT: simplify/avoid a few cfg attributes

* RMT: factor address calculation into new function channel_ram_start()

* RMT: don't repeatedly read *ChannelInternal::memsize()

Moving this into separate variable greatly increases readability of the
code. It also avoids unnecessary repeated volatile reads of the
corresponding register.

* RMT: rework SingleShotTxTransaction offset calculation

This is not a big simplification yet, but will help will help with
simplifying the somewhat obscure `ram_index` calculation.

* RMT: rework SingleShotTxTransaction offset calculation, part 2

This removes the somewhat hard to parse
    let ram_index = (((self.index - memsize) / (memsize / 2)) % 2) * (memsize / 2);
calculation, by resorting to the ping-pong method also used by the idf
code.

Importantly, even with the previous code, ram_index cannot in fact assume any
possible in-range value in channel RAM, but only either 0 or memsize / 2
(except at the end of a transaction, when there's no data left).

Thus we can update it via
    ram_index = memsize / 2 - ram_index
such that will alternate ("ping-pong") between 0 and memsize / 2.

* RMT: error out on config.memsize == 0

* RMT: fix bogus cfg attributes

This is inside of a #[cfg(any(esp32, esp32s2))] block, so esp32s3 can
never happen: The result of nested cfg attributes was still correct, but
writing it like this doesn't make any sense.

* RMT: remove unnecessary integer literal type annotation

* RMT: remove spurious code from clear_interrupts()

- update() is known to be a no-op here
- For other chips, resetting pointers and setting mem_owner is not done
  in clear_interrupts(), but in start_rx. clear_interrupts() is only used in
  situations where either the channel was unused before (i.e. should be
  stopped), or we explicitly called Self::stop() before. Thus, match
  other chips here.

* RMT: clear mem_owner in start_tx

While I haven't seen this happen, it appears to be possible that one of
the subsequent channels (or even the current channel) was used for RX before.
Thus, ensure that mem_owner is set correctly for TX.

* RMT: small refactoring

There should be no functional change, but this should make it even more
obvious that the return value is exactly the number of codes written.

* RMT: in SingleShotTxTransaction, improve error handling

I haven't seen any error here in practise, but it seems that this could
have locked up in the `while !is_threshold_set()` loop before in case of
an error or early stop code in the data.

* RMT: avoid one register access

* RMT: update HIL tests to use wrapping and extended RAM

* RMT: address review regarding data-writing loops

Make the code less startling by performing writes to the hardware in a
more imperative style via the for-loop; slightly refactor slice
splitting.

* RMT: Update changelog
2025-05-20 13:11:26 +00:00
Dániel Buga
aeaab9a95b
Give more time to ECC tests (#3500) 2025-05-19 14:46:06 +00:00
Dániel Buga
74de9d65d6
Update allocator_api2 (#3487) 2025-05-19 07:38:07 +00:00
Dániel Buga
e2a9fc7437
Try to fix timeout errors when the I2C driver is preempted (#3458)
* Add test case

* Check completion before error
2025-05-08 15:05:22 +00:00
Dániel Buga
9c0512c1be
Hopefully innocent I2C-related cleanups (#3460)
* Simplify test

* Clean up
2025-05-07 13:47:58 +00:00
Dániel Buga
5df246c702
Rely on esp-metadata for chip feature check (#3447) 2025-05-06 08:11:53 +00:00
Dániel Buga
8011a30bd0
Fix write_str returning early (#3452) 2025-05-05 13:41:07 +00:00
Dániel Buga
16897bb68d
Tweak features and dependencies (#3425)
* Group optional dependencies

* Separate version from crate name

* Restore defmt-log mutual exclusivity

* Gate ufmt

* Remove usb-device

* Feature-gate unsable dependencies behind unstable

* S2: assume single core for portable-atomic

* Clean up feature flag docs

* Sack debug

* Fix clippy

* Update examples

* Fix usb-otg feature

* Fix fmt

* Add version to log dep

* Also mark bluetooth private

* Correct changelog/MG

* Clean up esp-hal-embassy

* Clean up ieee802154

* Clean up esp-println

* Move the timestamp function up

* Move info from readme to feature docs

* Clean up esp-storage

* Clean up esp-wifi

* Fix examples

* Add a note for the private features
2025-05-05 11:33:55 +00:00
Dániel Buga
a828331a62
GPIO interrupts, once more (#3408)
* Add test case

* Split into files

* Do not clear interrupt status bits in handler

* Document changes

* Refactor gpio tests to test the default interrupt handler by default

* Fix typo

* Extract mk_static

* Write a bit about interrupt handling

* Various fixes

* Test that the future doesn't resolve for a preceding interrupt

* Add multi-core test

* ESP32: handle GPIO interrupt on the listening core

* Fix multi-core edge case
2025-04-30 13:03:33 +00:00
Dániel Buga
5c97eaf8ba
Fix panic on long waits (#3433)
Co-authored-by: Scott Mabin <scott@mabez.dev>
2025-04-29 08:00:27 +00:00
Dániel Buga
68ffb747db
Update embedded-test (#3432) 2025-04-28 11:29:58 +01:00
Dániel Buga
cb4b09fb62
Rework GPIO matrix impl (#3395)
* WIP

* Clean up init_gpio

* Expand docs a bit

* Remove Input/OutputConnection

* Not everything has PCNT and it's not important for the example

* Remove Frozen, enable input when creating the signal

* Hide fields, add getters

* Update MG

* Add force GPIO matrix fns

* Fix formatting

* Mention latency in the docs

* Rename number to gpio_number

* Deduplicate pin setup code

* Reword associated peripheral

* Rename with_inverted_input/output

* Remove link to doc-hidden OutputSignal

* Fix link syntax
2025-04-25 10:33:29 +00:00
Dániel Buga
fec36e3be3
Implement ReadReady and WriteReady (#3423) 2025-04-25 07:54:58 +00:00
Dániel Buga
b1f487093b
Update dependencies (#3416) 2025-04-24 13:41:20 +00:00
Björn Quentin
11ff06a368
Fix esp32 coex (#3403)
* Make sure to enable relevant interrupts

* Fix more

* Make `current_runlevel` public

* Check that interrupts are enabled when initializing

* Try to be more honest in `is_in_isr`

* Adjust log levels

* Really fix ESP32 COEX

* Improve COEX example

* fmt

* CHANGELOG

* CHANGELOG

* Clarify on `esp_bt_controller_config_t`

* Take INTENABLE into account

* Test esp-wifi init fails

* Simplify test code

* Clarify comment

* fmt

* Rename

* Adapt the test

* Revert unrelated changes (esp_bt_controller_config_t)

* Align Xtensa (current_runlevel)

* Additional test

* Change test
2025-04-24 11:39:07 +00:00
Kirill Mikhailov
04b71139be
disconnect unused connections (#3407) 2025-04-22 15:50:09 +00:00
Kirill Mikhailov
ec6aec4b59
Fix I2C HIL tests (#3405) 2025-04-22 13:32:58 +00:00
Dániel Buga
ffbcae162a
Simplify Flex (#3387)
* Simplify Flex

* Rename functions
2025-04-22 12:30:34 +00:00
Björn Quentin
4bc9ef2f5b
Check for ST_TOUT / MAIN_ST_TOUT (#3333)
* Check for ST_TOUT / MAIN_ST_TOUT

* Fix & CHANGELOG

* cfg gate

* Field renaming in PACs

* Introduce FsmTimeout type

* `new_const`

* Review comments

* Async I2C tests

* Remove FSM timeout for S2

* Add test

* Don't run `async_test_timeout_when_scl_kept_low` on S2 - we know it fails

* Fix

---------

Co-authored-by: Scott Mabin <scott@mabez.dev>
2025-04-22 11:11:11 +00:00