Skip to content

Commit

Permalink
[bsp][ESP32_C3]增加ble和wifi驱动|add ble & wifi drivers (RT-Thread#8104)
Browse files Browse the repository at this point in the history
  • Loading branch information
WCX1024979076 authored Oct 16, 2023
1 parent 38e42b7 commit 61f7d48
Show file tree
Hide file tree
Showing 17 changed files with 971 additions and 32 deletions.
28 changes: 26 additions & 2 deletions bsp/ESP32_C3/.config
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ CONFIG_FINSH_USING_OPTION_COMPLETION=y
#
CONFIG_RT_USING_DEVICE_IPC=y
CONFIG_RT_UNAMED_PIPE_NUMBER=64
# CONFIG_RT_USING_SYSTEM_WORKQUEUE is not set
CONFIG_RT_USING_SYSTEM_WORKQUEUE=y
CONFIG_RT_SYSTEM_WORKQUEUE_STACKSIZE=2048
CONFIG_RT_SYSTEM_WORKQUEUE_PRIORITY=23
CONFIG_RT_USING_SERIAL=y
CONFIG_RT_USING_SERIAL_V1=y
# CONFIG_RT_USING_SERIAL_V2 is not set
Expand Down Expand Up @@ -207,6 +209,10 @@ CONFIG_RT_LIBC_TZ_DEFAULT_SEC=0
# CONFIG_RT_USING_SAL is not set
# CONFIG_RT_USING_NETDEV is not set
# CONFIG_RT_USING_LWIP is not set
# CONFIG_RT_USING_LWIP141 is not set
# CONFIG_RT_USING_LWIP203 is not set
# CONFIG_RT_USING_LWIP212 is not set
# CONFIG_RT_USING_LWIP_LATEST is not set
# CONFIG_RT_USING_AT is not set

#
Expand All @@ -220,6 +226,7 @@ CONFIG_RT_LIBC_TZ_DEFAULT_SEC=0
# CONFIG_RT_USING_ADT is not set
# CONFIG_RT_USING_RT_LINK is not set
# CONFIG_RT_USING_VBUS is not set
# CONFIG_RT_USING_KTIME is not set

#
# RT-Thread Utestcases
Expand Down Expand Up @@ -261,6 +268,11 @@ CONFIG_RT_LIBC_TZ_DEFAULT_SEC=0
#
# CONFIG_PKG_USING_WLAN_WICED is not set
# CONFIG_PKG_USING_RW007 is not set

#
# CYW43012 WiFi
#
# CONFIG_PKG_USING_WLAN_CYW43012 is not set
# CONFIG_PKG_USING_COAP is not set
# CONFIG_PKG_USING_NOPOLL is not set
# CONFIG_PKG_USING_NETUTILS is not set
Expand Down Expand Up @@ -303,6 +315,7 @@ CONFIG_RT_LIBC_TZ_DEFAULT_SEC=0
# CONFIG_PKG_USING_NMEALIB is not set
# CONFIG_PKG_USING_PDULIB is not set
# CONFIG_PKG_USING_BTSTACK is not set
# CONFIG_PKG_USING_BT_CYW43012 is not set
# CONFIG_PKG_USING_LORAWAN_ED_STACK is not set
# CONFIG_PKG_USING_WAYZ_IOTKIT is not set
# CONFIG_PKG_USING_MAVLINK is not set
Expand All @@ -322,6 +335,7 @@ CONFIG_RT_LIBC_TZ_DEFAULT_SEC=0
# CONFIG_PKG_USING_ZFTP is not set
# CONFIG_PKG_USING_WOL is not set
# CONFIG_PKG_USING_ZEPHYR_POLLING is not set
# CONFIG_PKG_USING_MATTER_ADAPTATION_LAYER is not set

#
# security packages
Expand Down Expand Up @@ -368,7 +382,6 @@ CONFIG_RT_LIBC_TZ_DEFAULT_SEC=0
# LVGL: powerful and easy-to-use embedded GUI library
#
# CONFIG_PKG_USING_LVGL is not set
# CONFIG_PKG_USING_LITTLEVGL2RTT is not set
# CONFIG_PKG_USING_LV_MUSIC_DEMO is not set
# CONFIG_PKG_USING_GUI_GUIDER_DEMO is not set

Expand Down Expand Up @@ -443,6 +456,7 @@ CONFIG_RT_LIBC_TZ_DEFAULT_SEC=0
# CONFIG_PKG_USING_HASH_MATCH is not set
# CONFIG_PKG_USING_ARMV7M_DWT_TOOL is not set
# CONFIG_PKG_USING_VOFA_PLUS is not set
# CONFIG_PKG_USING_ZDEBUG is not set

#
# system packages
Expand Down Expand Up @@ -484,6 +498,8 @@ CONFIG_PKG_FREERTOS_USING_CONFIG_H=y
# CONFIG_PKG_FREERTOS_USING_MEMMANG is not set
CONFIG_PKG_USING_FREERTOS_WRAPPER_LATEST_VERSION=y
CONFIG_PKG_FREERTOS_WRAPPER_VER="latest"
# CONFIG_PKG_USING_LITEOS_SDK is not set
# CONFIG_PKG_USING_TZ_DATABASE is not set
# CONFIG_PKG_USING_CAIRO is not set
# CONFIG_PKG_USING_PIXMAN is not set
# CONFIG_PKG_USING_PARTITION is not set
Expand All @@ -507,6 +523,7 @@ CONFIG_PKG_FREERTOS_WRAPPER_VER="latest"
# CONFIG_PKG_USING_QBOOT is not set
# CONFIG_PKG_USING_PPOOL is not set
# CONFIG_PKG_USING_OPENAMP is not set
# CONFIG_PKG_USING_RPMSG_LITE is not set
# CONFIG_PKG_USING_LPM is not set
# CONFIG_PKG_USING_TLSF is not set
# CONFIG_PKG_USING_EVENT_RECORDER is not set
Expand All @@ -520,6 +537,8 @@ CONFIG_PKG_FREERTOS_WRAPPER_VER="latest"
# CONFIG_PKG_USING_AGILE_UPGRADE is not set
# CONFIG_PKG_USING_FLASH_BLOB is not set
# CONFIG_PKG_USING_MLIBC is not set
# CONFIG_PKG_USING_TASK_MSG_BUS is not set
# CONFIG_PKG_USING_SFDB is not set

#
# peripheral libraries and drivers
Expand Down Expand Up @@ -710,6 +729,7 @@ CONFIG_PKG_ESP_IDF_VER="latest"
# CONFIG_PKG_USING_UKAL is not set
# CONFIG_PKG_USING_DIGITALCTRL is not set
# CONFIG_PKG_USING_KISSFFT is not set
# CONFIG_PKG_USING_CMSIS_DSP is not set

#
# miscellaneous packages
Expand Down Expand Up @@ -931,6 +951,7 @@ CONFIG_PKG_ESP_IDF_VER="latest"
#
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_GFX_LIBRARY is not set
# CONFIG_PKG_USING_ARDUINO_U8G2 is not set
# CONFIG_PKG_USING_ARDUINO_TFT_ESPI is not set
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_ST7735 is not set
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SSD1306 is not set
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_ILI9341 is not set
Expand Down Expand Up @@ -1015,3 +1036,6 @@ CONFIG_RT_BSP_UART_RX_PIN=20
CONFIG_BSP_USING_GPIO=y
CONFIG_BSP_USING_UART=y
# CONFIG_BSP_USING_I2C0 is not set
# CONFIG_BSP_USING_WIFI is not set
# CONFIG_BSP_USING_BLE is not set
# CONFIG_BSP_ENABLE_GDBSTUB is not set
46 changes: 46 additions & 0 deletions bsp/ESP32_C3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,52 @@ 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) |
| 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., and we are still trying to solve it |
| BLE | Partially supported | There are currently some problems, such as running errors caused by the same `PC` and `SP` pointers after `NimBLE` is started for a period of time |
| GDBStub | Support | You can use the GDB provided by ESP-IDF by turning on the `BSP_ENABLE_GDBSTUB` switch, which will enter GDB mode after a chip error |

Note:

1. WIFI and BLE cannot be enabled at the same time. When using the BLE driver, be sure to turn off the `RT_USING_WIFI` and `LWIP` switches in `menuconfig`. In addition, due to limited personal abilities and lack of debugging equipment, there are problems with the operation of WIFI and BLE drivers. If you can solve it, please contact me [timwcx@qq.com](mailto:timwcx@qq.com), I will be grateful.

2. The BLE driver only supports `NimBLE` and is provided by the `bluetooth` component in `esp-idf`. To use the BLE driver, please refer to `bsp/ESP32_C3/packages/ESP-IDF-latest/examples/bluetooth/nimble` Sample program, please note that the `esp_timer_init()` function must be called to initialize the clock driver before calling the `NimBLE` related interface.

One way to run the BLE sample is to add the sample program to `scons` compilation and call the clock initialization program and sample program entry in `bsp/ESP32_C3/main/main.c`.

```c
int main(void) {
...
#ifdef BSP_USING_BLE
esp_timer_init(); //Call clock initialization program
app_main(); //Call the BLE sample program entry
#endif
...
}
```
3、 Regarding the use of the GDBStub component, please see [ESP-IDF official documentation on GDBStub](https://docs.espressif.com/projects/esp-idf/zh_CN/latest/esp32c3/api-guides/tools/idf- monitor.html?#gdbstub-gdb), currently I have provided a debugging script `esp32c3.gdb`, the specific usage method is as follows.
```sh
wcx@tim  ~/rt-thread/bsp/ESP32_C3   esp32 ±  sudo riscv32-esp-elf-gdb # Enter gdb debugging
GNU gdb (crosstool-NG esp-2022r1-RC1) 9.2.90.20200913-git
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-build_pc-linux-gnu --target=riscv32-esp-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) source esp32c3.gpb # Load gdb script
0x3fca8c30 in __stack_start__ ()
(gdb)
```

## Environment construction and compilation

Expand Down
47 changes: 47 additions & 0 deletions bsp/ESP32_C3/README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,53 @@
| GPIO | 支持 | |
| UART | 支持 | 使用LUATOS_ESP32C3开发板需要在UART0_TX和UART0_RX连接串口转USB芯片(如CP2102)|
| JTAG调试 | 支持 | ESP32C3采用USB方式和PC链接的开发板可以调试 |
| WIFI | 部分支持 | 目前存在一些问题,例如不能在ISR中使用`rt_mq_recive`等,还在尝试解决中 |
| BLE | 部分支持 | 目前存在一些问题,例如`NimBLE`启动一段时间后`PC``SP`指针相同导致运行错误 |
| GDBStub | 支持 | 通过开启`BSP_ENABLE_GDBSTUB`开关即可使用ESP-IDF所提供的GDB,其会在芯片出错后进入GDB模式 |

注:

1、WIFI和BLE不能同时启用,在使用BLE驱动时注意在`menuconfig`中关闭`RT_USING_WIFI``LWIP`开关。另外由于个人能力有限且缺乏调试设备,WIFI和BLE驱动运行都有问题,如果可以解决联系我[timwcx@qq.com](mailto:timwcx@qq.com),本人感激不尽。

2、BLE驱动仅支持`NimBLE`,并且由`esp-idf`中的`bluetooth`组件提供,使用BLE驱动可以参考`bsp/ESP32_C3/packages/ESP-IDF-latest/examples/bluetooth/nimble`下的样例程序,注意在调用`NimBLE`相关接口之前要调用`esp_timer_init()`函数初始化时钟驱动。

一种运行BLE样例的方案是将样例程序加入到`scons`编译并在`bsp/ESP32_C3/main/main.c`中调用时钟初始化程序和样例程序入口。

```c
int main(void) {
...
#ifdef BSP_USING_BLE
esp_timer_init(); //调用时钟初始化程序
app_main(); //调用BLE样例程序入口
#endif
...
}
```
3、关于GDBStub组件的使用,文档见[ESP-IDF关于GDBStub官方文档](https://docs.espressif.com/projects/esp-idf/zh_CN/latest/esp32c3/api-guides/tools/idf-monitor.html?#gdbstub-gdb),目前个人提供了一个调试脚本`esp32c3.gdb`,具体使用方法如下。
```sh
wcx@tim  ~/rt-thread/bsp/ESP32_C3   esp32 ±  sudo riscv32-esp-elf-gdb # 进入gdb调试
GNU gdb (crosstool-NG esp-2022r1-RC1) 9.2.90.20200913-git
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-build_pc-linux-gnu --target=riscv32-esp-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) source esp32c3.gpb # 加载gdb脚本
0x3fca8c30 in __stack_start__ ()
(gdb)
```


## 环境搭建及编译

Expand Down
Binary file modified bsp/ESP32_C3/builtin_imgs/partition-table.bin
Binary file not shown.
14 changes: 14 additions & 0 deletions bsp/ESP32_C3/drivers/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,22 @@ menu "On-chip Peripheral Drivers"
bool "Enable I2C0"
select RT_USING_I2C
default n

config BSP_USING_WIFI
bool "Enable WIFI"
select RT_USING_WIFI
default n

config BSP_USING_BLE
bool "Enable BLE"
default n

endmenu

config BSP_ENABLE_GDBSTUB
bool "Enable ESP_GDBSTUB compontent"
default n

endmenu


Loading

0 comments on commit 61f7d48

Please sign in to comment.