BetaFlight统一硬件配置文件研读

统一硬件配置文件的设计是一种非常好的设计模式,可以将硬件和软件的工作进行解耦。

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 更多内容展开

鉴于内容比较多,所以后续我们分章节进行(围绕配置命令展开):

关于驱动方面设计,后续我们找时间展开研讨!

4. 参考资料

【1】BetaFlight开源代码框架简介
【2】BetaFlight统一硬件资源简单配置修改
【3】BetaFlight模块设计之三十:Cli模块分析

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值