Win下搭建CLion配合远程Linux的联盛德W801开发环境(csky-elfabiv2-tools)

之前9块钱促销买了块海凌科(Hi-Link)的W801开发板HLK-W801-KIT-V1.1:

到手后看了各种资料用CDK IDE搭起了开发环境,简单试了试灯,还踩了个Upgrade Tools上传程序的坑:W801开发板Upgrade Tools上传程序失败问题,那之后这块板就吃灰了😂,最近因为发现网口WOL网络唤醒在电脑完全断电恢复后无法使用的问题(试了自己和朋友的几台电脑,华硕的x370主板、技嘉的x570主板、公司的技嘉z390主板都不行,网上看有人说自己的电脑可以掉电后WOL,介绍的各种设置方法也基本都试了个遍,无果), 打算研究个IoT远程开机功能,嘉立创的开源平台上一搜能搜到很多,但大都基于ESP的MCU,于是又想起了这块W801…不过用惯了VS、Xcode、CLion的我对之前使用CDK的体验着实不怎么样,在联盛德的官方论坛上也看到有人基于VSCode搭建了开发环境,有win下配msys的,也有走远程linux编译的,由于本人实在是对cgywin,mingw这类windows下移植linux环境的工具不感兴趣,所以这回打算尝试下远程linux编译的方式再次搭建下W801的开发环境,同时使用最近经常用的CLion IDE(我用的Nova版,写此文的时候还处于EAP状态,已经进入RC状态了,下载2024.1 RC版(设置中高级里启用ReSharper 引擎,重启后就是Nova办了),但实际测试并没发现什么严重问题,理论上稳定版对远程linux开发支持应该也是一样的),另外,多说一句,虽然说的是remote linux,其实WSL,或者本地虚拟机也都是一个道理,那下面我就记录下这样搭环境的主要步骤。

首先,是要先调整好用于构建的linux机,这里我用的是CentOS 8 Stream,需要做的是主要是安装make等构建工具(应该主要就是make),然后去平头哥的官网下载交叉编译工具,写这篇文章时最新版本是“GCC-800系列 – V3.10.30”,这里下载https://www.xrvm.cn/community/download?id=4224178809689149440,(旁边就是上次剑池CDK的下载,也看了下,更新也都挺频繁的,不过不好意思,这次只是路过),注意下载64位linux版本x86_64的csky-elfabiv2-tools-x86_64-minilibc-20230301.tar.gz。

再后面就是去拿一份联盛德的W801 SDK,在这:https://www.winnermicro.com/html/1/156/158/558.html,这个页面的下面软件资料标签里W80X_SDK_v1.00.10.rar,写此文时的23年8月版,这个更新频率就不怎么频繁了,应该是相对稳定了。

编译工具和SDK都解压好后,直接测试下命令行make是否正常,进入sdk的根目录下执行make,注意要保证系统PATH路径里有编译工具解压后的bin路径,可以加个export在~/.bashrc内,如:

# .bashrc
  
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
then
    PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
export PATH

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions
export PATH=$PATH:/home/admin/w801/toolchain/bin/

建议使用这种方法,否则后面CLion触发远程构建时会找不到gcc,并且我试了下CLion工具链配置中的环境变量也不好使,所以,直接加bashrc里就好了。

make[1]: Entering directory '/home/admin/w801/W80X_SDK_v1.00.10/app'
make[1]: Leaving directory '/home/admin/w801/W80X_SDK_v1.00.10/app'
make[1]: Entering directory '/home/admin/w801/W80X_SDK_v1.00.10/demo'
make[2]: Entering directory '/home/admin/w801/W80X_SDK_v1.00.10/demo/console'
make[2]: Leaving directory '/home/admin/w801/W80X_SDK_v1.00.10/demo/console'
CC       wm_adc_demo.c
AR       libdemo.a
make[1]: Leaving directory '/home/admin/w801/W80X_SDK_v1.00.10/demo'
LINK     w800.elf
OBJCOPY  w800.bin
make[1]: Entering directory '/home/admin/w801/W80X_SDK_v1.00.10/tools/w800/zlib-1.2.11'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/admin/w801/W80X_SDK_v1.00.10/tools/w800/zlib-1.2.11'
generate normal image completed.
generate normal image completed.
compress binary completed.
generate compressed image completed.
build finished!

一切正常的话,可以看到sdk已经正常构建出固件了,这时可以先拿回来sdk文件夹下的bin/w800/w800.fls,用Upgrade Tools上传下试试是否可以正常运行。

上述操作都成功后,就可以开始win下CLion远程linux交叉编译环境的配置了。先将sdk找个地方解压缩,然后直接用CLion打开sdk根目录下的Makefile,并让CLion以Makefile工程的方式加载而不是单开Makefile文件。

然后,在CLion的设置界面,按如下位置配置远程Linux开发Toolchain,Toolchains页的加号点后选Remote Host:

配置好linux的ssh登录信息,Test Connection可以成功后关闭即可,不需要管识别出来的CMake,gcc,g++,gdb这些,因为不是我们交叉编译要用的,将Remote Host上提味default,关闭设置页面,刷新下Makefile项目:

这时CLion会触发远程工程上传,如果和我一样linux环境真的是远程的话,这步可能会消耗一些时间。

完成后可以看到CLion分析出了Makefile的各种target,如下:

我们需要用的主要是all和distclean,选中all,点下旁边的小铁锤,触发build,可以看到类似如下的输出:

====================[ Build | all ]=============================================
make --jobs=14 all
make: *** No rule to make target 'bin/build/w800/lib/libuser.a', needed by 'bin/build/w800/image/w800.elf'.  Stop.
make: *** Waiting for unfinished jobs....
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
make[1]: Entering directory '/tmp/tmp.6hzf7kgoFv/app'
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       main.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
AR       libuser.a
csky-abiv2-elf-ar: creating ../bin/build/w800/lib/libuser.a
make[1]: Leaving directory '/tmp/tmp.6hzf7kgoFv/app'
make[1]: Entering directory '/tmp/tmp.6hzf7kgoFv/demo'
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
make[2]: Entering directory '/tmp/tmp.6hzf7kgoFv/demo/console'
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_rtc_demo.c
CC       wm_slave_spi_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_apsta_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_i2s_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_7816_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_iperf_auto_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_mqtt_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_i2c_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_timer_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_pwm_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_flash_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_fatfs_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_socket_client_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_udp_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_demo_console_task.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_master_spi_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_lcd_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_sck_client_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_dsp_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_pmu_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_crypt_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_wps_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_avoid_copy_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_rsa_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_crypt_hard_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_adc_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_gpio_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_mcast_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_mbedtls_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_http_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_softap_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_socket_server_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_uart_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
AR       libconsole.a
csky-abiv2-elf-ar: creating ../../bin/build/w800/lib/libconsole.a
make[2]: Leaving directory '/tmp/tmp.6hzf7kgoFv/demo/console'
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_scan_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_ntp_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_ssl_server_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_sck_server_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_websockets_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_https_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_sdio_host_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_touchsensor_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_connect_net_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
AR       libdemo.a
csky-abiv2-elf-ar: creating ../bin/build/w800/lib/libdemo.a
make[1]: Leaving directory '/tmp/tmp.6hzf7kgoFv/demo'

Process finished with exit code 2

可以看到编译工具链调用正常,但是报了No rule to make target的错误,导致最后build失败,没有生成fls文件,仔细对比下CLion构建时调用的make命令,发现是make –jobs=14 all,手动ssh到linux的sdk下也执行下,额。。。一样报错,估计是平头哥的toolchain不支持–jobs并发,所以,需要修改下CLion执行make时的参数:

打开Settings,按上图中的设置项位置,修改Build options为V=s,让CLion在linux上执行make命令时不要传递jobs参数,保存后再次build,可以看到如下成功信息:

====================[ Build | all ]=============================================
make V=s all
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
make[1]: Entering directory '/tmp/tmp.6hzf7kgoFv/app'
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       main.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
AR       libuser.a
csky-abiv2-elf-ar: creating ../bin/build/w800/lib/libuser.a
make[1]: Leaving directory '/tmp/tmp.6hzf7kgoFv/app'
make[1]: Entering directory '/tmp/tmp.6hzf7kgoFv/demo'
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
make[2]: Entering directory '/tmp/tmp.6hzf7kgoFv/demo/console'
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_demo_console_task.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
AR       libconsole.a
csky-abiv2-elf-ar: creating ../../bin/build/w800/lib/libconsole.a
make[2]: Leaving directory '/tmp/tmp.6hzf7kgoFv/demo/console'
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_rtc_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_slave_spi_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_apsta_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_i2s_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_7816_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_iperf_auto_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_mqtt_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_i2c_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_timer_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_pwm_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_flash_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_fatfs_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_socket_client_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_udp_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_master_spi_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_lcd_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_sck_client_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_dsp_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_pmu_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_crypt_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_wps_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_avoid_copy_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_rsa_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_crypt_hard_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_adc_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_gpio_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_mcast_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_mbedtls_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_http_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_softap_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_socket_server_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_uart_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_scan_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_ntp_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_ssl_server_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_sck_server_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_websockets_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_https_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_sdio_host_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_touchsensor_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
CC       wm_connect_net_demo.c
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
AR       libdemo.a
csky-abiv2-elf-ar: creating ../bin/build/w800/lib/libdemo.a
make[1]: Leaving directory '/tmp/tmp.6hzf7kgoFv/demo'
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
LINK     w800.elf
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
OBJCOPY  w800.bin
make[1]: Entering directory '/tmp/tmp.6hzf7kgoFv/tools/w800/zlib-1.2.11'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/tmp/tmp.6hzf7kgoFv/tools/w800/zlib-1.2.11'
generate normal image completed.
generate normal image completed.
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
compress binary completed.
generate compressed image completed.
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.GBK)
build finished!

Process finished with exit code 0

Building 'all' finished

到此为止,使用CLion的远程构建环境已经搭建好了,可以手动拿回CLion上传工程到的临时路径(我这是/tmp/tmp.6hzf7kgoFv)中的fls文件,下载到开发板上测试。

然而,这篇博文还没有结束,因为使用CLion最重要的一个功能,目前还不正常,那就是强大的智能感知功能(这也是CDK让我感觉体验不好的主要原因)。可以看到目前的智能感知是不可用状态,所有的标准库头文件、标准库函数,sdk的api都无法感知,也找不到搜索路径中的头文件。一番研究过后,在CLion官方文档中找到了解决方法:https://www.jetbrains.com/help/clion/remote-projects-support.html#resync,在Tools 菜单中,点击 Resync with Remote Hosts,这样CLion就会根据当前工程,远端编译工具上文,将需要的各种头文件下载到本地临时路径,并设置好标准库、工程的头文件搜索路径,随后智能感知就正常了,效果如下:

不得不说,最近这几年JetBrains的各种IDE真的是越做越好,我朝的CDK还需要再打磨打磨(不过实话说,Keil那些也不咋地,感觉嵌入式开发的大佬们可能对IDE并没有太高要求,只是可能博主我这种常年做软件开发的太过挑剔了吧)。

至此,基于win下CLion配合linux的W801开发环境搭建就算完成了,上传程序部分,联盛德的Upgrade Tools可以支持http的fls文件下载加上传MCU,所以如果嫌手动搬麻烦的话,还可以在CLion中配置将构建成品cp到简单web服务器路径,然后直接一键上传了。

博主友情提示:

如您在评论中需要提及如QQ号、电子邮件地址或其他隐私敏感信息,欢迎使用>>博主专用加密工具v3<<处理后发布,原文只有博主可以看到。