车手屏固件(STM32F407ZET6,经 FSMC 驱动 SSD1963 800×480 IPS 屏,LVGL 9.5)和 PC/macOS 模拟器。固件接收 CANB、方向盘 CAN2 与 UM982 GNSS 数据并显示,同时向 CANB 发送 GPS、里程、圈速、驾驶模式请求和方向盘合并指令。仪表盘界面 stm32_port/Core/Src/dashboard_view.c 由固件和模拟器共用。
| 路径 | 内容 |
|---|---|
stm32_port/ |
车手屏固件,CubeIDE 工程名仍沿用旧名 DATA_COLLECTION_INTEGRAL。外设配置源是 DATA_COLLECTION_INTEGRAL.ioc(本仓库的车手屏 .ioc 只有这一个),应用代码在 Core/Src,Core/lvgl 是固件用的 LVGL 副本 |
src/、CMakeLists.txt、config/、lv_conf.h、run_sim_mac.sh |
PC/macOS 模拟器(SDL2 + FreeRTOS) |
build_fw.sh |
固件命令行构建,调用 stm32_port/ 下的 CMake 工程(CMakeLists.txt、CMakePresets.json、cmake/) |
tools/ |
字体、Logo 和开屏位图生成(gen_dash_splash.sh)、开屏动画浏览器原型(splash_preview/)、固件内存报告、固件回归测试、GPS 测试数据生成(gen_nmea.py,输出 UM982 NMEA 测试语句)、ST-Link 烧写(flash_stlink.sh) |
docs/ |
设计与参考文档,索引见下节 |
legacy/ |
不参与构建的遗留与参考资料,含旧版 F103 板(另一个 .ioc),见 legacy/README.md |
lvgl/、FreeRTOS/、SDL2-2.32.10/ |
第三方源码,见下节 |
simulator.code-workspace |
打开仓库的工作区入口,复用 .vscode/ 中的任务、调试和扩展配置 |
lv_conf.defaults、licence.txt |
上游 lv_port_pc_vscode 遗留:前者未被构建引用,后者是上游 MIT 许可证 |
| 文档 | 内容 |
|---|---|
| 硬件映射 | 时钟、引脚、CAN 位时序、FSMC 读写时序、背光、触摸、指示灯编码、与 .ioc 的有意差异 |
| CAN 网络分工 | 两条总线、各节点收发什么、车手屏做哪三类事(显示、发送、方向盘网关) |
| 方向盘与车手屏 | 方向盘按钮板和车手屏各做什么、每个控件的作用、操作的完整过程、已知限制 |
| 方向盘相关代码 | 方向盘固件和车手屏侧处理的代码级细节与测试覆盖 |
| CAN 接口 | CAN1/CAN2 收发全表、超时与有效性、方向盘帧处理、发送队列、与中央库未对齐项 |
| 配置表 | GPS、圈速、CAN、显示与实时的可调常量:位置、单位、影响 |
| GPS、圈速与冲刺 | NMEA 处理、信号等级、里程、过线检测、75 m 冲刺、模式锁、降级行为 |
| 串口诊断 CLI | USART2 命令行:report、gps capture 等命令、报告字段与判读、延迟测量范围 |
| 仪表盘界面 | 布局、触摸区域、绘制约束、字库与 Logo、验证命令 |
| 固件资源与性能优化 | Flash/SRAM/CCM 预算、任务与栈、运行诊断 |
| 里程存储 | 内部 Flash 扇区 7 的记录格式与掉电行为 |
| 更新记录 | 完成的变更、未验证项与待办 |
docs/reference/ |
Unicore(UM982)高精度产品命令手册 PDF |
| 目录 | 版本 | 使用方 |
|---|---|---|
lvgl/ |
9.5.0,完整源码树 | 模拟器(CMake) |
stm32_port/Core/lvgl/ |
9.5.0,固件所需的裁剪子集;src/ 与 lvgl/src 一致,仅 lv_obj_style_gen.h 一处缩进不同 |
固件(CubeIDE 与 CMake) |
FreeRTOS/ |
V11.1.0 | 仅模拟器(Windows 用 MinGW 端口,其余用 POSIX 端口) |
stm32_port/Middlewares/Third_Party/FreeRTOS/ |
V10.3.1 | 固件,由 CubeMX 管理 |
SDL2-2.32.10/ |
2.32.10 | 仅 Windows(MinGW)模拟器;macOS/Linux 使用系统安装的 SDL2 |
升级 LVGL 时两份一起替换,并对照模拟器的根目录 lv_conf.h 与固件的 stm32_port/Core/lv_conf.h(后者是真机内存和功能预算,二者不要互相覆盖)。
模拟器对 LVGL 有一处本地补丁:lvgl/src/drivers/sdl/lv_sdl_window.c 按 LV_SDL_ALLOW_HIGHDPI(根目录 lv_conf.h)给窗口加 SDL_WINDOW_ALLOW_HIGHDPI,使高 DPI 屏按物理像素渲染而不发糊。替换 LVGL 后需补回。
stm32_port/Debug/、stm32_port/build/、cmake-build-mac/、bin/ 和 Keil 的 MDK-ARM/DATA_COLLECTION_INTEGRAL/ 都被 .gitignore 忽略;2026-10-10 前误入库的产物已改为不跟踪,旧版本仍可从 git 历史取回。固件请用 ./build_fw.sh 或 CubeIDE 重新构建。根目录 .settings/ 是本机 IDE 状态,不入库;.vscode/(任务、调试、CMake 和扩展设置)入库,不写本机路径和串口号等个人信息。
stm32_port/MDK-ARM/ 的 Keil 工程只含 CubeMX 生成的文件(还包括已移除的 FatFs/SD),没有 LVGL 和 gps.c、dashboard_*.c、odometer_flash.c 等应用模块,不能构建当前固件,以 CubeIDE 工程和 build_fw.sh 为准。
- Windows: 64 位 MinGW(
gcc.exe、g++.exe,调试另需gdb.exe)加入 PATH;在 STM32Cube 扩展中安装 CMake、Ninja、GNU Tools for STM32 和 Programmer。SDL2 使用仓库中的 MinGW 开发包,补齐方式见下方 Windows 说明。 - macOS (Homebrew):
brew install sdl2 cmake make - Linux:
- Debian/Ubuntu:
sudo apt install build-essential cmake libsdl2-dev - Arch:
sudo pacman -S base-devel cmake sdl2 - Fedora:
sudo dnf install @development-tools cmake SDL2-devel
- Debian/Ubuntu:
- Manual Installation of SDL: Download from SDL’s website and place headers/libraries in your project.
- Verify Installation:
sdl2-config --version,cmake --version,gcc --version,g++ --version(should return the installed version).
git clone https://github.com/BITFSAE/HMI_Display.gitLVGL 与 FreeRTOS 已作为普通文件纳入本仓库(非 git 子模块),无需 --recursive。
直接打开仓库文件夹或 simulator.code-workspace。Ctrl+Shift+B 默认执行 Build Simulator;在 Tasks: Run Task 中可选择日间/夜间模拟器、固件增量/全量构建以及 ST-Link 烧写;F5 选择 Debug Simulator 或 Debug Simulator (night),使用 PATH 中的 GDB。
Windows 任务调用 tools/windows_task.ps1,无需 Bash。CMake、Ninja 和 ARM 工具链优先从 CUBE_BUNDLE_PATH、%LOCALAPPDATA%/stm32cube/bundles 查找,再回退到 PATH;STM32_PROGRAMMER_CLI 可覆盖烧写工具。模拟器显式使用 PATH 中的 64 位 MinGW,构建缓存放在 cmake-build-win/,程序为 bin/main.exe;构建时为旧版 MinGW 启用 C++ 格式宏、预先包含 stdlib.h(保留对齐分配函数声明),并复制 SDL2.dll 到程序目录。固件仍使用 stm32_port/build/<预设>/,全量任务通过 --clean-first 清理。
仓库的 bin/ 忽略规则导致 SDL2 开发包中的运行库未纳入版本控制。若缺少 SDL2-2.32.10/x86_64-w64-mingw32/bin/SDL2.dll,从 SDL2 2.32.10 官方开发包 解压该文件到对应位置即可,保留仓库中原有的头文件和导入库。
powershell.exe -NoProfile -ExecutionPolicy Bypass -File tools/windows_task.ps1 -Action BuildSimulator
powershell.exe -NoProfile -ExecutionPolicy Bypass -File tools/windows_task.ps1 -Action RunSimulator -Night
powershell.exe -NoProfile -ExecutionPolicy Bypass -File tools/windows_task.ps1 -Action BuildFirmware
powershell.exe -NoProfile -ExecutionPolicy Bypass -File tools/windows_task.ps1 -Action BuildFirmware -Clean
powershell.exe -NoProfile -ExecutionPolicy Bypass -File tools/windows_task.ps1 -Action FlashFirmware固件可加 -Preset Release;优化等级沿用 FW_OPT 环境变量。默认烧写 Debug 产物,连接与擦写行为见固件构建。
依赖:brew install cmake ninja sdl2。在仓库根目录执行:
./run_sim_mac.sh # 构建并运行 800x480 模拟器窗口
./run_sim_mac.sh --night # 以夜间模式启动(额外参数原样传给 bin/main)
./run_sim_mac.sh --build-only # 仅构建- 构建目录固定为
cmake-build-mac/,产物bin/main。不要使用build/:VS Code 的 STM32Cube 扩展会用 ARM 工具链自动配置该目录,与模拟器无关。 - macOS 要求窗口与事件循环在主线程,故 macOS 下
main()直接在主线程运行 LVGL 循环,不启动 FreeRTOS 调度器,且lv_conf.h中LV_USE_OS为LV_OS_NONE;其他平台仍走 FreeRTOS 任务。 - 若
cmake-build-mac/曾被 VS Code 的 CMake Tools/STM32Cube 扩展用 ARM 工具链配置过,缓存里会残留arm-none-eabi-ar,链接报archive member '//' not a mach-o file;run_sim_mac.sh检测到后会自动清目录重配,并显式指定 Apple 的ar/ranlib。 - VS Code(macOS):直接打开仓库文件夹,
.vscode/tasks.json与launch.json已配置Build Simulator(⇧⌘B)、Run Simulator(任务Tasks: Run Test Task)与 F5Debug Simulator,三者均调用run_sim_mac.sh;需装 C/C++ 扩展。.vscode/settings.json让 CMake Tools 指向固件工程stm32_port,不会再用 ARM kit 去配置根目录的模拟器工程;状态栏的 CMake Build/▷ 按钮对应固件,模拟器请用上述任务。首次 lldb 调试若提示开发者工具授权,按提示输入密码或执行sudo DevToolsSecurity -enable。
固件有两套互不影响的构建:CubeIDE 工程(stm32_port/.cproject)和 CMake 工程(stm32_port/CMakeLists.txt,与 CAN2RS485 等同级工程同一套机制)。CMake 工程的源码目录与 LVGL 排除清单直接读 .cproject,在 CubeIDE 里调整排除项或新增 .c/.s 后无需改 CMake 文件。.ioc 的 Toolchain 保持 STM32CubeIDE,CubeMX 重新生成不会覆盖 CMake 文件。
VS Code(STM32Cube 扩展包):
- 安装 STM32Cube for VS Code 扩展包(含 CMake Tools)。
- 直接打开仓库根目录即可。
.vscode/settings.json把cmake.sourceDirectory指向stm32_port并强制使用CMakePresets.json,CMake Tools 因此以固件工程而不是根目录的模拟器工程为准,模拟器使用独立任务,二者互不影响。也可以用File > Open Folder只打开stm32_port/。 - 扩展提示配置所发现的 CMake 工程时确认。它按
stm32_port/.settings/bundles.store.json自动安装 CMake、Ninja、GNU Tools for STM32 和 clangd,并配置Debug预设;之后用状态栏的 Build 按钮或CMake: Build构建,产物在stm32_port/build/Debug/。
命令行(macOS/Linux),不依赖 CubeIDE,在仓库根目录执行:
./build_fw.sh # 增量构建 STM32F407 固件,打印 text/data/bss
./build_fw.sh clean # 全量重编build_fw.sh只是找到工具后执行cmake --preset Debug和cmake --build --preset Debug。编译参数与.cproject的 Debug 配置一致(-Os -g3,Cortex-M4F 硬浮点,链接STM32F407ZETX_FLASH.ld)。PRESET=Release换预设,FW_OPT=-O0临时换优化等级。- 产物位于
stm32_port/build/<预设>/,包括 ELF、BIN、HEX、MAP 和内存报告(已被.gitignore忽略)。构建会打印 Flash、主 SRAM、CCM 占用和最大单函数栈帧;报告脚本需要 Python 3。不复用 CubeIDE 在stm32_port/Debug/生成的 makefile:旧版入库的那份缺Core/lvgl/**的subdir.mk,且写死了 Windows 下的链接脚本绝对路径。 - 固件优化、任务栈、运行诊断和回归验证见 固件资源与性能优化。CubeIDE 的
Debug/不入库,克隆后需在 CubeIDE 里完整构建一次。 - 工具链优先取 STM32 VS Code 扩展 bundles 里的 CMake、Ninja 和 GNU Tools for STM32,否则用 PATH 中的同名工具;扩展之外可用
-DARM_GNU_TOOLCHAIN_BIN=<bin 目录>指定工具链。 - VS Code 任务:
Build Firmware、Rebuild Firmware (clean)(Tasks: Run Task),编译报错可点击跳转。 - ST-Link 烧写:
tools/flash_stlink.sh [文件]用 STM32CubeProgrammer 命令行经 SWD 烧写stm32_port/build/Debug/DATA_COLLECTION_INTEGRAL.hex并回读校验、复位运行;只擦程序用到的扇区,里程记录保留。找工具的顺序见脚本头注释,也可用STM32_PROGRAMMER_CLI指定路径。VS Code 任务Flash Firmware (ST-Link)、Build & Flash Firmware (ST-Link)(先Build Firmware再烧写)已纳入.vscode/tasks.json,Windows 使用原生 PowerShell 入口。 - 模拟器与固件共用
stm32_port/Core/Src/dashboard_view.c界面,只是数据换成动画演示,设计与约束见 仪表盘界面。 - 窗口内按键:空格循环模式,
D/A/X/8/E选 Default/Acceleration/Autocross/Skidpad/Endurance,0–7滑移等级,R圈速计时,N夜间模式,F推入演示告警,YREADY 横幅,[]/G信号强度,Esc退出。鼠标点击区域与触摸屏相同:顶栏开关计时,左上 Logo 重放开屏动画(开屏中点任意处跳过),驾驶模式色块轮转模式,告警条消除一条,眼睛按钮切换夜间。
打开仓库文件夹或 simulator.code-workspace 后安装推荐扩展。模拟器与固件使用同一份 .vscode/ 任务,工作区文件不再覆盖工具路径或任务。构建、运行与调试方式见上方对应平台说明。
VSCode does not officially provide an installation package under Arch, you need to use the AUR manager paru to install it.
The command is as follows:
paru -S visual-studio-code-binApple's default clang does not support the -fsanitize=leak flag.
to build using the latest version of clang from homebrew, do the following:
-
brew install llvm -
cmd+shift+p and run
Cmake: select a kit, then[Scan for kits] -
then cmd+shift+p and run
Cmake: select a kit, select the version of clang you just installed from homebrew (it should sayUsing compilers C=/opt/homebrew/opt/llvm/bin/clang ...) -
reconfigure by running cmd+shift+p
Cmake: Configure -
build using step 4 above
模拟器默认启用 FreeRTOS(CMakeLists.txt 中 USE_FREERTOS 为 ON,入口 src/freertos_main.c;设为 OFF 则回到上游的 src/main.c 演示入口)。lv_conf.h 里 macOS 的 LV_USE_OS 为 LV_OS_NONE,其余平台为 LV_OS_FREERTOS。FreeRTOS 堆在 config/FreeRTOSConfig.h,当前 96 KB。该配置与真机(stm32_port/Core/Inc/FreeRTOSConfig.h,由 CubeMX 管理)相互独立,改一边不影响另一边。
This project uses CMake under the hood which can be used without Visula Studio Code too. Just type these in a Terminal when you are in the project's root folder:
mkdir build
cd build
cmake ..
make -j本节仅适用于 USE_FREERTOS=OFF 时的上游入口 src/main.c(默认的 src/freertos_main.c 显示仪表盘)。By default, the widgets demo (lv_demo_widgets()) will run. If you want to run a different demo or example from the LVGL library,
simply replace the demo function call in the code with another one—such as lv_demo_benchmark() or lv_example_label_1().
int main(int argc, char **argv)
{
/* ... */
/* Run the default demo */
/* To try a different demo or example, replace this with one of: */
/* - lv_demo_benchmark(); */
/* - lv_demo_stress(); */
/* - lv_example_label_1(); */
/* - etc. */
lv_demo_widgets();
while(1) {
/* ... */
}
return 0;
}There are also FreeType and FFmpeg support. You can install these according to the followings:
# FreeType support
wget https://kumisystems.dl.sourceforge.net/project/freetype/freetype2/2.13.2/freetype-2.13.2.tar.xz
tar -xf freetype-2.13.2.tar.xz
cd freetype-2.13.2
make
make install# FFmpeg support
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpeg
git checkout release/6.0
./configure --disable-all --disable-autodetect --disable-podpages --disable-asm --enable-avcodec --enable-avformat --enable-decoders --enable-encoders --enable-demuxers --enable-parsers --enable-protocol='file' --enable-swscale --enable-zlib
make
sudo make installWorks with any OS like pthred, Windows, FreeRTOS, etc. It has build in support for FreeRTOS.
This project is configured for VSCode and is tested on:
- Ubuntu Linux
- Windows WSL (Ubuntu Linux)
It requires a working version of GCC, GDB and make in your path.
To allow debugging inside VSCode you will also require a GDB extension or other suitable debugger. All the requirements, build and debug settings have been pre-configured in the .workspace file.
The project can use SDL but it can be easily relaced by any other built-in LVGL dirvers.
This project supports integration with LVGL Pro projects for UI development.
- Configure CMake with your LVGL Pro project folder:
cmake -B build -DLVGL_PRO_PROJECT_DIR=<path-to-lvgl-pro-project>Build your project:
cmake --build buildIn your main.c, include the UI header from your LVGL Pro project and replace the default demo with your screen.
#include "ui.h"
int main(void) {
/*Initialization code for LVGL*/
/* Initialize the LVGL Pro UI */
ui_init("<path-to-lvgl-pro-project>");
/* ... rest of your application ...*/
}