一、说明
AI-Talk开发板使用ESP32-C3扩展WIFI通信功能,与CSK6011A通过SPI接口通信。
与处理器的信号连接:
ESP32-C3需要烧录hosted固件,参考:AI-Talk开发板更新ESP32固件_esp32 固件-CSDN博客
二、工程
1、创建项目
进入examples/目录,执行创建项目的命令:
lisa zep create
选择 wifi_scan_ap,然后确定。此时examples目录下有一个wifi_scan_ap的工程,目录结构如下:
2、设备树
这个例程是基于csk6011a_c3_nano硬件平台,设备树文件为snap/lisa/x1/.listenai/csk-sdk-v2/csk/boards/arm/csk6011a_c3_nano/csk6011a_c3_nano.dts,但是硬件配置和AI-Talk开发板不一致。这里在项目下创建一个设备树覆盖文件,重新配置SPI、leds、gpio_keys。
在wifi_scan_ap根目录下创建boards目录,并增加csk6011a_c3_nano.overlay设备树配置文件:
wifi_scan_ap
├─boards //设备树板型文件
└─csk6011a_c3_nano.overlay //设备树配置文件
...
在csk6011a_c3_nano.overlay文件中添加spi0节点的配置,具体内容如下:
/*
* Copyright (c) 2023 Anhui(Shenzhen) Listenai Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/dt-bindings/adc/adc.h>
/ {
aliases {
csk6-exmcu = &csk6_ch32v003;
};
leds {
compatible = "gpio-leds";
green_led: led1 {
gpios = <&exgpioa 2 GPIO_ACTIVE_LOW>;
};
};
gpio_keys {
compatible = "gpio-keys";
user_button_0: button_0 {
gpios = <&gpiob 0 0>;
};
};
};
&pinctrl {
pinctrl_i2c1_scl_default: i2c1_scl_default{
pinctrls = <I2C1_SCL_GPIOB_09>;
};
pinctrl_i2c1_sda_default: i2c1_sda_default{
pinctrls = <I2C1_SDA_GPIOB_08>;
};
pinctrl_spi0_sclk_default: spi0_sclk_default {
pinctrls = <SPI0_CLK_GPIOB_05>;
};
pinctrl_spi0_miso_default: spi0_miso_default{
pinctrls = <SPI0_MISO_GPIOB_03>;
};
pinctrl_spi0_mosi_default: spi0_mosi_default {
pinctrls = <SPI0_MOSI_GPIOB_02>;
};
pinctrl_spi0_cs_default: spi0_cs_default {
pinctrls = <SPI0_CS_N_GPIOB_04>;
};
};
&spi0 {
pinctrl-0 = <&pinctrl_spi0_sclk_default &pinctrl_spi0_mosi_default &pinctrl_spi0_miso_default &pinctrl_spi0_cs_default>;
pinctrl-names = "default";
status = "okay";
wifi_module: esp32c3@0 {
compatible = "espressif,esp-hosted";
spi-max-frequency = <25000000>;
reg = <0>;
dataready-gpios = <&gpiob 6 0>;
handshake-gpios = <&gpiob 1 0>;
reset-gpios = <&exgpioc 3 0>;
status = "okay";
};
};
&i2c1 {
status = "okay";
pinctrl-0 = <&pinctrl_i2c1_scl_default &pinctrl_i2c1_sda_default>;
pinctrl-names = "default";
csk6_ch32v003: csk6_ch32v003@6c {
/**
* Please make sure that the external MCU firmware has been loaded
* SCL --> external MCU PC5
* SDA --> external MCU PC6
*/
compatible = "listenai,csk-i2c-ch32v003";
reg = <0x6c>;
status = "okay";
#address-cells = <1>;
#size-cells = <0>;
/* CH32V003-GPIOA */
exgpioa: gpio@0 {
compatible = "listenai,csk-gpio-ch32003-port";
reg = <0x00>;
status = "okay";
ngpios = <8>;
#gpio-cells = <2>;
gpio-controller;
pin_mask = <0x00>;
};
/* CH32V003-GPIOB */
exgpiob: gpio@1 {
compatible = "listenai,csk-gpio-ch32003-port";
reg = <0x01>;
status = "okay";
ngpios = <8>;
#gpio-cells = <2>;
gpio-controller;
pin_mask = <0x00>;
};
/* CH32V003-GPIOC */
exgpioc: gpio@2 {
compatible = "listenai,csk-gpio-ch32003-port";
reg = <0x02>;
status = "okay";
ngpios = <8>;
#gpio-cells = <2>;
gpio-controller;
pin_mask = <0x00>;
};
/* CH32V003-GPIOD */
exgpiod: gpio@3 {
compatible = "listenai,csk-gpio-ch32003-port";
reg = <0x03>;
status = "okay";
ngpios = <8>;
#gpio-cells = <2>;
gpio-controller;
pin_mask = <0x00>;
};
exadc: adc@4 {
/**
* external adc channel map
*
* CH0 --> PA2
* CH1 --> PA1
* CH2 --> PC4
* CH3 --> PD2
* CH4 --> PD3
* CH5 --> PD5
* CH6 --> PD6
* CH7 --> PD4
*
*/
compatible = "listenai,csk-adc-ch32v003";
reg = <0x4>;
status = "okay";
#io-channel-cells = <1>;
#address-cells = <1>;
#size-cells = <0>;
channel@2 {
reg = <2>;
zephyr,gain = "ADC_GAIN_1";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,resolution = <10>;
};
};
expwm: pwm-controller@5 {
compatible = "listenai,csk-ch32v003-pwm";
reg = <0x5>;
status = "okay";
clock-prescaler = <480>;
clock-frequency = <48000000>;
#pwm-cells = <4>;
};
};
};
由于snap/lisa/x1/.listenai/csk-sdk-v2/csk/boards/arm/csk6011a_nano/csk6011a_c3_nano.dts文件中定义了wifi_module,与csk6011a_c3_nano.overlay中定义的wifi_module冲突了,将csk6011a_c3_nano.dts中wifi_module相关的注释屏蔽掉:
&spi1 {
pinctrl-0 = <&pinctrl_spi1_sclk_default &pinctrl_spi1_mosi_default &pinctrl_spi1_miso_default &pinctrl_spi1_cs_default>;
pinctrl-names = "default";
status = "okay";
// wifi_module: esp32c3@0 {
// compatible = "espressif,esp-hosted";
// spi-max-frequency = <25000000>;
// reg = <0>;
// dataready-gpios = <&gpioa 11 0>;
// handshake-gpios = <&gpioa 16 0>;
// reset-gpios = <&gpioa 10 0>;
// status = "okay";
// };
};
3、配置文件
prj.conf文件打开GPIO_CSK6_CH32V003的配置:
CONFIG_GPIO_CSK6_CH32V003=y
4、代码
代码不做修改。
三、编译
在wifi_scan_ap目录下执行编译命令:
lisa zep build -b csk6011a_c3_nano
编译生成的固件:examples/wifi_scan_ap/build/zephyr/zephyr.bin
四、烧录
固件的烧录及查看运行日志参照:AI-Talk开发板CSK6固件烧录-CSDN博客
五、运行
连接AI-Talk开发板的调试接口,PC端运行终端软件可以接收到如下日志:
[00:00:00.000,000] <inf> csk6_spi: SPI REG ADDR:0x45500000
[00:00:00.000,000] <inf> csk6_spi: SPI REG ADDR:0x45400000
[00:00:00.000,000] <inf> csk6_exmcu_i2c: exmcu addr:0x6C
[00:00:00.040,000] <inf> csk6_exmcu_i2c: exmcu info, chip type:ch32v003, ver:1.3
*** Booting Zephyr OS build zephyr-v3.4.0-46-gb8fcc47cc045 ***
*** ListenAI CSK SDK Version: 2.0.0.0-f097b7f9df ***
[00:00:00.084,000] <dbg> csk_wifi: wifi_obj_set_sm: (97)STA_SM: current[WIFI_SM_ON_STARTUP], next[WIFI_SM_ON_STARTUP]
Firmware Version: 0.4, commit: 77c953e
App EVENT: ESP INIT
[00:00:02.654,000] <dbg> csk_wifi: wifi_obj_set_sm: (97)STA_SM: current[WIFI_SM_ON_STARTUP], next[WIFI_SM_STARTUP_DONE]
[00:00:02.665,000] <dbg> csk_wifi: wifi_obj_set_sm: (97)STA_SM: current[WIFI_SM_STARTUP_DONE], next[WIFI_SM_STA_ON_SCAN]
[00:00:04.555,000] <dbg> csk_wifi: wifi_obj_set_sm: (97)STA_SM: current[WIFI_SM_STA_ON_SCAN], next[WIFI_SM_STA_SCAN_DONE]
[00:00:04.555,000] <dbg> csk_wifi: wifi_command_handler: wifi_scan_list scan_list.count = 11
scan done
--------------------------------------------Scan AP list---------------------------------------------
|ssid: CMCC-2106 | bssid: 90:76:9f:23:a3:58 | channel: 1 | rssi: -57|
|ssid: | bssid: 92:76:9f:43:a3:58 | channel: 1 | rssi: -58|
|ssid: CMCC-5EnZ | bssid: 48:ca:c6:82:5f:84 | channel: 11 | rssi: -68|
|ssid: 1-1-2206 | bssid: 78:60:5b:f7:bc:ca | channel: 11 | rssi: -71|
|ssid: | bssid: 82:60:5b:f7:bc:ca | channel: 11 | rssi: -71|
|ssid: CMCC-QzDF | bssid: 94:28:6f:bb:10:9f | channel: 6 | rssi: -78|
|ssid: | bssid: 96:28:6f:9b:10:9f | channel: 6 | rssi: -78|
|ssid: TP-LINK_5031 | bssid: 4c:10:d5:5a:50:31 | channel: 1 | rssi: -81|
|ssid: TPGuest_5031 | bssid: 4e:10:d5:5b:50:31 | channel: 1 | rssi: -81|
|ssid: Xiaomi_B953 | bssid: a4:39:b3:89:b9:54 | channel: 1 | rssi: -82|
|ssid: | bssid: 96:28:6f:1b:3e:cb | channel: 6 | rssi: -85|
-----------------------------------------------------------------------------------------------------
[00:00:05.555,000] <dbg> csk_wifi: wifi_obj_set_sm: (97)STA_SM: current[WIFI_SM_STA_SCAN_DONE], next[WIFI_SM_STA_ON_SCAN]
[00:00:07.444,000] <dbg> csk_wifi: wifi_obj_set_sm: (97)STA_SM: current[WIFI_SM_STA_ON_SCAN], next[WIFI_SM_STA_SCAN_DONE]
[00:00:07.444,000] <dbg> csk_wifi: wifi_command_handler: wifi_scan_list scan_list.count = 11
scan done
--------------------------------------------Scan AP list---------------------------------------------
|ssid: CMCC-2106 | bssid: 90:76:9f:23:a3:58 | channel: 1 | rssi: -58|
|ssid: | bssid: 92:76:9f:43:a3:58 | channel: 1 | rssi: -58|
|ssid: | bssid: 82:60:5b:f7:bc:ca | channel: 11 | rssi: -71|
|ssid: | bssid: 96:28:6f:9b:10:9f | channel: 6 | rssi: -79|
|ssid: TPGuest_5031 | bssid: 4e:10:d5:5b:50:31 | channel: 1 | rssi: -81|
|ssid: Xiaomi_B953 | bssid: a4:39:b3:89:b9:54 | channel: 1 | rssi: -83|
|ssid: CMCC-dGN7 | bssid: 94:28:6f:1b:3e:cb | channel: 6 | rssi: -84|
|ssid: | bssid: 96:28:6f:1b:3e:cb | channel: 6 | rssi: -84|
|ssid: | bssid: f6:f6:47:91:c3:7a | channel: 6 | rssi: -92|
|ssid: CMCC-Uw9e | bssid: 80:3e:48:02:81:6c | channel: 11 | rssi: -92|
|ssid: CMCC-2901 | bssid: f4:d9:c6:00:6f:6a | channel: 1 | rssi: -93|
-----------------------------------------------------------------------------------------------------
会不断的扫描周围的路由器,并且显示信号强度。
六、遇到问题
由于焊接错误导致CSK6011A的19脚(RST)和20脚(GPIOB_05)短路,造成只要配置SPI0相关的GPIOB_02、GPIOB_03、GPIOB_04、GPIOB_05,芯片就无法启动,并且VDD_CORE的电压为0.54V,正常应该为0.95V。