欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Alios-Things入坑记之rtl8710bn初体验

程序员文章站 2023-12-21 14:11:04
...

--作者:燕十三(flyingcys)

-- blog:http://blog.csdn.net/flyingcys

--QQ:294102238

一、概述

        Alios-Things是一款由阿里巴巴开发的面向IoT领域的轻量级物联网嵌入式操作系统,致力于搭建云端一体化IoT基础设备。具备极致性能,极简开发、云端一体、丰富组件、安全防护等关键能力,并支持中断设备连接到阿里Link,可广泛应用在智能家居、智慧城市、新出行等领域。
Alios-Things源码目前托管在github上,地址为:https://github.com/alibaba/AliOS-Things,当前最新正式版为1.3.1,处于快速更新迭代中。
架构描述:
Alios-Things的架构可以适用于分层架构和组件化架构。从底部到顶部,Alios-Things包括:
  • 板级支持包(BSP):主要由Soc供应商开发和维护
  • 硬件抽象层(HAL):比如WiFi和Uart
  • 内核:包括Rhino实时操作系统内核、Yloop、VFS、KV存储
  • 协议栈:包括TCP/IP协议栈(LwIP),uMesh网络协议栈
  • 安全:安全传输层协议(TLS)、可信服务框架(TFS)、可信运行环境(TEE)
  • AOS API:提供可供应用软件和中间件使用的API
  • 中间件:包括常见的物联网组件和阿里巴巴增值服务中间件
  • 示例应用:阿里自主开发的示例代码,以及通过了完备测试的应用程序(比如Alinkapp)
  • 所有的模组都已经被组织成组件,且每个组件都有自己的.mk文件,用于描述它和其他组件间的依赖关系,方便应用开发者按需选用。

结构框图:

Alios-Things入坑记之rtl8710bn初体验


文件夹结构:

 文件夹名称 内容描述
board 评估板(如STM32L496G-Discovery)
build 编译框架
device 连接MCU/SoC的外设,比如支持使用AT命令的WiFi系列模组
example 代码示例,通过了完备测试的应用程序(比如Alink)
framework IoT 通用组件
include 系统头文件
kernel 包括Rhino和协议栈
platform 芯片架构支持的相关文件
security 包括TLS,TFS, TEE在内的安全组件
tools 命令行界面(CLI)和用于建立远程设备中心的testbed工具
utility IoT通用软件库,比如 cJSON
test UT测试用例

二、编译与运行:

编译环境搭建

      Alios-Things提供了基于Visual Studio Code插件的AliOS Studio集成开发环境(IDE),可提供编辑、编译、调试等功能,不过我是在Linux下(Ubuntu16.04 64bit)开发。在Ubuntu上开发需要先搭建开发环境。
1.依赖软件包安装,在命令行下输入
sudo apt-get install -y python gcc-multilib libssl-dev libssl-dev:i386 libncurses5-dev libncurses5-dev:i386 libreadline-dev libreadline-dev:i386 python-pip minicom
2.安装aos-cube,用python包管理器pip安装aos-cube和相关依赖包
pip install setuptools wheel aos-cube
请确认pip环境是基于python 2.7的,如果遇到权限问题,可能需要sudo来执行
3.下载源码
git clone https://github.com/alibaba/AliOS-Things.git
Alios Things仓库比较大,下载需要一些时间。

编译

下载完成后,在命令行下,进入Alios-Things根目录,执行编译命令aos make。编译采用的是aaa@qq.com的模式,如example为example目录下对应的应用helloworld,board则为对应的运行平台linuxhost。aos与aos make命令详细指令如下:
  • aos
usage: aos [-h] [--version]             ...

Code management tool for aos - https://code.aliyun.com/aos/aos
version 0.2.42

Use 'aos <command> -h|--help' for detailed help.
Online manual and guide available at https://code.aliyun.com/aos/aos-cube

optional arguments:
  -h, --help   show this help message and exit
  --version    print version number and exit

Commands:
             
    new        Create new aos program or component
    ls         List cube info, default components info
    import     Import program from URL
    add        Add component from AOS_SDK_PATH or URL
    rm         Remove component
    deploy     Find and add missing components and source codes
    codes      Import the optional component from the remote repository
    publish    Publish program or component
    update     Update to branch, tag, revision or latest
    sync       Synchronize aos component references
    status     Show version control status
               
    make       Make aos program/component
    scons      Make aos program/component by scons
    makelib    Compile static library
               
    config     Tool configuration
               
    upload     Upload aos image
    monitor    Serial port monitor
               
    upgrade    Upgrade aos-cube to latest
    help       This help screen
  • aos make
Usage: make <target> [download] [run | debug] [JTAG=xxx] [total] [VERBOSE=1] [BINS=app/framework/kernel]
       make run

  <target>
    One each of the following mandatory [and optional] components separated by '@'
      * Application (apps in example)
      * Board (cy8ckit-149 mk1101 gd32f4xx mk3080 mk3060 mk3239 stm32f429zi-nucleo xr871evb r5f565ne frdmkl27z stm32f769i-discovery lpcxpresso54102 rda8955 linuxhost uno-91h r5f100lea stm32l496g-discovery starterkit mk3165 atsame54-xpro eml3047 developerkit stm32l432kc-nucleo pca10056 esp32devkitc bk7231devkitc mk3166 esp8266 stm32l073rz-nucleo b_l475e rk1108 cb2201 amebaz_dev pca10040 bk7231udevkitc stm32l476rg-nucleo stm32l433rc-nucleo dh5021a_evb cy8ckit-062)
      * [debug | release] Building for debug or release configurations

  [download]
    Download firmware image to target platform

  [run]
    Reset and run an application on the target hardware

  [total]
    Build all targets related to this application and board

  [JTAG=xxx]
    JTAG interface configuration file from the tools/OpenOCD dirctory
    Default option is jlink_swd

  [VERBOSE=1]
    Shows the commands as they are being executed

  [BINS=app/framework/kernel]
    Build bins: app or framework or kernel

  Notes
    * Component names are case sensitive
    * 'rhino' and 'debug' are reserved component names
    * Component names MUST NOT include space or '@' characters
    * Building for debug is assumed unless '@release' is appended to the target

  Example Usage
    Build for Debug
       make aaa@qq.com

    Build, Download and Run using the default USB-JTAG programming interface
       make aaa@qq.com download run

    Build for Release
       make aaa@qq.com@release

    Reset and run an application on the target hardware
       make run

    Clean output directory
       make clean.  Stop.

执行aos make aaa@qq.com,目标文件在根目录out目录下对应目录下out/aaa@qq.com/binary。

运行

在命令行下执行./out/aaa@qq.com/binary/aaa@qq.com运行demo,可看到demo运行情况。
Alios-Things入坑记之rtl8710bn初体验

三、rtl8710bn

netmgrapp编译

    rtl8710bn是realtek最新推出的Cortex-M4F内核SOC WiFi,主频125MHz,512KB ROM,RAM:256KB,支持128MBFlash,RSIP/RDP固件保护。2xUart/SPI Master/SPI Slave,2xI2C,I2S,RTC,6PWM,12bit ADC等众多外设。
        rtl8710bn在Alios-Things对应board名为amebaz_dev,example这次我们选择的是netmgrapp,该example支持WiFi连接操作。
        在命令行输入aaa@qq.com_dev开始编译,aos将检测交叉编译器,如linux环境变量未发现对应的交叉编译器,aos将自动下载对应的交叉编译器。将rtl8710bn交叉编译器gcc-arm-none-eabi下载至build/compiler/gcc-arm-none-eabi/Linux64目录。交叉编译器下载完成后,开始编译:
vcall init auto_component
kernel_version:AOS-R-1.3.1
app_version:app-1.0.0-20180615.0148
app_version:app-1.0.0-20180615.0148
kernel_version:AOS-R-1.3.1
Build AOS Now
TOOLCHAIN_PATH=/home/share/samba/application/AliOS-Things/build/compiler/gcc-arm-none-eabi/Linux64/bin/
Compiling alicrypto
Compiling board_amebaz_dev
Compiling auto_component
Compiling cli
Compiling digest_algorithm
Compiling framework
Compiling hal
Compiling kernel_init
Compiling vfs_device
Compiling newlib_stub
Compiling log
Compiling kv
Compiling netmgr
Compiling netmgrapp
Compiling armv7m
Compiling rtl8710bn
Compiling rtl8710bn_Peripheral_Drivers
Compiling rtl8710bn_SDK
Compiling net
Compiling rhino
Compiling vcall
Compiling vfs
Compiling yloop
Making out/aaa@qq.com_dev/libraries/alicrypto.a
Making out/aaa@qq.com_dev/libraries/board_amebaz_dev.a
Making out/aaa@qq.com_dev/libraries/auto_component.a
Making out/aaa@qq.com_dev/libraries/cli.a
Making out/aaa@qq.com_dev/libraries/digest_algorithm.a
Making out/aaa@qq.com_dev/libraries/framework.a
Making out/aaa@qq.com_dev/libraries/hal.a
Making out/aaa@qq.com_dev/libraries/kernel_init.a
Making out/aaa@qq.com_dev/libraries/vfs_device.a
Making out/aaa@qq.com_dev/libraries/newlib_stub.a
Making out/aaa@qq.com_dev/libraries/log.a
Making out/aaa@qq.com_dev/libraries/kv.a
Making out/aaa@qq.com_dev/libraries/netmgr.a
Making out/aaa@qq.com_dev/libraries/netmgrapp.a
Making out/aaa@qq.com_dev/libraries/armv7m.a
Making out/aaa@qq.com_dev/libraries/rtl8710bn.a
Making out/aaa@qq.com_dev/libraries/rtl8710bn_Peripheral_Drivers.a
Making out/aaa@qq.com_dev/libraries/rtl8710bn_SDK.a
Making out/aaa@qq.com_dev/libraries/net.a
Making out/aaa@qq.com_dev/libraries/rhino.a
Making out/aaa@qq.com_dev/libraries/vfs.a
Making out/aaa@qq.com_dev/libraries/yloop.a
Making out/aaa@qq.com_dev/libraries/vcall.a
Making aaa@qq.com_dev.elf

Making aaa@qq.com_dev.xip2.elf
Making aaa@qq.com_dev.hex
Making aaa@qq.com_dev.bin
Can't parse memory configure, memory info get fail!

Making aaa@qq.com_dev.xip2.bin
Linux64 /home/share/samba/application/AliOS-Things netmgrapp amebaz_dev /home/share/samba/application/AliOS-Things/build/compiler/gcc-arm-none-eabi/Linux64/bin/
Generate Standard Flash Images: out/aaa@qq.com_dev/binary/aaa@qq.com_dev.all.bin
Build complete
Making .gdbinit
由上可见,默认编译显示编译信息较精简,可通过执行aos make VERBOSE=1 aaa@qq.com_dev 来查看详细的编译过程。
编译完成后,我们可以在out/aaa@qq.com_dev/binary/
Alios-Things入坑记之rtl8710bn初体验Alios-Things入坑记之rtl8710bn初体验

其中:
boot_all.bin是amebaz的Boot
image2_all_ota1.bin是amebaz的OTA1区固件;image2_all_ota2.bin是amebaz的OTA2区固件
aaa@qq.com_dev.all.bin是以上3个固件的合并固件。
Alios-Things入坑记之rtl8710bn初体验

其中boot只需要下载1次,不需要每次都下载。调试代码时可只下ota1,可节省下载时间。
运行
重新上电后,可通过串口看到正常启动log。
Alios-Things入坑记之rtl8710bn初体验

#为Alios-Things命令行cli提示符,在命令行下输入:help查询当前支持的cli命令
Alios-Things入坑记之rtl8710bn初体验

rtl8710bn网络连接

netmgr为Alios-Things下的WiFi网络管理组件,支持start/clear/connect等功能。使用netmgr connect 360usbwifi 1234567890,连接路由器,ssid为360usbwifi,密码为1234567890。可看到连接成功log。

Alios-Things入坑记之rtl8710bn初体验

四、Alios-Things运行流程

Alios-Things入坑记之rtl8710bn初体验

  • aosaos初始化及启动
  • arch:芯片相关.hlwip配置文件
  • binboot_all.bin文件
  • halhal适配文件
  • lib:库文件
  • peripherals:外设驱动库
  • script:编译链接脚本
  • sdk:芯片SDK
  • toolsbin文件合成工具

入口

rtl8710bn应用入口在platform->mcu->rtl8710bn->aos目录下,其中main()位于aos.c中。
void main(void)
{
    aos_init();

    krhino_task_dyn_create(&g_aos_init, "aos-init", 0, AOS_DEFAULT_APP_PRI , 0, AOS_START_STACK, (task_entry_t)sys_init_func, 1);
    
    SysTick_Config(SystemCoreClock/RHINO_CONFIG_TICKS_PER_SECOND);

    aos_start();

    return;
}

运行流程

  1. 调用aos_init()->krhino_init()完成krhion初始化。
  2. 在sys_init_func任务内完成hal初始化及启动、wlan初始化及启动、aos_kernel_init()完成各种组件初始化,并调用application()函数,完成netmgrapp初始化及启动。
  3. 初始化systick定时器
  4. 4.调用aos_start(),启动Alios-Things

上一篇:

下一篇: