Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed a race condition causing SpiDma to stop working unexpectedly (#869)
- Fixed async uart serial, and updated the embassy_serial examples (#871).
- Fix ESP32-S3 direct-boot (#873)
- Fix ESP32-C6 ADC (#876)

### Removed

Expand Down
13 changes: 13 additions & 0 deletions esp-hal-common/src/analog/adc/riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,19 @@ where
let attenuation = self.attenuations[channel as usize].unwrap() as u8;
ADCI::config_onetime_sample(channel, attenuation);
ADCI::start_onetime_sample();

// see https://github.com/espressif/esp-idf/blob/b4268c874a4cf8fcf7c0c4153cffb76ad2ddda4e/components/hal/adc_oneshot_hal.c#L105-L107
// the delay might be a bit generous but longer delay seem to not cause problems
#[cfg(esp32c6)]
{
extern "C" {
fn ets_delay_us(us: u32);
}
unsafe {
ets_delay_us(40);
}
ADCI::start_onetime_sample();
Copy link
Contributor

@bugadani bugadani Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the same sequence as the linked C code: that is a bit_clear(); wait; bit_set() sequence, while this looks like two bit sets. It's interesting how the workaround still seems to work, I wonder what actually needs the delay.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's not the same thing - but works

}
}

// Wait for ADC to finish conversion
Expand Down