安信可 Ai-WB2 系列模组二次开发指南

AiThinker WB2 Development Guide 是由安信可官方推出的针对 Ai-WB2 系列模组二次开发教程,以及API接口说明。

快速入门

API参考

API指南

快速入门

API参考

API指南

联系我们

  1. 样品购买: https://anxinke.taobao.com

  2. 样品资料: https://docs.ai-thinker.com

  3. 商务合作: 0755-29162996

  4. 公司地址: 深圳市宝安区西乡固戍华丰智慧创新港C栋403、408~410

快速入门

本文档旨在指导用户搭建 Ai-WB2 系列硬件开发的软件环境,通过一个简单的示例展示如何使用安信可提供的代码框架进行编译、下载固件至开发板等步骤。

Ai-WB2系列模组

  • 2.4 GHz Wi-Fi

  • 高性能 32 位 RISC-V 单核处理器

  • 多种外设

  • 支持 IEEE 802.11 b/g/n 协议

  • Wi-Fi安全支持WPS/WEP/WPA/WPA2 Personal/WPA2 Enterprise/WPA3

  • 支持20MHz带宽,最高速率 72.2 Mbps

  • Bluetooth 低能耗5.0,Bluetooth Mesh

  • 支持 Station + BLE模式、Station + SoftAP + BLE模式

  • 支持32-bit RISC CPU,276KB RAM

  • 安全启动,支持使用ECC-256签名的镜像

  • 支持QSPI/SPI Flash即时AES解密(OTFAD),支持AES 128 CTR模式

  • 支持AES 128/192/256位加密引擎

  • 支持SHA-1/224/256

  • 支持真实随机数发生器 (TRNG)

  • 公钥加速器 (PKA), 支持大数基本运算, 软件提供签名,验证等应用程序接口

  • 支持SDIO,SPI,UART,I2C,IR remote,PWM,ADC,DAC,PIR,GPIO等

  • 集成 Wi-Fi MAC/BB/RF/PA/LNA/BT

  • 支持多种休眠模式,深度睡眠电流12μA

  • 通用AT指令可快速上手

  • 支持二次开发,集成了Windows、Linux开发环境

Ai-WB2系列环境搭建

1.Linux环境搭建请参考: Ai-WB2系列模组linux开发环境搭建

2.window环境搭建请参考: Ai-WB2系列的eclipes搭建环境教程

Ai-WB2系列烧录指导

烧录指导参考: Ai-WB2系列模组、开发板烧录指导

示例参考

例程参考

这里汇集了Ai-WB2系列SDK中的例程
get-started示例
安信可 get-started示例

hello world Example
Example Output

Starts a FreeRTOS task to print “Hello World”. As you run the example, you will see the log :

 Booting Ai-WB2 Modules...
 ------------------------------------------------------------
 RISC-V Core Feature:RV32-ACFIMX
 Build Version: release_bl_iot_sdk_1.6.38
 Build Date: Oct  8 2022
 Build Time: 14:51:34
 ------------------------------------------------------------
blog init set power on level 2, 2, 2.
[IRQ] Clearing and Disable all the pending IRQ...
[         0][INFO: hal_boot2.c: 282] [HAL] [BOOT2] Active Partition[0] consumed 596 Bytes
[         0][INFO: hal_boot2.c:  82] ======= PtTable_Config @0x4200d168=======
[         0][INFO: hal_boot2.c:  83] magicCode 0x54504642; version 0x0000; entryCnt 7; age 0; crc32 0x12DF9A26
[         0][INFO: hal_boot2.c:  89] idx  type device activeIndex     name   Address[0]  Address[1]  Length[0]   Length[1]   age
[         0][INFO: hal_boot2.c:  91] [00]  00     0         0            FW  0x00010000  0x000e8000  0x000d8000  0x00088000  0
[         0][INFO: hal_boot2.c:  91] [01]  02     0         0           mfg  0x00170000  0x00000000  0x00032000  0x00000000  0
[         0][INFO: hal_boot2.c:  91] [02]  03     0         0         media  0x001a2000  0x00000000  0x00047000  0x00000000  0
[         0][INFO: hal_boot2.c:  91] [03]  04     0         0           PSM  0x001e9000  0x00000000  0x00008000  0x00000000  0
[         0][INFO: hal_boot2.c:  91] [04]  05     0         0           KEY  0x001f1000  0x00000000  0x00002000  0x00000000  0
[         0][INFO: hal_boot2.c:  91] [05]  06     0         0          DATA  0x001f3000  0x00000000  0x00005000  0x00000000  0
[         0][INFO: hal_boot2.c:  91] [06]  07     0         0       factory  0x001f8000  0x00000000  0x00007000  0x00000000  0
[         0][INFO: bl_flash.c: 391] ======= FlashCfg magiccode @0x42049c18=======
[         0][INFO: bl_flash.c: 392] mid               0x5E
[         0][INFO: bl_flash.c: 393] clkDelay  0x1
[         0][INFO: bl_flash.c: 394] clkInvert         0x1
[         0][INFO: bl_flash.c: 395] sector size       4KBytes
[         0][INFO: bl_flash.c: 396] page size 256Bytes
[         0][INFO: bl_flash.c: 397] ---------------------------------------------------------------
[         0][INFO: hal_board.c:1249] [MAIN] [BOARD] [FLASH] addr from partition is 001f8000, ret is 0
[         0][INFO: hal_board.c:1257] [MAIN] [BOARD] [XIP] addr from partition is 231e7000, ret is 0
Hello World.
Restarting in 10 seconds...
Restarting in 9 seconds...
Restarting in 8 seconds...
Restarting in 7 seconds...
Restarting in 6 seconds...
Restarting in 5 seconds...
Restarting in 4 seconds...
Restarting in 3 seconds...
Restarting in 2 seconds...
Restarting in 1 seconds...
Restarting in 0 seconds...
```
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

WiFi示例
安信可 softAP静态IP示例

Wi-Fi SoftAP custom IP Setting Example
Introduction

This example shows how to use the Wi-Fi Station functionality of the Wi-Fi driver of WB2 serial development board and set custom IP address.

How to use example

Open the project,set AP_SSID,AP_PASSWORD and custom IP address at line 3,line 4 and line 7. For example :

#define AP_SSID "Ai-WB2"
#define AP_PASSWORD "12345678"
#define AP_IP "192.168.100.1"

Finally,running command below to compile project on ubuntu.

make -j8

Burn firmware

Running command below to burn firmware after connecting WB2 serial development board to ubuntu.

make flash p=/dev/ttyUSB0 b=921600

Debug

Open the serial port debugging assistant software,select the COM port of the development board,and press the reset button on development board to run the program finally.

Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

简介

本例程主要介绍如何实现WB2系列开发板AP模式下设置自定义IP。

如何使用该例程

打开项目,在第3、4以及第7行设置AP_SSID、AP_PASSWORD以及自定义IP地址 如下:

#define AP_SSID "Ai-WB2"
#define AP_PASSWORD "12345678"
#define AP_IP "192.168.100.1"

最后,在ubuntu下运行以下指令编译工程。

make -j8

烧录固件

将WB2开发板连接ubuntu之后,运行以下指令烧录固件。

make flash p=/dev/ttyUSB0 b=921600

调试

打开“串口调试助手软件”,选择并打开开发板的COM口,最后按下复位键启动程序。

问题排除

若有任何问题,请在github中提交一个[issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues),我们会尽快回复。

安信可 Iperf Example示例

Introduction

This example shows how to test Ai-WB2 serial module’s network throughput using Iperf.

How to use example

Open the project,set WIFI_SSID,WIFI_PASSWORD at line 3,line 4 in wifi_execute.c file. For example :

#define STA_SSID "Ai-WB2-x"
#define STA_PASSWORD "12345678"

Finally,running command below to compile project on ubuntu.

make -j8

Burn firmware

Running command below to burn firmware after connecting WB2 serial development board to ubuntu.

make flash p=/dev/ttyUSB0 b=921600

Debug
Preparation of iperf tool

Get the installation package of the iperf tool (version: 2.0.9) from iperf download link

Get the “iperf-2.0.9-win32” folder by unzipping the ” iperf-2.0.9-win32.zip ” compressed package. Go to this folder directory and run ” cmd ” command to open the command line window.

Preparation of serial tool

Get the serial tool from Serial tool download link

Unzip the serial tool compressed package. Open the serial port debugging assistant software,select the COM port of the development board,and press the reset button on development board to run the program.

Debug

running “wifi_sta_connect SSID PASSWORD” command on module through serial tool to connect to WiFi, as below:(PC need to connect to the same WiFi)

_images/WB2_WIFI.png

1)setting module as UDP client and PC as server

running “iperf.exe -s -u -i 1” command on PC to setup UDP server, as below:

_images/PC_UDP_SERVER.png

running “ipu 192.168.43.8” command on module through serial tool to connect to UDP server, as below: (“192.168.43.8” is server IP)

_images/WB2_UDP_CLIENT.png

2)setting module as TCP client and PC as server

running “iperf.exe -s -i 1” command on PC to setup TCP server, as below:

_images/PC_TCP_SERVER.png

running “ipc 192.168.43.8” command on module through serial tool to connect to TCP server, as below: (“192.168.43.8” is server IP)

_images/WB2_TCP_CLIENT.png

3)setting module as UDP server and PC as client

running “ipus” command on module through serial tool to setup UDP server, as below:

_images/WB2_UDP_SERVER.png

running “iperf.exe -u -c 192.168.43.27 -t 360 -i 1” command on PC to connect to UDP server, as below: (“192.168.43.27” is server IP)

_images/PC_UDP_CLIENT.png

4)setting module as TCP server and PC as client

running “ips” command on module through serial tool to setup TCP server, as below:

_images/WB2_TCP_SERVER.png

running “iperf.exe -c 192.168.43.27 -t 360 -i 1” command on PC to connect to TCP server, as below: (“192.168.43.27” is server IP)

_images/PC_TCP_CLIENT.png
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

简介

本例程主要介绍如何通过iperf测试Ai-WB2系列模组的吞吐量。

如何使用该例程

打开项目,在 “wifi_execute.c” 文件第3行以及第4行设置指定wifi的账号和密码,STA_SSID、STA_PASSWORD,如下:

#define STA_SSID "Ai-WB2-x"
#define STA_PASSWORD "12345678"

最后,在ubuntu下运行以下指令编译工程。

make -j8

烧录固件

将WB2开发板连接ubuntu之后,运行以下指令烧录固件。

make flash p=/dev/ttyUSB0 b=921600

调试
iperf工具的准备

从iperf下载链接 iperf download link 中获取iperf(2.0.9版本)工具;

解压“iperf-2.0.9-win32.zip”压缩包,获取“iperf-2.0.9-win32”文件夹,进入该文件夹下运行cmd指令,打开指令运行窗口;

串口工具的准备

从串口工具下载链接 Serial tool download link 中获取串口工具;

解压串口工具包,打开“串口调试助手软件”,选择并打开开发板的COM口,按下复位键启动程序;

联调

通过运行指令“wifi_sta_connect SSID PASSWORD”连接指定wifi。(调试用PC机需连接同一个WIFI)

_images/WB2_WIFI.png

1)在指令运行终端运行“iperf.exe -s -u -i 1”指令创建UDP服务器,如下:

_images/PC_UDP_SERVER.png

在串口助手中,运行“ipu 192.168.43.8”指令连接UDP服务器,如下:(其中“192.168.43.8”为服务器的IP地址)

_images/WB2_UDP_CLIENT.png

2)在指令运行终端中运行“iperf.exe -s -i 1”指令创建TCP服务器,如下:

_images/PC_TCP_SERVER.png

在串口助手中,运行“ipc 192.168.43.8”指令连接TCP服务器,如下:(其中“192.168.43.8”为服务器的IP地址)

_images/WB2_TCP_CLIENT.png

3)在串口助手中,运行“ipus”指令创建UDP服务器,如下:

_images/PC_UDP_CLIENT.png

4)在串口助手中,运行“ips”指令创建TCP服务器,如下:

_images/WB2_TCP_SERVER.png

在指令运行终端运行“iperf.exe -c 192.168.43.27 -t 360 -i 1”指令连接TCP服务器,如下:(其中“192.168.43.27”为服务器的IP地址)

_images/PC_TCP_CLIENT.png
问题排除

若有任何问题,请在github中提交一个[issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues),我们会尽快回复。

安信可 Scan 示例

WiFi scan example
Example Output
(other log)...
INFO (487)[main.c:  47] [APP] [EVT] INIT DONE 487
[BL] Initi Wi-Fi with MAC #### 7C:B9:4C:1D:CC:9F ####
hostname: Bouffalolab_BL602-1dcc9f
[WF] country code CN used, num of channel 13
-----------------------------------------------------
[IPC] [TX] Low level size 204, driver size 100, total size 304
Enable BMX IRQ
[WF] [KEY] [CFG] nVAP is 2, endidx 12, startidx 8
td_init
td_reset idx=0
td_reset idx=1
[version] lmac 5.4.0.0
[version] version_machw_1 000055FB
[version] version_machw_2 000001B3
[version] version_phy_1 00822111
[version] version_phy_2 00000000
[version] features 001089DF
[ME] HT supp 1, VHT supp 0
[WF] country code CN used, num of channel 13
[WF][SM] reload tsen
[WF][SM] Exiting ifaceDown state
[WF][SM] State Action ###ifaceDown### --->>> ###idle###
[WF][SM] Entering idle state
INFO (562)[main.c:  53] [APP] [EVT] MGMR DONE 562
------>>>>>> Scan CMD
[WIFI] [IND] SCAN Done
wifi_mgmr_scan_complete_callback: scan complete
INFO (3832)[main.c:  62] [APP] [EVT] SCAN Done 3832
cached scan list
****************************************************************************************************
index[00]: channel 13, bssid 76:50:4E:5A:94:22, rssi -73, ppm abs:rel   0 :   0, auth             WPA2-PSK, cipher:         AES, SSID ChinaNet-WiFi5-9422
index[01]: channel 13, bssid 76:50:4E:1A:94:22, rssi -73, ppm abs:rel   0 :   0, auth             WPA2-PSK, cipher:         AES, SSID STTIAN
index[02]: channel 13, bssid 48:A0:F8:45:E3:7D, rssi -76, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:         AES, SSID ChinaNet-nRnS
index[03]: channel 13, bssid 50:3A:A0:C5:C2:C0, rssi -69, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:         AES, SSID MERCURY_JLLK
index[04]: channel 11, bssid 78:44:FD:DB:EF:60, rssi -58, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:         AES, SSID 509509
index[05]: channel 11, bssid F8:8C:21:B4:40:6C, rssi -83, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:    TKIP/AES, SSID AXK
index[06]: channel 13, bssid E2:F8:8A:A9:FC:4F, rssi -43, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:    TKIP/AES, SSID HUAWEI
index[07]: channel 11, bssid 90:DE:80:58:B0:11, rssi -59, ppm abs:rel   0 :   0, auth             WPA2-PSK, cipher:         AES, SSID MSI
index[08]: channel 11, bssid A0:DF:15:AF:4E:D8, rssi -66, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:    TKIP/AES, SSID ChinaNet-SACn
index[09]: channel 11, bssid 2C:C5:46:A8:47:FC, rssi -79, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:    TKIP/AES, SSID Galaxy Cloud
index[10]: channel 11, bssid 54:A7:03:3F:F3:E2, rssi -55, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:    TKIP/AES, SSID Aithinker-visitor
index[11]: channel 11, bssid C8:BF:4C:30:00:B9, rssi -74, ppm abs:rel   0 :   0, auth             WPA2-PSK, cipher:         AES, SSID redmi-xin
index[12]: channel 11, bssid F8:8C:21:B4:2D:88, rssi -72, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:    TKIP/AES, SSID AXK
index[13]: channel 10, bssid A8:02:DB:B3:02:24, rssi -60, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:         AES, SSID ChinaNet-402
index[14]: channel 11, bssid EC:41:18:4D:C1:50, rssi -57, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:    TKIP/AES, SSID Meet
index[15]: channel 11, bssid 1E:BC:5A:8F:66:E0, rssi -54, ppm abs:rel   0 :   0, auth             WPA2-PSK, cipher:         AES, SSID 还可以_guest
index[16]: channel 11, bssid CA:E2:65:59:A9:ED, rssi -68, ppm abs:rel   0 :   0, auth             WPA2-PSK, cipher:         AES, SSID JOHHN
index[17]: channel 11, bssid F8:8C:21:02:51:ED, rssi -55, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:         AES, SSID MEETING
index[18]: channel 11, bssid 94:D9:B3:20:3F:7F, rssi -50, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:         AES, SSID 001
index[19]: channel 11, bssid F8:8C:21:B4:3F:61, rssi -59, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:    TKIP/AES, SSID AXK
index[20]: channel 11, bssid 18:BC:5A:8F:66:E0, rssi -54, ppm abs:rel   0 :   0, auth             WPA2-PSK, cipher:         AES, SSID 还可以
index[21]: channel 11, bssid EC:9C:32:2E:E6:13, rssi -46, ppm abs:rel   0 :   0, auth             WPA2-PSK, cipher:         AES, SSID HAP_D96015182
index[22]: channel 10, bssid B4:BA:12:27:B4:88, rssi -62, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:    TKIP/AES, SSID CMCC-zpDL
index[23]: channel 09, bssid CC:08:FB:EB:F1:28, rssi -49, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:         AES, SSID ZLM
index[24]: channel 10, bssid 90:94:97:6E:5C:40, rssi -45, ppm abs:rel   0 :   0, auth             WPA2-PSK, cipher:         AES, SSID Rita
index[25]: channel 09, bssid 28:93:7D:21:A0:03, rssi -76, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:    TKIP/AES, SSID ChinaNet-AA4V
index[26]: channel 09, bssid EC:41:18:4F:FE:D5, rssi -46, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:    TKIP/AES, SSID zifeng
index[27]: channel 08, bssid 98:A9:42:02:F9:0A, rssi -63, ppm abs:rel   0 :   0, auth             WPA2-PSK, cipher:         AES, SSID CMCC-F9a9
index[28]: channel 06, bssid 58:41:20:3F:5E:14, rssi -67, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:         AES, SSID 美迪电商
index[29]: channel 01, bssid F8:8C:21:B4:4A:38, rssi -43, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:    TKIP/AES, SSID AXK
index[30]: channel 06, bssid 3A:1A:52:55:F4:79, rssi -76, ppm abs:rel   0 :   0, auth             WPA2-PSK, cipher:         AES, SSID DIRECT-52557479
index[31]: channel 08, bssid B8:F8:83:0D:9E:2A, rssi -37, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:         AES, SSID FAE@Seahi
index[32]: channel 06, bssid 64:64:4A:B3:5F:CA, rssi -43, ppm abs:rel   0 :   0, auth             WPA2-PSK, cipher:         AES, SSID Alive
index[33]: channel 06, bssid 00:9A:CD:7D:C9:A8, rssi -51, ppm abs:rel   0 :   0, auth             WPA2-PSK, cipher:         AES, SSID PADS 9.5
index[34]: channel 06, bssid EC:41:18:09:E0:CD, rssi -50, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:    TKIP/AES, SSID zifeng02
index[35]: channel 06, bssid 14:DE:39:06:86:E4, rssi -33, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:    TKIP/AES, SSID aithinker123
index[36]: channel 06, bssid 54:48:F6:B2:8B:B6, rssi -44, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:    TKIP/AES, SSID TEST1
index[37]: channel 06, bssid 9C:9D:7E:59:3E:83, rssi -34, ppm abs:rel   0 :   0, auth             WPA2-PSK, cipher:         AES, SSID AIOT@FAE
index[38]: channel 02, bssid F4:2A:7D:E2:66:58, rssi -62, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:         AES, SSID 402
index[39]: channel 01, bssid DC:A3:33:AA:04:9A, rssi -57, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:    TKIP/AES, SSID ChinaNet-EPt9
index[40]: channel 01, bssid F0:92:B4:8C:BC:A1, rssi -79, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:    TKIP/AES, SSID ChinaNet-rk7Z
index[41]: channel 01, bssid 7A:D6:CB:79:D9:53, rssi -65, ppm abs:rel   0 :   0, auth                 Open, cipher:        NONE, SSID H3C_GUEST
index[42]: channel 01, bssid CA:50:E9:8B:5A:0C, rssi -59, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:    TKIP/AES, SSID ChinaNet-uL5X
index[43]: channel 01, bssid F0:92:B4:85:8A:A1, rssi -72, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:    TKIP/AES, SSID ChinaNet-NK9Z
index[44]: channel 01, bssid 54:75:95:4F:74:5E, rssi -50, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:         AES, SSID TP-LINK_745E
index[45]: channel 01, bssid 7C:B9:4C:1D:BF:41, rssi -65, ppm abs:rel   0 :   0, auth                 Open, cipher:        NONE, SSID axk_1dbf41
index[46]: channel 01, bssid 74:D6:CB:79:D9:53, rssi -73, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:         AES, SSID jiudao103
index[47]: channel 01, bssid F4:83:CD:A0:1B:9D, rssi -62, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:         AES, SSID 弘正商务
index[48]: channel 03, bssid 48:A0:F8:46:B2:BD, rssi -56, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:         AES, SSID ChinaNet-HHZm
index[49]: channel 03, bssid B4:CF:E0:A1:C2:89, rssi -62, ppm abs:rel   0 :   0, auth     WPA2-PSK/WPA-PSK, cipher:    TKIP/AES, SSID ChinaNet-2RAy
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

安信可 smartconfig 示例

smartconfig example

if you want usb smartconfig,plese call

wifi_smartconfig_v1_start();

if you want usb airkiss ,plese call

wifi_airkiss_v1_start();

App and mini program souce code: https://docs.ai-thinker.com/esp8266/smartconfig

Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

安信可 softAP示例

WiFi soft AP Example
Configuration before use

The default configuration of WiFi soft routine is ssid=”ai thinker”, password=”12345678”. You can modify ssid and password according to the following macro definitions:

#define AP_SSID "ai-thinker"
#define AP_PWD "12345678"

If you need to modify the IP address of the soft AP, you can use the written function to directly modify it.

/**
* @brief wifi_ap_ip_set
*      Set the IP address of soft AP
* @param ip_addr IPV4 addr
* @param netmask netmask
* @param gw DNS
*/
wifi_ap_ip_set(char* ip_addr, char* netmask, char* gw)
build and download

Compile with instructions and download firmware.

make -j16 flash p=/dev/ttyUSB0 b=921600

j16:j16 is the number of cores in the system

Example Output
(other log)...
[       456][INFO: main.c: 105] <<<<<<<<< startting soft ap <<<<<<<<<<<
[lwip] netif status callback
IP: 192.168.11.1
MK: 255.255.255.0
GW: 0.0.0.0
[WF][SM] Conf max sta supported 4...
[WF] MM_ADD_IF_REQ Sending: AP
td_start idx=0
[WF] MM_ADD_IF_REQ Done
[WF] vif_index from LAMC is 0
[lwip] netif status callback
IP: 192.168.169.1
MK: 255.255.255.0
GW: 0.0.0.0
[DHCP] ip_start: [192.168.169.2]
[DHCP] ip_start: [192.168.169.254]
[WF][SM] start AP with ssid ai-thinker;
[WF][SM]               pwd  12345678;
[WF][SM]               channel  6;
[WF] APM_START_REQ Sending with vif_index 0
[WF] received APM Start apm_start_req_handler:74
[WF] return with other handler
[WF] APM_START_REQ Done
[WF] status is 00
[WF] vif_idx is 00
[WF] ch_idx is 00
[WF] bcmc_idx is 05
[WF][SM] stateGlobalGuard_AP: AP iface has started!
[lwip] netif status callback
IP: 192.168.169.1
MK: 255.255.255.0
GW: 0.0.0.0
[WF][SM] stateGlobalGuard_AP: AP iface has started!
[lwip] netif status callback
IP: 192.168.4.1
MK: 255.255.255.0
GW: 0.0.0.0
[WF][SM] stateGlobalGuard_AP: AP iface has started!
[lwip] netif status callback
IP: 192.168.4.1
MK: 255.255.255.0
GW: 8.8.8.8
[WF][SM] stateGlobalGuard_AP: AP iface has started!
[      1152][INFO: main.c:  78] [softAP]:SSID:ai-thinker,PASSWORD:12345678,IP addr:192.168.4.1
[      1160][INFO: main.c: 109] <<<<<<<<< startt soft ap OK<<<<<<<<<<<
...
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

安信可 Station静态IP示例

Wi-Fi Station Static IP Setting Example
Introduction

This example shows how to use the Wi-Fi Station functionality of the Wi-Fi driver of WB2 serial development board and set custom IP address.

How to use example

Open the project,set WIFI_SSID,WIFI_PASSWORD and target IP address at line 3,line 4 and line 7. For example :

#define STA_SSID "Ai-WB2-x"
#define STA_PASSWORD "12345678"
#define STA_STATIC_IP "192.168.43.133"

Finally,running command below to compile project on ubuntu.

make -j8

Notice! The network segment of designated AP should be known before setting the IP address.

Burn firmware

Running command below to burn firmware after connecting WB2 serial development board to ubuntu.

make flash p=/dev/ttyUSB0 b=921600

Debug

Open the serial port debugging assistant software,select the COM port of the development board,and press the reset button on development board to run the program finally.

Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

简介

本例程主要介绍如何实现WB2系列开发板STA模式下设置静态IP地址。

如何使用该例程

打开项目,在第3、4以及第7行设置WIFI_SSID、WIFI_PASSWORD以及静态IP地址 如下:

#define STA_SSID "Ai-WB2-x"
#define STA_PASSWORD "12345678"
#define STA_STATIC_IP "192.168.43.133"

最后,在ubuntu下运行以下指令编译工程。

make -j8

烧录固件

将WB2开发板连接ubuntu之后,运行以下指令烧录固件。

make flash p=/dev/ttyUSB0 b=921600

调试

打开“串口调试助手软件”,选择并打开开发板的COM口,最后按下复位键启动程序。

问题排除

若有任何问题,请在github中提交一个[issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues),我们会尽快回复。

安信可 station示例

WiFi station example
Configuration project

By default, the connected wifi AP in this project is ssid=”ssid” and password=”password”. You need to modify it according to your own AP configuration.

#define ROUTER_SSID "ssid"
#define ROUTER_PWD "password"
Build and download

Compile with instructions and download firmware.

make -j16 flash p=/dev/ttyUSB0 b=921600

j16:j16 is the number of cores in the system

Example Output
Connection succeeded
(other log)...
[WF][SM] State Action ###connecting### --->>> ###wifiConnected_ipObtaining###
[WF][PF] Using profile, idx is @0
[WF][SM] Entering wifiConnected_ipObtaining state
[WF][SM] DHCP Starting...0x420148dc
[APP] [EVT] connected 4530
-----------------> AABA Request:
A-MSDU: Permitted
Block Ack Policy: Immediate Block Ack
TID: 0
Number of Buffers: 64
-----------------> AABA Response:
A-MSDU: Not Permitted
Block Ack Policy: Immediate Block Ack
TID: 0
Number of Buffers: 8
ssn: 0
timeout: 0
tid 0
IP:192.168.1.105
MASK: 255.255.255.0
Gateway: 192.168.1.1
[lwip] netif status callback
IP: 192.168.1.105
MK: 255.255.255.0
GW: 192.168.1.1
[WF][SM] Exiting wifiConnected_ipObtaining state
[WF][SM] State Action ###wifiConnected_ipObtaining### --->>> ###wifiConnected_IPOK###
[APP] [EVT] GOT IP 5593
[SYS] Memory left is 156528 Bytes
Connection failed
(other log)...
===end sm_get_bss_params===
[WF][SM] Entering connecting state
[APP] [EVT] Reconnect 38121
[APP] [EVT] Connecting 38123
===start sm_get_bss_params===
bssid[0] = 0xffff
bssid[1] = 0xffff
bssid[2] = 0xffff
search ssid = ssid
result ssid index = -1
===end sm_get_bss_params===
ind ix 0x4201d19c, chan_ctxt is 0x00000000
connect failure, ssid = ssid, index = -1
[RX] Connection Status
[RX]   status_code 12
[RX]   reason_code 65535
[RX]   connect result: SSID error, scan no bssid and channel
[RX]   MAC 00:00:00:00:00:00
[RX]   vif_idx 0
[RX]   ap_idx 255
[RX]   ch_idx 0
[RX]   qos 0
[RX]   acm 0
[RX]   assoc_req_ie_len 0
[RX]   assoc_rsp_ie_len 0
[RX]   aid 0
[RX]   band 0
[RX]   center_freq 0
[RX]   width 0
[RX]   center_freq1 0
[RX]   center_freq2 0
[WF][SM] Exiting connecting state
[WF][SM] State Action ###connecting### --->>> ###disconnect###
[WF][SM] Entering disconnect state
[APP] [EVT] disconnect 41444

**If there is a connection error, this log message will be sent repeatedly**
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

storage示例
安信可 storage示例
例程参考
easyflash示例
安信可 EasyFlash示例
EasyFlash Example
Example Output

Starts a FreeRTOS task to print “easyflash write/read demo”. As you run the example, you will see the log :

Booting Ai-WB2 Modules...
------------------------------------------------------------
RISC-V Core Feature:RV32-ACFIMX
Build Version: release_bl_iot_sdk_1.6.38
Build Date: Oct 17 2022
Build Time: 14:08:51
------------------------------------------------------------
blog init set power on level 2, 2, 2.
[IRQ] Clearing and Disable all the pending IRQ...
[         0][INFO: hal_boot2.c: 282] [HAL] [BOOT2] Active Partition[0] consumed 596 Bytes
[         0][INFO: hal_boot2.c:  82] ======= PtTable_Config @0x4200d420=======
[         0][INFO: hal_boot2.c:  83] magicCode 0x54504642; version 0x0000; entryCnt 7; age 0; crc32 0x12DF9A26
[         0][INFO: hal_boot2.c:  89] idx  type device activeIndex     name   Address[0]  Address[1]  Length[0]   Length[1]   age
[         0][INFO: hal_boot2.c:  91] [00]  00     0         0            FW  0x00010000  0x000e8000  0x000d8000  0x00088000  0
[         0][INFO: hal_boot2.c:  91] [01]  02     0         0           mfg  0x00170000  0x00000000  0x00032000  0x00000000  0
[         0][INFO: hal_boot2.c:  91] [02]  03     0         0         media  0x001a2000  0x00000000  0x00047000  0x00000000  0
[         0][INFO: hal_boot2.c:  91] [03]  04     0         0           PSM  0x001e9000  0x00000000  0x00008000  0x00000000  0
[         0][INFO: hal_boot2.c:  91] [04]  05     0         0           KEY  0x001f1000  0x00000000  0x00002000  0x00000000  0
[         0][INFO: hal_boot2.c:  91] [05]  06     0         0          DATA  0x001f3000  0x00000000  0x00005000  0x00000000  0
[         0][INFO: hal_boot2.c:  91] [06]  07     0         0       factory  0x001f8000  0x00000000  0x00007000  0x00000000  0
[         0][INFO: bl_flash.c: 391] ======= FlashCfg magiccode @0x42049c18=======
[         0][INFO: bl_flash.c: 392] mid                 0x5E
[         0][INFO: bl_flash.c: 393] clkDelay    0x1
[         0][INFO: bl_flash.c: 394] clkInvert   0x1
[         0][INFO: bl_flash.c: 395] sector size 4KBytes
[         0][INFO: bl_flash.c: 396] page size   256Bytes
[         0][INFO: bl_flash.c: 397] ---------------------------------------------------------------
[         0][INFO: hal_board.c:1249] [MAIN] [BOARD] [FLASH] addr from partition is 001f8000, ret is 0
[         0][INFO: hal_board.c:1257] [MAIN] [BOARD] [XIP] addr from partition is 231e7000, ret is 0
--------easyflash write/read demo--------[MTD] >>>>>> Hanlde info Dump >>>>>>
name PSM
id 0
offset 0x001e9000(2002944)
size 0x00008000(32Kbytes)
xip_addr 0x231d8000
[MTD] <<<<<< Hanlde info End <<<<<<
[EF] Found Valid PSM partition, XIP Addr 231d8000, flash addr 001e9000, size 32768
ENV AREA SIZE 32768, SECTOR NUM 8
*default_env_size = 0x00000001
ENV start address is 0x00000000, size is 32768 bytes.
EasyFlash V4.0.99 is initialize success.
You can get the latest version on https://github.com/armink/EasyFlash .
ef_bytes_key write bytes: 0 1 2 3 4 5 6 7 8 9
ef_bytes_key read bytes: 0 1 2 3 4 5 6 7 8 9
ef_u8_key write uint8: 8
ef_u8_key read uint8: 8
ef_u16_key write uint16: 1616
ef_u16_key read uint16: 1616
ef_u32_key write uint32: 32323232
ef_u32_key read uint32: 32323232
ef_int_key write int: -666
ef_int_key read int: -666
ef_str_key write string: Hello World!
ef_str_key read string: Hello World!
ef_float_key write float: 3.141592
ef_float_key read float: 3.141592
How to use?
easyflash_init();
API
 /**
* @description: easyflash write bytes
* @param {char} *key
* @param {uint8_t} *value
* @param {int} len
* @return {*}
*/
bool ef_set_bytes(const char *key, uint8_t *value, int len);
/**
* @description: easyflash read bytes
* @param {char} *key
* @param {uint8_t} *value
* @param {int} len
* @return {*}
*/
int ef_get_bytes(const char *key, uint8_t *value, int len);
/**
* @description: easyflash delete key
* @param {char} *key
* @return {*}
*/
bool ef_del_key(const char *key);
/**
* @description: easyflash write uint8_t
* @param {char} *key
* @param {uint8_t} value
* @return {*}
*/
bool ef_set_u8(const char *key, uint8_t value);
/**
* @description: easyflash read uint8_t
* @param {char} *key
* @param {uint8_t} *value
* @return {*}
*/
bool ef_get_u8(const char *key, uint8_t *value);
/**
* @description: easyflash write uint16_t
* @param {char} *key
* @param {uint16_t} value
* @return {*}
*/
bool ef_set_u16(const char *key, uint16_t value);
/**
* @description: easyflash read uint16_t
* @param {char} *key
* @param {uint16_t} *value
* @return {*}
*/
bool ef_get_u16(const char *key, uint16_t *value);
/**
* @description: easyflash write uint32_t
* @param {char} *key
* @param {uint32_t} value
* @return {*}
*/
bool ef_set_u32(const char *key, uint32_t value);
/**
* @description: easyflash read uint32_t
* @param {char} *key
* @param {uint32_t} *value
* @return {*}
*/
bool ef_get_u32(const char *key, uint32_t *value);
/**
* @description: easyflash write int
* @param {char} *key
* @param {int} value
* @return {*}
*/
bool ef_set_int(const char *key, int value);
/**
* @description: easyflash read int
* @param {char} *key
* @param {int} *value
* @return {*}
*/
bool ef_get_int(const char *key, int *value);
/**
* @description: easyflash write float
* @param {char} *key
* @param {float} value
* @return {*}
*/
bool ef_set_float(const char *key, float value);
/**
* @description: easyflash read float
* @param {char} *key
* @param {float} *value
* @return {*}
*/
bool ef_get_float(const char *key, float *value);
/**
* @description: easyflash write string
* @param {char} *key
* @param {char} *str
* @return {*}
*/
bool ef_set_str(const char *key, char *str);
/**
* @description: easyflash read string
* @param {char} *key
* @param {char} *str
* @param {int} len
* @return {*}
*/
bool ef_get_str(const char *key, char *str, int len);
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

flash示例
安信可 Flash示例
Flash Example

This example for write/read data to a row address/partitoin on a Flash, If you want to save data in the form of key-value pairs, you can refer to the [easyflash](../easyflash/) demo.

Example Output

Starts a FreeRTOS task to print “flash write/read demo”. As you run the example, you will see the log :

--------flash write/read demo--------
INFO (5)[main.c: 125] --------flash write/read demo--------
[MTD] >>>>>> Hanlde info Dump >>>>>>
     name DATA
     id 0
     offset 0x001f3000(2043904)
     size 0x00005000(20Kbytes)
     xip_addr 0x00000000
[MTD] <<<<<< Hanlde info End <<<<<<
INFO (26)[main.c:  45] partition name         : DATA
INFO (31)[main.c:  46] partition start address: 0x001f3000
INFO (37)[main.c:  47] partition length       : 20480
INFO (73)[main.c:  77] hal flash partition data R/W successful!
INFO (78)[main.c: 116] hal flash addr R/W successful!
API
 /**
* @brief Open a flash partition device
*
* @param[in]  name     flash partition name
* @param[in]  flags    flash flags
*               - HOSAL_FLASH_FLAG_ADDR_0
*               - HOSAL_FLASH_FLAG_ADDR_1
*               - HOSAL_FLASH_FLAG_BUSADDR
*
* @return
*  - NULL flash open error
*  - otherwise is flash partition device
*/
hosal_flash_dev_t *hosal_flash_open(const char *name, unsigned int flags);
/**
* @brief Get the information of the specified flash area
*
* @param[in]  p_dev     The target flash logical partition device
* @param[out] partition The buffer to store partition info
*
* @return
*  - 0 On success
*  - otherwise is error
*/
int hosal_flash_info_get(hosal_flash_dev_t *p_dev, hosal_logic_partition_t *partition);
/**
* @brief Erase an area on a Flash logical partition
*
* @note  Erase on an address will erase all data on a sector that the
*        address is belonged to, this function does not save data that
*        beyond the address area but in the affected sector, the data
*        will be lost.
*
* @param[in]  p_dev         The target flash logical partition which should be erased
* @param[in]  off_set       Start address of the erased flash area
* @param[in]  size          Size of the erased flash area
*
* @return
*  - 0 On success
*  - otherwise is error
*/
int hosal_flash_erase(hosal_flash_dev_t *p_dev, uint32_t off_set, uint32_t size);
/**
* @brief Write data to an area on a flash logical partition without erase
*
* @param[in]  p_dev           The target flash logical partition which should be read which should be written
* @param[in/out]  off_set     Point to the start address that the data is written to, and
*                             point to the last unwritten address after this function is
*                             returned, so you can call this function serval times without
*                             update this start address.
* @param[in]  in_buf          point to the data buffer that will be written to flash
* @param[in]  in_buf_size     The size of the buffer
*
* @return
*  - 0 On success
*  - otherwise is error
*/
int hosal_flash_write(hosal_flash_dev_t *p_dev, uint32_t *off_set,
                   const void *in_buf, uint32_t in_buf_size);
/**
* @brief Write data to an area on a flash logical partition with erase first
*
* @param[in]  p_dev           The target flash logical partition which should be read which should be written
* @param[in/out]  off_set     Point to the start address that the data is written to, and
*                             point to the last unwritten address after this function is
*                             returned, so you can call this function serval times without
*                             update this start address.
* @param[in]  in_buf          point to the data buffer that will be written to flash
* @param[in]  in_buf_size     The length of the buffer
*
* @return
*  - 0 On success
*  - otherwise is error
*/
int hosal_flash_erase_write(hosal_flash_dev_t *p_dev, uint32_t *off_set,
                         const void *in_buf, uint32_t in_buf_size);
/**
* @brief Read data from an area on a Flash to data buffer in RAM
*
* @param[in]  p_dev           The target flash logical partition which should be read
* @param[in/out]  off_set     Point to the start address that the data is read, and
*                             point to the last unread address after this function is
*                             returned, so you can call this function serval times without
*                             update this start address.
* @param[in]  out_buf         Point to the data buffer that stores the data read from flash
* @param[in]  out_buf_size    The length of the buffer
*
* @return
*  - 0 On success
*  - otherwise is error
*/
int hosal_flash_read(hosal_flash_dev_t *p_dev, uint32_t *off_set,
                  void *out_buf, uint32_t out_buf_size);
/**
* @brief Close a flash partition device
*
* @param[in]  p_dev     flash partition device
*
* @return
*  - 0 On success
*  - otherwise is error
*/
int hosal_flash_close(hosal_flash_dev_t *p_dev);
/**
* @brief Read data from a row address on a Flash to data buffer in RAM
*
* @param[in]  buffer          Point to the data buffer that stores the data read from flash
* @param[in]  address         Address on flash to read from
* @param[in]  length          Length (in bytes) of data to read
*
* @return
*  - 0 On success
*  - otherwise is error
*/
int hosal_flash_raw_read(void *buffer, uint32_t address, uint32_t length);
/**
* @brief Write data to a row address on a Flash
*
* @param[in]  buffer          Point to the data buffer that will be written to flash
* @param[in]  address         Address on flash to write to
* @param[in]  length          Length (in bytes) of data to write
*
* @return
*  - 0 On success
*  - otherwise is error
*/
int hosal_flash_raw_write(void *buffer, uint32_t address, uint32_t length);
/**
* @brief Erase a region of the flash
*
* @param[in]  start_addr      Address to start erasing flash.
* @param[in]  length          Length of region to erase.
*
* @return
*  - 0 On success
*  - otherwise is error
*/
int hosal_flash_raw_erase(uint32_t start_addr, uint32_t length);
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

spiffs_demo示例
安信可 SPIFFS示例
SPIFFS Example

Starts a FreeRTOS task to print “spiffs write/read demo”. As you run the example, you will see the log :

INFO (5)[main.c:  94] --> spiffs write/read demo <--
INFO (25)[main.c:  71] spiffs mount success
INFO (33)[main.c:  88] --> Hello world <--
How to use?
//Add Configuration
spiffs_config cfg = {
   .phys_size = 0x00047000,                 // use spi flash size
   .phys_addr = DEMO_HOSAL_FLASH_TEST_ADDR, // start spiffs at start of flash
   .phys_erase_block = 4096,                // physical sector size
   .log_block_size = 4096,                  // logical sector size (Must be an integer multiple of physical sectors)
   .log_page_size = LOG_PAGE_SIZE,          // logical page size
   .hal_read_f = spiffs_read_flash,         // flash read function
   .hal_write_f = spiffs_write_flash,       // flash write function
   .hal_erase_f = spiffs_erase_flash,       // flash erase function
};
//SPIFFS Mount
int res = SPIFFS_mount(&fs,
                       &cfg,
                       spiffs_work_buf,
                       spiffs_fds,
                       sizeof(spiffs_fds),
                       spiffs_cache_buf,
                       sizeof(spiffs_cache_buf),
                       0);
API

[SPIFFS API - Weki](https://github.com/pellepl/spiffs/wiki/Using-spiffs)

Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

protocols示例
安信可 protocols示例
例程参考
mqtt示例
安信可 MQTT_SSL示例
MQTT_SSL Example
Configure WiFi Connected

Please configure the ssid and password that need to be connected to WiFi in advance,in main.c.

Configure mqttt server

Please configure the server url in demo.c.

axk_mqtt_client_config_t mqtt_cfg = {
 .uri="mqtts://mqtt.eclipseprojects.io:8883",
 .cert_pem=CA_CRT,
 .client_cert_pem=CLIENT_CRT,
 .client_key_pem=CLIENT_KEY,
 .event_handle = event_cb,

};

Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

安信可 MQTT_TCP示例
MQTT_TCP Example
Configure WiFi Connected

Please configure the ssid and password that need to be connected to WiFi in advance,in main.c.

Configure mqttt server

Please configure the server url in demo.c.

axk_mqtt_client_config_t mqtt_cfg = {
.uri = "mqtt://mqtt.eclipseprojects.io",
.event_handle = event_cb,

};

Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

安信可 MQTT_WS示例
MQTT_WS Example
Configure WiFi Connected

Please configure the ssid and password that need to be connected to WiFi in advance,in main.c.

Configure mqttt server

Please configure the server url in demo.c.

axk_mqtt_client_config_t mqtt_cfg = {
   .uri="ws://mqtt.eclipseprojects.io:80/mqtt",
   .event_handle = event_cb,

};

Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

安信可 MQTT_WSS示例
MQTT_WSS Example
Configure WiFi Connected

Please configure the ssid and password that need to be connected to WiFi in advance,in main.c.

Configure mqttt server

Please configure the server url in demo.c.

axk_mqtt_client_config_t mqtt_cfg = {
  .uri="wss://mqtt.eclipseprojects.io:443/mqtt",
  .cert_pem=CA_CRT,
  .event_handle = event_cb,

};

Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

socket示例
安信可 tcp_client示例
tcp_client Example
Configure

Please configure the ssid and password that need to be connected to WiFi in advance,in main.c.

#define ROUTER_SSID "your ssid"
#define ROUTER_PWD "your password"

Then configure the IP address and port number of the TCP server

Compile and download

Compile command

make -j16

`-j8`is the number of cores in the system.

make flash p=/dev/ttyUSBx b=921600 `/dev/ttyUSBx`is the port number of the Ai-WB2 connection, usually ttyUSB0

Example Output
(other log)...
Server ip Address : 192.168.31.156 port:7878
-----------------> AABA Request:
A-MSDU: Permitted
Block Ack Policy: Immediate Block Ack
TID: 0
Number of Buffers: 64
-----------------> AABA Response:
A-MSDU: Not Permitted
Block Ack Policy: Immediate Block Ack
TID: 0
Number of Buffers: 8
ssn: 0
timeout: 0
tid 0
[      7383][INFO: main.c:  54] tcp_client_task:tcp client connect OK
[      7387][INFO: main.c:  62] tcp client send OK

After the TCP client connects, it sends a “hello tcp server” to the server.The server sends a close message to close the connection.

Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

安信可 tcp_server Example示例
tcp_server Example
Configuration project

By default, the connected wifi AP in this project is ssid=”ssid” and password=”password”. You need to modify it according to your own AP configuration.

#define ROUTER_SSID "ssid"
#define ROUTER_PWD "password"

Server default configuration

  • IP Address: station IPv4 addr

  • Port: 7878

The current project supports simultaneous access of 4 clients, you are at src/tcp_ Server.c can modify the following macro definitions to modify the maximum number of connections.

build and download

Compile with instructions and download firmware.

make -j16 flash p=/dev/ttyUSB0 b=921600

j16 is the number of cores in the system

Example Output
 (other log)...
 [WF][PF] Using profile, idx is @0
 [WF][SM] Entering wifiConnected_ipObtaining state
 [WF][SM] DHCP Starting...0x42014b74
 [APP] [EVT] connected 4448
 -----------------> AABA Request:
 A-MSDU: Permitted
 Block Ack Policy: Immediate Block Ack
 TID: 0
 Number of Buffers: 64
 -----------------> AABA Response:
 A-MSDU: Not Permitted
 Block Ack Policy: Immediate Block Ack
 TID: 0
 Number of Buffers: 8
 ssn: 0
 timeout: 1
 tid 0
 IP:192.168.1.105
 MASK: 255.255.255.0
 Gateway: 192.168.1.1
[lwip] netif status callback
IP: 192.168.1.105
MK: 255.255.255.0
GW: 192.168.1.1
[WF][SM] Exiting wifiConnected_ipObtaining state
[WF][SM] State Action ###wifiConnected_ipObtaining### --->>> ###wifiConnected_IPOK###
[WF][SM] Entering wifiConnected_IPOK state
[APP] [EVT] GOT IP 5594
[SYS] Memory left is 155872 Bytes
tcp server start ip:192.168.1.105:7878
tcp server listening.....
Message Receiving and Sending

When the client access succeeds, the server forwards the message to the client when it receives it:

(other log)...
client:192.168.1.106:1,id:0
client:192.168.1.106:2,id:1
192.168.1.106:Jdkdj
192.168.1.106:Jdkdj
192.168.1.106:Jdkdj
192.168.1.106:Jdkdj
192.168.1.106:Jdkdj
192.168.1.106:Jdkdj
...
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

安信可 UDP client示例
UDP client Example

Please configure the ssid and password that need to be connected to WiFi in advance,in main.c.

#define ROUTER_SSID "your ssid"
#define ROUTER_PWD "your password"

The UDP server IP address demonstrated in the project cannot be used and needs to be modified to the actual server IP address

build and download

Compile with instructions and download firmware.

make -j16 flash p=/dev/ttyUSB0 b=921600

j16 is the number of cores in the system

Example Output

When the client connects, it will send a “shell udp server” to the server and start listening for messages.

(other log)...
[WF][SM] State Action ###connecting### --->>> ###wifiConnected_ipObtaining###
[WF][PF] Using profile, idx is @0
[WF][SM] Entering wifiConnected_ipObtaining state
[WF][SM] DHCP Starting...0x42014b54
[APP] [EVT] connected 4914
-----------------> AABA Request:
A-MSDU: Permitted
Block Ack Policy: Immediate Block Ack
TID: 0
Number of Buffers: 64
-----------------> AABA Response:
A-MSDU: Not Permitted
Block Ack Policy: Immediate Block Ack
TID: 0
Number of Buffers: 8
ssn: 0
timeout: 0
tid 0
IP:192.168.1.105
MASK: 255.255.255.0
Gateway: 192.168.1.1
[lwip] netif status callback
IP: 192.168.1.105
MK: 255.255.255.0
GW: 192.168.1.1
[WF][SM] Exiting wifiConnected_ipObtaining state
[WF][SM] State Action ###wifiConnected_ipObtaining### --->>> ###wifiConnected_IPOK###
[WF][SM] Entering wifiConnected_IPOK state
[APP] [EVT] GOT IP 5593
[SYS] Memory left is 155904 Bytes
[      5599][INFO: main.c:  46] udp client task run
Server ip Address : 192.168.1.100 port:7878
[      5607][INFO: main.c:  53] udp_client_task:udp client connect OK
[      5614][INFO: main.c:  61] udp client send OK
Receive data
(other log)...
[     11102][INFO: main.c:  67] udp_client_task:udp receive data:Hello udp client
[     11561][INFO: main.c:  67] udp_client_task:udp receive data:Hello udp client
[     11783][INFO: main.c:  67] udp_client_task:udp receive data:Hello udp client
[     11920][INFO: main.c:  67] udp_client_task:udp receive data:Hello udp client
[     12107][INFO: main.c:  67] udp_client_task:udp receive data:Hello udp client
[     12294][INFO: main.c:  67] udp_client_task:udp receive data:Hello udp client
[     12436][INFO: main.c:  67] udp_client_task:udp receive data:Hello udp client
[     12617][INFO: main.c:  67] udp_client_task:udp receive data:Hello udp client
[     12795][INFO: main.c:  67] udp_client_task:udp receive data:Hello udp client
[     12952][INFO: main.c:  67] udp_client_task:udp receive data:Hello udp client
[     13142][INFO: main.c:  67] udp_client_task:udp receive data:Hello udp client
[     13291][INFO: main.c:  67] udp_client_task:udp receive data:Hello udp client
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

安信可 UDP multicast示例
UDP multicast Example
Configuration project

By default, the connected wifi AP in this project is ssid=”ssid” and password=”password”. You need to modify it according to your own AP configuration.

#define ROUTER_SSID "ssid"
#define ROUTER_PWD "password"

Multicast default configuration

  • Muliticast addr: 224.0.1.0

  • Port: 7878

You can go to the main The macro definition in c modifies the IP address and port number of multicast

build and download

Compile with instructions and download firmware.

make -j16 flash p=/dev/ttyUSB0 b=921600

j16 is the number of cores in the system

Example Output

When the client connects, it will send a “shell udp server” to the server and start listening for messages.

Multicast started successfully
(other log)...
[WF][SM] Exiting connecting state
[WF][SM] State Action ###connecting### --->>> ###wifiConnected_ipObtaining###
[WF][PF] Using profile, idx is @0
[WF][SM] Entering wifiConnected_ipObtaining state
[WF][SM] DHCP Starting...0x42014b54
[APP] [EVT] connected 4539
-----------------> AABA Request:
A-MSDU: Permitted
Block Ack Policy: Immediate Block Ack
TID: 0
Number of Buffers: 64
-----------------> AABA Response:
A-MSDU: Not Permitted
Block Ack Policy: Immediate Block Ack
TID: 0
Number of Buffers: 8
ssn: 0
timeout: 0
tid 0
IP:192.168.1.112
MASK: 255.255.255.0
Gateway: 192.168.1.1
[lwip] netif status callback
IP: 192.168.1.112
MK: 255.255.255.0
GW: 192.168.1.1
[WF][SM] Exiting wifiConnected_ipObtaining state
[WF][SM] State Action ###wifiConnected_ipObtaining### --->>> ###wifiConnected_IPOK###
[WF][SM] Entering wifiConnected_IPOK state
[APP] [EVT] GOT IP 5594
[SYS] Memory left is 155904 Bytes
[      5601][INFO: main.c:  70] <<<<<<<<<<<<<<<<<<udp multicast start<<<<<<<<<<<<<
[      5606][INFO: main.c:  71] multicast addr:224.0.1.0:7878
Message Receiving and Sending

Other nodes participating in multicast must maintain the same network segment as Ai-WB2 to achieve communication.

The project will send the same multicast message when receiving the multicast message.
(other log)...
[    221662][INFO: main.c:  76] 192.168.1.111:Hello Ai-WB2
[    221666][INFO: main.c:  81] udp multicast data:Hello Ai-WB2
[    223070][INFO: main.c:  76] 192.168.1.111:Hello Ai-WB2
[    223074][INFO: main.c:  81] udp multicast data:Hello Ai-WB2
[    223828][INFO: main.c:  76] 192.168.1.111:Hello Ai-WB2
[    223832][INFO: main.c:  81] udp multicast data:Hello Ai-WB2
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

安信可 udp_server示例
udp_server Example
Configuration project

By default, the connected wifi AP in this project is ssid=”ssid” and password=”password”. You need to modify it according to your own AP configuration.

#define ROUTER_SSID "ssid"
#define ROUTER_PWD "password"

Server default configuration

  • IP Address: station IPv4 addr

  • Port: 7878

The current project supports simultaneous access of 4 clients, you are at src/udp_ Server.c can modify the following macro definitions to modify the maximum number of connections.

build and download

Compile with instructions and download firmware.

make -j16 flash p=/dev/ttyUSB0 b=921600

j16 is the number of cores in the system

Example Output
Server started successfully
(other log)...
[WF][SM] Exiting connecting state
[WF][SM] State Action ###connecting### --->>> ###wifiConnected_ipObtaining###
[WF][PF] Using profile, idx is @0
[WF][SM] Entering wifiConnected_ipObtaining state
[WF][SM] DHCP Starting...0x42014a5c
[APP] [EVT] connected 4488
-----------------> AABA Request:
A-MSDU: Permitted
Block Ack Policy: Immediate Block Ack
TID: 0
Number of Buffers: 64
-----------------> AABA Response:
A-MSDU: Not Permitted
Block Ack Policy: Immediate Block Ack
TID: 0
Number of Buffers: 8
ssn: 0
timeout: 0
tid 0
IP:192.168.1.100
MASK: 255.255.255.0
Gateway: 192.168.1.1
[lwip] netif status callback
IP: 192.168.1.100
MK: 255.255.255.0
GW: 192.168.1.1
[WF][SM] Exiting wifiConnected_ipObtaining state
[WF][SM] State Action ###wifiConnected_ipObtaining### --->>> ###wifiConnected_IPOK###
[WF][SM] Entering wifiConnected_IPOK state
[APP] [EVT] GOT IP 5093
[SYS] Memory left is 156144 Bytes
udp server start ip:192.168.1.100:7878
Message Receiving and Sending
(other log)...
[     10402][INFO: main.c:  65] 192.168.1.106:hellc
[     12005][INFO: main.c:  65] 192.168.1.106:hellc
[     12758][INFO: main.c:  65] 192.168.1.106:hellc
[     17812][INFO: main.c:  65] 192.168.1.107:Hello Server
[     18516][INFO: main.c:  65] 192.168.1.107:Hello Server
[     19070][INFO: main.c:  65] 192.168.1.107:Hello Server
[     19874][INFO: main.c:  65] 192.168.1.107:Hello Server
[     20428][INFO: main.c:  65] 192.168.1.107:Hello Server
[     20832][INFO: main.c:  65] 192.168.1.107:Hello Server
[     21286][INFO: main.c:  65] 192.168.1.107:Hello Server
[     52940][INFO: main.c:  65] 192.168.1.107:close

When a close is received, the current connection is closed.

Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

http_client_socket示例
安信可 http_client_socket示例
Http client socket Example
Configure WiFi Connected

Please configure the ssid and password that need to be connected to WiFi in advance,in main.c.

#define ROUTER_SSID "your ssid"
#define ROUTER_PWD "your password"
Compile and download
Compile command

make -j16

`-j16`is the number of cores in the system.

download

make flash p=/dev/ttyUSBx b=921600

`/dev/ttyUSBx`is the port number of the Ai-WB2 connection, usually ttyUSB0

Example Output
successfully request web url
INFO (11611)[demo.c:  68] ... connected
INFO (11614)[demo.c:  78] ... socket send success
INFO (11618)[demo.c:  91] ... set socket receiving timeout success
HTTP/1.0 200 OK
Age: 316063
Cache-Control: max-age=604800
Content-Type: text/html; charset=UTF-8
Date: Fri, 21 Oct 2022 07:50:25 GMT
Etag: "3147526947+ident"
Expires: Fri, 28 Oct 2022 07:50:25 GMT
Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
Server: ECS (sab/56CE)
Vary: Accept-Encoding
X-Cache: HIT
Content-Length: 1256
Connection: close

<!doctype html>
<html>
<head>
<title>Example Domain</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
       background-color: #f0f0f2;
       margin: 0;
       padding: 0;
       font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;

   }
   div {
       width: 600px;
       margin: 5em auto;
       padding: 2em;
       background-color: #fdfdff;
       border-radius: 0.5em;
       box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
   }
   a:link, a:visited {
       color: #38488f;
       text-decoration: none;
   }
   @media (max-width: 700px) {
       div {
           margin: 0 auto;
           width: auto;
       }
   }
   </style>
   </head>

   <body>
   <div>
   <h1>Example Domain</h1>
   <p>This domain is for use in illustrative examples in documents. You may use this
   domain in literature without prior coordination or asking for permission.</p>
   <p><a href="https://www.iana.org/domains/example">More information...</a></p>
   </div>
   </body>
   </html>


   INFO (11922)[demo.c: 107] ... done reading from socket. Last read return=0 errno=107
   INFO (11932)[demo.c: 111] 10...
   INFO (12934)[demo.c: 111] 9...
   INFO (13935)[demo.c: 111] 8...
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

http_server示例
http_server示例
安信可 http simple_server示例
Simple HTTP server Example

This example shows how setup a simple http server.

Introduction

Please configure the ssid and password that need to be connected to WiFi in advance,in main.c.

How to use example

Open the project,set WIFI_SSID,WIFI_PASSWORD in “wifi_execute.c” file at line 3,line 4 and set listen port in “http_server.c” file at line 3.

For example :

#define STA_SSID "Ai-WB2-x"
#define STA_PASSWORD "12345678"
#define SERVER_PORT 80

Finally,running command below to compile project on ubuntu.

make -j8

Burn firmware

Running command below to burn firmware after connecting WB2 serial development board to ubuntu.

make flash p=/dev/ttyUSB0 b=921600

Debug

Open the serial port debugging assistant software,select the COM port of the development board,and press the reset button on development board to run the program finally. Access the IP address of the module through the browser of the PC or other devices, and you can get the web page responded by the server, as shown in the following figure:(Notic:the device which access the IP address of the module should be in the same LAN with module.In other words,connect to the same AP.)

_images/ip_access.jpg
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

简易HTTP服务器搭建例程
简介

本例程主要介绍如何搭建一个简易HTTP服务器。

如何使用该例程

打开项目,在“wifi_execute.c”文件第3、4行设置WIFI_SSID、WIFI_PASSWORD以及在“http_server.c”文件中设置服务器监听端口号 如下:

#define STA_SSID "Ai-WB2-x"
#define STA_PASSWORD "12345678"
#define SERVER_PORT 80

最后,在ubuntu下运行以下指令编译工程。

make -j8

烧录固件

将WB2开发板连接ubuntu之后,运行以下指令烧录固件。

make flash p=/dev/ttyUSB0 b=921600

调试

打开“串口调试助手软件”,选择并打开开发板的COM口,最后按下复位键启动程序。 打开浏览器,访问模组的IP地址,模组将响应该请求,回复一个网页过来,效果如附件:(注意:访问该IP的设备需与模组在同一局域网下,即:连接同一个AP热点)

_images/ip_access.jpg
问题排除

若有任何问题,请在github中提交一个[issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues),我们会尽快回复。

https_mbedtls示例
安信可 HTTP server with TLS support using mbedTLS示例
HTTP server with TLS support using mbedTLS

Simple HTTPS example that uses mbedTLS to establish a secure socket connection using the certificate bundle with two custom certificates added for verification》

Configure WiFi Connected

Please configure the ssid and password that need to be connected to WiFi in advance,in main.c.

#define ROUTER_SSID "your ssid"
#define ROUTER_PWD "your password"
Compile and download
Compile command

make -j16

`-j16`is the number of cores in the system.

make flash p=/dev/ttyUSB0 b=921600

`/dev/ttyUSBx`is the port number of the Ai-WB2 connection, usually ttyUSB0

Example Output
[WF][SM] Exiting wifiConnected_ipObtaining state
[WF][SM] State Action ###wifiConnected_ipObtaining### --->>> ###wifiConnected_IPOK###
[WF][SM] Entering wifiConnected_IPOK state
[APP] [EVT] GOT IP 5535
[SYS] Memory left is 146104 Bytes
INFO (5536)[demo.c:  74] Seeding the random number generator
INFO (5538)[demo.c:  86] Loading the CA root certificate...
INFO (5604)[demo.c:  98] Setting hostname for TLS session...
INFO (5604)[demo.c: 107] Setting up the SSL/TLS structure...
INFO (5606)[demo.c: 137] Connecting to www.howsmyssl.com:443...
-----------------> AABA Request:
   A-MSDU: Permitted
   Block Ack Policy: Immediate Block Ack
   TID: 0
   Number of Buffers: 64
-----------------> AABA Response:
   A-MSDU: Not Permitted
   Block Ack Policy: Immediate Block Ack
   TID: 0
   Number of Buffers: 8
-----------------> AABA Request:
   A-MSDU: Permitted
   Block Ack Policy: Immediate Block Ack
   TID: 3
   Number of Buffers: 64
-----------------> AABA Response:
   A-MSDU: Not Permitted
   Block Ack Policy: Immediate Block Ack
   TID: 3
   Number of Buffers: 8
INFO (6071)[demo.c: 146] Connected.
INFO (6071)[demo.c: 150] Performing the SSL/TLS handshake...
INFO (8014)[demo.c: 161] Verifying peer X.509 certificate...
WARN (8014)[demo.c: 166] Failed to verify peer certificate!
WARN (8015)[demo.c: 169] verification info:   ! The certificate is not correctly signed by the trusted CA

INFO (8015)[demo.c: 176] Cipher suite is TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256
INFO (8016)[demo.c: 178] Writing HTTP request...
INFO (8018)[demo.c: 188] 103 bytes written
INFO (8018)[demo.c: 198] Reading HTTP response...
511 bytes read

511 bytes read

157 bytes read

511 bytes read

431 bytes read

INFO (8242)[demo.c: 251] Completed 1 requests
INFO (8243)[demo.c: 255] 10...
INFO (9243)[demo.c: 255] 9...
INFO (10243)[demo.c: 255] 8...
INFO (11243)[demo.c: 255] 7...
INFO (12243)[demo.c: 255] 6...
INFO (13243)[demo.c: 255] 5...
INFO (14243)[demo.c: 255] 4...
INFO (15243)[demo.c: 255] 3...
INFO (16243)[demo.c: 255] 2...
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

sntp示例
安信可 sntp示例
sntp Example
Configure project

By default, the connected wifi AP in this project is ssid=”ssid” and password=”password”. You need to modify it according to your own AP configuration.

#define ROUTER_SSID "your ssid"
#define ROUTER_PWD "your password"
Example Output
(other log)...
INFO (6094)[main.c: 122] [APP] [EVT] GOT IP 6094
INFO (6099)[main.c: 123] [SYS] Memory left is 158376 Bytes
INFO (6105)[main.c:  36] --------------------------------------- Start NTP now

[SNTP] pcb isready, 0x4204a908
INFO (6116)[main.c:  40] --------------------------------------- Start NTP Done

-----------------> AABA Request:
   A-MSDU: Permitted
   Block Ack Policy: Immediate Block Ack
   TID: 0
   Number of Buffers: 64
-----------------> AABA Response:
   A-MSDU: Not Permitted
   Block Ack Policy: Immediate Block Ack
   TID: 0
   Number of Buffers: 8
SNTP time now
Try process
Processing...
sntp_process: 1670898031, 820829 us
INFO (11124)[main.c:  52] [NTP] time is 1670898034:3526293

INFO (11127)[main.c:  54] Date & time is: 2022-12-13 10:20:34 (Day 2 of week, Day 347 of Year)

INFO (12136)[main.c:  52] [NTP] time is 1670898035:3526305

INFO (12139)[main.c:  54] Date & time is: 2022-12-13 10:20:35 (Day 2 of week, Day 347 of Year)

INFO (13148)[main.c:  52] [NTP] time is 1670898036:3526317

INFO (13151)[main.c:  54] Date & time is: 2022-12-13 10:20:36 (Day 2 of week, Day 347 of Year)

INFO (14160)[main.c:  52] [NTP] time is 1670898037:3526329

INFO (14163)[main.c:  54] Date & time is: 2022-12-13 10:20:37 (Day 2 of week, Day 347 of Year)

INFO (15172)[main.c:  52] [NTP] time is 1670898038:3526341

INFO (15175)[main.c:  54] Date & time is: 2022-12-13 10:20:38 (Day 2 of week, Day 347 of Year)
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

peripherals示例
安信可 peripherals参考
UART示例
安信可 Uart Example 参考
Example Output

Starts a FreeRTOS task to run UART Example . Ple connect communication uart tx pin GPIO16 and rx pin GPIO7 , the log uart rx pin is GPIO3 and the tx pin is GPIO4.

Ai-WB2 WiFi&BLE Module has 2 group UART(UART0 and UART1).

Remember
  • the blog_info(); funtion log output always by the uart0 .

  • if you want to set no log output after reboot , Ple set project_config.mk CONFIG_SYS_REBOOT_LOG_DISENABLE:=1

Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

ADC示例
安信可 ADC 示例参考
Example

Ai-WB2 Series SoC Module ADC usage

Hardware Setup and Wiring

Ai-WB2 Series SoC Module Pinout

Peripheral Pinout

ADC

Voltage Probe (i.e. 3.3V or 5V VCC pinout)

3V3

VCC

GND

GND

Build and Flash

shell

make -j

make flash

Run _images/demo6.jpg
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

GPIO示例
安信可 GPIO 示例参考
Example

Ai-WB2 Series SoC Module GPIO usage

Hardware Setup and Wiring

Ai-WB2 Series SoC Module Pinout

Peripheral Pinout

IO14

LED

IO8

Button

3V3

VCC

GND

GND

Build and Flash

shell

make -j

make flash

Run _images/demo7.jpg
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

I2C示例
安信可 I2C示例参考
Example

Ai-WB2 Series SoC Module Reads SHT30 Temperature and Humidity Sensor via I²C Bus

Hardware Setup and Wiring

Ai-WB2 Series SoC Module Pinout

Peripheral Pinout

IO12

SCL

IO3

SDA

3V3

VCC

GND

GND

Build and Flash

shell

make -j

make flash

Run _images/demo8.jpg
Logic Analyzer Output _images/logic_analyzer6.jpg
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

PWM示例
安信可 PWM示例参考
Example

Ai-WB2 Series SoC Module Hardware PWM Module Output

Hardware Setup and Wiring

Ai-WB2 Series SoC Module Pinout

LED Pinout

IO14

Red

IO17

Green

IO3

Blue

3V3

VCC

GND

GND

Build and Flash

shell

make -j

make flash

Run _images/demo10.jpg
Logic Analyzer Output _images/logic_analyzer8.jpg

See [data.csv] for complete output.

data.csv详见链接

Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

SPI示例
安信可 SPI示例参考
Example

Ai-WB2 Series SoC Module Drives SSD1306 Monochrome 128x64 Resolution OLED Display via SPI

Hardware Setup and Wiring

Ai-WB2 Series SoC Module Pinout

LED Pinout

IO4

CS

IO5

DC

EN/NC

RST

IO12

DI

IO3

CLK

3V3

VCC

GND

GND

Build and Flash

shell

make -j

make flash

Run _images/demo11.jpg
Logic Analyzer Output _images/logic_analyzer9.jpg

See [data.csv] for complete output. data.csv详见链接

Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

IR示例
安信可 IR示例
Ai-WB2 Series SoC Module IR Receive & Transmit Example

Ai-WB2 Series SoC Module Pinout

Model Name

IO12

IR Receiver Output

IO11

Cathode of IR LED

VCC

Anode of IR LED

VCC

IR Receiver Vcc

GND

IR Receiver GND

_images/wiring1.jpg
Build and Flash

make -j

make flash

Run _images/demo9.jpg
Logic Analyzer Output _images/logic_analyzer7.jpg
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

Timer示例
安信可 Timer示例
Example: Ai-WB2 Series SoC Module Timer Sample

Ai-WB2 Series SoC Module Pinout

Connect to

IO3

Probe

Build and Flash

make -j

make flash

Logic Analyzer Output _images/logic_analyzer10.jpg
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

iot-solution示例
安信可 iot-solution示例参考
iot-solution参考
亚马逊云示例
安信可 亚马逊云示例
aws iot Example
Configure

Please configure the ssid and password that need to be connected to WiFi in advance,in main.c.

#define ROUTER_SSID "your ssid"
#define ROUTER_PWD "your password"

According to the AWS IoT Development Guide, the developer shall obtain:

xxx.cert.pem

xxx.private.key

AmazonRootCA1.pem

xxx-ats.iot.us-east-2.amazonaws.com(endpoint)

Download the above certificate to replace the certificate and host in aws_test_cert.h

Subscribe

Subscribe to the topic “$aws/things/AiThinker-Kat/shadow/update” in the MQTT test client.

Publish

Publish to the topic “$aws/things/AiThinker-Kat/shadow/update/accepted” in the MQTT test client.

Example Output
(other log)...
[WF][SM] Exiting wifiConnected_ipObtaining state
[WF][SM] State Action ###wifiConnected_ipObtaining### --->>> ###wifiConnected_IPOK###
[WF][SM] Entering wifiConnected_IPOK state
[APP] [EVT] GOT IP 5949
[SYS] Memory left is 155496 Bytes

AWS IoT SDK Version 3.0.1-
                         Connecting...
DEBUG Seeding the random number generator...
DEBUG Loading embedded CA root certificate ...
DEBUG ok (0 skipped)
DEBUG Loading embedded client certificate...
DEBUG Loading embedded client private key...
DEBUG ok
DEBUG Connecting to a1r0zs8txbyccm-ats.iot.us-west-2.amazonaws.com/443...
-----------------> AABA Request:
   A-MSDU: Permitted
   Block Ack Policy: Immediate Block Ack
   TID: 0
   Number of Buffers: 64
-----------------> AABA Response:
   A-MSDU: Not Permitted
   Block Ack Policy: Immediate Block Ack
   TID: 0
   Number of Buffers: 8
   ssn: 0
   timeout: 1
   tid 0
DEBUG ok
DEBUG Setting up the SSL/TLS structure...
DEBUG SSL state connect : 0
DEBUG ok
DEBUG SSL state connect : 0
DEBUG Performing the SSL/TLS handshake...
DEBUG Verify requested for (Depth 2):
DEBUG cert. version     : 3
                          serial number     : 06:6C:9F:CF:99:BF:8C:0A:39:E2:F0:78:8A:43:E6:96:36:5B:CA
                                                                                                      issuer name       : C=US, O=Amazon, CN=Amazon Root CA 1
   subject name      : C=US, O=Amazon, CN=Amazon Root CA 1
                                                          issued  on        : 2015-05-26 00:00:00
                                                                                                 exp
DEBUG   This certificate has no flags
DEBUG Verify requested for (Depth 1):
DEBUG cert. version     : 3
                          serial number     : 06:7F:94:57:85:87:E8:AC:77:DE:B2:53:32:5B:BC:99:8B:56:0D
                                                                                                      issuer name       : C=US, O=Amazon, CN=Amazon Root CA 1
   subject name      : C=US, O=Amazon, OU=Server CA 1B, CN=Amazon
                                                                 issued  on        : 2015-10-22 00:00
DEBUG   This certificate has no flags
DEBUG Verify requested for (Depth 0):
DEBUG cert. version     : 3
                          serial number     : 03:26:78:7E:14:AE:12:15:7E:D1:48:79:D9:4F:C6:C5
                                                                                             issuer name       : C=US, O=Amazon, OU=Server CA 1B, CN=Amazon
 subject name      : CN=*.iot.us-west-2.amazonaws.com
                                                     issued  on        : 2022-05-16 00:00:00
                                                                                            expires
DEBUG   This certificate has no flags
DEBUG ok [ Protocol is TLSv1.2 ]    [ Ciphersuite is TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256 ]
DEBUG  [ Record expansion is 29 ]
DEBUG Verifying peer X.509 certificate...
DEBUG ok
Connect ok!!!, start Subscribing Topic=[$aws/things/AiThinker-Kat/shadow/update/accepted]...
 ...
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

腾讯云示例
安信可 腾讯云示例
qcloud_demo example
硬件连接

设备连接云端后,通过KEY可控制LED亮灭,并上报属性到云端

LED——————->GPIO14

KEY——————->GPIO8

重新配网————–>GPIO4

进入配网模式LED闪烁

#define ROUTER_SSID "ssid"
#define ROUTER_PWD "password"
设备创建

公共实例—>新建项目—>新建产品(标准品类、智慧生活、电工照明、灯)—>设置配网方式(softAP或标准BLE辅助)—>设备调试(新建设备)

设备配网方式设置

设备支持softAP、LLSync蓝牙辅助配网(主推蓝牙辅助配网)。默认配网方式为LLSync蓝牙辅助配网,切换配网方式需要修改下面的宏定义:

#define WIFI_PROV_SOFT_AP_ENABLE         0  ///< wifi provisioning method: device AP, need Wechat Applets
#define WIFI_PROV_SMART_CONFIG_ENABLE    0  ///< wifi provisioning method: smart config, need Wechat Applets
#define WIFI_PROV_AIRKISS_CONFIG_ENABLE  0  ///< wifi provisioning method: airkiss, need Wechat Applets
#define WIFI_PROV_SIMPLE_CONFIG_ENABLE   0  ///< wifi provisioning method: simple config, need Wechat Applets
#define WIFI_PROV_BT_COMBO_CONFIG_ENABLE 1  ///< wifi provisioning method: bt combo config, need Wechat Applets
三元组修改

用户需要在云平台找到设备对应的三元组,替换/qcloud_demo/components/qcloud_iot_c_sdk/platform/HAL_Device_freertos.c里的三元组

sg_product_id : product Id

sg_device_name : device name

sg_product_secret : product secret for device dynamic Registration

sg_device_secret:device secret

补丁

sofeAP配网需要在4网段,需要使用git apply在bl_iot_sdk打补丁dhcp_server_ip.patch

配网

腾讯连连小程序蓝牙配网流程: 进入腾讯连连小程序,进入“添加设备”,在添加设备界面小程序会自动扫描附近的设备,扫描到之后点击进入配网界面,按照提示完成配网即可。

Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

bh1750示例
安信可 bh1750示例
Ai-WB2 Series SoC Module Reads BH1750 Sensor via I²C Bus Example
Hardware Setup and Wiring

Ai-WB2 Series SoC Module Pinout

BH1750 Pinout

IO12

SCL

IO3

SDA

3V3

VCC

GND

GND

Build and Flash

make -j

make flash

Run _images/demo.jpg
Logic Analyzer Output _images/logic_analyzer.jpg
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

dht11示例
安信可 DHT11示例
Ai-WB2 Series SoC Module Reads DHT11 Sensor via GPIO Example
Hardware Setup and Wiring

Ai-WB2 Series SoC Module Pinout

DHT11 Pinout

IO4

DATA

3V3

VCC

GND

GND

Build and Flash

make -j

make flash

Run _images/demo1.jpg
Logic Analyzer Output _images/logic_analyzer1.jpg
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

ds18b20示例
安信可 ds18b20示例
Ai-WB2 Series SoC Module Reads DS18B20 Sensor via GPIO Example
Hardware Setup and Wiring

Ai-WB2 Series SoC Module Pinout

DS18B20 Pinout

IO4

DATA

3V3

VCC

GND

GND

Build and Flash

make -j

make flash

Run _images/demo2.jpg
Logic Analyzer Output _images/logic_analyzer2.jpg
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

mpu6050示例
安信可 mpu6050示例
Ai-WB2 Series SoC Module Reads MPU6050 Sensor via I²C Bus Example
Hardware Setup and Wiring

Ai-WB2 Series SoC Module Pinout

MPU6050 Pinout

IO4

SCL

IO5

SDA

3V3

VCC

GND

GND

Build and Flash

make -j

make flash

Run _images/demo3.jpg
Logic Analyzer Output _images/logic_analyzer3.jpg
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

ntc示例
安信可 NTC示例
Ai-WB2 Series SoC Module Temperature Measurement via NTC Example
Hardware Setup and Wiring _images/schematic.jpg _images/wiring.jpg
Solve NTC Resistor Value _images/schematic.jpg

make flash

Run _images/1.jpg _images/2.jpg _images/3.jpg
Relationship between Resistor Value & Temperature

https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/blob/main/applications/iot-solution/demo_ntc/img/RT.csv

Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

sht3x示例
安信可 sht3x示例
Ai-WB2 Series SoC Module Reads SHT30 Temperature and Humidity Sensor via I²C Bus Example
Hardware Setup and Wiring

Ai-WB2 Series SoC Module Pinout

SHT30 Pinout

IO12

SCL

IO3

SDA

3V3

VCC

GND

GND

Build and Flash

make -j

make flash

Run _images/demo4.jpg
Logic Analyzer Output _images/logic_analyzer4.jpg
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

w25qxx示例
安信可 w25qxx示例
Ai-WB2 Series SoC Module Reads SHT30 Temperature and Humidity Sensor via I²C Bus Example
Hardware Setup and Wiring

Ai-WB2 Series SoC Module Pinout

w25qxx Pinout

IO12

SCL

IO3

SDA

3V3

VCC

GND

GND

Build and Flash

make -j

make flash

Run _images/demo5.jpg
Logic Analyzer Output _images/logic_analyzer5.jpg
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

lvgl示例
安信可 LVGL Arc示例
LVGL Arc Example

The screen used in this routine is a 240 * 240 TFT display screen driven by ST7789.

LVGL config

LVGL configuration is unified in the lv_conf.h file. You can configure the model, size and drive pin of the display,

Model configuration
#define LV_DISPLAY_ST7789
SPI pin configuration
#define ST7789_DC 4
#define ST7789_CS 5
#define ST7789_RST 14
#define ST7789_CLK 3
#define ST7789_MOSI 12
#define ST7789_MISO 17
Display direction configuration
#define CONFIG_LV_DISPLAY_ORIENTATION 1
  • CONFIG_ LV_ DISPLAY_ ORIENTATION can be configured as 0 to 3, respectively identifying four display directions

#define LV_HOR_RES_MAX 240
#define LV_VER_RES_MAX 240
#define MY_DISP_VER_RES LV_VER_RES_MAX
#define MY_DISP_HOR_RES LV_HOR_RES_MAX
_images/example1.jpg _images/example2.gif
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

安信可LVGL Bar示例
LVGL Arc Example

The screen used in this routine is a 240 * 240 TFT display screen driven by ST7789。

LVGL config

LVGL configuration is unified in the lv_conf.h file. You can configure the model, size and drive pin of the display,

Model configuration
#define LV_DISPLAY_ST7789
SPI pin configuration
#define ST7789_DC 4
#define ST7789_CS 5
#define ST7789_RST 14
#define ST7789_CLK 3
#define ST7789_MOSI 12
#define ST7789_MISO 17
Display direction configuration
#define CONFIG_LV_DISPLAY_ORIENTATION 1
  • CONFIG_ LV_ DISPLAY_ ORIENTATION can be configured as 0 to 3, respectively identifying four display directions

#define LV_HOR_RES_MAX 240
#define LV_VER_RES_MAX 240
#define MY_DISP_VER_RES LV_VER_RES_MAX
#define MY_DISP_HOR_RES LV_HOR_RES_MAX

example 1

docs/api-reference/iot-solution/demo_lvgl/Bar_img/example1.jpg

example 2

docs/api-reference/iot-solution/demo_lvgl/Bar_img/example2.gif
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

安信可LVGL button示例
LVGL button Example

The screen used in this routine is a 240 * 240 TFT display screen driven by ST7789。

LVGL config

LVGL configuration is unified in the lv_conf.h file. You can configure the model, size and drive pin of the display,

Model configuration
#define LV_DISPLAY_ST7789
SPI pin configuration
#define ST7789_DC 4
#define ST7789_CS 5
#define ST7789_RST 14
#define ST7789_CLK 3
#define ST7789_MOSI 12
#define ST7789_MISO 17
Display direction configuration
#define CONFIG_LV_DISPLAY_ORIENTATION 1
  • CONFIG_ LV_ DISPLAY_ ORIENTATION can be configured as 0 to 3, respectively identifying four display directions

#define LV_HOR_RES_MAX 240
#define LV_VER_RES_MAX 240
#define MY_DISP_VER_RES LV_VER_RES_MAX
#define MY_DISP_HOR_RES LV_HOR_RES_MAX

example 1

_images/example11.jpg

example 2

_images/example2.jpg

example 3

_images/example3.jpg
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

安信可LVGL button_matrix示例
LVGL button_matrix Example

The screen used in this routine is a 240 * 240 TFT display screen driven by ST7789。

LVGL config

LVGL configuration is unified in the lv_conf.h file. You can configure the model, size and drive pin of the display,

Model configuration
#define LV_DISPLAY_ST7789
SPI pin configuration
#define ST7789_DC 4
#define ST7789_CS 5
#define ST7789_RST 14
#define ST7789_CLK 3
#define ST7789_MOSI 12
#define ST7789_MISO 17
Display direction configuration
#define CONFIG_LV_DISPLAY_ORIENTATION 1
  • CONFIG_ LV_ DISPLAY_ ORIENTATION can be configured as 0 to 3, respectively identifying four display directions

#define LV_HOR_RES_MAX 240
#define LV_VER_RES_MAX 240
#define MY_DISP_VER_RES LV_VER_RES_MAX
#define MY_DISP_HOR_RES LV_HOR_RES_MAX

example 1

_images/example12.jpg

example 2

_images/example21.jpg

example 3

_images/example31.jpg
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

安信可 LVGL checkbox示例
LVGL checkbox Example

The screen used in this routine is a 240 * 240 TFT display screen driven by ST7789。

LVGL config

LVGL configuration is unified in the lv_conf.h file. You can configure the model, size and drive pin of the display,

Model configuration
#define LV_DISPLAY_ST7789
SPI pin configuration
#define ST7789_DC 4
#define ST7789_CS 5
#define ST7789_RST 14
#define ST7789_CLK 3
#define ST7789_MOSI 12
#define ST7789_MISO 17
Display direction configuration
#define CONFIG_LV_DISPLAY_ORIENTATION 1
  • CONFIG_ LV_ DISPLAY_ ORIENTATION can be configured as 0 to 3, respectively identifying four display directions

#define LV_HOR_RES_MAX 240
#define LV_VER_RES_MAX 240
#define MY_DISP_VER_RES LV_VER_RES_MAX
#define MY_DISP_HOR_RES LV_HOR_RES_MAX

example 1

_images/example13.jpg

example 2

_images/example22.jpg
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

安信可 LVGL示例
LVGL Example

The display driver used in this routine is SSD1306,and the size is 128 * 64.I2C communication mode。

LVGL config

LVGL configuration is unified in the lv_conf.h file. You can configure the model, size and drive pin of the display,

Model configuration
#define LV_DISPLAY_SSD1306
I2C pin configuration
#define OLED_IIC_SCL 12
#define OLED_IIC_SDA 3
Display direction configuration
 #define LV_DISPLAY_ORIENTATION_LANDSCAPE
// #define LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED
  • LV_DISPLAY_ORIENTATION_LANDSCAPE:Normal display

  • LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED: Mirror Display

#define MY_DISP_HOR_RES    128
#define MY_DISP_VER_RES    64
#define LV_VER_RES_MAX     10
_images/ssd1306.jpg
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

安信可 LVGL Label示例
LVGL Label Example

The screen used in this routine is a 240 * 240 TFT display screen driven by ST7789.

LVGL config

LVGL configuration is unified in the lv_conf.h file. You can configure the model, size and drive pin of the display,

Model configuration
#define LV_DISPLAY_ST7789
SPI pin configuration
#define ST7789_DC 4
#define ST7789_CS 5
#define ST7789_RST 14
#define ST7789_CLK 3
#define ST7789_MOSI 12
#define ST7789_MISO 17
Display direction configuration
#define CONFIG_LV_DISPLAY_ORIENTATION 1
  • CONFIG_ LV_ DISPLAY_ ORIENTATION can be configured as 0 to 3, respectively identifying four display directions

#define LV_HOR_RES_MAX 240
#define LV_VER_RES_MAX 240
#define MY_DISP_VER_RES LV_VER_RES_MAX
#define MY_DISP_HOR_RES LV_HOR_RES_MAX
_images/example1.gif _images/example23.jpg _images/example32.jpg _images/example4.jpg
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

open_project 示例
安信可 radar_node示例
Ai-WB2 Series SoC Module Reads Rd-01 Sensor via UART example
Hardware Setup and Wiring

Ai-WB2 Series SoC Module Pinout

Rd-01 Pinout

IO4

RXD

IO3

TXD

3V3

VCC

GND

GND

Build and Flash

make -j

make flash

NOTE

Rd-01 status

Value

NOT TARGET

0x00

ACTIVE TARGET

0x01

STATIC TARGET

0x02

ACTIVE & STATIC TARGET

0x03

  • LOCAL UDP LISTEN PORT 7878

Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

安信可 sensor_node示例
Ai-WB2 Series SoC Module Reads SHT30 Temperature and Humidity Sensor via I²C Bus example
Hardware Setup and Wiring

Ai-WB2 Series SoC Module Pinout

SHT30 Pinout

IO12

SCL

IO3

SDA

3V3

VCC

GND

GND

Build and Flash

make -j

make flash

Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

system示例
安信可 system示例参考
例程参考
app_json示例
安信可 app_json示例
app_json Example

This project uses the cjson component in the components component.

It is located in`components`–>`stage`–>`cjson` When using, reference this component in the Makefile, and then reference the header file in the source file.

Use of Makefile
COMPONENTS_VFS     := romfs cjson
References to source files
#include <cJSON.h>

This project takes the following json data as an example to create and parse the data. Finally,running command below to compile project on ubuntu.

{
"name": "aithinker",
"age": 22,
"address": {
 "country": "China",
 "zip-code": 111111
},
"skill": ["C", "Java", "Python"],
"KOL": false
}
Example Output
Booting Ai-WB2 Modules...
------------------------------------------------------------
RISC-V Core Feature:RV32-ACFIMX
Build Version: release_bl_iot_sdk_1.6.38
Build Date: Oct 21 2022
Build Time: 22:03:06
------------------------------------------------------------

blog init set power on level 2, 2, 2.
[IRQ] Clearing and Disable all the pending IRQ...
INFO (0)[hal_boot2.c: 285] [HAL] [BOOT2] Active Partition[0] consumed 596 Bytes
INFO (0)[hal_boot2.c:  82] ======= PtTable_Config @0x4200d380=======
INFO (0)[hal_boot2.c:  83] magicCode 0x54504642; version 0x0000; entryCnt 7; age 0; crc32 0x12DF9A26
INFO (0)[hal_boot2.c:  91] idx  type device activeIndex     name   Address[0]  Address[1]  Length[0]   Length[1]   age
INFO (0)[hal_boot2.c:  93] [00]  00     0         0            FW  0x00010000  0x000e8000  0x000d8000  0x00088000  0
INFO (0)[hal_boot2.c:  93] [01]  02     0         0           mfg  0x00170000  0x00000000  0x00032000  0x00000000  0
INFO (0)[hal_boot2.c:  93] [02]  03     0         0         media  0x001a2000  0x00000000  0x00047000  0x00000000  0
INFO (0)[hal_boot2.c:  93] [03]  04     0         0           PSM  0x001e9000  0x00000000  0x00008000  0x00000000  0
INFO (0)[hal_boot2.c:  93] [04]  05     0         0           KEY  0x001f1000  0x00000000  0x00002000  0x00000000  0
INFO (0)[hal_boot2.c:  93] [05]  06     0         0          DATA  0x001f3000  0x00000000  0x00005000  0x00000000  0
INFO (0)[hal_boot2.c:  93] [06]  07     0         0       factory  0x001f8000  0x00000000  0x00007000  0x00000000  0
INFO (0)[bl_flash.c: 392] ======= FlashCfg magiccode @0x42049c18=======
INFO (0)[bl_flash.c: 393] mid           0x5E
INFO (0)[bl_flash.c: 394] clkDelay      0x1
INFO (0)[bl_flash.c: 395] clkInvert     0x1
INFO (0)[bl_flash.c: 396] sector size   4KBytes
INFO (0)[bl_flash.c: 397] page size     256Bytes
INFO (0)[bl_flash.c: 398] ---------------------------------------------------------------
INFO (0)[hal_board.c:1289] [MAIN] [BOARD] [FLASH] addr from partition is 001f8000, ret is 0
INFO (0)[hal_board.c:1297] [MAIN] [BOARD] [XIP] addr from partition is 231e7000, ret is 0
INFO (5)[main.c: 121] json demo Start
INFO (8)[main.c:  57] {
"name": "aithinker",
"age": 22,
"address": {
 "country": "China",
 "zip-code": 111111
},
"skill": ["C", "Java", "Python"],
"KOL": false
}
INFO (22)[main.c:  58] {"name":"aithinker","age":22,"address":{"country":"China","zip-code":111111},"skill":["C","Java","Python"],"KOL":false}
INFO (1007)[main.c:  81] name=aithinker
INFO (1009)[main.c:  84] age=22
INFO (1012)[main.c:  87] p_kol=0
INFO (1016)[main.c:  91] country=China
INFO (1020)[main.c:  94] zip_code=111111
INFO (1025)[main.c: 101] stu_arr_size: 3
INFO (1029)[main.c: 106] id:0, skills=C
INFO (1033)[main.c: 106] id:1, skills=Java
INFO (1038)[main.c: 106] id:2, skills=Python
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

blog_demo示例
安信可 blog_demo示例
blog_demo world Example

The SDK has the following levels in total:

typedef enum _blog_leve {
  BLOG_LEVEL_ALL = 0,
  BLOG_LEVEL_DEBUG,
  BLOG_LEVEL_INFO,
  BLOG_LEVEL_WARN,
  BLOG_LEVEL_ERROR,
  BLOG_LEVEL_ASSERT,
  BLOG_LEVEL_NEVER,
} blog_level_t;

In which, DEBUG level does not print by default, even if it has been set to DEBUG level, there will be no output

You can start the output of DEBUG level through the macro definition in “blog_cfg. h”

 #define BLOG_POWERON_SOFTLEVEL_FILE
(BLOG_LEVEL_INFO) //BLOG_LEVEL_INFO ---> BLOG_LEVEL_DEBUG

This routine enables DEBUG level to demonstrate DEBUG output.

Example Output
Booting Ai-WB2 Modules...
------------------------------------------------------------
RISC-V Core Feature:RV32-ACFIMX
Build Version: release_bl_iot_sdk_1.6.38
Build Date: Oct 22 2022
Build Time: 16:07:11
------------------------------------------------------------

blog init set power on level 2, 1, 2.
[IRQ] Clearing and Disable all the pending IRQ...
INFO (0)[hal_boot2.c: 285] [HAL] [BOOT2] Active Partition[0] consumed 596 Bytes
INFO (0)[hal_boot2.c:  82] ======= PtTable_Config @0x4200d158=======
INFO (0)[hal_boot2.c:  83] magicCode 0x54504642; version 0x0000; entryCnt 7; age 0; crc32 0x12DF9A26
INFO (0)[hal_boot2.c:  91] idx  type device activeIndex     name   Address[0]  Address[1]  Length[0]   Length[1]   age
INFO (0)[hal_boot2.c:  93] [00]  00     0         0            FW  0x00010000  0x000e8000  0x000d8000  0x00088000  0
INFO (0)[hal_boot2.c:  93] [01]  02     0         0           mfg  0x00170000  0x00000000  0x00032000  0x00000000  0
INFO (0)[hal_boot2.c:  93] [02]  03     0         0         media  0x001a2000  0x00000000  0x00047000  0x00000000  0
INFO (0)[hal_boot2.c:  93] [03]  04     0         0           PSM  0x001e9000  0x00000000  0x00008000  0x00000000  0
INFO (0)[hal_boot2.c:  93] [04]  05     0         0           KEY  0x001f1000  0x00000000  0x00002000  0x00000000  0
INFO (0)[hal_boot2.c:  93] [05]  06     0         0          DATA  0x001f3000  0x00000000  0x00005000  0x00000000  0
INFO (0)[hal_boot2.c:  93] [06]  07     0         0       factory  0x001f8000  0x00000000  0x00007000  0x00000000  0
INFO (0)[bl_flash.c: 392] ======= FlashCfg magiccode @0x42049c18=======
INFO (0)[bl_flash.c: 393] mid           0x5E
INFO (0)[bl_flash.c: 394] clkDelay      0x1
INFO (0)[bl_flash.c: 395] clkInvert     0x1
INFO (0)[bl_flash.c: 396] sector size   4KBytes
INFO (0)[bl_flash.c: 397] page size     256Bytes
INFO (0)[bl_flash.c: 398] ---------------------------------------------------------------
INFO (0)[hal_board.c:1289] [MAIN] [BOARD] [FLASH] addr from partition is 001f8000, ret is 0
INFO (0)[hal_board.c:1297] [MAIN] [BOARD] [XIP] addr from partition is 231e7000, ret is 0
The log level is LOG_LEVEL_ALL
DEBUG (5)[main.c:  22] The log level is LOG_LEVEL_DEBUG
INFO (11)[main.c:  23] The log level is LOG_LEVEL_INFO
WARN (16)[main.c:  24] The log level is LOG_LEVEL_WARN
ERROR (22)[main.c:  25] The log level is LOG_LEVEL_ERROR
ASSERT (28)[main.c:  26] The log level is LOG_LEVEL_ASSERT
The log level is LOG_LEVEL_NEVER

DEBUG (37)[main.c:  31] The log level is LOG_LEVEL_DEBUG
INFO (43)[main.c:  32] The log level is LOG_LEVEL_INFO
WARN (48)[main.c:  33] The log level is LOG_LEVEL_WARN
ERROR (54)[main.c:  34] The log level is LOG_LEVEL_ERROR
ASSERT (60)[main.c:  35] The log level is LOG_LEVEL_ASSERT
The log level is LOG_LEVEL_NEVE

INFO (69)[main.c:  42] The log level is LOG_LEVEL_INFO
WARN (75)[main.c:  43] The log level is LOG_LEVEL_WARN
ERROR (80)[main.c:  44] The log level is LOG_LEVEL_ERROR
ASSERT (86)[main.c:  45] The log level is LOG_LEVEL_ASSERT
The log level is LOG_LEVEL_NEVER

WARN (95)[main.c:  53] The log level is LOG_LEVEL_WARN
ERROR (101)[main.c:  54] The log level is LOG_LEVEL_ERROR
ASSERT (107)[main.c:  55] The log level is LOG_LEVEL_ASSERT
The log level is LOG_LEVEL_NEVER

ERROR (116)[main.c:  64] The log level is LOG_LEVEL_ERROR
ASSERT (122)[main.c:  65] The log level is LOG_LEVEL_ASSERT
The log level is LOG_LEVEL_NEVER

ASSERT (131)[main.c:  75] The log level is LOG_LEVEL_ASSERT
The log level is LOG_LEVEL_NEVER

The log level is LOG_LEVEL_NEVER
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

ota示例
安信可 OTA示例
OTA Example
create ota firmware
  1. open the bl602_flash_download_tool

  2. Select the firmware you want to OTA

  3. click the Create&Download button

  4. The ota firmware will be created in chipsbl602ota directory, Select FW_OTA.bin (compressed upgrade) or fw_ota.bin.xz (dual-partition upgrade)

How to use example

_images/create_ota_firmware.jpg
  1. Add header information to ota firmware

open Ai-Thinker OTA Config Tools.exe(in tools directory) and Select FW_OTA.bin or fw_ota.bin.xz

_images/ota_config.jpg
Configure

Please configure the ssid and password that need to be connected to WiFi in advance,in main.c

#define ROUTER_SSID "your ssid"
#define ROUTER_PWD "your password"

Then configure the url for ota firmware

#define url "https://chencong--test.oss-cn-beijing.aliyuncs.com/test.bin"
Example Output
(other log)...
[WF][SM] Exiting wifiConnected_ipObtaining state
[WF][SM] State Action ###wifiConnected_ipObtaining### --->>> ###wifiConnected_IPOK###
[WF][SM] Entering wifiConnected_IPOK state
[APP] [EVT] GOT IP 6008
[SYS] Memory left is 154816 Bytes
[OTA] port:443 host:chencong--test.oss-cn-beijing.aliyuncs.com path:/test.bin
mbedtls_entropy_init
mbedtls_ctr_drbg_seed success
mbedtls_ssl_setup sucess
-----------------> AABA Request:
  A-MSDU: Permitted
  Block Ack Policy: Immediate Block Ack
  TID: 0
  Number of Buffers: 64
-----------------> AABA Response:
  A-MSDU: Not Permitted
  Block Ack Policy: Immediate Block Ack
  TID: 0
  Number of Buffers: 8
  ssn: 0
  timeout: 1
  tid 0
mbedtls_net_connect sucess
mbedtls_ssl_handshake sucess
SSL ciphersuite TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256
                                                   mbedtls_ssl_write success

Download new firmware begin, total size : 72169
                                             MBEDTLS_SSL_MAX_CONTENT_LEN = 16384
head_len = 480 writelen=544 index = 1024
version = 1.0.0
chip_type = 0004
http head md5:3BE39B7C06476F5534A8B7E0DEDCDEFF
[MTD] >>>>>> Hanlde info Dump >>>>>>
    name FW
    id 0
    offset 0x000e8000(950272)
    size 0x00088000(544Kbytes)
    xip_addr 0x00000000
[MTD] <<<<<< Hanlde info End <<<<<<
[OTA] activeID:0
init_ota_partition success, ota_addr:0xe8000, part_size:0x88000
[OTA] erase start_addr:0x0 size:0x12000
[OTA] write dst_offset:0x4316
[OTA] write dst_offset:0x84b6
[OTA] write dst_offset:0xc656
[OTA] write dst_offset:0x107f6

end

MD5 verify success
3BE39B7C06476F5534A8B7E0DEDCDEFF
[OTA] ota size:0x11940
OTA Success
Booting Ai-WB2 Modules...
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

bind_demo示例
安信可 Bind示例
Bind Example

This routine provides the chip detection function, so that the program can only run on the modules produced by Ai-Thinker.

Example Output
Validation succeeded
Starting bl602 now....
Booting Ai-WB2 Modules...
RISC-V Core Feature:RV32-ACFIMX
Build Version: release_bl_iot_sdk_1.6.38
Build Date: Dec 30 2022
Build Time: 09:30:16

blog init set power on level 2, 2, 2.
[IRQ] Clearing and Disable all the pending IRQ...
INFO (0)[hal_boot2.c: 251] [HAL] [BOOT2] Active Partition[0] consumed 596 Bytes
INFO (0)[hal_boot2.c:  53] ======= PtTable_Config @0x4200d4e4=======
INFO (0)[hal_boot2.c:  54] magicCode 0x54504642; version 0x0000; entryCnt 7; age 0; crc32 0x12DF9A26
INFO (0)[hal_boot2.c:  59] idx  type device activeIndex     name   Address[0]  Address[1]  Length[0]   Length[1]   age
INFO (0)[hal_boot2.c:  61] [00]  00     0         0            FW  0x00010000  0x000e8000  0x000d8000  0x00088000  0
INFO (0)[hal_boot2.c:  61] [01]  02     0         0           mfg  0x00170000  0x00000000  0x00032000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [02]  03     0         0         media  0x001a2000  0x00000000  0x00047000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [03]  04     0         0           PSM  0x001e9000  0x00000000  0x00008000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [04]  05     0         0           KEY  0x001f1000  0x00000000  0x00002000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [05]  06     0         0          DATA  0x001f3000  0x00000000  0x00005000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [06]  07     0         0       factory  0x001f8000  0x00000000  0x00007000  0x00000000  0
INFO (0)[bl_flash.c: 363] ======= FlashCfg magiccode @0x42049c18=======
INFO (0)[bl_flash.c: 364] mid           0xC8
INFO (0)[bl_flash.c: 365] clkDelay      0x1
INFO (0)[bl_flash.c: 366] clkInvert     0x1
INFO (0)[bl_flash.c: 367] sector size   4KBytes
INFO (0)[bl_flash.c: 368] page size     256Bytes
INFO (0)[bl_flash.c: 369] ---------------------------------------------------------------
INFO (0)[hal_board.c:1279] [MAIN] [BOARD] [FLASH] addr from partition is 001f8000, ret is 0
INFO (0)[hal_board.c:1287] [MAIN] [BOARD] [XIP] addr from partition is 231e7000, ret is 0
[OS] Starting aos_loop_proc task...
[OS] Starting OS Scheduler...
Init CLI with event Driven
INFO (7)[main.c:  21] SYN_EVT_COMPLETE: 0
running
running
running
running
running
running
running
running
running
running
running
Validation failed
Starting bl602 now....
Booting Ai-WB2 Modules...
RISC-V Core Feature:RV32-ACFIMX
Build Version: release_bl_iot_sdk_1.6.38
Build Date: Dec 30 2022
Build Time: 09:30:16

blog init set power on level 2, 2, 2.
[IRQ] Clearing and Disable all the pending IRQ...
INFO (0)[hal_boot2.c: 251] [HAL] [BOOT2] Active Partition[0] consumed 596 Bytes
INFO (0)[hal_boot2.c:  53] ======= PtTable_Config @0x4200d4e4=======
INFO (0)[hal_boot2.c:  54] magicCode 0x54504642; version 0x0000; entryCnt 7; age 0; crc32 0x12DF9A26
INFO (0)[hal_boot2.c:  59] idx  type device activeIndex     name   Address[0]  Address[1]  Length[0]   Length[1]   age
INFO (0)[hal_boot2.c:  61] [00]  00     0         0            FW  0x00010000  0x000e8000  0x000d8000  0x00088000  0
INFO (0)[hal_boot2.c:  61] [01]  02     0         0           mfg  0x00170000  0x00000000  0x00032000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [02]  03     0         0         media  0x001a2000  0x00000000  0x00047000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [03]  04     0         0           PSM  0x001e9000  0x00000000  0x00008000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [04]  05     0         0           KEY  0x001f1000  0x00000000  0x00002000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [05]  06     0         0          DATA  0x001f3000  0x00000000  0x00005000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [06]  07     0         0       factory  0x001f8000  0x00000000  0x00007000  0x00000000  0
INFO (0)[bl_flash.c: 363] ======= FlashCfg magiccode @0x42049c18=======
INFO (0)[bl_flash.c: 364] mid          0xEF
INFO (0)[bl_flash.c: 365] clkDelay     0x1
INFO (0)[bl_flash.c: 366] clkInvert    0x1
INFO (0)[bl_flash.c: 367] sector size  4KBytes
INFO (0)[bl_flash.c: 368] page size    256Bytes
INFO (0)[bl_flash.c: 369] ---------------------------------------------------------------
INFO (0)[hal_board.c:1279] [MAIN] [BOARD] [FLASH] addr from partition is 001f8000, ret is 0
INFO (0)[hal_board.c:1287] [MAIN] [BOARD] [XIP] addr from partition is 231e7000, ret is 0
[OS] Starting aos_loop_proc task...
[OS] Starting OS Scheduler...
Init CLI with event Driven
INFO (6)[main.c:  21] SYN_EVT_COMPLETE: 5
ERROR (9)[main.c:  36] invaild bind info
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

deep_sleep示例
安信可deep sleep示例
deep_sleep Example

weakup pin only can set gpio7 or gpio8

As you run the example, you will see the log :

Starting bl602 now....
Booting Ai-WB2 Modules...
RISC-V Core Feature:RV32-ACFIMX
Build Version: release_bl_iot_sdk_1.6.38
Build Date: Dec 13 2022
Build Time: 14:10:47

blog init set power on level 2, 2, 2.
[IRQ] Clearing and Disable all the pending IRQ...
INFO (0)[hal_boot2.c: 251] [HAL] [BOOT2] Active Partition[0] consumed 596 Bytes
INFO (0)[hal_boot2.c:  53] ======= PtTable_Config @0x4200d268=======
INFO (0)[hal_boot2.c:  54] magicCode 0x54504642; version 0x0000; entryCnt 7; age 0; crc32 0x12DF9A26
INFO (0)[hal_boot2.c:  59] idx  type device activeIndex     name   Address[0]  Address[1]  Length[0]   Length[1]   age
INFO (0)[hal_boot2.c:  61] [00]  00     0         0            FW  0x00010000  0x000e8000  0x000d8000  0x00088000  0
INFO (0)[hal_boot2.c:  61] [01]  02     0         0           mfg  0x00170000  0x00000000  0x00032000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [02]  03     0         0         media  0x001a2000  0x00000000  0x00047000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [03]  04     0         0           PSM  0x001e9000  0x00000000  0x00008000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [04]  05     0         0           KEY  0x001f1000  0x00000000  0x00002000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [05]  06     0         0          DATA  0x001f3000  0x00000000  0x00005000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [06]  07     0         0       factory  0x001f8000  0x00000000  0x00007000  0x00000000  0
INFO (0)[bl_flash.c: 363] ======= FlashCfg magiccode @0x42049c18=======
INFO (0)[bl_flash.c: 364] mid           0x5E
INFO (0)[bl_flash.c: 365] clkDelay      0x1
INFO (0)[bl_flash.c: 366] clkInvert     0x1
INFO (0)[bl_flash.c: 367] sector size   4KBytes
INFO (0)[bl_flash.c: 368] page size     256Bytes
INFO (0)[bl_flash.c: 369] ---------------------------------------------------------------
INFO (0)[hal_board.c:1279] [MAIN] [BOARD] [FLASH] addr from partition is 001f8000, ret is 0
INFO (0)[hal_board.c:1287] [MAIN] [BOARD] [XIP] addr from partition is 231e7000, ret is 0
[OS] Starting aos_loop_proc task...
[OS] Starting OS Scheduler...
test:60
enter sleep
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

RTC示例
安信可 RTC示例
RTC Example

As you run the example, you will see the log :

Starting bl602 now....
Booting Ai-WB2 Modules...
RISC-V Core Feature:RV32-ACFIMX
Build Version: release_bl_iot_sdk_1.6.38
Build Date: Dec 12 2022
Build Time: 15:22:34

blog init set power on level 2, 2, 2.
[IRQ] Clearing and Disable all the pending IRQ...
INFO (0)[hal_boot2.c: 251] [HAL] [BOOT2] Active Partition[0] consumed 596 Bytes
INFO (0)[hal_boot2.c:  53] ======= PtTable_Config @0x4200d170=======
INFO (0)[hal_boot2.c:  54] magicCode 0x54504642; version 0x0000; entryCnt 7; age 0; crc32 0x12DF9A26
INFO (0)[hal_boot2.c:  59] idx  type device activeIndex     name   Address[0]  Address[1]  Length[0]   Length[1]   age
INFO (0)[hal_boot2.c:  61] [00]  00     0         0            FW  0x00010000  0x000e8000  0x000d8000  0x00088000  0
INFO (0)[hal_boot2.c:  61] [01]  02     0         0           mfg  0x00170000  0x00000000  0x00032000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [02]  03     0         0         media  0x001a2000  0x00000000  0x00047000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [03]  04     0         0           PSM  0x001e9000  0x00000000  0x00008000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [04]  05     0         0           KEY  0x001f1000  0x00000000  0x00002000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [05]  06     0         0          DATA  0x001f3000  0x00000000  0x00005000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [06]  07     0         0       factory  0x001f8000  0x00000000  0x00007000  0x00000000  0
INFO (0)[bl_flash.c: 363] ======= FlashCfg magiccode @0x42049c18=======
INFO (0)[bl_flash.c: 364] mid           0x5E
INFO (0)[bl_flash.c: 365] clkDelay      0x1
INFO (0)[bl_flash.c: 366] clkInvert     0x1
INFO (0)[bl_flash.c: 367] sector size   4KBytes
INFO (0)[bl_flash.c: 368] page size     256Bytes
INFO (0)[bl_flash.c: 369] ---------------------------------------------------------------
INFO (0)[hal_board.c:1279] [MAIN] [BOARD] [FLASH] addr from partition is 001f8000, ret is 0
INFO (0)[hal_board.c:1287] [MAIN] [BOARD] [XIP] addr from partition is 231e7000, ret is 0
[OS] Starting aos_loop_proc task...
[OS] Starting OS Scheduler...
cnt:1003
cnt:2006
cnt:3010
cnt:4013
cnt:5017
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

soft_timer示例
安信可 soft timer示例
soft timer Example

As you run the example, you will see the log :

Starting bl602 now....
Booting Ai-WB2 Modules...
RISC-V Core Feature:RV32-ACFIMX
Build Version: release_bl_iot_sdk_1.6.38
Build Date: Dec 12 2022
Build Time: 13:54:49

blog init set power on level 2, 2, 2.
[IRQ] Clearing and Disable all the pending IRQ...
INFO (0)[hal_boot2.c: 251] [HAL] [BOOT2] Active Partition[0] consumed 596 Bytes
INFO (0)[hal_boot2.c:  53] ======= PtTable_Config @0x4200d170=======
INFO (0)[hal_boot2.c:  54] magicCode 0x54504642; version 0x0000; entryCnt 7; age 0; crc32 0x12DF9A26
INFO (0)[hal_boot2.c:  59] idx  type device activeIndex     name   Address[0]  Address[1]  Length[0]   Length[1]   age
INFO (0)[hal_boot2.c:  61] [00]  00     0         0            FW  0x00010000  0x000e8000  0x000d8000  0x00088000  0
INFO (0)[hal_boot2.c:  61] [01]  02     0         0           mfg  0x00170000  0x00000000  0x00032000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [02]  03     0         0         media  0x001a2000  0x00000000  0x00047000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [03]  04     0         0           PSM  0x001e9000  0x00000000  0x00008000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [04]  05     0         0           KEY  0x001f1000  0x00000000  0x00002000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [05]  06     0         0          DATA  0x001f3000  0x00000000  0x00005000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [06]  07     0         0       factory  0x001f8000  0x00000000  0x00007000  0x00000000  0
INFO (0)[bl_flash.c: 363] ======= FlashCfg magiccode @0x42049c18=======
INFO (0)[bl_flash.c: 364] mid           0x5E
INFO (0)[bl_flash.c: 365] clkDelay      0x1
INFO (0)[bl_flash.c: 366] clkInvert     0x1
INFO (0)[bl_flash.c: 367] sector size   4KBytes
INFO (0)[bl_flash.c: 368] page size     256Bytes
INFO (0)[bl_flash.c: 369] ---------------------------------------------------------------
INFO (0)[hal_board.c:1279] [MAIN] [BOARD] [FLASH] addr from partition is 001f8000, ret is 0
INFO (0)[hal_board.c:1287] [MAIN] [BOARD] [XIP] addr from partition is 231e7000, ret is 0
[OS] Starting aos_loop_proc task...
[OS] Starting OS Scheduler...
INFO (105)[main.c:  21] timer1_cb:1

INFO (205)[main.c:  21] timer1_cb:2

INFO (305)[main.c:  21] timer1_cb:3

INFO (405)[main.c:  21] timer1_cb:4

INFO (505)[main.c:  21] timer1_cb:5

INFO (605)[main.c:  21] timer1_cb:6

INFO (705)[main.c:  21] timer1_cb:7

INFO (805)[main.c:  21] timer1_cb:8

INFO (905)[main.c:  21] timer1_cb:9

INFO (1005)[main.c:  26] timer2_cb:delete timer2 and stop timer1

INFO (3006)[main.c:  33] timer3_cb:start timer1 again and change timer cycle

INFO (4011)[main.c:  21] timer1_cb:10

INFO (5011)[main.c:  21] timer1_cb:11

INFO (6011)[main.c:  21] timer1_cb:12

INFO (7011)[main.c:  21] timer1_cb:13

INFO (8011)[main.c:  21] timer1_cb:14

INFO (9011)[main.c:  21] timer1_cb:15

INFO (10011)[main.c:  21] timer1_cb:16

INFO (11011)[main.c:  21] timer1_cb:17
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

bluetooth示例
安信可 ble_ibeacon示例

Example: Ai-WB2 Series SoC Module ble ibeacon usage
Hardware Setup and Wiring

Ai-WB2 Series SoC Module Pinout

Peripheral Pinout

3V3

VCC

GND

GND

Build and Flash

make -j

make flash

Test

More detail to look for the foler docs.

Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

安信可 ble_master示例

概述:

实现蓝牙主机扫描透步骤如下: 1、相关硬件和基础服务初始化; 2、设置扫描参数; 3、设置连接参数; 4、设置配对参数(可选); 5、启动协议栈,开始运行; 6、等待相关事件,及事件处理,例如扫描事件等;

开发环境搭建

在Ubuntu环境下,打开终端,安装make,命令:sudo apt-get update、sudo apt-get install make。

获取sdk代码:git clone https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2

在Ai-Thinker-WB2/applications/ble下创建ble_master工程,仿照applications/get-started/hello工程写Makefile、proj_config.mk等编译规则文件以及自己的代码到ble_master工程里,使用make命令进行编译。

烧录及测试

准备好一块NodeMCU-Serices Ai-WB2-12F-Kit开发板连接电脑,打开Bouffalo Lab Dev Cube 1.8.0 for AiThinker -BL602/604烧录软件导入要下载的固件,配置好下载COM口和波特率等参数,然后点击软件上的Open UART按钮连接设备,再长按开发板上的BURM按键,同时短按一下EN按键,进入下载模式,最后点击烧录软件上Create&Download开始烧录。烧录软件上的配置截图如下:

_images/ble_master.png

打开串口调试助手,可以看到打印的扫描BLE设备信息,连接从机成功的信息

_images/ble_master_uart.png
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

安信可 ble_slave示例

Example: Ai-WB2 Series SoC Module ble slave usage
Hardware Setup and Wiring

Ai-WB2 Series SoC Module Pinout

Peripheral Pinout

3V3

VCC

GND

GND

Build and Flash

make -j

make flash

Test

More detail to look for the foler docs.

Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

安信可 Blufi 示例

Example:Ai-WB2 Blufi

This demo shows how to use the Blufi to configurate the Wi-Fi connection to AP.

The BluFi for Ai-WB2 is a Wi-Fi network configuration function via Bluetooth channel. It provides a secure protocol to pass Wi-Fi configuration and credentials to the Ai-WB2.

How to Use Example

Before project configuration and build, be sure to set the correct chip target using:

make flash

To test this demo, you need to prepare a mobile phone with blufi application installed. You can download the blufi application from Android version and iOS version.

Blufi is completely open source, here is the download link:

Blufi source code BluFi protocol iOS source code Android source code

Hardware Required
  • A development board with Ai-WB2 SoC (e.g., Ai-WB2-12F-Kit, etc.)

  • A USB cable for Power supply and programming

Build and Flash

Run make flash p=/dev/ttyUSB0 b=921600 to build, flash the project.

Example Output
[version] lmac 5.4.0.0
[version] version_machw_1 000055FB
[version] version_machw_2 000001B3
[version] version_phy_1 00822111
[version] version_phy_2 00000000
[version] features 001089DF
[ME] HT supp 1, VHT supp 0
[WF] country code CN used, num of channel 13
[WF][SM] reload tsen
[WF][SM] Exiting ifaceDown state
[WF][SM] State Action ###ifaceDown### --->>> ###idle###
[WF][SM] Entering idle state
[WIFI] [EVT] CODE_WIFI_ON_INIT_DONE
[WIFI] [EVT] CODE_WIFI_ON_MGMR_DONE
[BL] [SEC] TRNG Handler
[BL] [SEC] TRNG Handler
BD_ADDR:(MSB)7c:b9:4c:1d:d1:dc(LSB)
[blufi]btc_transfer_context msg 0 0 0x00000000
[blufi] btc_thread_handler msg 0 0 0x00000000
BLUFI example_event_callback event= ]0]
BLUFI init finish
[BLE] set adv
[BLE] en adv
[BL] [SEC] TRNG Handler
[BL] [SEC] TRNG Handler
[blufi]btc_transfer_context msg 1 3 0x420328dc
[blufi] btc_thread_handler msg 1 3 0x4201c640
BLUFI example_event_callback event= ]3]
BLUFI ble connect
blufi_security_init ok
blufi_security_init mbedtls_aes_init ok
[BLE] connected
[BLE] conn param request: int 0x0006-0x0006 lat 0 to 500
[BLE] conn param updated: int 0x0006 lat 0 to 500
[BLE] conn param request: int 0x0024-0x0024 lat 0 to 500
[BLE] conn param updated: int 0x0024 lat 0 to 500
[BLE] conn param updated: int 0x0028 lat 0 to 400
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

security示例
安信可 security示例
例程参考
AES示例
安信可 AES示例
AES Example

This routine demonstrates the routine of AEC’s ECB and CBC modes. Each mode shows how to perform 128 bit, 192 bit and 256 bit encryption

Example Output
Starting bl602 now....
Booting Ai-WB2 Modules...
RISC-V Core Feature:RV32-ACFIMX
Build Version: release_bl_iot_sdk_1.6.38
Build Date: Nov 17 2022
Build Time: 09:57:06

blog init set power on level 2, 2, 2.
[IRQ] Clearing and Disable all the pending IRQ...
INFO (0)[hal_boot2.c: 251] [HAL] [BOOT2] Active Partition[0] consumed 596 Bytes
INFO (0)[hal_boot2.c:  53] ======= PtTable_Config @0x4200d16c=======
INFO (0)[hal_boot2.c:  54] magicCode 0x54504642; version 0x0000; entryCnt 7; age 0; crc32 0x12DF9A26
INFO (0)[hal_boot2.c:  59] idx  type device activeIndex     name   Address[0]  Address[1]  Length[0]   Length[1]   age
INFO (0)[hal_boot2.c:  61] [00]  00     0         0            FW  0x00010000  0x000e8000  0x000d8000  0x00088000  0
INFO (0)[hal_boot2.c:  61] [01]  02     0         0           mfg  0x00170000  0x00000000  0x00032000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [02]  03     0         0         media  0x001a2000  0x00000000  0x00047000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [03]  04     0         0           PSM  0x001e9000  0x00000000  0x00008000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [04]  05     0         0           KEY  0x001f1000  0x00000000  0x00002000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [05]  06     0         0          DATA  0x001f3000  0x00000000  0x00005000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [06]  07     0         0       factory  0x001f8000  0x00000000  0x00007000  0x00000000  0
INFO (0)[bl_flash.c: 363] ======= FlashCfg magiccode @0x42049c18=======
INFO (0)[bl_flash.c: 364] mid           0xC8
INFO (0)[bl_flash.c: 365] clkDelay      0x1
INFO (0)[bl_flash.c: 366] clkInvert     0x1
INFO (0)[bl_flash.c: 367] sector size   4KBytes
INFO (0)[bl_flash.c: 368] page size     256Bytes
INFO (0)[bl_flash.c: 369] ---------------------------------------------------------------
INFO (0)[hal_board.c:1271] [MAIN] [BOARD] [FLASH] addr from partition is 001f8000, ret is 0
INFO (0)[hal_board.c:1279] [MAIN] [BOARD] [XIP] addr from partition is 231e7000, ret is 0
[OS] Starting aos_loop_proc task...
[OS] Starting OS Scheduler...
INFO (5)[main.c:  43] AES ecb 128 encrtpt:
INFO:(         7)[main.c:  44] AES ECB:0000-000F: 22 AB D4 A1 6C 7E E6 D8  42 7E C6 EA 2B C0 2E C8    "...l~..B~..+...
INFO (20)[main.c:  48] AES ecb 128 decrypt:hello-Ai-WB2-Kit

INFO (26)[main.c:  56] AES ecb 192 encrtpt:
INFO:(        30)[main.c:  57] AES ECB:0000-000F: 9F D5 F6 DF CC 06 55 59  A0 59 07 0C 14 B9 55 AF    ......UY.Y....U.
INFO (42)[main.c:  61] AES ecb 192 decrypt:hello-Ai-WB2-Kit

INFO:(        49)[main.c:  69] AES ECB:0000-000F: E1 F3 2F 76 30 C0 12 5F  70 EC B6 5F 4F E4 3D 6D    ../v0.._p.._O.=m
INFO (61)[main.c:  73] AES ecb 256 decrypt:hello-Ai-WB2-Kit
INFO (67)[main.c: 102] AES CBC 128 encrtpt:
INFO:(        71)[main.c: 103] AES CBC:0000-000F: 39 53 27 A9 BA 37 5F 2A  C8 C0 E8 32 C4 E5 CD 1B    9S'..7_*...2....
INFO (83)[main.c: 106] AES CBC 128 decrypt:hello-Ai-WB2-Kit

INFO (90)[main.c: 115] AES CBC 192 encrtpt:
INFO:(        94)[main.c: 116] AES CBC:0000-000F: D7 80 0D BB 2F EA 16 19  0C 84 67 C6 A5 BA 33 E7    ..../.....g...3.
INFO (106)[main.c: 119] AES CBC 192 decrypt:hello-Ai-WB2-Kit

INFO (113)[main.c: 129] AES CBC 256 encrtpt:
INFO:(       117)[main.c: 130] AES CBC:0000-000F: 95 DA C4 62 53 AC 37 83  54 56 AD 80 BB B0 C6 A1    ...bS.7.TV......
INFO (129)[main.c: 134] AES CBC 256 decrypt:hello-Ai-WB2-Kit
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

base64示例
安信可 base64示例
base64 Example
Example Output
Starting bl602 now....
Booting Ai-WB2 Modules...
RISC-V Core Feature:RV32-ACFIMX
Build Version: release_bl_iot_sdk_1.6.38
Build Date: Nov 15 2022
Build Time: 11:17:20

blog init set power on level 2, 2, 2.
[IRQ] Clearing and Disable all the pending IRQ...
INFO (0)[hal_boot2.c: 251] [HAL] [BOOT2] Active Partition[0] consumed 596 Bytes
INFO (0)[hal_boot2.c:  53] ======= PtTable_Config @0x4200d170=======
INFO (0)[hal_boot2.c:  54] magicCode 0x54504642; version 0x0000; entryCnt 7; age 0; crc32 0x12DF9A26
INFO (0)[hal_boot2.c:  59] idx  type device activeIndex     name   Address[0]  Address[1]  Length[0]   Length[1]   age
INFO (0)[hal_boot2.c:  61] [00]  00     0         0            FW  0x00010000  0x000e8000  0x000d8000  0x00088000  0
INFO (0)[hal_boot2.c:  61] [01]  02     0         0           mfg  0x00170000  0x00000000  0x00032000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [02]  03     0         0         media  0x001a2000  0x00000000  0x00047000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [03]  04     0         0           PSM  0x001e9000  0x00000000  0x00008000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [04]  05     0         0           KEY  0x001f1000  0x00000000  0x00002000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [05]  06     0         0          DATA  0x001f3000  0x00000000  0x00005000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [06]  07     0         0       factory  0x001f8000  0x00000000  0x00007000  0x00000000  0
INFO (0)[bl_flash.c: 363] ======= FlashCfg magiccode @0x42049c18=======
INFO (0)[bl_flash.c: 364] mid           0xC8
INFO (0)[bl_flash.c: 365] clkDelay      0x1
INFO (0)[bl_flash.c: 366] clkInvert     0x1
INFO (0)[bl_flash.c: 367] sector size   4KBytes
INFO (0)[bl_flash.c: 368] page size     256Bytes
INFO (0)[bl_flash.c: 369] ---------------------------------------------------------------
INFO (0)[hal_board.c:1271] [MAIN] [BOARD] [FLASH] addr from partition is 001f8000, ret is 0
INFO (0)[hal_board.c:1279] [MAIN] [BOARD] [XIP] addr from partition is 231e7000, ret is 0
[OS] Starting aos_loop_proc task...
[OS] Starting OS Scheduler...
INFO (6)[main.c:  33] base64 encode:aGVsbF9BaS1XQjI=
INFO (10)[main.c:  41] plain_text:hell_Ai-WB2
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

MD5示例
安信可 MD5示例
MD5 Example

This routine shows the MD5 verification process and the overall verification results,used to verify the correctness of process verification and overall verification.

Example Output
Starting bl602 now....
Ai-WB2 Modules...
RISC-V Core Feature:RV32-ACFIMX
Build Version: release_bl_iot_sdk_1.6.38
Build Date: Nov 17 2022
Build Time: 09:36:26

blog init set power on level 2, 2, 2.
[IRQ] Clearing and Disable all the pending IRQ...
INFO (0)[hal_boot2.c: 251] [HAL] [BOOT2] Active Partition[0] consumed 596 Bytes
INFO (0)[hal_boot2.c:  53] ======= PtTable_Config @0x4200d17c=======
INFO (0)[hal_boot2.c:  54] magicCode 0x54504642; version 0x0000; entryCnt 7; age 0; crc32 0x12DF9A26
INFO (0)[hal_boot2.c:  59] idx  type device activeIndex     name   Address[0]  Address[1]  Length[0]   Length[1]   age
INFO (0)[hal_boot2.c:  61] [00]  00     0         0            FW  0x00010000  0x000e8000  0x000d8000  0x00088000  0
INFO (0)[hal_boot2.c:  61] [01]  02     0         0           mfg  0x00170000  0x00000000  0x00032000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [02]  03     0         0         media  0x001a2000  0x00000000  0x00047000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [03]  04     0         0           PSM  0x001e9000  0x00000000  0x00008000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [04]  05     0         0           KEY  0x001f1000  0x00000000  0x00002000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [05]  06     0         0          DATA  0x001f3000  0x00000000  0x00005000  0x00000000  0
INFO (0)[hal_boot2.c:  61] [06]  07     0         0       factory  0x001f8000  0x00000000  0x00007000  0x00000000  0
INFO (0)[bl_flash.c: 363] ======= FlashCfg magiccode @0x42049c18=======
INFO (0)[bl_flash.c: 364] mid           0xC8
INFO (0)[bl_flash.c: 365] clkDelay      0x1
INFO (0)[bl_flash.c: 366] clkInvert     0x1
INFO (0)[bl_flash.c: 367] sector size   4KBytes
INFO (0)[bl_flash.c: 368] page size     256Bytes
INFO (0)[bl_flash.c: 369] ---------------------------------------------------------------
INFO (0)[hal_board.c:1271] [MAIN] [BOARD] [FLASH] addr from partition is 001f8000, ret is 0
INFO (0)[hal_board.c:1279] [MAIN] [BOARD] [XIP] addr from partition is 231e7000, ret is 0
[OS] Starting aos_loop_proc task...
[OS] Starting OS Scheduler...
INFO (5)[main.c:  40] Update process:hello
INFO (7)[main.c:  43] Update process:-
INFO (11)[main.c:  46] Update process:Ai-WB2-Kit
INFO:(        17)[main.c:  49] MD5:0000-000F: 6A A2 56 18 28 A0 45 F7  4E DB A1 7E A2 ED 96 65    j.V.(.E.N..~...e
INFO (28)[main.c:  55] Update process:hello-Ai-WB2-Kit
INFO:(        34)[main.c:  56] MD5:0000-000F: 6A A2 56 18 28 A0 45 F7  4E DB A1 7E A2 ED 96 65    j.V.(.E.N..~...e
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

senior示例
安信可 senior示例
例程参考
HMACMD5示例
安信可 HMACMD5示例
HMACMD5 Example

This routine shows the HMACMD5 verification process and the overall verification results,used to verify the correctness of process verification and overall verification.

Example Output
...(other log)
[OS] Starting aos_loop_proc task...
[OS] Starting OS Scheduler...
INFO (5)[main.c:  41] Update process:hello
INFO (7)[main.c:  43] Update process:-
INFO (12)[main.c:  45] Update process:Ai-WB2-Kit
INFO:(17)[main.c:  48] Segmental encryption:0000-000F: 7D 28 37 ED 18 C5 C0 6E  74 C9 18 20 E5 5A 37 7D    }(7....nt.. .Z7}
INFO:(29)[main.c:  53] Overall encryption:0000-000F: 7D 28 37 ED 18 C5 C0 6E  74 C9 18 20 E5 5A 37 7D    }(7....nt.. .Z7}
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

HMACSHA1示例
安信可 HMACSHA1示例
HMACSHA1 Example

This routine shows the HMACSHA1 verification process and the overall verification results,used to verify the correctness of process verification and overall verification.

Example Output
...(other log)
[OS] Starting aos_loop_proc task...
[OS] Starting OS Scheduler...
INFO (6)[main.c:  41] Update process:hello
INFO (8)[main.c:  43] Update process:-
INFO (12)[main.c:  45] Update process:Ai-WB2-Kit
INFO:(17)[main.c:  48] Segmental encryption:0000-0013: 6C E6 B5 01 31 83 8A 14  CD 9D A0 FB 49 E2 F4 0E  87 B4 87 5E   l...1.......I......^
INFO:(31)[main.c:  53] Overall encryption:0000-0013: 6C E6 B5 01 31 83 8A 14  CD 9D A0 FB 49 E2 F4 0E  87 B4 87 5E   l...1.......I......^
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

HMACSHA256示例
安信可 HMACSHA256示例
HMACSHA256 Example

This routine demonstrates the routine of AEC’s ECB and CBC modes. Each mode shows how to perform 128 bit, 192 bit and 256 bit encryption

Example Output
...(other log)
[OS] Starting aos_loop_proc task...
[OS] Starting OS Scheduler...
INFO (5)[main.c:  41] Update process:hello
INFO (8)[main.c:  43] Update process:-
INFO (12)[main.c:  45] Update process:Ai-WB2-Kit
INFO:(17)[main.c:  48] Segmental encryption:0000-001F: 6B 28 50 9A 09 55 E6 53  4E 00 7B BA BC 19 B4 4C  E5 0F 16 A4 3D EB DA 3A  3A B4 69 EC 1A EF 0E A7    k(P..U.SN.{....L....=..::.i.....
INFO:(35)[main.c:  53] Overall encryption:0000-001F: 6B 28 50 9A 09 55 E6 53  4E 00 7B BA BC 19 B4 4C  E5 0F 16 A4 3D EB DA 3A  3A B4 69 EC 1A EF 0E A7    k(P..U.SN.{....L....=..::.i.....
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

HMACSHA512示例
安信可 HMACSHA512示例
HMACSHA512 Example

This routine shows the HMACSHA512 verification process and the overall verification results,used to verify the correctness of process verification and overall verification.

Example Output
...(other log)
[OS] Starting aos_loop_proc task...
[OS] Starting OS Scheduler...
INFO (6)[main.c:  40] Update process:hello
INFO (8)[main.c:  42] Update process:-
INFO (12)[main.c:  44] Update process:Ai-WB2-Kit
INFO:(17)[main.c:  47] Segmental encryption:0000-003F: 3A 3F 4E 91 08 98 F8 36  38 9A B4 31 A5 FE 94 FC  FA F8 03 BE EC 2B 59 19  3F 18 FC 3A 7C 54 3B 51  A8 76 AF 07 30 37 CC 42  CA 0A A3 C1 15 94 C7 56  9D 36 B5 02 C4 4C 8D 2A  80 34 77 E0 77 69 AE 07    :?N....68..1.........+Y.?..:|T;Q
INFO:(44)[main.c:  52] Overall encryption:0000-003F: 3A 3F 4E 91 08 98 F8 36  38 9A B4 31 A5 FE 94 FC  FA F8 03 BE EC 2B 59 19  3F 18 FC 3A 7C 54 3B 51  A8 76 AF 07 30 37 CC 42  CA 0A A3 C1 15 94 C7 56  9D 36 B5 02 C4 4C 8D 2A  80 34 77 E0 77 69 AE 07    :?N....68..1.........+Y.?..:|T;Q
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

SHA示例
安信可 SHA示例
例程参考
SHA1示例
安信可 SHA1示例
SHA1 Example

This routine shows the SHA1 verification process and the overall verification results,used to verify the correctness of process verification and overall verification.

Example Output
...(other log)

[OS] Starting aos_loop_proc task...
[OS] Starting OS Scheduler...
INFO (5)[main.c:  36] Update process:hello
INFO (7)[main.c:  40] Update process:-
INFO (11)[main.c:  44] Update process:Ai-WB2-Kit
INFO:(17)[main.c:  48] sha1 Segmentation check:0000-0013: 17 0A 41 14 37 81 C9 59  C4 86 63 62 4A 39 B6 89  32 1B C8 4A   ..A.7..Y..cbJ9..2..J
INFO:(31)[main.c:  54] sha1 Overall verification:0000-0013: 17 0A 41 14 37 81 C9 59  C4 86 63 62 4A 39 B6 89  32 1B C8 4A   ..A.7..Y..cbJ9..2..J
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

SHA256示例
安信可 SHA256示例
SHA256 Example

This routine shows two encryption algorithms, SHA224 and SHA256.The results of the segmented and the overall checks are also shown.

Example Output
...(other log)
INFO (6)[main.c:  68] Update process:hello
INFO (8)[main.c:  72] Update process:-
INFO (12)[main.c:  76] Update process:Ai-WB2-Kit
INFO:(17)[main.c:  80] sha224 Segmentation check:0000-001B: BC C8 73 57 27 57 75 D4  40 46 0C A3 29 51 EC EF  8D CA 25 74 A5 F2 85 C0  F3 86 85 3A   ..sW'Wu.@F..)Q....%t.......:
INFO:(34)[main.c:  86] sha224 Overall verification:0000-001B: BC C8 73 57 27 57 75 D4  40 46 0C A3 29 51 EC EF  8D CA 25 74 A5 F2 85 C0  F3 86 85 3A   ..sW'Wu.@F..)Q....%t.......:
INFO (51)[main.c:  36] Update process:hello
INFO (56)[main.c:  40] Update process:-
INFO (60)[main.c:  44] Update process:Ai-WB2-Kit
INFO:(66)[main.c:  48] sha256 Segmentation check:0000-001F: ED D8 A1 AF 00 A1 CA 20  53 39 67 65 04 64 A0 30  CF 9B 9B 3B D3 28 23 B5  28 90 7B 76 89 E7 CD 25    ....... S9ge.d.0...;.(#.(.{v...%
INFO:(84)[main.c:  54] sha256 Overall verification:0000-001F: ED D8 A1 AF 00 A1 CA 20  53 39 67 65 04 64 A0 30  CF 9B 9B 3B D3 28 23 B5  28 90 7B 76 89 E7 CD 25    ....... S9ge.d.0...;.(#.(.{v...%
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

SHA512示例
安信可 SHA512示例
SHA512 Example

This routine shows two encryption algorithms, SHA384 and SHA512.The results of the segmented and the overall checks are also shown.

Example Output
...(other log)
[OS] Starting aos_loop_proc task...
[OS] Starting OS Scheduler...
INFO (5)[main.c:  70] Update process:hello
INFO (7)[main.c:  74] Update process:-
INFO (11)[main.c:  78] Update process:Ai-WB2-Kit
INFO:(17)[main.c:  82] sha384 Segmentation check:0000-002F: 0C 4F A1 A0 5B 20 A7 9E  B7 B2 40 7C EE DE FE 11  64 44 50 C7 A1 27 DC BD  48 13 C4 2F F9 7B BD DB  B7 E7 A3 60 AF B2 04 67  8F B9 CC 55 F5 B6 48 A4    .O..[ ....@|....dDP..'..H../.{.....`...g...U..H.
INFO:(41)[main.c:  88] sha384 Overall verification:0000-002F: 0C 4F A1 A0 5B 20 A7 9E  B7 B2 40 7C EE DE FE 11  64 44 50 C7 A1 27 DC BD  48 13 C4 2F F9 7B BD DB  B7 E7 A3 60 AF B2 04 67  8F B9 CC 55 F5 B6 48 A4    .O..[ ....@|....dDP..'..H../.{.....`...g...U..H.
INFO (65)[main.c:  36] Update process:hello
INFO (70)[main.c:  40] Update process:-
INFO (74)[main.c:  44] Update process:Ai-WB2-Kit
INFO:(80)[main.c:  48] sha512 Segmentation check:0000-003F: EE 9F 34 7F 3D 0D 36 B7  BF 89 72 86 FC D3 99 48  C3 16 C2 C1 FE 2F B7 8C  DA 10 0C 7D 4C 0C EB 34  1F 96 3F 22 93 3E A9 77  5D 22 AA 43 87 0B E1 59  80 AB 64 B2 39 51 4D 34  41 D1 CB 8D C4 E5 C5 94    ..4.=.6...r....H...../.....}L..4
INFO:(107)[main.c:  55] sha512 Overall verification:0000-003F: EE 9F 34 7F 3D 0D 36 B7  BF 89 72 86 FC D3 99 48  C3 16 C2 C1 FE 2F B7 8C  DA 10 0C 7D 4C 0C EB 34  1F 96 3F 22 93 3E A9 77  5D 22 AA 43 87 0B E1 59  80 AB 64 B2 39 51 4D 34  41 D1 CB 8D C4 E5 C5 94    ..4.=.6...r....H...../.....}L..4
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

cipher示例
安信可 AES PKCS7 PADDING示例
AES PKCS7 PADDING Example

This routine shows how to perform encryption and decryption in AES/128/192/256-CBC mode and PKCS7 padding.

Example Output
...(other log)
[OS] Starting aos_loop_proc task...
[OS] Starting OS Scheduler...
INFO (5)[main.c:  39] AES-128-CBC PKCS7 padding
INFO (8)[main.c:  78] aes_cbc:0000-001F: 40 90 9C 66 77 EF 24 80  8C 01 68 0F 5E B7 2F 20  5B 00 39 5F EB 1C CB 41  C3 FF A1 DA 7B 4C 3E 4D    @..fw.$...h.^./ [.9_...A....{L>M
INFO (25)[main.c:  88] decrypt value:0000-000F: 68 65 6C 6C 6F 2D 41 69  2D 57 42 32 2D 4B 69 74    hello-Ai-WB2-Kit
INFO (37)[main.c:  90] padding value:0000-000F: 10 10 10 10 10 10 10 10  10 10 10 10 10 10 10 10    ................
INFO (49)[main.c:  49] AES-192-CBC PKCS7 padding
INFO (54)[main.c:  78] aes_cbc:0000-001F: A4 D2 45 F1 EA AE 48 7F  F0 51 AA 22 A2 3A 0F 65  60 1C 52 41 38 7F 13 D3  A9 93 8E 8D 8D E0 B6 BA    ..E...H..Q.".:.e`.RA8...........
INFO (71)[main.c:  88] decrypt value:0000-000F: 68 65 6C 6C 6F 2D 41 69  2D 57 42 32 2D 4B 69 74    hello-Ai-WB2-Kit
INFO (83)[main.c:  90] padding value:0000-000F: 10 10 10 10 10 10 10 10  10 10 10 10 10 10 10 10    ................
INFO (95)[main.c:  58] AES-256-CBC PKCS7 padding
INFO (100)[main.c:  78] aes_cbc:0000-001F: 08 C3 94 00 51 B0 EE 85  CB FE CA 21 9B 9F AA DE  BF E4 14 3E A4 B8 2C D3  2A AC 9F 77 D2 4B 96 B8    ....Q......!.......>..,.*..w.K..
INFO (117)[main.c:  88] decrypt value:0000-000F: 68 65 6C 6C 6F 2D 41 69  2D 57 42 32 2D 4B 69 74    hello-Ai-WB2-Kit
INFO (129)[main.c:  90] padding value:0000-000F: 10 10 10 10 10 10 10 10  10 10 10 10 10 10 10 10    ................
Troubleshooting

For any technical queries, please open an [issue](https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2/issues) on GitHub. We will get back to you soon.

API指南

这里汇集了Ai-WB2系列使用开发所涉及到的各类API

WiFi系列

WiFi API指南
API参考
Header File
  • components/network/wifi_manager/bl60x_wifi_driver/include/wifi_mgmr_ext.h

Functions
int wifi_mgmr_psk_cal(char *password, char *ssid, int ssid_len, char *output)
int wifi_mgmr_drv_init(wifi_conf_t *conf)
int wifi_mgmr_init(void)
void wifi_mgmr_start(void)
void wifi_mgmr_start_background(wifi_conf_t *conf)
void wifi_mgmr_get_wifi_channel_conf(wifi_conf_t *wifi_chan_conf)
wifi_interface_t wifi_mgmr_sta_enable(void)
int wifi_mgmr_sta_disable(wifi_interface_t *interface)
struct netif *wifi_mgmr_sta_netif_get(void)
struct netif *wifi_mgmr_ap_netif_get(void)
int wifi_mgmr_sta_mac_set(uint8_t mac[6])
int wifi_mgmr_sta_mac_get(uint8_t mac[6])
int wifi_mgmr_sta_ip_get(uint32_t *ip, uint32_t *gw, uint32_t *mask)
int wifi_mgmr_sta_ip_set(uint32_t ip, uint32_t mask, uint32_t gw, uint32_t dns1, uint32_t dns2)
int wifi_mgmr_sta_dns_get(uint32_t *dns1, uint32_t *dns2)
int wifi_mgmr_sta_ip_unset(void)
int wifi_mgmr_sta_connect_ext(wifi_interface_t *wifi_interface, char *ssid, char *passphr, const ap_connect_adv_t *conn_adv_param)
int wifi_mgmr_sta_connect_mid(wifi_interface_t *wifi_interface, char *ssid, char *psk, char *pmk, uint8_t *mac, uint8_t band, uint8_t chan_id, uint8_t use_dhcp, uint32_t flags)
int wifi_mgmr_sta_connect(wifi_interface_t *wifi_interface, char *ssid, char *psk, char *pmk, uint8_t *mac, uint8_t band, uint8_t chan_id)
int wifi_mgmr_sta_disconnect(void)
int wifi_sta_ip4_addr_get(uint32_t *addr, uint32_t *mask, uint32_t *gw, uint32_t *dns)
int wifi_mgmr_sta_ps_enter(uint32_t ps_level)
int wifi_mgmr_sta_ps_exit()
int wifi_mgmr_sta_autoconnect_enable(void)
int wifi_mgmr_sta_autoconnect_disable(void)
void wifi_mgmr_sta_ssid_set(char *ssid)
void wifi_mgmr_sta_passphr_set(char *passphr)
void wifi_mgmr_sta_psk_set(char *psk)
void wifi_mgmr_sta_connect_ind_stat_get(wifi_mgmr_sta_connect_ind_stat_info_t *wifi_mgmr_ind_stat)
wifi_interface_t wifi_mgmr_ap_enable(void)
int wifi_mgmr_ap_mac_set(uint8_t mac[6])
int wifi_mgmr_ap_mac_get(uint8_t mac[6])
int wifi_mgmr_ap_ip_get(uint32_t *ip, uint32_t *gw, uint32_t *mask)
int wifi_mgmr_ap_stop(wifi_interface_t *interface)
int wifi_mgmr_ap_start(wifi_interface_t *interface, char *ssid, int hidden_ssid, char *passwd, int channel)
int wifi_mgmr_ap_start_adv(wifi_interface_t *interface, char *ssid, int hidden_ssid, char *passwd, int channel, uint8_t use_dhcp)
int wifi_mgmr_ap_start_atcmd(wifi_interface_t *interface, char *ssid, int hidden_ssid, char *passwd, int channel, int max_sta_supported)
int wifi_mgmr_ap_sta_cnt_get(uint8_t *sta_cnt)
int wifi_mgmr_ap_sta_info_get(struct wifi_sta_basic_info *sta_info, uint8_t idx)
int wifi_mgmr_ap_sta_delete(uint8_t sta_idx)
int wifi_mgmr_ap_set_gateway(char *gateway)
int wifi_mgmr_sniffer_enable(void)
int wifi_mgmr_sniffer_disable(void)
int wifi_mgmr_rate_config(uint16_t config)
int wifi_mgmr_conf_max_sta(uint8_t max_sta_supported)
int wifi_mgmr_sniffer_register(void *env, sniffer_cb_t cb)
int wifi_mgmr_sniffer_unregister(void *env)
int wifi_mgmr_sniffer_register_adv(void *env, sniffer_cb_adv_t cb)
int wifi_mgmr_sniffer_unregister_adv(void *env)
int wifi_mgmr_state_get(int *state)
int wifi_mgmr_detailed_state_get(int *state, int *state_detailed)
int wifi_mgmr_status_code_get(int *s_code)
int wifi_mgmr_rssi_get(int *rssi)
int wifi_mgmr_channel_get(int *channel)
int wifi_mgmr_channel_set(int channel, int use_40Mhz)
int wifi_mgmr_all_ap_scan(wifi_mgmr_ap_item_t **ap_ary, uint32_t *num)
int wifi_mgmr_scan_filter_hidden_ssid(int filter)
int wifi_mgmr_scan(void *data, scan_complete_cb_t cb)
int wifi_mgmr_scan_adv(void *data, scan_complete_cb_t cb, uint16_t *channels, uint16_t channel_num, const uint8_t bssid[6], const char *ssid, uint8_t scan_mode, uint32_t duration_scan)
int wifi_mgmr_cfg_req(uint32_t ops, uint32_t task, uint32_t element, uint32_t type, uint32_t length, uint32_t *buf)
int wifi_mgmr_scan_complete_callback()
int wifi_mgmr_cli_scanlist(void)
int wifi_mgmr_cli_init(void)
int wifi_mgmr_scan_ap(char *ssid, wifi_mgmr_ap_item_t *item)
int wifi_mgmr_scan_ap_all(wifi_mgmr_ap_item_t *env, uint32_t *param1, scan_item_cb_t cb)
int wifi_mgmr_raw_80211_send(uint8_t *pkt, int len)
int wifi_mgmr_set_country_code(char *country_code)
int wifi_mgmr_ext_dump_needed()
const char *wifi_mgmr_status_code_str(uint16_t status_code)
int wifi_mgmr_beacon_interval_set(uint16_t beacon_int)
void wifi_mgmr_conn_result_get(uint16_t *status_code, uint16_t *reason_code)
int wifi_mgmr_set_wifi_active_time(uint32_t ms)
int wifi_mgmr_set_listen_interval(uint16_t itv)
int wifi_mgmr_pm_ops_register(void)
int wifi_mgmr_fw_affair_ops(void)
int wifi_mgmr_bcnind_auth_to_ext(int auth)
int wifi_mgmr_bcnind_cipher_to_ext(int cipher)
struct sm_connect_tlv_desc *wifi_mgmr_diagnose_tlv_get_ele(void)
void wifi_mgmr_diagnose_tlv_free_ele(struct sm_connect_tlv_desc *ele)
Structures
struct ap_info
struct ap_connect_adv
struct bl_rx_info
struct wifi_mgmr_ap_item
struct wifi_mgmr_sta_connect_ind_stat_info
struct wifi_sta_basic_info
struct wifi_sta_ps_conf

Public Members

int listen_interval

num of beacons

uint16_t wifi_active_period

wifi active ms.

struct wifi_conf
Macros
WIFI_CONNECT_STOP_SCAN_ALL_CHANNEL_IF_TARGET_AP_FOUND
WIFI_CONNECT_PCI_EN
WIFI_CONNECT_STOP_SCAN_CURRENT_CHANNEL_IF_TARGET_AP_FOUND
WIFI_CONNECT_PMF_CAPABLE
WIFI_CONNECT_PMF_REQUIRED
WIFI_STATE_AP_IS_ENABLED(status)
Type Definitions
typedef struct ap_connect_adv ap_connect_adv_t
typedef struct bl_rx_info bl_rx_info_t
typedef struct wifi_mgmr_ap_item wifi_mgmr_ap_item_t
typedef struct wifi_mgmr_sta_connect_ind_stat_info wifi_mgmr_sta_connect_ind_stat_info_t
typedef struct wifi_sta_basic_info wifi_sta_basic_info_t
typedef struct wifi_sta_ps_conf wifi_sta_ps_conf_t
typedef void *wifi_interface_t
typedef void (*sniffer_cb_t)(void *env, uint8_t *pkt, int len, bl_rx_info_t *info)
typedef void (*sniffer_cb_adv_t)(void *env, void *pkt_wrap, bl_rx_info_t *info)
typedef void (*scan_item_cb_t)(wifi_mgmr_ap_item_t *env, uint32_t *param1, wifi_mgmr_ap_item_t *item)
typedef void (*scan_complete_cb_t)(void *data, void *param)
typedef struct wifi_conf wifi_conf_t
Enumerations
enum ap_info_type

Values:

  • AP_INFO_TYPE_SUGGEST

  • AP_INFO_TYPE_PRESIST

enum wifi_mgmr_ap_cipher_t

Values:

  • WM_WIFI_CIPHER_NONE=0

  • WM_WIFI_CIPHER_WEP

  • WM_WIFI_CIPHER_AES

  • WM_WIFI_CIPHER_TKIP

  • WM_WIFI_CIPHER_TKIP_AES

  • WM_WIFI_CIPHER_MAX

enum wifi_mgmr_ap_auth_mode_t

Values:

  • WM_WIFI_AUTH_UNKNOWN = 0

  • WM_WIFI_AUTH_OPEN

  • WM_WIFI_AUTH_WEP

  • WM_WIFI_AUTH_WPA_PSK

  • WM_WIFI_AUTH_WPA2_PSK

  • WM_WIFI_AUTH_WPA_WPA2_PSK

  • WM_WIFI_AUTH_WPA_ENTERPRISE

  • WM_WIFI_AUTH_WPA3_SAE

  • WM_WIFI_AUTH_WPA2_PSK_WPA3_SAE

  • WM_WIFI_AUTH_MAX

enum [anonymous] Power Save mode setting.

Values:

  • PS_MODE_OFF Power-save off.

  • PS_MODE_ON Power-save on - Normal mode.

  • PS_MODE_ON_DYN Power-save on - Dynamic mode.

enum WIFI_STATE_ENUM_LIST

Values:

  • WIFI_STATE_UNKNOWN = 0x00

  • WIFI_STATE_IDLE = 0x01

  • WIFI_STATE_CONNECTING = 0x02

  • WIFI_STATE_CONNECTED_IP_GETTING = 0x03

  • WIFI_STATE_CONNECTED_IP_GOT = 0x04

  • WIFI_STATE_DISCONNECT = 0x05

  • WIFI_STATE_WITH_AP_IDLE = 0x11

  • WIFI_STATE_WITH_AP_CONNECTING = 0x12

  • WIFI_STATE_WITH_AP_CONNECTED_IP_GETTING = 0x13

  • WIFI_STATE_WITH_AP_CONNECTED_IP_GOT = 0x14

  • WIFI_STATE_WITH_AP_DISCONNECT = 0x15

  • WIFI_STATE_IFDOWN = 0x06

  • WIFI_STATE_SNIFFER = 0x07

  • WIFI_STATE_PSK_ERROR = 0x08

  • WIFI_STATE_NO_AP_FOUND = 0x09

enum WIFI_SCAN_DONE_EVENT_TYPE

Values:

  • WIFI_SCAN_DONE_EVENT_OK = 0x00

  • WIFI_SCAN_DONE_EVENT_BUSY = 0x01

enum WIFI_COEX_PM_LEVEL

Values:

  • WIFI_COEX_PM_STA_NONE = PM_MODE_STA_NONE

  • WIFI_COEX_PM_STA_IDLE = PM_MODE_STA_IDLE

  • WIFI_COEX_PM_STA_MESH = PM_MODE_STA_MESH

  • WIFI_COEX_PM_STA_DOZE = PM_MODE_STA_DOZE

  • WIFI_COEX_PM_STA_COEX = PM_MODE_STA_COEX

  • WIFI_COEX_PM_STA_DOWN = PM_MODE_STA_DOWN

  • WIFI_COEX_PM_AP_IDLE = PM_MODE_AP_IDLE

  • WIFI_COEX_PM_MAX = PM_MODE_MAX

蓝牙系列

蓝牙 API指南

API参考
Functions

controller层初始化

void ble_controller_init(uint8_t task_priority)
Parameters
  • task_priority 任务优先级

    return

HCI接口驱动初始化

int hci_driver_init(void)
Parameters
  • return

ble使能

int bt_enable(bt_ready_cb_t cb)
Parameters
  • cb:如果成功调用回调函数

    return

  • 0:成功,

  • != 0:失败

开启BLE扫描

int bt_le_scan_start(const struct bt_le_scan_param *param, bt_le_scan_cb_t cb)
Parameters
  • param: 指向广播配置参数指针

  • cb: 扫描回调函数

    return

  • 0:成功,

  • != 0:失败

停止BLE扫描

int bt_le_scan_stop(void)
Parameters
  • return

  • 0:成功,

  • != 0:失败

设置连接安全等级

int bt_conn_set_security(struct bt_conn *conn, bt_security_t sec)
Parameters
  • conn:指向连接对象的指针

  • sec:安全等级

    return

  • 0:成功,

  • != 0:失败

注册连接回调函数

void bt_conn_cb_register(struct bt_conn_cb *cb)
Parameters
  • conn:指向连接对象的指针

    return

注册认证回调函数

int bt_conn_auth_cb_register(const struct bt_conn_auth_cb *cb)
Parameters
  • cb:回调函数指针

    return

  • 0:成功,

  • != 0:失败

设置/清除SMP配对请求/响应数据认证需求中的绑定标志

void bt_set_bondable(bool enable)
Parameters
  • enable: 1,使能,0:不使能

return

外设系列

ADC API指南
概述

模数转换器(analog-to-digital converter,通常称为ADC)是一种模拟与数字转换器,支持12路外部模拟输入和若干内部模拟信号选择。 ADC支持以下四种模式:单次单通道转换、连续单通道转换、单次多通道转换和连续多通道转换模式。 转换结果为12/14/16bits左对齐模式。ADC拥有深度为32的FIFO,支持多种中断和DMA操作。 ADC除了用于普通模拟信号测量外,还可以用于测量供电电压, 此外ADC还可以通过测量内/外部二极管电压用于温度检测。

API参考
Header File
  • components/platform/hosal/include/hosal_adc.h

Functions
int hosal_adc_init(hosal_adc_dev_t *adc)

Initialises an ADC interface, Prepares an ADC hardware interface for sampling.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • adc: the interface which should be initialised

int hosal_adc_add_channel(hosal_adc_dev_t *adc, uint32_t channel)

Add a channel to an ADC interface.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • adc: the interface which should be sampled

  • channel: adc channel

int hosal_adc_remove_channel(hosal_adc_dev_t *adc, uint32_t channel)

Remove a channel to an ADC interface.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • adc: the interface which should be sampled

  • channel: adc channel

hosal_adc_dev_t *hosal_adc_device_get(void)

Takes adc device handle from an ADC interface.

return

  • other get adc device success

  • NULL if an error occurred with any step

int hosal_adc_value_get(hosal_adc_dev_t *adc, uint32_t channel, uint32_t timeout)

Takes a single sample from an ADC interface.

return

  • other get adc data success

  • -1 if an error occurred with any step

Parameters

  • adc: the interface which should be sampled

  • channel: adc channel

  • timeout: ms timeout

int hosal_adc_tsen_value_get(hosal_adc_dev_t *adc)

Takes a tsen sample from an ADC interface.

return

  • other get adc data success

  • -1 if an error occurred with any step

Parameters

  • adc: the interface which should be sampled

int hosal_adc_sample_cb_reg(hosal_adc_dev_t *adc, hosal_adc_cb_t cb)

ADC sampling cb register.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • adc: the ADC interface

  • cb: Non-zero pointer is the sample callback handler NULL pointer for send unregister operation adc in cb must be the same pointer with adc pointer passed to hosal_adc_sample_cb_reg driver must notify upper layer by calling cb if ADC data is ready in HW or memory(DMA)

int hosal_adc_start(hosal_adc_dev_t *adc, void *data, uint32_t size)

ADC sampling start.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • adc: the ADC interface

  • data: adc data buffer

  • size: data buffer size aligned with resolution (until the next power of two)

int hosal_adc_stop(hosal_adc_dev_t *adc)

ADC sampling stop.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • adc: the ADC interface

int hosal_adc_finalize(hosal_adc_dev_t *adc)

De-initialises an ADC interface, Turns off an ADC hardware interface.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • adc: the interface which should be de-initialised

Structures
struct hosal_adc_data_t

ADC data type.

uint32_t size

sampled data size

void *data

sampled data, aligned with resolution (until the next power of two)

struct hosal_adc_config_t

Define ADC config args.

Public Members

uint32_t sampling_freq

sampling frequency in Hz

uint32_t pin

adc pin

hosal_adc_sample_mode_t mode

adc sampling mode

uint8_t sample_resolution

adc sampling resolution

struct hosal_adc_dev_t

Define ADC dev hosal handle.

Public Members

uint8_t port

adc port

hosal_adc_config_t config

adc config

hosal_dma_chan_t dma_chan

adc dma channel

hosal_adc_irq_t cb

adc callback

void *p_arg

p_arg data

void *priv

priv data

Macros
HOSAL_WAIT_FOREVER

Define the wait forever timeout macro.

TIMER_RELOAD_ONCE

timer reload once and need to reload manually

Type Definitions
typedef enum __ADC_INT_EVENTS__ hosal_adc_event_t

ADC interrupt events.

typedef void (*hosal_adc_irq_t)(void *parg)

ADC interrupt function.

Parameters
  • parg: Set the custom parameters specified

typedef void (*hosal_adc_cb_t)(hosal_adc_event_t event, void *data, uint32_t size)

ADC interrupt callback.

Parameters
  • parg: Set the custom parameters specified when the callback function is set

Enumerations
enum __ADC_INT_EVENTS__

ADC interrupt events.

Values:

HOSAL_ADC_INT_OV
  • Overrun error.

HOSAL_ADC_INT_EOS
  • End of sample.

HOSAL_ADC_INT_DMA_TRH
  • DMA transceive half.

HOSAL_ADC_INT_DMA_TRC
  • DMA transceive complete.

HOSAL_ADC_INT_DMA_TRE
  • @briefDMA transceive error

enum hosal_adc_sample_mode_t

ADC MODE type.

Values:

HOSAL_ADC_ONE_SHOT
  • Single time sampling.

HOSAL_ADC_CONTINUE
  • Continuous sampling.

DAC API指南

DAC
概述

数模转换器(digital-to-analog converter,通常称为DAC)是一种数字与模拟转换器,,FIFO深度为1,支持2路DAC调制输出。 可用于音频播放,常规的模拟信号调制。

API参考
Header File

components/platform/hosal/include/hosal_dac.h

Functions
int hosal_dac_init(hosal_dac_dev_t *dac)

Initialises an dac interface.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • dac: the interface which should be initialised

int hosal_dac_finalize(hosal_dac_dev_t *dac)

De-initialises an dac interface, Turns off an dac hardware interface.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • dac: the interface which should be de-initialised

int hosal_dac_start(hosal_dac_dev_t *dac)

Start output dac (no DMA mode)

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • dac: the interface which should be started

int hosal_dac_stop(hosal_dac_dev_t *dac)

Stop output dac.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • dac: the interface which should be stopped

int hosal_dac_set_value(hosal_dac_dev_t *dac, uint32_t data)

Output a value to an dac interface.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • dac: the interface to set value

  • data: the value to output, output unit: μV

int hosal_dac_get_value(hosal_dac_dev_t *dac)

Returns the last data output value of the selected dac channel.

return

  • dac output value, output unit: μV

    Parameters

  • dac: the interface to get value

int hosal_dac_dma_cb_reg(hosal_dac_dev_t *dac, hosal_dac_cb_t callback, void *arg)

DAC cb register.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • dac: the DAC interface

  • callback: callback handler

  • arg: callback arg

int hosal_dac_dma_start(hosal_dac_dev_t *dac, uint32_t *data, uint32_t size)

DAC use DMA mode.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • adc: the DAC interface

  • data: dac data buffer

  • size: data buffer size

int hosal_dac_dma_stop(hosal_dac_dev_t *dac)

Stop output dac.

return

  • 0 on success

  • EIO if an error occurred with any step

    Parameters

  • dac: the interface which should be stopped

Structures
struct hosal_dac_config_t

This struct define dac config args.

Public Members

uint8_t dma_enable

1: use dma, 0: no dma

uint32_t pin

dac pin

uint32_t freq

dac freq

struct hosal_dac_dev_t

This struct define dac device type.

Public Members

uint8_t port

dac id

hosal_dac_config_t config

dac config

hosal_dac_cb_t cb

dma callback

hosal_dma_chan_t dma_chan

dac dma channel

void *arg

arg data

void *priv

priv data

Type Definitions
typedef void (*hosal_dac_cb_t)(void *arg)

hosal dac callback

Parameters

arg: Set the custom parameters specified when the callback function is set

GPIO API指南
概述

通用型之输入输出(General-purpose input/output,通常称为GPIO),GPIO管理功能提供GPIO控制寄存器,实现软件对 GPIO 属性的配置,使用户能够方便地操作 GPIO。每个GPIO可以配置为输入、输出和可选功能三种模式。在每个模式下(除模拟可选功能),提供设置上拉,下拉,浮空三种端口状态,此外GPIO还提供中断功能,可以配置为上升沿触发,下降沿触发或者高电平/低电平触发。

API参考
Header File
  • components/platform/hosal/include/hosal_gpio.h

Functions
int hosal_gpio_init(hosal_gpio_dev_t *gpio)

Initialises a GPIO pin.

Note

Prepares a GPIO pin for use.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • gpio: the gpio pin which should be initialised

int hosal_gpio_output_set(hosal_gpio_dev_t *gpio, uint8_t value)

Set GPIO output high or low.

Note

Using this function on a gpio pin which is set to input mode is undefined.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • gpio: the gpio pin which should be set

  • value: 0 : output low | >0 : output high

int hosal_gpio_input_get(hosal_gpio_dev_t *gpio, uint8_t *value)

Get the state of an input GPIO pin. Using this function on a gpio pin which is set to output mode will return an undefined value.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • gpio: the gpio pin which should be read

  • value: gpio value

int hosal_gpio_irq_set(hosal_gpio_dev_t *gpio, hosal_gpio_irq_trigger_t trigger_type, hosal_gpio_irq_handler_t handler, void *arg)

Enables an interrupt trigger for an input GPIO pin. Using this function on a gpio pin which is set to output mode is undefined.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • gpio: the gpio pin which will provide the interrupt trigger

  • trigger: the type of trigger (rising/falling edge or both)

  • handler: a function pointer to the interrupt handler

  • arg: an argument that will be passed to the interrupt handler

int hosal_gpio_irq_mask(hosal_gpio_dev_t *gpio, uint8_t mask)

Clear an interrupt status for an input GPIO pin. Using this function on a gpio pin which has generated a interrupt.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • gpio: the gpio pin which provided the interrupt trigger

  • mask: 0 : mask | 1 : umask

int hosal_gpio_finalize(hosal_gpio_dev_t *gpio)

Set a GPIO pin in default state.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • gpio: the gpio pin which should be deinitialised

Structures
struct hosal_gpio_ctx

hosal gpio ctx, use for multi gpio irq

struct hosal_gpio_dev_t

GPIO dev struct.

Public Members

uint8_t port

gpio port

hosal_gpio_config_t config

gpio config

void *priv

priv data

Type Definitions
typedef void (*hosal_gpio_irq_handler_t)(void *arg)

GPIO interrupt callback handler.

Parameters

  • parg: :Set the custom parameters specified

typedef struct hosal_gpio_ctx hosal_gpio_ctx_t

hosal gpio ctx, use for multi gpio irq

Enumerations
enum hosal_gpio_config_t

gpio config struct

Values:

ANALOG_MODE

Used as a function pin, input and output analog.

INPUT_PULL_UP

Input with an internal pull-up resistor - use with devices that actively drive the signal low - e.g. button connected to ground.

INPUT_PULL_DOWN

Input with an internal pull-down resistor - use with devices that actively drive the signal high - e.g. button connected to a power rail.

INPUT_HIGH_IMPEDANCE

Input - must always be driven, either actively or by an external pullup resistor.

OUTPUT_PUSH_PULL

Output actively driven high and actively driven low - must not be connected to other active outputs - e.g. LED output.

OUTPUT_OPEN_DRAIN_NO_PULL

Output actively driven low but is high-impedance when set high - can be connected to other open-drain/open-collector outputs. Needs an external pull-up resistor.

OUTPUT_OPEN_DRAIN_PULL_UP

Output actively driven low and is pulled high with an internal resistor when set high - can be connected to other open-drain/open-collector outputs.

OUTPUT_OPEN_DRAIN_AF

Alternate Function Open Drain Mode.

OUTPUT_PUSH_PULL_AF

Alternate Function Push Pull Mode.

enum hosal_gpio_irq_trigger_t

GPIO interrupt trigger.

Values:

HOSAL_IRQ_TRIG_NEG_PULSE

GPIO negedge pulse trigger interrupt.

HOSAL_IRQ_TRIG_POS_PULSE

GPIO posedge pulse trigger interrupt.

HOSAL_IRQ_TRIG_NEG_LEVEL

GPIO negedge level trigger interrupt (32k 3T)

HOSAL_IRQ_TRIG_POS_LEVEL

GPIO posedge level trigger interrupt (32k 3T)

I2C API指南

I2C API
概述

I2C (Inter-Intergrated Circuit)是一种串行通讯总线,使用多主从架构,用来连接低速外围装置。 每个器件都有一个唯一的识别地址,并且都可以作为一个发送器或接收器。 如果有两个或多个主机同时初始化,数据传输可以通过冲突检测和仲裁防止数据被破坏。 BL602/BL604包含一个I2C控制器主机,可灵活配置slaveAddr、subAddr以及传输数据,方便与从设备通信,提供2个word深度的fifo,提供中断功能,可搭配DMA使用提高效率,可灵活调整时钟频率。

API参考
Header File
  • components/platform/hosal/include/hosal_i2c.h

Functions
int hosal_i2c_init(hosal_i2c_dev_t *i2c)

Initialises an I2C interface.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • i2c: the device for which the i2c port should be initialised

int hosal_i2c_master_send(hosal_i2c_dev_t *i2c, uint16_t dev_addr, const uint8_t *data, uint16_t size, uint32_t timeout)

I2c master send.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • i2c: the i2c device

  • dev_addr: device address

  • data: i2c send data

  • size: i2c send data size

  • timeout: timeout in milisecond, set this value to HAL_WAIT_FOREVER if you want to wait forever

int hosal_i2c_master_recv(hosal_i2c_dev_t *i2c, uint16_t dev_addr, uint8_t *data, uint16_t size, uint32_t timeout)

I2c master recv.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • i2c: the i2c device

  • dev_addr: device address

  • data: i2c receive data

  • size: i2c receive data size

  • timeout: timeout in milisecond, set this value to HAL_WAIT_FOREVER if you want to wait forever

int hosal_i2c_slave_send(hosal_i2c_dev_t *i2c, const uint8_t *data, uint16_t size, uint32_t timeout)

I2c slave send.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • i2c: the i2c device

  • data: i2c slave send data

  • size: i2c slave send data size

  • timeout: timeout in milisecond, set this value to HAL_WAIT_FOREVER if you want to wait forever

int hosal_i2c_slave_recv(hosal_i2c_dev_t *i2c, uint8_t *data, uint16_t size, uint32_t timeout)

I2c slave receive.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • i2c: tthe i2c device

  • data: i2c slave receive data

  • size: i2c slave receive data size

  • timeout: timeout in milisecond, set this value to HAL_WAIT_FOREVER if you want to wait forever

int hosal_i2c_mem_write(hosal_i2c_dev_t *i2c, uint16_t dev_addr, uint32_t mem_addr, uint16_t mem_addr_size, const uint8_t *data, uint16_t size, uint32_t timeout)

I2c mem write.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • i2c: the i2c device

  • dev_addr: device address

  • mem_addr: mem address

  • mem_addr_size: mem address

  • data: i2c master send data

  • size: i2c master send data size

  • timeout: timeout in milisecond, set this value to HAL_WAIT_FOREVER if you want to wait forever

int hosal_i2c_mem_read(hosal_i2c_dev_t *i2c, uint16_t dev_addr, uint32_t mem_addr, uint16_t mem_addr_size, uint8_t *data, uint16_t size, uint32_t timeout)

I2c master mem read.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • i2c: the i2c device

  • dev_addr: device address

  • mem_addr: mem address

  • mem_addr_size: mem address

  • data: i2c master send data

  • size: i2c master send data size

  • timeout: timeout in milisecond, set this value to HAL_WAIT_FOREVER if you want to wait forever

int hosal_i2c_finalize(hosal_i2c_dev_t *i2c)

Deinitialises an I2C device.

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • i2c: the i2c device

Structures
structhosal_i2c_config_t

I2C configuration.

Public Members

uint32_t address_width

Addressing mode: 7 bit or 10 bit.

uint32_t freq

CLK freq.

uint8_t scl

i2c clk pin

uint8_t sda

i2c data pin

uint8_t mode

master or slave mode

structhosal_i2c_dev_t

I2C device type.

Public Members

uint8_t port

i2c port

hosal_i2c_config_t config

i2c config

void *priv

priv data

Macros
HOSAL_WAIT_FOREVER

Define the wait forever timeout macro.

HOSAL_I2C_MODE_MASTER

i2c communication is master mode

HOSAL_I2C_MODE_SLAVE

i2c communication is slave mode

HOSAL_I2C_MEM_ADDR_SIZE_8BIT

i2c memory address size 8bit

HOSAL_I2C_MEM_ADDR_SIZE_16BIT

i2c memory address size 16bit

HOSAL_I2C_MEM_ADDR_SIZE_24BIT

i2c memory address size 24bit

HOSAL_I2C_MEM_ADDR_SIZE_32BIT

i2c memory address size 32bit

HOSAL_I2C_ADDRESS_WIDTH_7BIT

7 bit mode

HOSAL_I2C_ADDRESS_WIDTH_10BIT

10 bit mode

PWM API指南

PWM API
概述

脉冲宽度调制(Pulse width modulation,简称PWM)是一种模拟控制方式,根据相应载荷的变化来调制晶体管基极或MOS管栅极的偏置,来实现晶体管或MOS管导通时间的改变,从而实现开关稳定电源输出的改变。这种方式能使电源的输出电压在工作条件变化时保持恒定,是利用微处理器的数字信号对模拟电路进行控制的一种非常有效的技术,广泛应用在从测量、通信到功率控制与变换的许多领域中。

API参考
Header File
  • components/platform/hosal/include/hosal_pwm.h

Functions
int hosal_pwm_init(hosal_pwm_dev_t *pwm)

Initialises a PWM pin.

return

  • success

  • other: fail

Parameters

  • pwm: the PWM device

int hosal_pwm_start(hosal_pwm_dev_t *pwm)

Starts Pulse-Width Modulation signal output on a PWM pin.

return

  • success

  • other: fail

Parameters

  • pwm: the PWM device

int hosal_pwm_stop(hosal_pwm_dev_t *pwm)

Stops output on a PWM pin.

return

  • success

  • other: fail

Parameters

  • pwm: the PWM device

int hosal_pwm_para_chg(hosal_pwm_dev_t *pwm, hosal_pwm_config_t para)

@change the para of pwm

return

  • success

  • other: fail

Parameters

  • pwm: the PWM device

  • para: the para of pwm

int hosal_pwm_freq_set(hosal_pwm_dev_t *pwm, uint32_t freq)

update PWM frequency

return

  • success

  • other: fail

Parameters

  • pwm: the PWM device

  • freq: the PWM frequency (0~40M under limited duty)

int hosal_pwm_freq_get(hosal_pwm_dev_t *pwm, uint32_t *p_freq)

get PWM frequency

return

  • success

  • other: fail

Parameters

  • pwm: the PWM device

  • p_freq: the pointer to memory frequency

int hosal_pwm_duty_set(hosal_pwm_dev_t *pwm, uint32_t duty)

set PWM duty

return

  • success

  • other: fail

Parameters

  • pwm: the PWM device

  • duty: the PWM duty (original duty * 100)

int hosal_pwm_duty_get(hosal_pwm_dev_t *pwm, uint32_t *p_duty)

get PWM duty

return

  • success

  • other: fail

Parameters

  • pwm: the PWM device

  • p_duty: the pointer to memory duty(original duty * 100)

int hosal_pwm_finalize(hosal_pwm_dev_t *pwm)

De-initialises an PWM interface, Turns off an PWM hardware interface.

return

  • success

  • other: fail

Parameters

  • pwm: the PWM device

  • pwm: the interface which should be de-initialised

Structures
struct hosal_pwm_config_t

pwm config struct

Public Members

uint8_t pin

pwm pin

uint32_t duty_cycle

the pwm duty_cycle 0 ~ 10000(0 ~ 100%)

uint32_t freq

the pwm freq,range is between 0 and 40M

struct hosal_pwm_dev_t

pwm dev struct

Public Members

uint8_t port

pwm port

hosal_pwm_config_t config

pwm config

void *priv

priv data

RNG API指南

RNG API
概述

随机数生成器(Random number generation),可以生成指定长度的随机数。

API参考
Header File
  • components/platform/hosal/include/hosal_rng.h

Functions
int hosal_rng_init(void)

init rng

return

  • 0 : success

  • other: fail

int hosal_random_num_read(void *buf, uint32_t bytes)

Fill in a memory buffer with random data.

return

  • 0 : success

  • other: fail

    Parameters

  • buf: Point to a valid memory buffer, this function will fill in this memory with random numbers after executed

  • bytes: Length of the memory buffer (bytes)

RTC API指南

RTC API
概述

RTC(real-time clock)为操作系统中的实时时钟设备,为操作系统提供精准的实时时间和定时报警功能。当设备下电后,通过外置电池供电,RTC继续记录操作系统时间;设备上电后,RTC提供实时时钟给操作系统,确保断电后系统时间的连续性。

API参考
Header File
  • components/platform/hosal/include/hosal_rtc.h

Functions
int hosal_rtc_init(hosal_rtc_dev_t *rtc)

This function will initialize the on board CPU real time clock.

return

  • 0 : success

  • other : fail

Parameters

  • rtc: rtc device

int hosal_rtc_set_time(hosal_rtc_dev_t *rtc, const hosal_rtc_time_t *time)

This function will set MCU RTC time to a new value.

return

  • 0 : success

  • other : fail

Parameters

  • rtc: rtc device

  • time: pointer to a time structure

int hosal_rtc_get_time(hosal_rtc_dev_t *rtc, hosal_rtc_time_t *time)

This function will return the value of time read from the on board CPU real time clock.

return

  • 0 : success

  • other : fail

Parameters

  • rtc: rtc device

  • time: pointer to a time structure

int hosal_rtc_set_count(hosal_rtc_dev_t *rtc, uint64_t *time_stamp)

This function will set MCU RTC time to a new value.

return

  • 0 : success

  • other : fail

Parameters

  • rtc: rtc device

  • time_stamp: new time value

int hosal_rtc_get_count(hosal_rtc_dev_t *rtc, uint64_t *time_stamp)

This function will return the value of time read from the on board CPU real time clock.

return

  • 0 : success

  • other : fail

Parameters

  • rtc: rtc device

  • time_stamp: new time value

int hosal_rtc_finalize(hosal_rtc_dev_t *rtc)

De-initialises an RTC interface, Turns off an RTC hardware interface.

return

  • 0 : success

  • other : fail

Parameters

  • RTC: the interface which should be de-initialised

Structures
struct hosal_rtc_config_t

rtc config struct

Public Members

uint8_t format

time formart DEC or BCD

struct hosal_rtc_dev_t

rtc dev struct

Public Members

uint8_t port

rtc port

hosal_rtc_config_t config

rtc config

void *priv

priv data

struct hosal_rtc_time_t
RTC time struct.

Public Members

uint8_t sec

DEC format:value range from 0 to 59, BCD format:value range from 0x00 to 0x59

uint8_t min

DEC format:value range from 0 to 59, BCD format:value range from 0x00 to 0x59

uint8_t hr

DEC format:value range from 0 to 23, BCD format:value range from 0x00 to 0x23

uint8_t date

DEC format:value range from 1 to 31, BCD format:value range from 0x01 to 0x31

uint8_t month

DEC format:value range from 1 to 12, BCD format:value range from 0x01 to 0x12

uint16_t year

DEC format:value range from 0 to 9999, BCD format:value range from 0x0000 to 0x9999

Macros
HOSAL_RTC_FORMAT_DEC

RTC DEC format

HOSAL_RTC_FORMAT_BCD

RTC BCD format

SPI API指南

SPI API
概述

串行外设接口(Serial Peripheral Interface Bus, SPI)是一种用于短程通信的同步串行通信接口规范,装置之间使用全双工模式通信,是一个主机和一个或多个从机的主从模式。需要至 少4根线,事实上3根也可以(单向传输时),包括SDI(数据输入)、SDO(数据输出)、SCLK(时钟)、CS(片选)

API参考
Header File
  • components/platform/hosal/include/hosal_spi.h

Functions
int hosal_spi_init(hosal_spi_dev_t *spi)

Initialises the SPI interface for a given SPI device.

return

  • 0 : on success

  • other : error

Parameters

  • spi: the spi device

int hosal_spi_send(hosal_spi_dev_t *spi, const uint8_t *data, uint16_t size, uint32_t timeout)

Spi send.

return

  • 0 : on success

  • other : error

Parameters

  • spi: the spi device

  • data: spi send data

  • size: spi send data size

  • timeout: timeout in milisecond, set this value to HAL_WAIT_FOREVER if you want to wait forever

int hosal_spi_recv(hosal_spi_dev_t *spi, uint8_t *data, uint16_t size, uint32_t timeout)

Spi recv.

return

  • 0 : success

  • other : error

Parameters

  • spi: the spi device

  • data: spi recv data

  • size: spi recv data size

  • timeout: timeout in milisecond, set this value to HAL_WAIT_FOREVER if you want to wait forever

int hosal_spi_send_recv(hosal_spi_dev_t *spi, uint8_t *tx_data, uint8_t *rx_data, uint16_t size, uint32_t timeout)

spi send data and recv

return

  • 0 : success

  • other : error

Parameters

  • spi: the spi device

  • tx_data: spi send data

  • rx_data: spi recv data

  • size: spi data to be sent and recived

  • timeout: timeout in milisecond, set this value to HAL_WAIT_FOREVER if you want to wait forever

int hosal_spi_irq_callback_set(hosal_spi_dev_t *spi, hosal_spi_irq_t pfn, void *p_arg)
int hosal_spi_set_cs(uint8_t pin, uint8_t value)

spi software set cs pin high/low only for master device

return

  • 0 : success

  • other : error

Parameters

  • pin: cs pin

  • value: 0 or 1

int hosal_spi_finalize(hosal_spi_dev_t *spi)

De-initialises a SPI interface.

return

  • 0 : success

  • other : error

Parameters

  • spi: the SPI device to be de-initialised

Structures
struct hosal_spi_config_t

Define spi config args.

Public Members

uint8_t mode

spi communication mode

uint8_t dma_enable

enable dma tansmission or not

uint8_t polar_phase

spi polar and phase

uint32_t freq

communication frequency Hz

uint8_t pin_clk

spi clk pin

uint8_t pin_mosi

spi mosi pin

uint8_t pin_miso

spi miso pin

struct hosal_spi_dev_t

Define spi dev handle.

Public Members

uint8_t port

spi port

hosal_spi_config_t config

spi config

hosal_spi_irq_t cb

spi interrupt callback

void *p_arg

arg pass to callback

void *priv

priv data

Macros
HOSAL_SPI_MODE_MASTER

spi communication is master mode

HOSAL_SPI_MODE_SLAVE

spi communication is slave mode

HOSAL_WAIT_FOREVER

Define the wait forever timeout macro.

Type Definitions
typedef void (*hosal_spi_irq_t)(void *parg)

spi irq callback function

TIMER API指南
概述

通用定时器,用于定时,当时间到达我们所设置的定时时间会产生定时中断,可以用来完成定时任务。

API参考
Header File
  • components/platform/hosal/include/hosal_timer.h

Functions
int hosal_timer_init(hosal_timer_dev_t *tim)

init a hardware timer

return

  • 0 : on success

  • other :error

    Parameters

  • tim: timer device

int hosal_timer_start(hosal_timer_dev_t *tim)

start a hardware timer

return

  • 0 : on success

  • other : error

    Parameters

  • tim: timer device

void hosal_timer_stop(hosal_timer_dev_t *tim)

stop a hardware timer

return

none

Parameters

  • tim: timer device

int hosal_timer_finalize(hosal_timer_dev_t *tim)

De-initialises an TIMER interface, Turns off an TIMER hardware interface

return

  • 0 : success

  • other : error

    Parameters

  • tim: timer device

Structures
struct hosal_timer_config_t

Define timer config args

Public Members

uint32_t period

timer period, us

uint8_t reload_mode

auto reload or not

hosal_timer_cb_t cb

timer handle when expired

void *arg

timer handle args

struct hosal_timer_dev_t

Define timer dev handle

Public Members

int8_t port

timer port

hosal_timer_config_t config

timer config

void *priv

priv data

Macros
TIMER_RELOAD_PERIODIC

timer reload automatic

TIMER_RELOAD_ONCE

timer reload once and need to reload manually

Type Definitions
typedef void (*hosal_timer_cb_t)(void *arg)

Define timer handle function type

UART API指南
概述

通用异步收发传输器(Universal Asynchronous Receiver/Transmitter,通常称为UART)是一种异步收发传输器,提供了与外部设备进行全双工数据交换的灵活方式。 BL602共有2组UART口(UART0和UART1),通过配合DMA使用,可以实现高效的数据通信。

Note

需要注意的是gpio的pin脚作为uart功能使用时,选取的gpio pin脚对8取余不能相等,如gpio0和gpio8不能同时做为uart的引脚。

API参考
Header File
  • components/platform/hosal/include/hosal_uart.h

Functions
int hosal_uart_abr_get(hosal_uart_dev_t *uart, uint8_t mode)

Get auto baudrate on a UART interface.

return

  • 0 : on success

  • EIO if an error occurred with any step

Parameters

  • uart: the UART interface

  • mode: auto baudrate detection mode(codeword 0x55 or start bit)

int hosal_uart_init(hosal_uart_dev_t *uart)

Initialises a UART interface.

return

  • 0 : on success

  • EIO if an error occurred with any step

Parameters

  • uart: the interface which should be initialised

int hosal_uart_send(hosal_uart_dev_t *uart, const void *txbuf, uint32_t size)

Poll transmit data on a UART interface.

return

  • 0 : success

  • EIO if an error occurred with any step

Parameters

  • uart: the UART interface

  • txbuf: pointer to the start of data

  • size: number of bytes to transmit

int hosal_uart_receive(hosal_uart_dev_t *uart, void *data, uint32_t expect_size)

Poll receive data on a UART interface.

return

  • 0 number of bytes to receive

  • EIO if an error occurred with any step

Parameters

  • uart: the UART interface

  • rxbuf: pointer to the buffer which will store incoming data

  • expect_size: expect number of bytes to receive

int hosal_uart_ioctl(hosal_uart_dev_t *uart, int ctl, void *p_arg)

hal uart ioctl

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • uart: the UART interface

  • ctl: Control request
    • HOSAL_UART_BAUD_SET : baud set, p_arg is baud

    • HOSAL_UART_BAUD_GET : baud get, p_arg is baud’s pointer

    • HOSAL_UART_DATA_WIDTH_SET : set data width,p_arg is hosal_uart_data_width_t

    • HOSAL_UART_DATA_WIDTH_GET : get data width,p_arg is hosal_uart_data_width_t’s pointer

    • HOSAL_UART_STOP_BITS_SET : set stop bits, p_arg is hosal_uart_stop_bits_t

    • HOSAL_UART_STOP_BITS_GET : get stop bits, p_arg is hosal_uart_stop_bits_t’s pointer

    • HOSAL_UART_PARITY_SET : set parity, p_arg is hosal_uart_parity_t

    • HOSAL_UART_PARITY_GET : get parity, p_arg is hosal_uart_parity_t’s pointer

    • HOSAL_UART_MODE_SET : UART mode set, p_arg is hosal_uart_mode_t

    • HOSAL_UART_MODE_GET : UART mode get, p_arg is hosal_uart_mode_t’s pointer

    • HOSAL_UART_FLOWMODE_SET : UART flow mode set, p_arg is hosal_uart_flow_control_t

    • HOSAL_UART_FLOWSTAT_GET : UART flow state get, p_arg is hosal_uart_flow_control_t’s pointer

    • HOSAL_UART_FREE_TXFIFO_GET : get uart free tx fifo size (bytes)

    • HOSAL_UART_FREE_RXFIFO_GET : get uart free rx fifo size (bytes)

    • HOSAL_UART_FLUSH : Wait for the send to complete

    • HOSAL_UART_TX_TRIGGER_ON : UART TX trigger on

    • HOSAL_UART_TX_TRIGGER_OFF : UART TX trigger off

    • HOSAL_UART_DMA_CONFIG : p_arg is hosal_uart_dma_cfg_t’s pointer

    • HOSAL_UART_DMA_TX_START : UART DMA TX start trans p_arg is hosal_uart_dma_cfg_t’s pointer

    • HOSAL_UART_DMA_RX_START : UART DMA RX start trans p_arg is hosal_uart_dma_cfg_t’s pointer

  • p_arg: parameter

int hosal_uart_callback_set(hosal_uart_dev_t *uart, int callback_type, hosal_uart_callback_t pfn_callback, void *arg)

hal uart callback set

return

  • 0 on success

  • EIO if an error occurred with any step

Parameters

  • uart: the UART interface

  • callback_type: callback type

    • HOSAL_UART_TX_CALLBACK

    • HOSAL_UART_RX_CALLBACK

    • HOSAL_UART_TX_DMA_CALLBACK

    • HOSAL_UART_RX_DMA_CALLBACK

  • pfn_callback: callback function

  • arg: callback function parameter

int hosal_uart_finalize(hosal_uart_dev_t *uart)

Deinitialises a UART interface.

return

  • 0 on success

  • EIO if an error occurred with any step

    Parameters

  • uart: the interface which should be deinitialised

Structures
struct hosal_uart_dma_cfg_t

UART DMA configuration.

Public Members

uint8_t *dma_buf

UART DMA trans buffer When the transmission is TX, the address is the src address When the transmission is RX, the address is the dest address.

uint32_t dma_buf_size

UART DMA trans buffer size.

struct hosal_uart_config_t

UART configuration.

Public Members

uint8_t uart_id

UART id.

uint8_t tx_pin

UART tx pin.

uint8_t rx_pin

UART rx pin.

uint8_t cts_pin

UART cts pin.

uint8_t rts_pin

UART rts pin.

uint32_t baud_rate

UART baud rate.

hosal_uart_data_width_t data_width

UART data width.

hosal_uart_parity_t parity

UART parity bit.

hosal_uart_stop_bits_t stop_bits

UART stop btis.

hosal_uart_flow_control_t flow_control

UART flow control.

hosal_uart_mode_t mode

UART int or pull mode.

struct hosal_uart_dev_t

UART device type.

Public Members

uint8_t port

UART port.

hosal_uart_config_t config

UART config.

hosal_uart_callback_t tx_cb

UART tx callback.

void *p_txarg

UART tx callback arg.

hosal_uart_callback_t rx_cb

UART rx callback.

void *p_rxarg

UART rx callback arg.

void *p_txdma_arg

UART tx dma callback.

hosal_uart_callback_t rxdma_cb

UART rx dma callback.

void *p_rxdma_arg

UART rx dma callback arg.

hosal_dma_chan_t dma_tx_chan

UART dma rx channel.

hosal_uart_callback_t rx_cb

UART rx callback.

void *priv

UART private data.

Macros
HOSAL_UART_AUTOBAUD_0X55

UART auto baudrate detection using codeword 0x55.

HOSAL_UART_AUTOBAUD_STARTBIT

UART auto baudrate detection using start bit.

HOSAL_UART_TX_CALLBACK

UART tx idle interrupt callback.

HOSAL_UART_RX_CALLBACK

UART rx complete callback.

HOSAL_UART_TX_DMA_CALLBACK

UART tx DMA trans complete callback.

HOSAL_UART_RX_DMA_CALLBACK

UART rx DMA trans complete callback.

HOSAL_UART_BAUD_SET

UART baud set.

HOSAL_UART_BAUD_GET

UART baud get.

HOSAL_UART_DATA_WIDTH_SET

UART data width set.

HOSAL_UART_DATA_WIDTH_GET

UART data width get.

HOSAL_UART_STOP_BITS_SET

UART stop bits set.

HOSAL_UART_STOP_BITS_GET

UART stop bits get.

HOSAL_UART_FLOWMODE_SET

UART flow mode set.

HOSAL_UART_FLOWSTAT_GET

UART flow state get.

HOSAL_UART_PARITY_SET

UART flow mode set.

HOSAL_UART_PARITY_GET

UART flow state get.

HOSAL_UART_MODE_SET

UART mode set.

HOSAL_UART_MODE_GET

UART mode get.

HOSAL_UART_FREE_TXFIFO_GET

UART free tx fifo get.

HOSAL_UART_FREE_RXFIFO_GET

UART free rx fifo get.

HOSAL_UART_FLUSH

Wait for the send to complete.

HOSAL_UART_TX_TRIGGER_ON

UART TX trigger on.

HOSAL_UART_TX_TRIGGER_OFF

UART TX trigger off.

HOSAL_UART_DMA_TX_START

UART DMA TX start trans.

HOSAL_UART_DMA_RX_START

UART DMA RX start trans.

HOSAL_UART_CFG_DECL(cfg, id, tx, rx, baud)

define a UART default config

Parameters

  • cfg: config define

  • id: uart id

  • tx: uart tx pin

  • rx: uart rx pin

  • baud: uart baud

Type Definitions
typedef int (*hosal_uart_callback_t)(void *p_arg)

hosal uart callback

return

  • 0 on success

  • EIO if an error occurred with any step

    Parameters

  • p_arg: Set the custom parameters specified when the callback function is set

Enumerations
enum hosal_uart_data_width_t

UART data width.

Values:

HOSAL_DATA_WIDTH_5BIT

HOSAL_DATA_WIDTH_6BIT

HOSAL_DATA_WIDTH_7BIT

HOSAL_DATA_WIDTH_8BIT

HOSAL_DATA_WIDTH_9BIT

enum hosal_uart_stop_bits_t

UART stop bits.

Values:

HOSAL_STOP_BITS_1 = 1

HOSAL_STOP_BITS_2 = 3

enum hosal_uart_flow_control_t

UART flow control.

Values:

HOSAL_FLOW_CONTROL_DISABLED

HOSAL_FLOW_CONTROL_RTS

HOSAL_FLOW_CONTROL_CTS

HOSAL_FLOW_CONTROL_CTS_RTS

enum hosal_uart_parity_t

UART parity.

Values:

HOSAL_NO_PARITY

HOSAL_ODD_PARITY

HOSAL_EVEN_PARITY

enum hosal_uart_mode_t

UART mode.

Values:

HOSAL_UART_MODE_POLL

UART poll mode (default mode)

HOSAL_UART_MODE_INT_TX

UART TX int mode.

HOSAL_UART_MODE_INT_RX

UART RX int mode.

HOSAL_UART_MODE_INT

UART TX and RX int mode.

WDG API指南
概述

看门狗(Watchdog),又叫看门狗计时器(Watchdog timer),是一种硬件的计时设备,当系统的主程序发生某些错误时,导致未及时清除看门狗计时器的计时值,这时看门狗计时器就会对系统发出复位信号,使系统从悬停状态恢复到正常运作状态

API参考
Header File
  • components/platform/hosal/include/hosal_wdg.h

Functions
int hosal_wdg_init(hosal_wdg_dev_t *wdg)

This function will initialize the on board CPU hardware watch dog.

return

  • 0 : success

  • other: fail

    Parameters

  • wdg: the watch dog device

void hosal_wdg_reload(hosal_wdg_dev_t *wdg)

Reload watchdog counter.

Parameters

  • wdg: the watch dog device

int hosal_wdg_finalize(hosal_wdg_dev_t *wdg)

This function performs any platform-specific cleanup needed for hardware watch dog.

return

  • 0 : success

  • other: fail

Parameters

  • wdg: the watch dog device

Structures
struct hosal_wdg_config_t

wdg config struct

Public Members

uint32_t timeout

Watchdag timeout in ms

structhosal_wdg_dev_t

wdg dev struct

Public Members

uint8_t port

wdg port

hosal_wdg_config_t config

wdg config

void *priv

priv data



存储系列

Flash API指南
概述

SDK中使用分区表保存flash各区的信息,包括引导程序、各种应用程序二进制文件、数据及文件系统等。

API参考
Header File
  • components/platform/hosal/include/hosal_flash.h

Functions
hosal_flash_dev_t *hosal_flash_open(const char *name, unsigned int flags)

Open a flash partition device.

return

  • NULL flash open error

  • otherwise is flash partition device

    Parameters

  • name: flash partition name

  • flags: flash flags - HOSAL_FLASH_FLAG_ADDR_0 - HOSAL_FLASH_FLAG_ADDR_1 - HOSAL_FLASH_FLAG_BUSADDR

int hosal_flash_info_get(hosal_flash_dev_t *p_dev, hosal_logic_partition_t *partition)

Get the information of the specified flash area.

Return

  • 0 On success

  • otherwise is error

    Parameters

  • p_dev: The target flash logical partition device

  • partition: The buffer to store partition info

int hosal_flash_erase(hosal_flash_dev_t *p_dev, uint32_t off_set, uint32_t size)

Erase an area on a Flash logical partition.

Note

Erase on an address will erase all data on a sector that the address is belonged to, this function does not save data that beyond the address area but in the affected sector, the data will be lost.

return

  • 0 On success

  • otherwise is error

Parameters

  • p_dev: The target flash logical partition which should be erased

  • off_set: Start address of the erased flash area

  • size: Size of the erased flash area

int hosal_flash_write(hosal_flash_dev_t *p_dev, uint32_t *off_set, const void *in_buf, uint32_t in_buf_size)

Write data to an area on a flash logical partition without erase.

return

  • 0 On success

  • otherwise is error

    Parameters

  • p_dev: The target flash logical partition which should be read which should be written

  • [in/out]: off_set Point to the start address that the data is written to, and point to the last unwritten address after this function is returned, so you can call this function serval times without update this start address.

  • in_buf: point to the data buffer that will be written to flash

  • in_buf_size: The size of the buffer

int hosal_flash_erase_write(hosal_flash_dev_t *p_dev, uint32_t *off_set, const void *in_buf, uint32_t in_buf_size)

Write data to an area on a flash logical partition with erase first.

return

  • 0 On success

  • otherwise is error

    Parameters

  • p_dev: The target flash logical partition which should be read which should be written

  • [in/out]: off_set Point to the start address that the data is written to, and point to the last unwritten address after this function is returned, so you can call this function serval times without update this start address.

  • in_buf: point to the data buffer that will be written to flash

  • in_buf_size: The length of the buffer

int hosal_flash_read(hosal_flash_dev_t *p_dev, uint32_t *off_set, void *out_buf, uint32_t out_buf_size)

Read data from an area on a Flash to data buffer in RAM.

return

  • 0 On success

  • otherwise is error

    Parameters

  • p_dev: The target flash logical partition which should be read

  • [in/out]: off_set Point to the start address that the data is read, and point to the last unread address after this function is returned, so you can call this function serval times without update this start address.

  • out_buf: Point to the data buffer that stores the data read from flash

  • out_buf_size: The length of the buffer

int hosal_flash_close(hosal_flash_dev_t *p_dev)

Close a flash partition device.

return

  • 0 On success

  • otherwise is error

    Parameters

  • p_dev: flash partition device

int hosal_flash_raw_read(void *buffer, uint32_t address, uint32_t length)

Read data from a row address on a Flash to data buffer in RAM.

return

  • 0 On success

  • otherwise is error

    Parameters

  • buffer: Point to the data buffer that stores the data read from flash

  • address: Address on flash to read from

  • length: Length (in bytes) of data to read

int hosal_flash_raw_write(void *buffer, uint32_t address, uint32_t length)

Write data to a row address on a Flash.

return

  • 0 On success

  • otherwise is error

    Parameters

  • buffer: Point to the data buffer that will be written to flash

  • address: Address on flash to write to

  • length: Length (in bytes) of data to write

int hosal_flash_raw_erase(uint32_t start_addr, uint32_t length)

Erase a region of the flash.

return

  • 0 On success

  • otherwise is error

    Parameters

  • start_addr: Address to start erasing flash.

  • length: Length of region to erase.

Structures
struct hosal_flash_dev

Hal flash partition device.

Public Members

void *flash_dev

flash device

struct hosal_logic_partition_t

Hal flash partition manage struct.

Public Members

const char *partition_description

name

uint32_t partition_start_addr

start addr

uint32_t partition_length

length

uint32_t partition_options

options

Macros
HOSAL_FLASH_FLAG_ADDR_0

Open flash prtition address 0 in prtition table.

HOSAL_FLASH_FLAG_ADDR_1

Open flash prtition address 1 in prtition table.

HOSAL_FLASH_FLAG_BUSADD

Open the partition table and use the bus physical address of flash. (If it is not set, the offset address set in the partition table is used by default.)

Type Definitions
typedef struct hosal_flash_dev hosal_flash_dev_t

Hal flash partition device.

系统系列

system API指南

协议系列

protocol API指南