Browse Source

[bsp] [ESP32C3] Add dockerfile and update README (#10313)

bsp: ESP32C3: Add dockerfile and update README
wumingzi 1 month ago
parent
commit
9e9669b47d
3 changed files with 144 additions and 5 deletions
  1. 46 1
      bsp/ESP32_C3/README.md
  2. 50 4
      bsp/ESP32_C3/README_ZH.md
  3. 48 0
      bsp/ESP32_C3/docker/Dockerfile

+ 46 - 1
bsp/ESP32_C3/README.md

@@ -41,6 +41,8 @@ Each peripheral supporting condition for this BSP is as follows:
 | ------------------------ | --------------- | ------------------------------------------------------------ |
 | GPIO                     | Support         |                                                              |
 | UART                     | Support         | Using LUATOS_ESP32C3 development board requires connecting serial port to USB chip UART0_TX and UART0_RX (such as CP2102) |
+| I2C              | Supported     | Hardware I2C may encounter transmission errors. Software I2C is recommended, but it occupies a general hardware system timer. |
+| SPI              | Supported     | Supports custom configuration |
 | JTAG debug               | Support         | ESP32C3 usb-linked development boards can be debugged        |
 | WIFI | Partial support | There are currently some problems, such as `rt_mq_recive` cannot be used in ISR, etc. |
 | BLE | Partially supported | There are currently some problems, such as `NimBLE` running errors after starting for a while |
@@ -91,6 +93,48 @@ Type "apropos word" to search for commands related to "word".
 
 ## Environment construction and compilation
 
+### Docker deploy
+
+If you want to lightly experiment with the ESP32-C3, it is recommended to quickly set up the environment using Docker. Otherwise, use a native environment setup.
+
+  1. Ensure Docker is installed and the inner network environment is properly configured. You can obtain the Docker image either via a pre-built docker image or by building it from a Dockerfile. Note that the docker image may not always be up-to-date, while the Dockerfile allows you to fetch the latest main branch. Below are the setup commands:
+      * Setting up the development environment using a Dockerfile:
+
+      ```sh
+      cd docker
+      sudo docker build --build-arg HTTP_PROXY=http://ip:port --build-arg HTTPS_PROXY=http://ip:port -t image_name .
+      ``` 
+      Replace ip:port with your proxy server's IP and port. Otherwise, network issues may occur when pulling repositories.
+
+      * Setting up the development environment using a pre-built Docker image:
+
+      ```sh
+      sudo docker pull 1078249029/rtthread_esp32c3:latest
+      ```
+
+  2. Enter the Docker container:
+  
+      ```sh
+      sudo docker run -it --device=/dev/ttyUSB* image_name
+      ```
+
+      The --device parameter is used for debugging and flashing code. You can obtain the corresponding port by running ls /dev/ttyUSB* on the host machine. If you used the pre-built Docker image, replace image_name with 1078249029/rtthread_esp32c3.
+
+  3. Using the Environment:
+   
+      Flashing firmware:
+
+        ```sh
+        sudo esptool.py -b 115200 --before default_reset --after hard_reset write_flash --flash_mode dio --flash_size detect --flash_freq 80m 0x0 path/to/your/bootloader.bin 0x08000 path/to/your/partition-table.bin 0x010000 path/to/your/rtthread.bin
+        ```
+
+      Debugging:
+
+        ```sh
+        sudo minicom -c on -D /dev/ttyUSB*
+        ```
+### Native setup
+
 1. Download the RISC-V toolchain:
 
      ```sh
@@ -180,7 +224,8 @@ or we can check ESPRESSIF's [Troubleshooting](https://docs.espressif.com/project
 Maintainer: 
 
 - [supperthomas](https://github.com/supperthomas) email address: [78900636@qq.com](mailto:78900636@qq.com)
--  [tangzz98](https://github.com/tangzz98) email address: [tangz98@outlook.com](tangz98@outlook.com)
+- [tangzz98](https://github.com/tangzz98) email address: [tangz98@outlook.com](tangz98@outlook.com)
+- [wumingzi](https://github.com/1078249029) email address: [1078249029@qq.com](1078249029@qq.com)
 
 Special thanks to [chenyingchun0312](https://github.com/chenyingchun0312) for providing support on the RISC-V part working.
 

+ 50 - 4
bsp/ESP32_C3/README_ZH.md

@@ -48,6 +48,8 @@
 | :----------------- | :----------: | :------------------------------------- |
 | GPIO              |     支持     |  |
 | UART              |     支持     | 使用LUATOS_ESP32C3开发板需要在UART0_TX和UART0_RX连接串口转USB芯片(如CP2102)|
+| I2C              |     支持     | 硬件I2C会产生传输错误,推荐使用软件I2C,但使用软件I2C会占用一个硬件通用定时器 |
+| SPI              |     支持     | 支持自定义配置|
 | JTAG调试          |     支持     | ESP32C3采用USB方式和PC链接的开发板可以调试                                |
 | WIFI              | 部分支持 | 目前存在一些问题,例如不能在ISR中使用`rt_mq_recive`等 |
 | BLE             | 部分支持 | 目前存在一些问题,例如`NimBLE`启动一段时间后运行错误 |
@@ -99,12 +101,55 @@ Type "apropos word" to search for commands related to "word".
 
 ## 环境搭建及编译
 
+### Docker
+
+如果想要通轻度尝鲜esp32c3,推荐使用docker快速搭建环境,否则请使用原生环境搭建
+
+  1. 在确保已经安装 docker 并配置docker内部网络环境的基础上可以通过 docker image 或 dockerfile 获取镜像,docker image 不保证时效性,而 dockerfile 可以获取最新的主线分支,下面是对应的搭建命令
+      * 通过 dockerfile 搭建开发环境
+
+      ```sh
+      cd docker
+      sudo docker build --build-arg HTTP_PROXY=http://ip:port --build-arg HTTPS_PROXY=http://ip:port -t image_name .
+      ``` 
+      这里的 ip:port 需要修改为代理服务器 ip 和端口号,否则拉取仓库时可能会出现网络问题
+
+      * 通过docker image搭建开发环境
+
+      ```sh
+      sudo docker pull 1078249029/rtthread_esp32c3:latest
+      ```
+
+  2. 进入 docker 
+  
+      ```sh
+      sudo docker run -it --device=/dev/ttyUSB* image_name
+      ```
+
+      device 参数用于调试、烧录代码,通过在宿主机内执行`ls /dev/ttyUSB*`即可获得对应端口,如果是通过 docker image 搭建环境的需要将 image_name 替换为`1078249029/rtthread_esp32c3`
+
+  3. 环境使用
+   
+      使用下列命令烧录
+
+        ```sh
+        sudo esptool.py -b 115200 --before default_reset --after hard_reset write_flash --flash_mode dio --flash_size detect --flash_freq 80m 0x0 path/to/your/bootloader.bin 0x08000 path/to/your/partition-table.bin 0x010000 path/to/your/rtthread.bin
+        ```
+
+      使用下列命令调试
+
+        ```sh
+        sudo minicom -c on -D /dev/ttyUSB*
+        ```
+
+### 原生环境搭建
+
 1. 下载 RISC-V 工具链:
 
-    ```sh
-    wget https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
-    tar xf riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
-    ```
+ ```sh
+ wget https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
+ tar xf riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
+ ```
 
   2. 配置工具链的路径:
 
@@ -190,6 +235,7 @@ Linux 下可以使用先前下载的 esptool 进行烧录
 
 -  [supperthomas](https://github.com/supperthomas) 邮箱:<78900636@qq.com>
 -  [tangzz98](https://github.com/tangzz98) 邮箱:<tangz98@outlook.com>
+-  [wumingzi](https://github.com/1078249029) 邮箱:<1078249029@qq.com>
 
 ## 特别感谢
 

+ 48 - 0
bsp/ESP32_C3/docker/Dockerfile

@@ -0,0 +1,48 @@
+FROM ubuntu:22.04
+
+ARG HTTP_PROXY
+ARG HTTPS_PROXY
+ENV http_proxy=${HTTP_PROXY}
+ENV https_proxy=${HTTPS_PROXY}
+
+
+# 1. Basic options(with root)
+RUN apt update && \
+    apt install -y software-properties-common && \
+    add-apt-repository universe && \
+    apt update && \
+    apt install -y --no-install-recommends \
+        sudo git wget python3 python3-pip scons vim xz-utils minicom && \
+    pip3 install esptool && \
+    useradd -m dev && \
+    echo "dev ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
+
+# 2. Switch to dev user
+USER dev
+WORKDIR /home/dev
+
+# 3. Install esp-idf toolchains
+RUN wget -q https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz && \
+    sudo tar -xf riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz -C /opt
+
+# 4. Clone RT-Thread and switch master
+RUN git clone https://github.com/RT-Thread/rt-thread.git && \
+    cd rt-thread && \
+    git switch master
+
+# 5. Install env tools
+WORKDIR /home/dev/rt-thread
+RUN wget https://raw.githubusercontent.com/RT-Thread/env/master/install_ubuntu.sh && \
+    chmod +x install_ubuntu.sh && \
+    ./install_ubuntu.sh
+
+# 6. Modify toolchains path
+RUN sed -i "s|^.*EXEC_PATH.*|    EXEC_PATH   = r'/opt/riscv32-esp-elf/bin'|" bsp/ESP32_C3/rtconfig.py
+
+# 7. Set enviroment variables
+ENV PATH="/opt/riscv32-esp-elf/bin:/home/dev/.env/tools/scripts:$PATH"
+
+# 8. Update rtthread packages
+WORKDIR /home/dev/rt-thread/bsp/ESP32_C3
+RUN pkgs --update
+