Skip to content
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

ESP32: Some pins are not properly configured #594

Closed
SergioGasquez opened this issue Jun 15, 2023 · 5 comments
Closed

ESP32: Some pins are not properly configured #594

SergioGasquez opened this issue Jun 15, 2023 · 5 comments
Labels
bug Something isn't working peripheral:gpio GPIO peripheral

Comments

@SergioGasquez
Copy link
Member

See errata 3.6, we currently have a fix for this (

pub(crate) fn errata36(pin_num: u8, pull_up: bool, pull_down: bool) {
use crate::peripherals::RTC_IO;
let rtcio = unsafe { &*RTC_IO::PTR };
match pin_num {
0 => {
rtcio
.touch_pad1
.modify(|r, w| unsafe { w.bits(r.bits()).rue().bit(pull_up).rde().bit(pull_down) });
}
2 => {
rtcio
.touch_pad2
.modify(|r, w| unsafe { w.bits(r.bits()).rue().bit(pull_up).rde().bit(pull_down) });
}
4 => {
rtcio
.touch_pad0
.modify(|r, w| unsafe { w.bits(r.bits()).rue().bit(pull_up).rde().bit(pull_down) });
}
12 => {
rtcio
.touch_pad5
.modify(|r, w| unsafe { w.bits(r.bits()).rue().bit(pull_up).rde().bit(pull_down) });
}
13 => {
rtcio
.touch_pad4
.modify(|r, w| unsafe { w.bits(r.bits()).rue().bit(pull_up).rde().bit(pull_down) });
}
14 => {
rtcio
.touch_pad6
.modify(|r, w| unsafe { w.bits(r.bits()).rue().bit(pull_up).rde().bit(pull_down) });
}
15 => {
rtcio
.touch_pad3
.modify(|r, w| unsafe { w.bits(r.bits()).rue().bit(pull_up).rde().bit(pull_down) });
}
25 => {
rtcio.pad_dac1.modify(|r, w| unsafe {
w.bits(r.bits())
.pdac1_rue()
.bit(pull_up)
.pdac1_rde()
.bit(pull_down)
});
}
26 => {
rtcio.pad_dac2.modify(|r, w| unsafe {
w.bits(r.bits())
.pdac2_rue()
.bit(pull_up)
.pdac2_rde()
.bit(pull_down)
});
}
27 => {
rtcio
.touch_pad7
.modify(|r, w| unsafe { w.bits(r.bits()).rue().bit(pull_up).rde().bit(pull_down) });
}
32 => {
rtcio.xtal_32k_pad.modify(|r, w| unsafe {
w.bits(r.bits())
.x32n_rue()
.bit(pull_up)
.x32n_rde()
.bit(pull_down)
});
}
33 => {
rtcio.xtal_32k_pad.modify(|r, w| unsafe {
w.bits(r.bits())
.x32p_rue()
.bit(pull_up)
.x32p_rde()
.bit(pull_down)
});
}
_ => (),
}
}
) but is not always called, e.g. the i2c constructor does not apply this workaround.

@jessebraham jessebraham added the bug Something isn't working label Jun 15, 2023
@bjoernQ
Copy link
Contributor

bjoernQ commented Jul 20, 2023

Even with ESP-IDF (e.g. with a changed i2c_simple_main.c example) I don't get I2C to work on these pins without external pull-ups

@jessebraham jessebraham added the peripheral:gpio GPIO peripheral label Sep 19, 2023
@liebman
Copy link
Contributor

liebman commented Dec 27, 2023

This even fails for simple gpio input with pull up (at least with gpio33). Using the following leaving gpio33 unconnected and it waits for gpio33 top go high - it should be pulled up but it keeps waiting.

#![no_std]
#![no_main]

use esp_backtrace as _;
use esp_println::println;
use hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Delay, IO};

#[entry]
fn main() -> ! {
    let peripherals = Peripherals::take();
    let system = peripherals.SYSTEM.split();

    let clocks = ClockControl::max(system.clock_control).freeze();

    let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
    let input = io.pins.gpio33.into_pull_up_input();

    let mut delay = Delay::new(&clocks);

    loop {
        println!("wait for high...");
        while input.is_low().unwrap() {
            delay.delay_ms(10u32);
        }
        println!("wait for low...");
        while input.is_high().unwrap() {
            delay.delay_ms(10u32);
        }
    }
}

@liebman
Copy link
Contributor

liebman commented Dec 27, 2023

I found that for gpio32 and gpio33 they were reversed in the errata36 function. I'll send a PR.
Based on the datasheet:
gpio32 = x32p
gpio33 = x32n

@liebman
Copy link
Contributor

liebman commented Dec 27, 2023

PR added #1053

@SergioGasquez
Copy link
Member Author

Closed by #1053

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working peripheral:gpio GPIO peripheral
Projects
None yet
Development

No branches or pull requests

4 participants