64 Commits

Author SHA1 Message Date
bjoernQ
468d4a90c5 Fix IRAM/DRAM overlap for ESP32-S2 2022-08-22 11:29:33 +02:00
Gustavo Henrique Nihei
9d0a1f6685 esp32[c3|s2|s3]-hal: Add example for monitoring the XTAL frequency
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2022-08-19 21:55:54 +02:00
Gustavo Henrique Nihei
a1c417c037 esp32-s2: Fix stack area overlapping with ROM data reserved region
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2022-08-19 21:28:50 +02:00
Anthony Grondin
ede5007f71 Fix change detection of linker script on build files
In 7b59c9e76d
linker scripts have been moved in the ld/ sub-folder for every target.
The change detection path in build.rs of every target hasn't been updated, resulting in
the build script running at every code change, rather than only when there's a change in memory.x
2022-08-18 05:36:23 +02:00
har7an
2fe27536aa
SPI: Implement more SPI traits from embedded-hal 1.0.0-alpha.8 (#101)
* common/spi: Turn fifo size into const

instead of hard-coding it into the code in various places.

* common/spi: Alias `write_bytes` to `send_bytes`

since they share the same interface and the same code anyway.

* common/spi: Implement `read_bytes`

as counterpart to `send_bytes` that is responsible only for reading
bytes received via SPI.

* common/spi: Rewrite `transfer`

to use `send_bytes` and `read_bytes` under the hood and remove duplicate
code.

* common/spi: Create submodule for embedded_hal_1

that is re-exported when the `eh1` feature flag is active. This removes
lots of duplicate `#[cfg(...)]` macros previously part of the code.

* common/spi: Implement `SpiBus` and `SpiBusWrite`

traits from the `embedded-hal 1.0.0-alpha.8`.

* common/spi: Make `mosi` pin optional

* esp32-hal: Add new SPI example with `eh1` traits

* esp32-hal/examples/spi_eh1: Add huge transfer

and bump the SPI speed to 1 MHz.

* common/spi: Apply rustfmt

* common/spi: Use `memcpy` to read from registers

This cuts down the time between consecutive transfers from about 2 ms
to less than 1 ms.

* WIP: common/spi: Use `ptr::copy` to fill write FIFO

cutting down the time between transfers from just below 1 ms to ~370 us.

The implementation is currently broken in that it will always fill the
entire FIFO from the input it is given, even if that isn't FIFO-sized...

* common/spi: Add more documentation

* esp32/examples/spi_eh1: Fix `transfer_in_place`

* esp32/examples/spi_eh1: Add conditional compile

and compile a dummy instead when the "eh1" feature isn't present.

* esp32-hal: Ignore spi_eh1 example

in normal builds, where the feature flag "eh1" isn't given. Building the
example directly via `cargo build --example spi_eh1_loopback` will now
print an error that this requires a feature flag to be active.

* common/spi: Use `write_bytes`

and drop `send_bytes` instead. Previoulsy, both served the same purpose,
but `send_bytes` was introduced more recently and is hence less likely
to cause breaking changes in existing code.

* common/spi: Fix mosi pin setup

* Add SPI examples with ehal 1.0.0-alpha8 traits

to all targets.

* common/spi: Fix `read` behavior

The previous `read` implementation would only read the contents of the
SPI receive FIFO and return that as data. However, the `SpiBusRead`
trait defines that while reading, bytes should be written out to the bus
(Because SPI is transactional, without writing nothing can be read).

Reimplements the `embedded-hal` traits to correctly implement this
behavior.

* common/spi: Use full FIFO size on all variants

All esp variants except for the esp32s2 have a 64 byte FIFO, whereas the
esp32s2 has a 72 byte FIFO.

* common/spi: Use common pad byte for empty writes

* common/spi: Fix reading bytes from FIFO

by reverting to the old method of reading 32 bytes at a time and
assembling the return buffer from that. It turns out that the previous
`core::slice::from_raw_parts()` doesn't work for the esp32s2 and esp32s3
variants, returning bogus data even though the correct data is present
in the registers.

* common/spi: Fix typos

* examples: Fix spi_eh1_loopback examples
2022-08-17 11:57:55 +01:00
Gustavo Henrique Nihei
6e037b08ca ESP32-S2: Fix broken reference in documentation
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2022-08-16 19:57:55 +02:00
bjoernQ
91373ac6a0 Make RMT TX larger than one block work on ESP32-C3 and ESP32-S3 2022-08-09 16:30:19 +02:00
Gustavo Henrique Nihei
a33c0de7f6 rtc: Add RWDT examples for ESP32, ESP32-S2 and ESP32-S3
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2022-08-08 13:34:22 -03:00
Gustavo Henrique Nihei
91ea205446
ESP32-C3: Add driver for RTC Watchdog Timer (RWDT) (#134)
* esp32: Fix typo in Frequency word in some identifiers

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>

* esp32c3: Add support for PLL clock configuration

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>

* clock: Move definition of Clock types to common level

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>

* esp32c3: Add support for RTC Clock configuration

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>

* esp32c3: Add example for the RTC Watchdog Timer driver

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2022-08-08 15:36:19 +01:00
bjoernQ
275cede963 Fix LEDC divider calculation, use REF_TICK when needed 2022-08-08 14:41:55 +02:00
Juraj Sadel
ec6b58ee7d Add basic LEDC support for esp32, esp32c3, esp32s2 and esp32s3 2022-07-29 12:22:27 +02:00
bjoernQ
83ac67be23 Make it easy to leave out some of the SPI pins 2022-07-27 16:14:40 +02:00
Scott Mabin
1d02bf87c3
RISCV vectored interrupts (#118)
* RISCV interrupt vectoring

- Adds support for vectoring peripheral interrupts to PAC handlers
- Currently supports level interrupts with priorities from 1-15
- Updated the gpio interrupt example to reflect the new changes

* remove .vscode files

* Support vectored edge interrupts

This is as simple as making sure we clear the CPU interrupt whenever we
receive one. This also documents further what APIs are safe to call when
the `vectored` feature is enabled.

* fix all examples to use vectoring

* doc & cleanup

* run handlers from ram

* make xtensa::interrupt::vectored private, we rexport public items

* fix default handlers

* pass interrupt into EspDefaultHandler
2022-07-26 09:24:47 -07:00
Scott Mabin
1789780d06
Xtensa vectored interrupts (#103)
* Xtensa interrupt vectoring: peripheral source

- Initial Xtensa vectoring, updated esp32 gpio example to use new interrupt macro.
- Only peripheral sources supported.
- Only level one priority supported.
- CPU & Edge interrupts still need to be handled.

* Xtensa interrupt vectoring: CPU & EDGE

- Add support for handling CPU interrupts and edge interrupts
- PR required to xtensa-lx-rt for CPU handlers

* Xtensa interrupt vectoring: Priority

- Finally implement priortization
- Only three priorities available at the moment. Xtensa programmer guide
  discourages using highpri interrupts in Rust/C. Guide also mentions
  using software priortization to increase the number of Priorities
  available

* support CPU interrupts, using patch xtensa-lx-rt

* Update example

* Add support & examples for the s2 & s3 too

* Fix formatting and missing imports

* Run interrupt handling in ram, optionally run the vector handler in ram in the examples

* Use xtensa_lx::Mutex CS when enabling interrupts

* Run clippy on each target

* Remove redundant features

* Fix C3 builds

* make enable unsafe. Add note about preallocated interrupts in vectored mode.

* Remove `INTERRUPT_LEVELS` static

The interrupt levels static introduces a few issues
  - A lock is needed when configuring interrupts to keep
    INTERRUPT_LEVELS in a consistent state
  - Interrupts enabled from outside the Rust domain wouldn't be
    serviced, this is the case with the wifi blobs

To remove it, the prioty configuration is now calculated dynamically in
the interrupt handler. Essentially INTERRUPT_LEVELS is now created once
the interrupt triggers. It has some benefits, such as only having to
look at interrupts configured on the current core, not both, but there
is of course an overhead with doing this in the interrupt.

* Allow raw interrupts on levels 4-7, whilst also supporting vectoring on levels 1-3

* rename core number features

* Fix examples and formatting

* use xtensa-lx-rt release, update pacs

* Support passing the trap frame into interrupt handlers

* cfg away the #[interrupt] macro when not using vectoring

* rename enable to map

move vectored feature to chip specific hals

* export vectored functions

- rename `enable_with_priority` to `enable`
- add docs for interrupt macro

* Update all examples to use vectored interrupts
2022-07-25 07:12:34 -07:00
bjoernQ
70a9437f27 Add more documentation to the examples 2022-07-22 11:41:58 +02:00
Jesse Braham
4ba610d38d Do not enable the smartled feature by default 2022-07-20 10:38:48 -07:00
Jesse Braham
2a00119f94 Update the xtensa-lx-rt dependency to the newest version 2022-07-20 10:37:02 -07:00
Björn Quentin
147d8de988
Separate TIMG into timer0, (timer1), wdt (#104)
* Separate TIMG into timer0, (timer1), wdt
* Apply suggestions from code review
* Remove left-over code
* Ignore settings.json
2022-07-20 06:51:39 -07:00
bjoernQ
35a58490c6 Additional UART/Serial features 2022-07-13 22:46:34 +02:00
Björn Quentin
e612bd1120
Add some config options to the UART driver (#99)
* Add some config options to the UART driver
* Use esp-println 0.2.0
* Remove the NoPin type
* Serial constructor now doesn't return a Result anymore
2022-07-12 08:00:02 -07:00
bjoernQ
887798fd6f Reading raw ADC data for ESP32-C3 2022-07-07 18:39:11 +02:00
bjoernQ
568e37c166 Reading raw ADC data on ESP32 and ESP32-S2 2022-07-07 17:55:26 +02:00
Björn Quentin
7e25eebd8d
Implement DAC support for ESP32/ESP32-S2 (#92)
* Implement DAC support for ESP32/ESP32-S2
* Adapt the DAC samples after rebase
2022-06-30 11:57:16 -07:00
Jesse Braham
178a05522d Update all examples to reflect changes to Timer API 2022-06-29 17:57:23 -07:00
Jesse Braham
3d481901a5
Put the embedded-hal alpha trait implementations behind a feature (#88)
* Remove unused dependencies from HAL packages

* Put the `embedded-hal` alpha trait implementations behind a feature
2022-06-27 10:13:18 +01:00
Sergio Gasquez Arcos
fbd42865ef
Update MISO and CS pins to be optional (#89)
* Update CS and MISO pins to be optional
* Update examples
2022-06-23 10:10:57 -07:00
Jesse Braham
c5cdf68ddc Bump the xtensa-lx-rt version 2022-06-22 08:35:55 -07:00
bjoernQ
8a3a0e7cb9 Reading of some eFuses 2022-06-17 16:51:26 +02:00
Jesse Braham
e764194f2f Implement non-blocking SPI traits from embedded-hal alpha 2022-06-14 17:28:03 +02:00
Jesse Braham
8663153e12 Implement the embedded-hal alpha traits for the GPIO and I2C drivers 2022-06-14 17:28:03 +02:00
bjoernQ
9c244ba16c Make sure that HAL users don't need to depend on esp-hal-common 2022-06-13 16:38:58 +02:00
Scott Mabin
4acdf2516c
[esp32c3] SYSTIMER peripheral (#76)
* initial systimer impl
* Add systimer example
* Make Alarms real singletons
  * Remove runtime Option, turn into compile error
  * Make Systimer::now() not take self
* refactor shared alarm methods
* Implement esp32c3 delay with monotonic SystemTimer::now()
* Add extend systimer support to esp32s3 and add example
* systimer: esp32s2 support
2022-06-10 07:53:45 -07:00
Björn Quentin
3fd4b03144
Add boot-default ClockConfig (#77) 2022-06-09 13:51:17 +01:00
Juraj Sadel
b382a019d4
Feature/time types (#64)
* Use fugit time types for SPI peripheral, update examples

* initial WIP

* fix CI build errors

* Use extension trait in examples

Co-authored-by: Jesse Braham <jesse@beta7.io>
2022-05-31 11:39:44 +01:00
Robert Wiewel
a55c9d77ec Add RMT output channel support for all current ESP32 variants
- Add RMT output channel support for ESP32, ESP32-S2, ESP32-S3, ESP32-C3
- Add add RMT adapter for `smart-leds` crate
- Add example `hello_rgb` for ESP32-S2, ESP32-S3 and ESP32-C3 that either
  drives one LED at the pin where a LED is located on the official devkits
- Add example `hello_rgb` for ESP32 that is driving a 12-element RGB ring.
2022-05-17 15:56:25 +02:00
Jesse Braham
67bd5837cd Make cargo manifests consistent and bump dependencies 2022-05-05 11:56:43 +02:00
Jesse Braham
ec6a82b3f4 Clean up imports and format all packages 2022-05-05 11:16:05 +02:00
bjoernQ
67f21460f8 Implement workaround for ESP32 errata 3.6 2022-05-03 10:08:24 +02:00
bjoernQ
0f58f84873 Bump version of xtensa-lx, use correct features 2022-04-20 08:32:45 -07:00
bjoernQ
43c8f34e5f Update xtensa-lx-rt, fix interrupt related examples 2022-04-04 08:52:27 -07:00
bjoernQ
e83fd25e49 Optionally pass interrupt context to handlers for Xtensa 2022-03-29 09:31:09 -07:00
Douman
9a3b0a530f Introduce optional ufmt support 2022-03-21 16:31:20 +09:00
bjoernQ
15c34c23e4 Merge branch 'main' into feature/spi 2022-03-10 17:51:18 +01:00
Jesse Braham
bad8020abe Implement the embedded-hal Read trait for the RNG peripheral 2022-03-10 08:14:39 -08:00
bjoernQ
3f7a675b1e Implement SPI 2022-03-10 11:03:20 +01:00
bjoernQ
e7eea75ef8 Add timer interrupt support and examples 2022-03-04 09:54:28 -08:00
bjoernQ
e34319b763 Apply more suggestions from code review 2022-03-02 09:38:06 +01:00
bjoernQ
b3e8f930cf Disable WDT in I2C examples 2022-03-01 14:37:04 +01:00
bjoernQ
9bfe643f33 Implement I2C 2022-03-01 14:16:57 +01:00
bjoernQ
4cc78c4b6b Move GPIO type definitions to esp-hal-common 2022-03-01 14:16:57 +01:00