1.1.2. Esp-idf开发环境
在linux子系统命令行模式下依次执行如下指令:
cd ~
git clone https://gitee.com/EspressifSystems/esp-gitee-tools.git
git clone https://gitee.com/EspressifSystems/esp-idf.git
ls
执行结束后窗口如下所示:
执行如下指令:
cd esp-idf
git checkout v4.4.1
cd ~/esp-gitee-tools
./submodule-update.sh ~/esp-idf/
./install.sh ~/esp-idf/
( . /home/peter/esp-idf/export.sh)
(
Added the following directories to PATH:
/home/peter/esp-idf/components/esptool_py/esptool
/home/peter/esp-idf/components/espcoredump
/home/peter/esp-idf/components/partition_table
/home/peter/esp-idf/components/app_update
Done! You can now compile ESP-IDF projects.
Go to the project directory and run:
idf.py build
(检查一下PATH是否包含上述路径,$PATH)
等待命令结束,接着执行如下指令:
sudo nano /etc/profile
末尾加上以下一行:
export PATH="$PATH:~/esp-idf"
cd ~/esp-idf/
source export.sh
1.1.3. 编译固件
执行如下指令
cd ~
git clone https://gitee.com/CHN_ZC/micropython.git
sudo chmod a+rwx micropython
cd ~/micropython
make -C mpy-cross
cd ports/esp32
make submodules
make
最终执行结果:

1.1.4. 测试模块
Python文件模块放在esp32下的modules文件夹,进入该文件夹:
cd modules
新建一个测试用的python文件,如下:
nano test.py
文件内容如下:
from time import sleep
def hello():
print("hello world")
def hw(str):
print(str)
def cycle(str):
while True:
print(str)
sleep(1)
保存后回到esp32目录,执行编译操作:
cd ~/micropython #micropython根目录
make -C mpy-cross
cd ports/esp32/
编译esp32c3固件
make clean
更改ports/esp32/Makefile文件
找到 BOARD ?= GENERIC
改为 BOARD ?= GENERIC_C3
make
留意上面的三个文件及地址,分别是烧录文件及偏移地址。
注意:
严格按照执行后的提示执行一下,否则会导致环境变量等等没有设置,为后续编译带来很多麻烦
如果安装了虚拟机,比如在windows上安装了ubuntu,则可以将编译好的文件拷回windows系统再用工具烧录,比如将xxx拷贝到windows的d盘:
$ cp xxx /mnt/d/
$ cp build-GENERIC_C3/bootloader/bootloader.bin /mnt/d/
$ cp build-GENERIC_C3/partition_table/partition-table.bin /mnt/d/
$ cp build-GENERIC_C3/micropython.bin /mnt/d/