ESP32-C3 GPIO11 解锁教程:将 VDD_SPI 复用为 GPIO11

背景说明

在设计 ESP32-C3 原理图时,发现 GPIO 口数量不足。芯片手册提到,可以将 VDD_SPI 引脚复用为 GPIO11,因此我们将 VDD_SPI/GPIO11 设计为 I2C 的 SCL 引脚,用于与温湿度传感器进行通讯。

image-20240828105944778

注意事项

先说结果,程序上直接操作GPIO11是没有任何效果的,因为GPIO11 (VDD_SPI)默认功能是给 Fash 供电,所以不管我在程序中如何对该引脚如何初始化和操作都没有用,它始终是一个高电平。经过网上查找资料,得出以下结论:

VDD_SPI确实可以更改成GPIO11,但是这个结果不可逆,更改后不能复原(因为是设置熔丝位,不是寄存器,一次性操作)。

警告:如果你的芯片是内置Flash的话,当你把VDD_SPI更改成GPIO11后,芯片会烧录不进去,这是因为VDD_SPI被断开了,也就是Flash供电被断掉了,所以会烧录不了。

如何看你的芯片是不是内置Flash的,可以看一下芯片手册,下面是ESP32C3的芯片型号

image-20240828111621350

可以发现,只有ESP32-C3是没有内置Flash的,所以ESP32-C3在设计的时候可以外接Flash,并且给Flash独立供电,不从VDD_SPI供电,VDD_SPI就可以更改为GPIO11了,且可以烧录和运行。

我设计时芯片选用的是ESP32-C3FH4,所以在经过了两天的折腾之后,我成功的把VDD_SPI更改成GPIO11,但是芯片也报废了,烧录不了了(ˉ▽ˉ;)…最后只能把SCL跳线到别的引脚上/(ㄒoㄒ)/~~

以上是笔者踩的坑和注意事项,虽然最后没能成功用上GPIO11,但是如何将VDD_SPI更改成GPIO11还是有必要记录下来的,万一以后用上了呢,下面开始教程。

WSL 使用串口连接 ESP32-C3

我使用 Windows 子系统 (WSL2) 进行开发,因为需要使用串口与 ESP32-C3 进行通信。WSL 本身不支持直接连接 USB 设备,因此需要在 Windows 下安装开源的 usbipd-win 项目。

步骤 1:Windows 环境准备

1、安装 usbipd-win

将 ESP32-C3 与电脑通过串口连接,打开 CMD,执行以下命令:

winget install --interactive --exact dorssel.usbipd-win

image-20240828150436417

2、配置 usbipd-win

安装完成后,用管理员模式打开 PowerShell,运行以下命令查看设备列表:

usbipd list

image-20240828151318041

在列表中找到 ESP32-C3 的串口(例如 COM5),然后通过以下命令将其共享给 WSL:

usbipd attach --wsl --busid=<BUSID>

例如:

usbipd attach --wsl --busid=12-4

确保 COM5 的状态从 Not shared 变为 Attached

image-20240828151229314

步骤 2:WSL 环境准备

1、安装必要的软件包

进入 WSL,执行以下命令安装所需工具:

sudo apt install linux-tools-5.4.0-77-generic hwdata
sudo update-alternatives --install /usr/local/bin/usbip usbip /usr/lib/linux-tools/5.4.0-77-generic/usbip 20
2、验证设备连接

使用以下命令查看连接的 USB 设备和串口:

lsusb 
ls /dev/tty*

image-20240828153155246

可以看到COM5已经可以在WSL中可以看到了,串口设备名为 /dev/ttyUSB0

解锁GPIO11

步骤 1:进入 esptool 目录

在 WSL 中,进入 ESP-IDF 的 esptool 目录,通常路径如下:

cd ~/esp/esp-idf/components/esptool_py/esptool

image-20240828155439367

步骤 2:执行熔丝烧录命令

执行下面命令,将 VDD_SPI 更改为 GPIO11,因为我的芯片已经更改过了,所以显示的内容不太一样

python espefuse.py --port /dev/ttyUSB0 burn_efuse VDD_SPI_AS_GPIO 1

image-20240828155843660

正常内容应该如下

image-20240828160203755

执行成功后,VDD_SPI 将被永久更改为 GPIO11。

注意:

  • 如果更改后的芯片仍可以烧录,你就可以控制 GPIO11。
  • 如果芯片内置 Flash,可能会导致无法再进行烧录操作。

总结

更改 VDD_SPI 为 GPIO11 是一项不可逆的操作,对芯片功能具有重大影响。在执行之前,务必确认芯片型号和外设配置是否支持。如果不确定,建议在开发阶段谨慎操作或使用不影响关键功能的其他引脚。

通过本文介绍的方法,你可以成功在 WSL 环境中使用串口与 ESP32-C3 进行通信,并在需要时将 VDD_SPI 解锁为 GPIO11。

### ESP32-C3 GPIO Hold Configuration and Functionality For the ESP32-C3, configuring GPIO pins to be held at a certain state during reset or deep sleep is crucial for maintaining system stability and ensuring that specific hardware configurations persist through power cycles or low-power states[^1]. The `GPIO hold` function allows developers to lock the level of GPIOs when entering light-sleep mode or deep-sleep mode. To configure GPIO hold on an ESP32-C3 device: #### Enabling GPIO Hold via Software The SDK provides APIs specifically designed for setting up GPIO holds. Below is an example demonstrating how to enable this feature using C code within the Arduino IDE environment or IDF framework. ```c #include "driver/gpio.h" void setup_gpio_hold(int gpio_num){ // Enable GPIO hold capability. gpio_set_direction(gpio_num, GPIO_MODE_DISABLE); gpio_pullup_dis(gpio_num); gpio_pulldown_dis(gpio_num); // Set initial value before holding it. gpio_set_level(gpio_num, 0); // Or use 1 depending on your requirement // Finally apply hold command. gpio_hold_en(gpio_num); } ``` This snippet ensures that once configured, the specified pin will retain its logic level even after waking from sleep modes until explicitly released with `gpio_hold_dis()`. Moreover, regarding flexibility in usage scenarios, as mentioned previously about programmable properties where each IO line can serve multiple purposes like PWM generation, ADC input/output among others based upon software settings[^3]. In cases such as insufficient numbers of available general-purpose inputs/outputs (as encountered while designing schematics), alternative solutions involve repurposing special-function terminals into standard digital lines whenever possible without compromising core functionalities—like assigning VDD_SPI also known as GPIO11 for I2C communication tasks instead[^2]. --related questions-- 1. How does enabling GPIO hold affect current consumption during different operating modes? 2. What are some best practices when deciding which GPIO should have their levels preserved across resets? 3. Can all types of GPIO operations coexist alongside those being held simultaneously? If not, what limitations exist? 4. Are there any considerations one must take into account when reassigning specialized pins like VDD_SPI to generic roles? 5. Is it feasible to implement custom wake-up sources directly connected to these held-state outputs?
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值