文章目錄
- 前言
- 一、開發環境
- 二、硬體介紹
- 三、下載esp-idf
- 四、下載esp-iot-solution
- 五、配置idf
- 1、執行下載腳本
- 2、設定環境變數
- 3、宣告外部組件
- 六、構建例程
- 七、燒寫Flash
- 八、使用方法
- 九、感謝
前言
使用官方例程"usb_msc_wireless_disk",將ESP32S2開發板制作成一個支持wifi無線訪問的U盤設備,
一、開發環境
| SDK | https://github.com/espressif/esp-idf.git |
|---|---|
| 方案 | https://github.com/espressif/esp-iot-solution |
| 開發板 | 安信可ESP-12K開發板NodeMCU-32-S2 |
| OS | Windows 10 |
二、硬體介紹
- Board:ESP32-S3-USB-OTG, or any ESP32-Sx board
- MCU:ESP32-S2, ESP32-S3
- Flash:4MB NOR Flash
- Hardware Connection:
- GPIO19 to D- // 我用的是安信可ESP32S2-12K開發板,可根據自己的開發板確認管腳
- GPIO20 to D+
- SDCard IO varies from boards, you can defined your own in code. // 如MSC要映射到外部SDCARD時需要
三、下載esp-idf
cd esp // 是我的根目錄
git clone -b master --recursive https://github.com/espressif/esp-idf.git esp-idf // 下載master分支
cd esp-idf
git pull
git checkout d5f58ab13551cd8 // check到指定節點
git submodule update --init --recursive // 要確保各個子模塊更新成功
修改esp-idf/components/driver/spi_master.c:
diff --git a/components/driver/spi_master.c b/components/driver/spi_master.c
index 15cfceb9ac..c076ed631c 100644
--- a/components/driver/spi_master.c
+++ b/components/driver/spi_master.c
@@ -563,6 +563,7 @@ static void SPI_MASTER_ISR_ATTR spi_new_trans(spi_device_t *dev, spi_trans_priv_
//Call pre-transmission callback, if any
if (dev->cfg.pre_cb) dev->cfg.pre_cb(trans);
+ ets_delay_us(10); // 加上這一行
//Kick off transfer
spi_hal_user_start(hal);
}
四、下載esp-iot-solution
cd esp
git clone -b usb/add_usb_solutions --recursive https://github.com/espressif/esp-iot-solution
cd esp-iot-solution
xcopy /e /i examples\usb\device\usb_msc_wireless_disk usb_msc_wireless_disk
// 拷貝一份出來,不污染原檔案,
五、配置idf
1、執行下載腳本
cd esp
esp-idf\install.bat
如速度慢,添加一個新的環境變數(型別為用戶或系統都可以,名稱為 IDF_GITHUB_ASSETS,值為dl.espressif.com/github_assets);
如果之前安裝過其它版本的idf環境,可能會報錯,可以把.espressif\python_env刪掉,.espressif一般位于用戶根目錄,即打開一個命令列視窗所在的位置,
2、設定環境變數
cd esp
esp-idf\export.bat
3、宣告外部組件
cd esp
set IOT_SOLUTION_PATH=D:\xxx\code\esp\esp-iot-solution // 我們要使用esp-iot-solution中的組件
六、構建例程
cd esp-iot-solution\usb_msc_wireless_disk
idf.py set-target esp32s2 // 如果遇到報錯“找不到xxx檔案”、“xxx is not a directory”,很可能是子模塊沒有下載成功,可以進入對應目錄,手動checkout 出來(git checkout commitid)
idf.py menuconfig // 這步可選,如使用默認配置,則可跳過,
idf.py build // 如果之前有build失敗過,手動洗掉build目錄,
七、燒寫Flash
idf.py -p com5 flash // com序號根據實際情況
八、使用方法
1)將開發板的USB_D+、USB_D-、VCC_5V、GND分別連接USB插頭的綠、白、紅、黑線;
2)將USB插頭插入PC,能識別到一個1.5M左右的U盤;
2)PC連接熱點“ESP-Wireless-Disk”,無密碼;
3)連接成功后,PC瀏覽器打開“192.168.4.1”,即可訪問U盤;
九、感謝
使用ESP32S2原生USB自制U盤,可支持無線訪問
MIT 女極客 ESP32-S2 TinyUSB 直播教學,All about the ESP32-S2 by Espressif Systems
https://github.com/espressif/esp-iot-solution/tree/usb/add_usb_solutions/examples/usb/device/usb_msc_wireless_disk/README.md
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/300540.html
標籤:其他
