diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index 2b8cb31b7..f461bc927 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Fixed +- Fixing `esp-wifi` + `TRNG` issue on `ESP32-S2` (#1272) ### Changed diff --git a/esp-hal/src/rng.rs b/esp-hal/src/rng.rs index 2571c25a5..92757001c 100644 --- a/esp-hal/src/rng.rs +++ b/esp-hal/src/rng.rs @@ -76,7 +76,7 @@ pub struct Rng { impl Rng { /// Create a new random number generator instance pub fn new(_rng: impl Peripheral

) -> Self { - #[cfg(not(any(esp32p4, esp32s2)))] + #[cfg(not(esp32p4))] crate::soc::trng::ensure_randomness(); Self { @@ -138,5 +138,5 @@ impl rand_core::RngCore for Rng { } } -#[cfg(not(any(esp32p4, esp32s2)))] +#[cfg(not(esp32p4))] impl rand_core::CryptoRng for Rng {} diff --git a/esp-hal/src/soc/esp32s2/mod.rs b/esp-hal/src/soc/esp32s2/mod.rs index 3307011b4..6ea1779ee 100644 --- a/esp-hal/src/soc/esp32s2/mod.rs +++ b/esp-hal/src/soc/esp32s2/mod.rs @@ -18,7 +18,7 @@ pub mod peripherals; #[cfg(psram)] pub mod psram; pub mod radio_clocks; -// pub mod trng; +pub mod trng; pub mod ulp_core; pub(crate) mod constants { diff --git a/esp-hal/src/soc/esp32s2/trng.rs b/esp-hal/src/soc/esp32s2/trng.rs index 007ca0c76..27b3090c7 100644 --- a/esp-hal/src/soc/esp32s2/trng.rs +++ b/esp-hal/src/soc/esp32s2/trng.rs @@ -211,10 +211,6 @@ fn reg_get_bit(reg: u32, b: u32) -> u32 { unsafe { (reg as *mut u32).read_volatile() & b } } -fn reg_get_field(reg: u32, s: u32, v: u32) -> u32 { - unsafe { ((reg as *mut u32).read_volatile() >> s) & v } -} - fn reg_clr_bit(reg: u32, bit: u32) { unsafe { (reg as *mut u32).write_volatile((reg as *mut u32).read_volatile() & !bit); @@ -282,10 +278,8 @@ pub(crate) fn regi2c_write_mask(block: u8, _host_id: u8, reg_add: u8, msb: u8, l | (reg_add as u32 & I2C_RTC_ADDR_V as u32) << I2C_RTC_ADDR_S as u32; reg_write(I2C_RTC_CONFIG2, temp); while reg_get_bit(I2C_RTC_CONFIG2, I2C_RTC_BUSY) != 0 {} - temp = reg_get_field(I2C_RTC_CONFIG2, I2C_RTC_DATA_S, I2C_RTC_DATA_V); // Write the i2c bus register - temp &= (!(0xFFFFFFFF << lsb)) | (0xFFFFFFFF << (msb + 1)); - temp |= (data as u32 & (!(0xFFFFFFFF << (msb as u32 - lsb as u32 + 1)))) << (lsb as u32); + temp = (data as u32 & (!(0xFFFFFFFF << (msb as u32 - lsb as u32 + 1)))) << (lsb as u32); temp = ((block as u32 & I2C_RTC_SLAVE_ID_V as u32) << I2C_RTC_SLAVE_ID_S as u32) | ((reg_add as u32 & I2C_RTC_ADDR_V as u32) << I2C_RTC_ADDR_S as u32) | ((0x1 & I2C_RTC_WR_CNTL_V as u32) << I2C_RTC_WR_CNTL_S as u32)