-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: correct TRNG mechanism #1538
Conversation
I guess Trng should implement https://docs.rs/rand_core/0.6.4/rand_core/trait.CryptoRngCore.html not just CryptRng Would deserve some docs (but I see this is draft so you probably already thought about that) |
According to |
But RngCore isn't implemented? Maybe the diff looks weird for me |
Oh, I did it, but maybe it's lost in another branch 😄. Will double check when I'm near my PC again. |
c5eea25
to
9caefa3
Compare
e429145
to
b05d194
Compare
Looks good! Thanks for your continuous effort here. I think we should address the comment about the example code but otherwise looks good to me |
46901b6
to
878c859
Compare
I tested on hardware and with ADC example changed to this: //! Connect a potentiometer to an IO pin and see the read values change when
//! rotating the shaft.
//!
//! Alternatively, you could also connect the IO pin to GND or 3V3 to see the
//! maximum and minimum raw values read.
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
#![no_std]
#![no_main]
use esp_backtrace as _;
use esp_hal::{
analog::adc::{Adc, AdcConfig, Attenuation},
clock::ClockControl,
delay::Delay,
gpio::Io,
peripherals::Peripherals,
prelude::*,
rng::Trng,
system::SystemControl,
};
use esp_println::println;
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
cfg_if::cfg_if! {
if #[cfg(feature = "esp32")] {
let analog_pin = io.pins.gpio32;
} else if #[cfg(any(feature = "esp32s2", feature = "esp32s3"))] {
let analog_pin = io.pins.gpio3;
} else {
let analog_pin = io.pins.gpio2;
}
}
let mut adc = peripherals.ADC1;
let mut trng = esp_hal::rng::Trng::new(peripherals.RNG, &mut adc);
let mut buff = [0u8; 32];
trng.read(&mut buff);
println!("{:?}", buff);
core::mem::drop(trng);
// Create ADC instances
let mut adc1_config = AdcConfig::new();
let mut adc1_pin = adc1_config.enable_pin(analog_pin, Attenuation::Attenuation11dB);
let mut adc1 = Adc::new(&mut adc, adc1_config);
let delay = Delay::new(&clocks);
loop {
let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap();
println!("ADC reading = {}", pin_value);
delay.delay_millis(1500);
}
} The C6 reads 0 once and then dies. Looks good on all other targets for me |
After some tests, it turned out that there's a same issue in |
c401e4c
to
5349777
Compare
All the limitations for |
5349777
to
c23d46f
Compare
rustfmt
Downgrade for `esp32c6` is not implemented so far
c23d46f
to
7a91b2d
Compare
We probably should document that calling |
fbf8d52
to
c56db37
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - Thanks!
His review was addressed, but Scott's on vacation -> he can't mark it as "completed"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks
closes #1499
We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:
Submission Checklist 📝
CHANGELOG.md
in the proper section.\Pull Request Details 📖
Description
Based on what's discussed in #1499 and previous related issues, created a TRNG struct, which takes RNG peripheral and ADC instance. Working on using ADC peripheral instead of instance, this will be draft until it's done
Testing