BetaFlight统一硬件配置文件研读
BetaFlight统一硬件配置文件研读
- 1. 源由
- 2. 分析
- 2.1 硬件SOC
- 2.2 统一配置文件
- 2.3 cli命令
- 2.4 板级配置主要命令
- 2.4.1 board_name
- 2.4.2 manufacturer_id
- 2.4.3 resource
- 2.4.4 timer
- 2.4.5 dma
- 2.4.6 serial
- 2.4.7 set
- 2.4.8 feature
- 3. 实例研读
- 3.1 C遗留配置
- 3.2 BoardName - AOCODARCH7DUAL
- 3.3 ManufacturerId - SJET
- 3.4 更多内容展开
- 4. 参考资料
统一硬件配置文件的设计是一种非常好的设计模式,可以将硬件和软件的工作进行解耦。
1. 源由
统一硬件配置文件的软硬件解耦方式通过一系列的cli命令组成,最终通过parameter参数调整,达到硬件配置功能。
如果不过多深究内部设计,可以简单参考:BetaFlight统一硬件资源简单配置修改
希望了解更多内部实现,那不是一两句话可以简单说清楚的,我们接下来,对这部分内容进行展开,希望通过分析得到更多设计上的细节。
2. 分析
统一硬件配置文件是由一系列的cli命令组成,这些命令对不同SOC框架的MCU硬件资源进行配置。
2.1 硬件SOC
Betaflight 4.4.1 Note, 比如:4.4.1固件 STM32F405/F411/F745/F7X2/G47X/H723/H730/H743/H750
2.2 统一配置文件
betaflight/unified-targets, 提供了各种厂家各类板子。如果硬件设计是参考过来的,这里就有原始配置文件。基于这个进行修改将事半功倍。
厂家名录详见:manufacturer_id
2.3 cli命令
在BetaFlight模块设计之三十:Cli模块分析中,已经初步介绍了BetaFlight Configurator如何将cli命令解析和识别,并最终与命令挂钩的。
# help
adjrange - configure adjustment ranges
<index> <unused> <range channel> <start> <end> <function> <select channel> [<center> <scale>]
aux - configure modes
<index> <mode> <aux> <start> <end> <logic>
batch - start or end a batch of commands
start | end
beacon - enable/disable Dshot beacon for a condition
list
<->[name]
beeper - enable/disable beeper for a condition
list
<->[name]
bind_rx - initiate binding for RX SPI or SRXL2
bl - reboot into bootloader
[rom]
board_name - get / set the name of the board model
[board name]
color - configure colors
defaults - reset to defaults and reboot
{show} {nosave} {bare} {group_id <id>}
diff - list configuration changes from default
[master|profile|rates|hardware|all] {defaults|bare}
dma - show/set DMA assignments
<> | <device> <index> list | <device> <index> [<option>|none] | list | show
dshot_telemetry_info - display dshot telemetry info and stats
dshotprog - program DShot ESC(s)
<index> <command>+
dump - dump configuration
[master|profile|rates|hardware|all] {defaults|bare}
escprog - passthrough esc to serial
<mode [sk/bl/ki/cc]> <index>
exit
feature - configure features
list
<->[name]
flash_erase - erase flash chip
flash_info - show flash chip info
flash_read
<length> <address>
flash_scan - scan flash device for errors
flash_write
<address> <message>
get - get variable value
[name]
gpspassthrough - passthrough gps to serial
gyroregisters - dump gyro config registers contents
help - display command help
[search string]
led - configure leds
manufacturer_id - get / set the id of the board manufacturer
[manufacturer id]
map - configure rc channel order
[<map>]
mcu_id - id of the microcontroller
mixer - configure mixer
list
<name>
mmix - custom motor mixer
mode_color - configure mode and special colors
motor - get/set motor
<index> [<value>]
msc - switch into msc mode
[<timezone offset minutes>]
play_sound
[<index>]
profile - change profile
[<index>]
rateprofile - change rate profile
[<index>]
rc_smoothing_info - show rc_smoothing operational settings
resource - show/set resources
<> | <resource name> <index> [<pin>|none] | show [all]
rxfail - show/set rx failsafe settings
rxrange - configure rx channel ranges
save - save and reboot
sd_info - sdcard info
serial - configure serial ports
serialpassthrough - passthrough serial data data from port 1 to VCP / port 2
<id1> [<baud1>] [<mode1>] [none|<dtr pinio>|reset] [<id2>] [<baud2>] [<mode2>]
servo - configure servos
set - change setting
[<name>=<value>]
signature - get / set the board type signature
[signature]
simplified_tuning - applies or disables simplified tuning
apply | disable
smix - servo mixer
<rule> <servo> <source> <rate> <speed> <min> <max> <box>
reset
load <mixer>
reverse <servo> <source> r|n
status - show status
tasks - show task stats
timer - show/set timers
<> | <pin> list | <pin> [af<alternate function>|none|<option(deprecated)>] | list | show
version - show version
vtx - vtx channels on switch
<index> <aux_channel> <vtx_band> <vtx_channel> <vtx_power> <start_range> <end_range>
vtx_info - vtx power config dump
vtxtable - vtx frequency table
<band> <bandname> <bandletter> [FACTORY|CUSTOM] <freq> ... <freq>
2.4 板级配置主要命令
通常来说,与板子配置相关的主要命令如下:
2.4.1 board_name
board_name - get / set the name of the board model
[board name]
2.4.2 manufacturer_id
manufacturer_id - get / set the id of the board manufacturer
[manufacturer id]
2.4.3 resource
resource - show/set resources
<> | <resource name> <index> [<pin>|none] | show [all]
2.4.4 timer
timer - show/set timers
<> | <pin> list | <pin> [af<alternate function>|none|
2.4.5 dma
dma - show/set DMA assignments
<> | <device> <index> list | <device> <index> [<option>|none] | list | show
2.4.6 serial
serial - configure serial ports
2.4.7 set
set - change setting
[<name>=<value>]
2.4.8 feature
feature - configure features
list
<->[name]
3. 实例研读
手边正好有一块AOCODARC H7DUAL的板子,后续将就这块板子进行一个配置研读。
3.1 C遗留配置
以下配置内容,主要是说明该板子使用了一下硬件芯片:
- 陀螺仪:BMI270
- 气压计:DPS310
- SPI Flash:W25N01G
- 模拟OSD芯片:MAX7456
#define USE_ACCGYRO_BMI270
#define USE_BARO_DPS310
#define USE_FLASH_W25N01G
#define USE_MAX7456
3.2 BoardName - AOCODARCH7DUAL
board_name AOCODARCH7DUAL
static void cliBoardName(const char *cmdName, char *cmdline)
{
const unsigned int len = strlen(cmdline);
const char *boardName = getBoardName();
if (len > 0 && strlen(boardName) != 0 && boardInformationIsSet() && (len != strlen(boardName) || strncmp(boardName, cmdline, len))) { //合法性检查
cliPrintErrorLinef(cmdName, ERROR_MESSAGE, "BOARD_NAME", boardName);
} else {
if (len > 0 && !configIsInCopy && setBoardName(cmdline)) { //设置板子名称
boardInformationUpdated = true;
cliPrintHashLine("Set board_name.");
}
printBoardName(DUMP_ALL);
}
}
3.3 ManufacturerId - SJET
manufacturer_id SJET
static void cliManufacturerId(const char *cmdName, char *cmdline)
{
const unsigned int len = strlen(cmdline);
const char *manufacturerId = getManufacturerId();
if (len > 0 && boardInformationIsSet() && strlen(manufacturerId) != 0 && (len != strlen(manufacturerId) || strncmp(manufacturerId, cmdline, len))) { //合法性验证
cliPrintErrorLinef(cmdName, ERROR_MESSAGE, "MANUFACTURER_ID", manufacturerId);
} else {
if (len > 0 && !configIsInCopy && setManufacturerId(cmdline)) { //设置生产商名称
boardInformationUpdated = true;
cliPrintHashLine("Set manufacturer_id.");
}
printManufacturerId(DUMP_ALL);
}
}
3.4 更多内容展开
鉴于内容比较多,所以后续我们分章节进行(围绕配置命令展开):
- 【1】BetaFlight统一硬件配置文件研读之resource命令
- 【2】BetaFlight统一硬件配置文件研读之timer命令
- 不断更新中,谢谢关注。。。 。。。
4. 参考资料
【1】BetaFlight开源代码框架简介
【2】BetaFlight统一硬件资源简单配置修改
【3】BetaFlight模块设计之三十:Cli模块分析