type
status
slug
date
summary
tags
category
password
icon
前言:
由于PX4的底层使用的是nuttx,也正巧下学期将要学习RTOS的内容,所以打算从nuttx入手学习RTOS
Nuttx Getting started
Install
预备
First, install the following set of system dependencies according to your Operating System:
KConfig frontend
NuttX configuration system uses KConfig which is exposed via a series of interactive menu-based frontends, part of the
kconfig-frontends
package. Depending on your OS you may use a precompiled package or you will have to build it from source, which is available in the NuttX tools repository:我的是ubuntu20.04:
sudo apt install kconfig-frontends
NuttX also supports kconfiglib by default, which is a Kconfig tool implemented in Python 2/3. Compared with
kconfig-frontends
, kconfiglib provides NuttX with the possibility of multi-platform support(configure NuttX in Winodws native/Visual Studio), and also kconfiglib
has a stronger Kconfig syntax check, this will help developers to avoid some Kconfig syntax errors. Install kconfiglib via following command: pip install kconfiglib
Toolchain
这里我已经下载了13.2版本的最新gcc工具链,不过看到它(nuttx官网)有一个docker的方式,以后可以试试。
Download NuttX 🙋
Apache NuttX is actively developed on GitHub. There are two main repositories, nuttx and apps, where the latter is technically optional (but recommended for complete set of features). If you intend to contribute changes, you need the absolute latest version or you simply prefer to work using git, you should clone these repositories (recommended). Otherwise you can choose to download any stable release archive.
我们当然是选择git方式啦,需要最新的代码学习:
接下来的compile部分我打算选择cmake来完成💨
Compiling with CMake
Initialize Configuration with CMake
当然你需要找到nuttx适配的板子
The first step is to initialize NuttX configuration for a given board, based on a pre-existing configuration. To list all supported configurations you can do:
The output is in the format
<board name>:<board configuration>
. You will see that generally all boards support the nsh
configuration which is a good starting point since it enables booting into the interactive command line NuttShell (NSH).这里建议不要人肉搜索,加一个grep命令来搜索吧。下面是grep结合正则表达式的介绍
To choose a configuration you pass the
<board name>:<board configuration>
such as:有个问题捏,是不是忘记stm32的型号规则了?我使用的板子是stm32F401RE,但是找到的stm32F401的只有:
先回顾一下命名规整
由上可知,选择RC即可,我们的RE只是flash更大。
这里我又搜索到了真正的,换成:
nucleo-f4x1re:f401-nsh
这个才对•
-GNinja
: 指定生成 Ninja 构建系统的构建文件。Ninja 是一种快速且并行构建的工具,它可以加速构建过程。👇出现报错
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
使用
apt install ninja-build
完成configuration
You can then customize this configuration by using the menu based configuration system with:
$
cd nuttx
$
cmake --build build -t menuconfig
Modifying the configuration is covered in Configuring.
Build NuttX with CMake
We can now build NuttX. To do so, you can simply run:
The build will complete by generating the binary outputs inside
build/
directory. Typically this includes the nuttx
ELF file (suitable for debugging using gdb
) and a nuttx.bin
file that can be flashed to the board.这里的原文我做了更改,因为感觉有问题,相应的我也向管理员提交了PR,看看是不是真有问题吧,反正我现在只有这样才能运行。
To clean the build, you can do:
尝试板块
后面反复的make编译会报错,我一直怀疑是工具链的问题,于是我打算使用docker的工具链进行。(待续,因为stm32F401 Nucleo板子烧成了,并且能用picocom来连接使用nsh)
Running 👾
这里就要回忆之前的嵌入式环境搭建了。回去看看settings.json和launch.json就可以了。
这个引脚图也比较重要,并且我们要知道引脚分配
补充JTAG的TMS、TCK和SWD的SWDIO、SWCLK的联系
JTAG的TMS脚对应SWD的SWDIO脚,以及JTAG的TCK脚对应SWD的SWCLK脚,其它如TDO脚可以不连接,复位脚RSET与电源监测Vref可以选用
在JTAG接口中,最常用的信号有四个,分别是TCK/TMS/TDO/TDI
TCK:测试时钟
TMS:测试模式选择,TMS用来设置JTAG接口处于某种特定的测试模式
TDO:测试数据输出,数据通过TDO引 脚从JTAG接口输出
TDI:测试数据输入,数据通过TDI引脚输入JTAG接口
SWD接口,算是一种和JTAG不同的调试模式,使用的调试协议也应该不一样,所以最直接的体现在调试接口上,与JTAG的20个引脚相比,SWD只需要4个(或者5个)引脚,结构简单,但是使用范围没有JTAG广泛,主流调试器上也是后来才加的SWD调试模式。
看看我们stm32F401RE的电路图,其中焊桥:SB3,5,7,9接上的,SB4,6,8,10未连接
nuttx学习
从boards开始
boards/
Directory Structure
The
boards/
directory contains board specific configuration logic. Each board must provide a subdirectory <board>
under boards/
with the following characteristics:这里在找我nucleo stm32F401Re的时候遇到了个问题,发现src目录下没有找到Makefile,梳理了一下,发现所在目录有一个common文件夹:
- 作者:liamY
- 链接:https://liamy.clovy.top/article/nuttx/beginer
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。