Skip to content
Merged
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
ESP32-C3: Disable usb_pad_enable when setting GPIO18/19 to input/ou…
…tput
  • Loading branch information
jessebraham committed Mar 29, 2023
commit 301711f72b010330e1845d3735da4232d9d6a5fd
18 changes: 18 additions & 0 deletions esp-hal-common/src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,15 @@ where
#[cfg(esp32)]
crate::soc::gpio::errata36(GPIONUM, pull_up, pull_down);

// NOTE: Workaround to make GPIO18 and GPIO19 work on the ESP32-C3, which by
// default are assigned to the `USB_SERIAL_JTAG` peripheral.
#[cfg(esp32c3)]
if GPIONUM == 18 || GPIONUM == 19 {
unsafe { &*crate::peripherals::USB_DEVICE::PTR }
.conf0
.modify(|_, w| w.usb_pad_enable().clear_bit());
}

get_io_mux_reg(GPIONUM).modify(|_, w| unsafe {
w.mcu_sel()
.bits(GPIO_FUNCTION as u8)
Expand Down Expand Up @@ -1144,6 +1153,15 @@ where
gpio.func_out_sel_cfg[GPIONUM as usize]
.modify(|_, w| unsafe { w.out_sel().bits(OutputSignal::GPIO as OutputSignalType) });

// NOTE: Workaround to make GPIO18 and GPIO19 work on the ESP32-C3, which by
// default are assigned to the `USB_SERIAL_JTAG` peripheral.
#[cfg(esp32c3)]
if GPIONUM == 18 || GPIONUM == 19 {
unsafe { &*crate::peripherals::USB_DEVICE::PTR }
.conf0
.modify(|_, w| w.usb_pad_enable().clear_bit());
}

get_io_mux_reg(GPIONUM).modify(|_, w| unsafe {
w.mcu_sel()
.bits(alternate as u8)
Expand Down