Skip to content

Commit

Permalink
conemu可以正常工作,并完善说明文档
Browse files Browse the repository at this point in the history
  • Loading branch information
ComerLater committed Aug 12, 2024
1 parent 79c32ce commit 681e42f
Show file tree
Hide file tree
Showing 11 changed files with 843 additions and 32 deletions.
53 changes: 39 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Nextpilot Develop Toolchain for Windows

nextpilot-windows-toolchain是nextpilot-flight-control在windows平台下的开发工具链,主要集成了以下开发工具:
`nextpilot-windows-toolchain``nextpilot-flight-control``windows` 平台下的开发工具链,主要集成了以下开发工具:

|工具|版本|路径|
|---|---|---|
|python|python-3.11.9-amd64|toolchain/python/python-3.11.9-amd64|
|gcc-arm|gcc-arm-none-eabi-10.3-2021.10|toolchain/gcc/gcc-arm-none-eabi-10.3-2021.10|
|qemu|qemu-w64-v8.2.0|toolchain/qemu/qemu-w64-v8.2.0|
|git|MinGit-2.42.0.2-64-bit|toolchain/git/MinGit-2.42.0.2-64-bit|
|conemu|ConEmuPack.230724|toolchain/conemu/ConEmuPack.230724|

## 目录结构

```
├─document
├─rtthread # 保存rt-thread官方工具和代码
│ ├─bin # menuconfig/pkgs/env等可执行文件,本质是rtt-env的exe封装
│ ├─env # rtt-env的python代码
│ └─pkg # rtt-pkg的kconfig文件
├─toolchain # 第三方工具链,主要是python/arm-gcc等
Expand All @@ -23,6 +23,7 @@ nextpilot-windows-toolchain是nextpilot-flight-control在windows平台下的开
│ ├─mconf # kconfig-frontends,在windows下使用kconfig
│ ├─python # python,已经添加了所需的模块
│ ├─qemu # qemu,硬件模拟器,用于运行飞行仿真
│ ├─conemu # coemu,命令行终端(集成了clink)
│ └─vscode # vscode,文本编辑器,已安装所需的插件
└─workspace # 工作目录
```
Expand All @@ -31,15 +32,15 @@ nextpilot-windows-toolchain是nextpilot-flight-control在windows平台下的开

1 下载工具链到`c:\nextpilot-windows-toolchain`**当前只支持该路径**,不支持其它自定义路径哈,否则会报错找不到python.exe

原因是安装pip软件包时会将python绝对路径的写入exe文件中,工具链中预装pip包时用的路径是`c:\nextpilot-windows-toolchain`,如果将toolchain安装到其它路径,运行`scons.exe`等工具的时候会提示找不到`C:\nextpilot-windows-toolchain\toolchain\python\python-3.11.9-amd64\python.exe`,告警信息如下:
> 原因是安装pip软件包时会将python绝对路径的写入exe文件中,工具链中预装pip包时用的路径是`c:\nextpilot-windows-toolchain`,如果将toolchain安装到其它路径,运行`scons.exe`等工具的时候会提示找不到`C:\nextpilot-windows-toolchain\toolchain\python\python-3.11.9-amd64\python.exe`,告警信息如下:
```bat
rem 如果将工具链安装到d:\nextpilot-windows-toolchain,而不是c:\nextpilot-windows-toolchain,则会提示如下错误
Fatal error in launcher: Unable to create process using '"C:\nextpilot-windows-toolchain\toolchain\python\python-3.11.9-amd64\python.exe" "D:\nextpilot-windows-toolchain\toolchain\python\python-3.11.9-amd64\Scripts\scons.exe" ': ???????????
```

2 双击根目录下的`start.bat`脚本(为了方便下次使用,建议将start.bat添加桌面快捷方式),启动cmd终端
2 双击根目录下的`start.bat`脚本(为了方便下次使用,建议将start.bat添加桌面快捷方式),启动终端。如果已经添加了右键菜单,则可以在`bsps/sitl/qemu`文件夹上点击鼠标右键方式启动终端。

![](./toolchain/conemu/start-from-contex-menu.jpg)

```bat
https://github.com/chrisant996/clink
Expand All @@ -63,8 +64,6 @@ Clink v1.6.14 is available.
# LaterComer @ LAPTOP-TL7N7OT4 in C:\nextpilot-windows-toolchain on git:master x [10:36:17]
```

> 注意:Clink是用户自行安装的,目前工具链中没有集成Clink。
3 在cmd中切换到`nextpilot-flight-control`的bsp目录,然后执行配置、编译、仿真等

```bat
Expand All @@ -73,6 +72,11 @@ cd nextpilot-flight-control\bsps\sitl\qemu
rem 配置编译模块,非必须
scons --menuconfig
scons default --menuconfig
rem 生成keil工程
scons --target=mdk5
scons default --target=mdk5
rem 编译固件
scons -j10
Expand All @@ -82,15 +86,36 @@ rem 启动仿真
qemu.bat
```

> 注意:`bsps/sitl/qemu/config/`文件夹下面保存了很多`*.config`文件(比如default.config),`scons default`表示使用`default.config`配置文件
## 常见问题

### 如何将添加到Windows Terminal
### 添加到右键菜单

打开 ConEmu 设置页面,按照下图所示可以添加右键快捷菜单:

- Menu item:`NextPilot Here`
- Command:`{cmd} -cur_console:n`
- Icon file:`C:\nextpilot-windows-toolchain\toolchain\conemu\ConEmuPack.230724\ConEmu64.exe,0`

![](./toolchain/conemu/add-to-contex-menu.jpg)

### 集成到Windows Terminal

打开 Windows Termial 设置页面,选择`添加新配置文件`,按照如下填写

- 名称:`NextPilot Windows Toolchain`
- 命令行:`cmd.exe /k C:\nextpilot-windows-toolchain\init.bat`
- 其它设置,全部保持默认即可

![](./toolchain/conemu/add-to-window-terminal.jpg)

### 如何添加到右键菜单
> 为了方便使用,可以通过 `Windows Terminal > Setting > 启动 > 默认配置文件`,将 NextPilot Windows Toolchain 设置为默认终端
### 如何安装其它pip模块
### 安装其它pip模块

当前已集成pip工具以及开发所需pip包,如果还希望安装其他模块,直接通过`pip install`安装即可。如果是国内环境,建议切换pip源为:
工具链默认已集成 NextPilot 开发所需的所有pip包,请参考[requirements.txt](./toolchain/python/requirements.txt)
如果还希望安装其他模块,直接通过`pip install`安装即可。如果是国内环境,建议切换pip源为:

```bat
rem 使用清华大学pip源
Expand All @@ -101,10 +126,10 @@ pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
```

### 如何切换python版本
### 切换python版本

当前已集成了`python-3.11.9-amd64`,由于项目中部分依赖的软件包仅支持python3,因此nextpilot不支持python2。如果希望切换到其它python版本,请参考[toolchain/python/README.md](toolchain/python/README.md)安装python后,再修改[init.bat](init.bat)中python路径为新的python路径即可。

### 如何切换arm-gcc版本
### 切换arm-gcc版本

当前已集成了`gcc-arm-none-eabi-10.3-2021.10`,安装其他版本gcc-arm请参考[toolchain/gcc/README.md](toolchain/gcc/README.md),并将[init.bat](init.bat)中关于gcc-arm的路径修改为新版本gcc-arm路径。
File renamed without changes.
67 changes: 57 additions & 10 deletions init.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ title NextPilot Windows Toolchain

rem Simple "ver" prints empty line before Windows version
rem Use this construction to print just a version info
cmd /d /c ver | "%windir%\system32\find.exe" "Windows"
@REM cmd /d /c ver | "%windir%\system32\find.exe" "Windows"

@REM chcp 65001 > nul

echo.
echo ******************************************************************
echo * _ __ __ ____ _ __ __
echo * / ^| / /___ _ __ / /_ / __ \ (_)/ /____ / /_
Expand All @@ -17,6 +19,25 @@ echo *
echo * Copyright All Reserved (C) 2015-2024 NextPilot Development Team
echo ******************************************************************


if /i not "%~dp0"=="C:\nextpilot-windows-toolchain\" (
echo.
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo ERROR: Toolchain must be installed in "C:\nextpilot-windows-toolchain"
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
)

rem Do not repeat run
if not "%NdtInited%" == "" goto :eof


REM ============= Change Command Prompt ==================

:set_command_prompt

rem Run in ConEmu
if not "%ConEmuBaseDir%" == "" goto :add_toolchain_path

rem Now we form the command prompt
rem This will start prompt with `User@PC `
set PROMPT0=$E[m$E[32m$E]9;8;"USERNAME"$E\@$E]9;8;"COMPUTERNAME"$E\$S
Expand All @@ -43,21 +64,35 @@ set PROMPT3=$E[m$S$E]9;12$E\
prompt %prompt1%%prompt2%%prompt3%


REM ============= Nextpilot Toolchain Path ==================
REM ============= Activate Python Venv ==================

:activate_python_venv

@REM set VENV_ROOT=%~dp0\.venv
@REM if not exist "%VENV_ROOT%" (
@REM echo Create Python Venv
@REM %~dp0\toolchain\python\python-3.11.9-amd64\python.exe -m pip uninstall pip -y
@REM %~dp0\toolchain\python\python-3.11.9-amd64\python.exe -m ensurepip
@REM %~dp0\toolchain\python\python-3.11.9-amd64\python.exe -m venv "%VENV_ROOT%"
@REM echo Activate Python Venv in %VENV_ROOT%
@REM %VENV_ROOT%\Scripts\activate.bat
@REM echo Install Python Packages
@REM pip install -r %~dp0\toolchain\python\requirements.txt
@REM ) else (
@REM echo Activate Python Venv in %VENV_ROOT%
@REM %VENV_ROOT%\Scripts\activate.bat
@REM )


REM ============= Add Toolchain Path ==================

:add_toolchain_path

@REM Setlocal ENABLEDELAYEDEXPANSION

@REM NDT_ROOT
set NDT_ROOT=%~dp0

if /i not "%~dp0"=="C:\nextpilot-windows-toolchain\" (
echo.
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo ERROR: Toolchain must be installed in "C:\nextpilot-windows-toolchain"
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
)

set PATH=%SystemRoot%\system32;%PATH%

@REM python
Expand Down Expand Up @@ -91,4 +126,16 @@ set PKGS_ROOT=%ENV_ROOT%\packages
set PKGS_DIR=%ENV_ROOT%\packages
@REM set PATH=%ENV_ROOT%\bin;%PATH%

@REM cmd /K

@REM set inited flag
@REM set NdtInited=1


REM ============= Inject Clink Tools ==================

:inject_clink

rem Run in ConEmu
if not "%ConEmuBaseDir%" == "" goto :eof

%~dp0\toolchain\conemu\ConEmuPack.230724\ConEmu\clink\clink.bat inject
6 changes: 5 additions & 1 deletion start.bat
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
@cmd /K call %~dp0\init.bat
@echo off

@REM start %~dp0\toolchain\conemu\ConEmuPack.230724\ConEmu.exe
start %~dp0\toolchain\conemu\ConEmuPack.230724\ConEmu.exe -run cmd /k %~dp0\init.bat

Loading

0 comments on commit 681e42f

Please sign in to comment.