阿里物联网alios-things基于ESP8266搭建RTOS开发环境

2 篇文章 0 订阅
1 篇文章 0 订阅

一、资料信息

项目源码地址:
码云 https://gitee.com/alios-things
教学资料:
https://www.bilibili.com/video/BV1X64y1c7rb

#Linux环境安装
https://help.aliyun.com/document_detail/161037.html

环境:利用笔记本已有的CentOS7,直接安装到硬盘上的,不是虚拟机。
硬件为ESP8288(ESP-12F)的NodeMCU

二、安装

安装基础包

# apt-get install -y python python-pip git

我是CentOS7换为yum命令,直接使用root用户安装。
再安装依赖库和aos-cube,步骤如下:

# python -m pip install setuptools wheel aos-cube

python版本问题处理

这里运行aos -h报错,是由于python 2.7.5版本过低,文档要求(64bits,2.7.14和3.5已验证)
报错:

[root@xycto ~]# aos --version
Traceback (most recent call last):
  File "/bin/aos", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 3007, in <module>
    working_set.require(__requires__)
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 728, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 626, in resolve
    raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: configparser

原因:安装aos-cube时出现几个unknown的软件。

Running setup.py install for aos-cube ... done
Successfully installed aos-cube-0.5.11 click-7.1.2 ecdsa-0.16.0 esptool-2.8 paho-mqtt-1.5.0 progressbar2-3.52.1 pyaes-1.6.1 pyserial-3.4 python-utils-2.4.0 unknown-4.0.1 unknown-4.0.1 wheel-0.35.1
You are using pip version 8.1.2, however version 20.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

解决方法:
手工更换为python3,重新安装aos-cube

[root@xycto ~]# python3 -V
Python 3.6.8
[root@xycto ~]# python3 -m pip install aos-cube
同时把python软连接到python3
[root@xycto ~]# rm /bin/python
python      python2     python2.7   python3     python3.6   python3.6m  
[root@xycto ~]# rm /bin/python
rm: remove symbolic link ‘/bin/python’? y
[root@xycto ~]# ln -s /bin/python3 /bin/python
普通用户也可以正常查询 版本
[xy@xycto ~]$ aos --version
0.5.11

下载AliOS Things源代码

普通用户
[xy@xycto ~]$ git clone https://gitee.com/alios-things/AliOS-Things.git
生成目录AliOS-Things约2.3G,下载很快

三、aos命令行编译

配置环境变量

给aos make查找源码使用
$ vi ~/.bashrc
文件末尾添加环境变量,指向AliOS Things源码目录,并保存退出
export AOS_SDK_PATH=/home/xy/AliOS-Things
使配置立即生效
$ source ~/.bashrc

查看设备信息

此时可以连接好设备,查看是否可以正常检查到。我的是芯片集成了usb驱动的ESP8288

[xy@xycto AliOS-Things]$ aos list devices
[
    {
        "device": "/dev/ttyUSB0",
        "name": "ttyUSB0",
        "description": "USB Serial",
        "hwid": "USB VID:PID=1A86:7523 LOCATION=2-3",
        "vid": 6790,
        "pid": 29987,
        "serial_number": null,
        "location": "2-3",
        "manufacturer": null,
        "product": "USB Serial",
        "interface": null,
        "usb_device_path": "/sys/devices/pci0000:00/0000:00:14.0/usb2/2-3",
        "device_path": "/sys/devices/pci0000:00/0000:00:14.0/usb2/2-3/2-3:1.0/ttyUSB0",
        "subsystem": "usb-serial",
        "usb_interface_path": "/sys/devices/pci0000:00/0000:00:14.0/usb2/2-3/2-3:1.0"
    }
]

如果没有查询到设备,显示[]。
这个设备发货默认是开启路由器模式的,pc和手机都可以正常连接,54 Mb/s,PC可以ping通路由器地址192.168.4.1。

创建项目

在自己的工作目录(注意:非AliOS Things的目录或子目录)下面,运行:
$ aos create project -h 查看创建项目的格式

[xy@xycto AliOS-Things]$ aos create project -h
Usage: aos create project [OPTIONS] [PROJECTNAME]

  Create new project from template

Options:
  -b, --board TEXT        Board for creating project  [required]
  -d, --projectdir TEXT   The project directory
  -t, --templateapp TEXT  Template application for creating project
  -h, --help              Show this message and exit.

ls $AOS_SDK_PATH/application/example 查看样例,对应-t
ls $AOS_SDK_PATH/platform/board 查看支持的单板,对应-b

[xy@xycto ~]$ aos create project -b esp8266 -t helloworld_demo myEspApp
...
Checking config output: /home/xy/myEspApp/.config ...
[Info] Project Initialized at: /home/xy/myEspApp

如果不指定-d,默认在当前目录下创建目录,和项目名称相同。

编译

$ cd myEspApp
[xy@xycto myEspApp]$ aos make

aos-cube version: 0.5.11
Check if required tools for esp8266 exist
Toolchain gcc-xtensa-lx106 missing, start download ...
https://gitee.com/alios-things/gcc-xtensa-lx106-linux.git -> /home/xy/AliOS-Things/build/compiler/gcc-xtensa-lx106/Linux64
Cloning into 'gcc-xtensa-lx106'...
remote: Enumerating objects: 1108, done.
remote: Counting objects: 100% (1108/1108), done.
remote: Compressing objects: 100% (711/711), done.
remote: Total 1108 (delta 371), reused 1108 (delta 371), pack-reused 0
Receiving objects: 100% (1108/1108), 25.64 MiB | 7.89 MiB/s, done.
Resolving deltas: 100% (371/371), done.
Download toolchain gcc-xtensa-lx106 succeed
Parsing all components ...

Build Configuration:
====================
App: myEspApp
Board: esp8266
====================

Making config file for first time
which: no xtensa-lx106-elf-gcc in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/xy/.local/bin:/home/xy/bin:/home/oracle/app/oracle/product/11.2.0/dbhome_2/bin)
processing components: myEspApp esp8266 app_adapter
*** All Components: myEspApp esp8266 app_adapter osal_aos mcu_esp8266 kernel_init network rhino yloop newlib_stub lwip netmgr arch_xtensa_lx106 ulog lib_rbtree vfs kv
Build AOS Now
TOOLCHAIN_PATH=
which: no xtensa-lx106-elf-gcc in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/xy/.local/bin:/home/xy/bin:/home/oracle/app/oracle/product/11.2.0/dbhome_2/bin)
Compiling myEspApp
Compiling board_esp8266
Compiling app_adapter
Compiling osal_aos
Compiling mcu_esp8266
/home/xy/AliOS-Things/platform/mcu/esp8266/hal/misc.c: In function 'hal_reboot':
/home/xy/AliOS-Things/platform/mcu/esp8266/hal/misc.c:32:5: warning: implicit declaration of function 'rom_i2c_writeReg' [-Wimplicit-function-declaration]
     rom_i2c_writeReg(0x67, 4, 1, 8);
     ^
/home/xy/AliOS-Things/platform/mcu/esp8266/hal/misc.c: In function 'hal_reboot_bank':
/home/xy/AliOS-Things/platform/mcu/esp8266/hal/misc.c:44:5: warning: implicit declaration of function 'ota_msleep' [-Wimplicit-function-declaration]
     ota_msleep(300);
     ^
/home/xy/AliOS-Things/platform/mcu/esp8266/hal/uart.c: In function 'hal_uart_send':
/home/xy/AliOS-Things/platform/mcu/esp8266/hal/misc.c:48:9: warning: implicit declaration of function 'system_upgrade_process' [-Wimplicit-function-declaration]
         system_upgrade_process();
         ^
/home/xy/AliOS-Things/platform/mcu/esp8266/hal/misc.c:49:9: warning: implicit declaration of function 'system_restart_in_nmi' [-Wimplicit-function-declaration]
         system_restart_in_nmi();
         ^
/home/xy/AliOS-Things/platform/mcu/esp8266/hal/uart.c:24:9: warning: implicit declaration of function 'uart0_write_char' [-Wimplicit-function-declaration]
         uart0_write_char(pdata[i]);
         ^
Compiling kernel_init
Compiling rhino
/home/xy/AliOS-Things/platform/mcu/esp8266/hal/wifi_port.c: In function 'register_wlan_mgnt_monitor_cb':
/home/xy/AliOS-Things/platform/mcu/esp8266/hal/wifi_port.c:733:9: warning: implicit declaration of function 'wifi_set_sta_rx_probe_req' [-Wimplicit-function-declaration]
         wifi_set_sta_rx_probe_req(esp_mgmt_filter);
         ^
/home/xy/AliOS-Things/platform/mcu/esp8266/hal/wifi_port.c: At top level:
/home/xy/AliOS-Things/platform/mcu/esp8266/hal/wifi_port.c:801:5: warning: initialization from incompatible pointer type [enabled by default]
     .get_wireless_info   = get_wireless_info,
     ^
/home/xy/AliOS-Things/platform/mcu/esp8266/hal/wifi_port.c:801:5: warning: (near initialization for 'aos_wifi_esp8266.get_wireless_info') [enabled by default]
Compiling yloop
Compiling newlib_stub
Compiling netmgr
Compiling arch_xtensa_lx106
Compiling ulog
Compiling lib_rbtree
Compiling vfs
Compiling kv
Making /home/xy/myEspApp/out/myEspApp@esp8266/ld/eagle.app.v6.new.1024.app1.ld
Making /home/xy/myEspApp/out/myEspApp@esp8266/libraries/myEspApp.a
Making /home/xy/myEspApp/out/myEspApp@esp8266/libraries/app_adapter.a
Making /home/xy/myEspApp/out/myEspApp@esp8266/libraries/board_esp8266.a
Making /home/xy/myEspApp/out/myEspApp@esp8266/libraries/mcu_esp8266.a
Making /home/xy/myEspApp/out/myEspApp@esp8266/libraries/osal_aos.a
Making /home/xy/myEspApp/out/myEspApp@esp8266/libraries/kernel_init.a
Making /home/xy/myEspApp/out/myEspApp@esp8266/libraries/rhino.a
Making /home/xy/myEspApp/out/myEspApp@esp8266/libraries/yloop.a
Making /home/xy/myEspApp/out/myEspApp@esp8266/libraries/newlib_stub.a
Making /home/xy/myEspApp/out/myEspApp@esp8266/libraries/netmgr.a
Making /home/xy/myEspApp/out/myEspApp@esp8266/libraries/arch_xtensa_lx106.a
Making /home/xy/myEspApp/out/myEspApp@esp8266/libraries/ulog.a
Making /home/xy/myEspApp/out/myEspApp@esp8266/libraries/lib_rbtree.a
Making /home/xy/myEspApp/out/myEspApp@esp8266/libraries/vfs.a
Making /home/xy/myEspApp/out/myEspApp@esp8266/libraries/kv.a
Making myEspApp@esp8266.elf

Making myEspApp@esp8266.bin
Making myEspApp@esp8266.hex

                        AOS MEMORY MAP                            
|=================================================================|
| MODULE                                   | ROM       | RAM      |
|=================================================================|
| app_adapter                              | 76        | 12       |
| arch_xtensa_lx106                        | 2662      | 2784     |
| board_esp8266                            | 1326      | 44       |
| kernel_init                              | 112       | 0        |
| kv                                       | 2224      | 24       |
| libcirom                                 | 27509     | 1200     |
| libcrypto                                | 14512     | 0        |
| libgcc                                   | 2167      | 0        |
| libhal                                   | 37        | 0        |
| liblwip                                  | 30717     | 1596     |
| libmain                                  | 30412     | 708      |
| libnet80211                              | 42675     | 3213     |
| libphy                                   | 48158     | 461      |
| libpp                                    | 43992     | 18013    |
| libwpa                                   | 17240     | 626      |
| mcu_esp8266                              | 8158      | 559      |
| myEspApp                                 | 98        | 0        |
| netmgr                                   | 94        | 8        |
| newlib_stub                              | 363       | 0        |
| osal_aos                                 | 670       | 0        |
| rhino                                    | 11701     | 3288     |
| ulog                                     | 573       | 7        |
| vfs                                      | 1440      | 1113     |
| yloop                                    | 1996      | 32       |
| *fill*                                   | 2080      | 124      |
|=================================================================|
| TOTAL (bytes)                            | 290992    | 33812    |
|=================================================================|
Generate standard flash images /home/xy/myEspApp/out/myEspApp@esp8266/binary/myEspApp@esp8266.elf
bin crc: f594b4f3
Generate Raw OTA image: /home/xy/myEspApp/out/myEspApp@esp8266/binary/myEspApp@esp8266_ota.bin ...
Generate Compressed OTA image: /home/xy/myEspApp/out/myEspApp@esp8266/binary/myEspApp@esp8266_ota.bin.xz ...
293369
61ef1f898403341c2ffca46d83ec5a4b
195860
75e5cc20888811818069046e42a7da50
Build complete: myEspApp@esp8266
[xy@xycto myEspApp]$ 
[xy@xycto myEspApp]$ ll /home/xy/myEspApp/out/myEspApp@esp8266/binary/myEspApp@esp8266.elf
-rwxr-x--x. 1 xy xy 1129042 Sep  6 17:21 /home/xy/myEspApp/out/myEspApp@esp8266/binary/myEspApp@esp8266.elf
[xy@xycto myEspApp]$ /home/xy/myEspApp/out/myEspApp@esp8266/binary/myEspApp@esp8266.elf
-bash: /home/xy/myEspApp/out/myEspApp@esp8266/binary/myEspApp@esp8266.elf: cannot execute binary file
[xy@xycto myEspApp]$ file /home/xy/myEspApp/out/myEspApp@esp8266/binary/myEspApp@esp8266.elf
/home/xy/myEspApp/out/myEspApp@esp8266/binary/myEspApp@esp8266.elf: ELF 32-bit LSB executable, Tensilica Xtensa, version 1 (SYSV), statically linked, not stripped
[xy@xycto myEspApp]$

烧录 - Upload

aos upload
添加普通用户xy访问串口权限
[root@xycto bin]# usermod -a -G dialout xy

监测串口

[root@xycto bin]# aos monitor /dev/ttyUSB0 115200
— Miniterm on /dev/ttyUSB0 115200,8,N,1 —
— Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H —

— exit —
切换到921600波特率也无输出,按esp设备的reset会出现乱码然后报错,2个波特率都是这样。
— exit —
Exception in thread rx:

四、安装图形化调测软件

安装软件

vscode + alios-studio插件
https://code.visualstudio.com
在左上角的安装会链接到dnf安装方法。
在底部有rpm的安装包直接下载
在vscode的左下角,点击闪电图标,自动调用和选择bin文件进行烧录。

烧录报错,无tty权限。

> Executing task in folder myEspApp: aos upload myEspApp@esp8266 <

aos-cube version: 0.5.11
[INFO]: Target: myEspApp@esp8266

--- Available ports:
---  1: /dev/ttyUSB0         'USB Serial'
--- Enter port index or full name: 1
[INFO]: Running cmd:
        'esptool.py --chip esp8266 --port /dev/ttyUSB0 --baud 921600 write_flash --flash_size detect 0x0 /home/xy/AliOS-Things/platform/mcu/esp8266/bsp/boot_v1.7_921600.bin 0x3fc000 /home/xy/AliOS-Things/platform/mcu/esp8266/bsp/esp_init_data_default.bin 0x3fe000 /home/xy/AliOS-Things/platform/mcu/esp8266/bsp/blank.bin 0x1000 /home/xy/myEspApp/out/myEspApp@esp8266/binary/myEspApp@esp8266.bin'
esptool.py v2.8
Serial port /dev/ttyUSB0
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/serial/serialposix.py", line 265, in open
    self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
PermissionError: [Errno 13] Permission denied: '/dev/ttyUSB0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/esptool.py", line 3201, in <module>
    _main()
  File "/usr/local/bin/esptool.py", line 3194, in _main
    main()
  File "/usr/local/bin/esptool.py", line 2889, in main
    esp = chip_class(each_port, initial_baud, args.trace)
  File "/usr/local/bin/esptool.py", line 237, in __init__
    self._port = serial.serial_for_url(port)
  File "/usr/local/lib/python3.6/site-packages/serial/__init__.py", line 88, in serial_for_url
    instance.open()
  File "/usr/local/lib/python3.6/site-packages/serial/serialposix.py", line 268, in open
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 13] could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0'
---host_os:Linux64
[ERROR]: Firmware upload failed!

The terminal process "/bin/bash '-c', 'aos upload myEspApp@esp8266'" terminated with exit code: 255.

Terminal will be reused by tasks, press any key to close it.

原因分析:
PermissionError: [Errno 13] Permission denied: ‘/dev/ttyUSB0’
使用的USB串口没有权限,但实际前面已增加xy用户的dialout组。

[root@xycto ~]# id xy
uid=1000(xy) gid=1000(xy) groups=1000(xy),18(dialout),107(qemu),975(dockerroot),1002(dba),973(vboxusers)

但是以xy用户查看并未生效,新开终端也不生效。

[xy@xycto ~]$ id
uid=1000(xy) gid=1000(xy) groups=1000(xy),107(qemu),973(vboxusers),975(dockerroot),1002(dba) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

手工执行命令也无权限。

[xy@xycto ~]$ aos monitor /dev/ttyUSB0 115200
could not open port '/dev/ttyUSB0': [Errno 13] could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0'

解决方法:
退出图形界面,重新登录后,aos monitor显示正常。
— Miniterm on /dev/ttyUSB0 115200,8,N,1 —
— Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H —

vscode烧录(闪电图标)报错:Invalid head of packet (0xE0)

A fatal error occurred: Invalid head of packet (0xE0)
---host_os:Linux64
[ERROR]: Firmware upload failed!

The terminal process "/bin/bash '-c', 'aos upload myEspApp@esp8266'" terminated with exit code: 255.

参考官网SDK入门指南
https://www.espressif.com/sites/default/files/documentation/2a-esp8266-sdk_getting_started_guide_cn.pdf
烧录地址和4096KB的Flash也是匹配的,下面的命令只修改了格式

esptool.py --chip esp8266 --port /dev/ttyUSB0 --baud 921600 write_flash --flash_size detect \
0x0      /home/xy/AliOS-Things/platform/mcu/esp8266/bsp/boot_v1.7_921600.bin \
0x3fc000 /home/xy/AliOS-Things/platform/mcu/esp8266/bsp/esp_init_data_default.bin \
0x3fe000 /home/xy/AliOS-Things/platform/mcu/esp8266/bsp/blank.bin \
0x1000   /home/xy/myEspApp/out/myEspApp@esp8266/binary/myEspApp@esp8266.bin

esptool.py直接运行有帮助,2个查询命令,结果都是正常的。

[xy@xycto myEspApp]$ esptool.py --port /dev/ttyUSB0 read_flash_status
esptool.py v2.8
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 10:52:1c:ef:b8:8a
Uploading stub...
Running stub...
Stub running...
Status value: 0x0000
Hard resetting via RTS pin...
[xy@xycto myEspApp]$ 

这个脚本还是很强大。

$ esptool.py --port /dev/ttyUSB0 flash_id 命令可以多看到下面3个参数(无staus字段)
Manufacturer: 20
Device: 4016
Detected flash size: 4MB

查看具体参数

$ esptool.py write_flash -h
  --flash_size FLASH_SIZE, -fs FLASH_SIZE
                        SPI Flash size in MegaBytes (1MB, 2MB, 4MB, 8MB, 16M)
                        plus ESP8266-only (256KB, 512KB, 2MB-c1, 4MB-c1),
                        detect, or keep
指定为4MB或detect相同
A fatal error occurred: Invalid head of packet (0xE0)
指定为4MB-c1或keep时
A fatal error occurred: Timed out waiting for packet content
降低波特率--baud 115200 和boot_v1.7.bin文件后烧录成功
esptool.py --chip esp8266 --port /dev/ttyUSB0 --baud 115200 write_flash --flash_size detect \
0x0      /home/xy/AliOS-Things/platform/mcu/esp8266/bsp/boot_v1.7.bin \
0x3fc000 /home/xy/AliOS-Things/platform/mcu/esp8266/bsp/esp_init_data_default.bin \
0x3fe000 /home/xy/AliOS-Things/platform/mcu/esp8266/bsp/blank.bin \
0x1000   /home/xy/myEspApp/out/myEspApp@esp8266/binary/myEspApp@esp8266.bin

aos monitor /dev/ttyUSB0 74880 // 74880  115200 921600
$ aos monitor /dev/ttyUSB0 115200 显示乱码,只能新开窗口kill
$ aos monitor /dev/ttyUSB0 74880  看到下面 报错
epc1=0x401000b5, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000
Fatal exception (0): 

串口报错Fatal exception epc1=0x401000b5的问题

通过查看代码,应该是使用这个分区,但无法确认
board/esp8266/config/partition_conf.c:const hal_logic_partition_t hal_partitions_4M_1024x1024[] =
查看elf文件存在分区相关参数
[xy@xycto myEspApp]$ readelf -a out/myEspApp@esp8266/binary/myEspApp@esp8266.elf >a
通过查看报错地址401000和401001区间,很有可能是
1845: 40100070 0 NOTYPE GLOBAL DEFAULT 1 _DoubleExceptionVector
随后在/home/xy/myEspApp/out/myEspApp@esp8266/binary/myEspApp@esp8266.map中查看到地址分布,问题地址在0x0000000040100098,偏移0x28

*(.DoubleExceptionVector.text)
 .DoubleExceptionVector.text
                0x0000000040100070        0xf /home/xy/myEspApp/out/myEspApp@esp8266/libraries/arch_xtensa_lx106.a(xtensa_vectors.o)
                0x0000000040100070                _DoubleExceptionVector
                0x000000004010007f        0x4 LONG 0x0
                0x0000000040100083        0x4 LONG 0x0
                0x0000000040100087        0x4 LONG 0x0
                0x000000004010008b        0x4 LONG 0x0
                0x0000000040100090                . = ALIGN (0x10)
 *fill*         0x000000004010008f        0x1 
 *(.entry.text)
 *(.init.literal)
 *(.init)
 *mcu_esp8266.a:entry.o(.literal .text .literal.* .text.*)
 .literal.user_fatal_exception_handler
                0x0000000040100090        0x8 /home/xy/myEspApp/out/myEspApp@esp8266/libraries/mcu_esp8266.a(entry.o)
 .literal.wifi_nmi_post_soft_isr
                0x0000000040100098        0x0 /home/xy/myEspApp/out/myEspApp@esp8266/libraries/mcu_esp8266.a(entry.o)
                                          0x4 (size before relaxing)
 .literal       0x0000000040100098       0x50 /home/xy/myEspApp/out/myEspApp@esp8266/libraries/arch_xtensa_lx106.a(xtensa_vectors.o)
                                         0x68 (size before relaxing)
 .literal.SoftIsrHdl
                0x00000000401000e8        0xc /home/xy/myEspApp/out/myEspApp@esp8266/libraries/arch_xtensa_lx106.a(port.o)
                                         0x14 (size before relaxing)
 .literal.cpu_task_stack_init
                0x00000000401000f4        0x8 /home/xy/myEspApp/out/myEspApp@esp8266/libraries/arch_xtensa_lx106.a(port.o)
                                          0xc (size before relaxing)
.....
_DoubleExceptionVector                            /home/xy/myEspApp/out/myEspApp@esp8266/libraries/arch_xtensa_lx106.a(xtensa_vectors.o)

进入对应目录查看文件
[xy@xycto libraries]$ file arch_xtensa_lx106.a
arch_xtensa_lx106.a: current ar archive
解压
[xy@xycto b]$ ar x arch_xtensa_lx106.a
得到
-rw-rw-r–. 1 xy xy 9676 Sep 11 23:52 xtensa_vectors.o
[xy@xycto b]$ file xtensa_vectors.o
xtensa_vectors.o: ELF 32-bit LSB relocatable, Tensilica Xtensa, version 1 (SYSV), not stripped
readelf -h xtensa_vectors.o
无法分析
[xy@xycto ~]$ find . -name “xtensa_vectors
得到
-rw-r-----. 1 xy xy 48407 Sep 6 16:19 /home/xy/AliOS-Things/platform/arch/xtensa/lx106/xtensa_vectors.S
这个汇编很重要,但是看不懂
从其他地方拷贝一个xtensa_vectors.S过来替换
/home/xy/wind/Ai-Thinker/AiThinkerIDE…/ESP8266_RTOS_SDK
编译失败
/home/xy/AliOS-Things/platform/arch/xtensa/lx106/xtensa_vectors.S:57:38: fatal error: freertos/xtensa_rtos.h: No such file or directory
修改xtensa_vectors.S其中的include路径
不配套,一堆错误,恢复。

五、重新安装环境

处理python2版本问题

由于中途手工make install了python2.7.18,发现aos make找不到模块了。可能aos存在同时使用python2和3的情况。

首先卸载已安装的aos-cube

# pip uninstall aos-cube
# pip uninstall wheel
# pip uninstall setuptools

重新创建python2环境

# ln -s /bin/python2 /bin/python

复原后存在2个版本

[xy@xycto ~]$ python --version
Python 2.7.18
[xy@xycto ~]$ which python 
/usr/local/bin/python
[xy@xycto ~]$ /bin/python --version
Python 2.7.5   这个必须保留,否则yum无法正常运行

处理pip版本问题

重新安装aos-cube

[xy@xycto ~]$ pip install aos-cube

[xy@xycto ~]$ pip install setuptools wheel aos-cube
Traceback (most recent call last):
  File "/bin/pip", line 5, in <module>
    from pkg_resources import load_entry_point
ImportError: No module named pkg_resources

重新安装仍然是 python2-pip-8.1.2-12.el7.noarch.rpm
版本无法配套
[root@xycto ~]# yum remove python-pip
[xy@xycto ~]$ sudo yum install python-pip
还是报错:
参考https://developer.aliyun.com/mirror/pypi 配置镜像源
参考https://blog.51cto.com/lizhiyuan/2119396 1.安装distribute
wget https://pypi.python.org/packages/source/d/distribute/distribute-0.7.3.zip --no-check-certificate
unzip distribute-0.7.3.zip
cd distribute-0.7.3
python setup.py install
安装pip 8.1.2成功
[xy@xycto ~]$ sudo easy_install pip
[xy@xycto ~]$ pip -V
pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)

更新pip版本20.2.3成功

[xy@xycto ~]$ python -m -pip install --upgrade pip
/usr/local/bin/python: No module named -pip
[xy@xycto ~]$ sudo pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/4e/5f/528232275f6509b1fff703c9280e58951a81abe24640905de621c9f81839/pip-20.2.3-py2.py3-none-any.whl (1.5MB)
    100% |████████████████████████████████| 1.5MB 678kB/s 
Installing collected packages: pip
  Found existing installation: pip 8.1.2
    Uninstalling pip-8.1.2:
      Successfully uninstalled pip-8.1.2
Successfully installed pip-20.2.3
[xy@xycto ~]$ pip -V
pip 20.2.3 from /usr/lib/python2.7/site-packages/pip (python 2.7)
[xy@xycto ~]$

再次验证安装情况

[xy@xycto ~]$ sudo yum install -y python python-pip git  提示都已经安装
[xy@xycto ~]$ sudo python -m pip install setuptools wheel aos-cube
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Requirement already satisfied: setuptools in ./distribute-0.7.3 (0.8b2)
Collecting wheel
  Using cached wheel-0.35.1-py2.py3-none-any.whl (33 kB)
Collecting aos-cube
  Using cached aos-cube-0.5.11.tar.gz (52 kB)
Requirement already satisfied: pyserial in /usr/lib/python2.7/site-packages (from aos-cube) (3.4)
Requirement already satisfied: esptool in /usr/lib/python2.7/site-packages (from aos-cube) (2.8)
Collecting scons
  Downloading scons-3.1.2-py2.py3-none-any.whl (837 kB)
     |████████████████████████████████| 837 kB 11 kB/s 
Requirement already satisfied: requests in /usr/lib/python2.7/site-packages (from aos-cube) (2.6.0)
Requirement already satisfied: click in /usr/lib/python2.7/site-packages (from aos-cube) (7.1.2)
Requirement already satisfied: paho-mqtt in /usr/lib/python2.7/site-packages (from aos-cube) (1.5.0)
Requirement already satisfied: progressbar2 in /usr/lib/python2.7/site-packages (from aos-cube) (3.52.1)
Collecting configparser
  Downloading configparser-4.0.2-py2.py3-none-any.whl (22 kB)
Requirement already satisfied: pyaes in /usr/lib/python2.7/site-packages (from esptool->aos-cube) (1.6.1)
Requirement already satisfied: ecdsa in /usr/lib/python2.7/site-packages (from esptool->aos-cube) (0.16.0)
Requirement already satisfied: six in /usr/lib/python2.7/site-packages (from progressbar2->aos-cube) (1.10.0)
Requirement already satisfied: python-utils>=2.3.0 in /usr/lib/python2.7/site-packages (from progressbar2->aos-cube) (2.4.0)
Using legacy 'setup.py install' for aos-cube, since package 'wheel' is not installed.
Installing collected packages: wheel, scons, configparser, aos-cube
    Running setup.py install for aos-cube ... done
Successfully installed aos-cube-0.5.11 configparser-4.0.2 scons-3.1.2 wheel-0.35.1
[xy@xycto ~]$

处理缺少click模块问题

创建项目提示缺少click模块

[xy@xycto ~]$ aos create project -b esp8266 -t helloworld_demo myEspApp
Traceback (most recent call last):
  File "/home/xy/AliOS-Things/build/scripts/gen_newproject.py", line 3, in <module>
    import click
ImportError: No module named click
[AliOS-Things] ERROR: "python" returned error code 1.
[AliOS-Things] ERROR: Command "python /home/xy/AliOS-Things/build/scripts/gen_newproject.py myEspApp -besp8266 -thelloworld_demo" in "/home/xy"
---

检查发现已安装click模块

[xy@xycto ~]$ pip list |grep click
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
click                            7.1.2
[xy@xycto ~]$ pip install click
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Requirement already satisfied: click in /usr/lib/python2.7/site-packages (7.1.2)
权限也是可读和执行的,正常
[xy@xycto ~]$ ls -dl /usr/lib/python2.7/site-packages
drwxr-xr-x. 174 root root 12288 Sep 13 11:47 /usr/lib/python2.7/site-packages

手工检查也包含了这个目录。

[xy@xycto ~]$ python
Python 2.7.18 (default, Sep 11 2020, 22:22:29) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.executable)
/usr/local/bin/python
>>> print(sys.path)
['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/home/xy/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/site-packages']

临时添加后执行正常

>>> sys.path.append("/usr/lib/python2.7/site-packages")
>>> import click
>>> 

但是重新进入python执行import click会报错。

3, 在当前sitepackages里面添加.pth文件
找到路径

[xy@xycto ~]$ python
>>> import site
>>> print(site.getsitepackages())
['/usr/local/lib/python2.7/site-packages', '/usr/local/lib/site-python']
>>> 

添加路径

[xy@xycto ~]$ cd /usr/local/lib/python2.7/site-packages
[xy@xycto site-packages]$ vi abc.pth
[xy@xycto site-packages]$ cat abc.pth 
/usr/lib/python2.7/site-packages

python执行import click正常。

重新创建项目:编译 ,烧录

重新创建项目成功,进入项目aos make,烧录aos upload
仍然上传失败 A fatal error occurred: Invalid head of packet (0xE0)
修改波特率–baud 115200写入成功,但复位后串口无输出
aos monitor /dev/ttyUSB0 74880
增加 --flash_mode dio --flash_size 4MB-c1

esptool.py --chip esp8266 --port /dev/ttyUSB0 --baud 115200 write_flash --flash_mode dio --flash_size 4MB-c1 0x0 /home/xy/AliOS-Things/platform/mcu/esp8266/bsp/boot_v1.7_921600.bin 0x3fc000 /home/xy/AliOS-Things/platform/mcu/esp8266/bsp/esp_init_data_default.bin 0x3fe000 /home/xy/AliOS-Things/platform/mcu/esp8266/bsp/blank.bin 0x1000 /home/xy/myEspApp/out/myEspApp@esp8266/binary/myEspApp@esp8266.bin

在windows下烧录验证成功

把4个文件拷贝到windows,用官网烧录工具,只烧前面2个文件无输出。
勾选4个文件,并先擦除再烧录,重启设备,串口打印正常,波特率921600。
手机连接wifi正常。
aliOS这个是以RTOS来进行开发的。

hello world! count 217 
hello world! count 218 
[WiFi] event 8
add 1
aid 1
station: 58:20:59:aa:bb:cc join, AID = 1
[WiFi] event 6
[WiFi] event 8
[WiFi] event 8
hello world! count 219 
hello world! count 220 
[WiFi] event 8
[WiFi] event 8
hello world! count 221 
hello world! count 222 
hello world! count 223 
hello world! count 224 
hello world! count 225 
hello world! count 226 
hello world! count 227 
hello world! count 228 
hello world! count 229 
[WiFi] event 8
[WiFi] event 8
[WiFi] event 8
hello world! count 230 
station: 58:20:59:aa:bb:cc leave, AID = 1
rm 1
[WiFi] event 7
hello world! count 231 
hello world! count 232 

六、总结

  1. 环境及配套要搞好:虽然中间对python2/3版本进行了调整,但根据视频教程的操作,运行错误(Fatal error)的主要问题可能在pip版本上,官网并未明确要求pip版本。

  2. 在linux的python.py脚本烧录会有问题,及时所有参数都(DIO/–baud 115200 --flash_mode dio --flash_size 4MB-c1)正确,仍然无法正常运行。

  3. RTOS是乐鑫后续支持和发展方向,阿里也采用的RTOS,后续可以继续深入。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值