AIR32F103(二) Linux环境和LibOpenCM3项目模板

目录

Linux 开发环境

在Linux下和STM32F1xx的开发环境是一样的, 可以使用 gcc-arm 编译, 用 st-flash 烧录. 开发库可以使用 SPL, 或者 Libopencm3.

安装 st-flash

首先检查一下系统中是否有st-flash和st-info命令, 没有的话需要安装

安装步骤

git clone https://github.com/stlink-org/stlink.git
cd stlink/
make
# 如果报 libusb 错误, 就安装一下 libusb-1.0-0-dev, 再make
sudo apt install libusb-1.0-0-dev
make clean
make
cd build/Release/
sudo make install

如果运行 st-info 出现下面的错误

st-info: error while loading shared libraries: libstlink.so.1: cannot open shared object file: No such file or directory

运行一下sudo ldconfig可以解决问题

将 AIR32F103 通过 stlink 接上PC后, 可以通过 st-info 查看信息, 似乎并不能正确识别, 但是无所谓, 能检测到就可以了

~$ st-info --probe
Failed to parse flash type or unrecognized flash type
Found 1 stlink programmers
  version:    V2J37S7
  serial:     56FF6B064966485627461667
  flash:      131072 (pagesize: 1024)
  sram:       20480
  chipid:     0x410
  dev-type:   STM32F1xx_MD

Update 2022-07-23: 检测同一型号贴在bluepill核心板上的 MH32F103ACBT6 识别的结果和 AIR32F103 还不一样, 输出是这样的

$ st-info --probe
Failed to parse flash type or unrecognized flash type
Found 1 stlink programmers
  version:    V2J37S7
  serial:     56FF6B064966485627461667
  flash:      262144 (pagesize: 2048)
  sram:       65536
  chipid:     0x414
  dev-type:   F1xx_HD

Libopencm3 项目模板

项目模板: https://github.com/IOsetting/libopencm3-freertos-template

  1. 安装 GCC ARM

在GCC ARM网站下载工具链接https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/downloads, 然后解压到合适的目录

tar xvf gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 
cd /opt/gcc-arm/
sudo mv ~/Backup/linux/gcc-arm-none-eabi-10.3-2021.10/ .
sudo chown -R root:root gcc-arm-none-eabi-10.3-2021.10/

检查版本

/opt/gcc-arm/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gcc --version
  1. 导出项目
git clone --recurse-submodules https://github.com/IOsetting/libopencm3-freertos-template.git your-project

如果导出子模块过程中出错了, 可以在项目目录下运行下面的命令修复

git submodule update --init

因为AIR32F103CBT6配置比C8T6高一规格, 需要修改下Makefile, 将 DEVICE 设成 stm32f103cbt6

DEVICE 			= stm32f103cbt6
  1. 编译 Libopencm3
cd your-project
PREFIX=/opt/gcc-arm/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi- make -C libopencm3
  1. 编译项目
PREFIX=/opt/gcc-arm/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi- make -C user

FreeRTOS例子的编译

如果编译带 FreeRTOS 的例子, 会提示错误fatal error: FreeRTOSConfig.h: No such file or directory,
编译需要带上选项FREERTOS=1

PREFIX=/opt/gcc-arm/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi- FREERTOS=1 make -C user
  1. 烧录
st-flash --reset write user/app.bin 0x8000000 

正常烧录的输出

st-flash 1.7.0-201-g254a525
Failed to parse flash type or unrecognized flash type
2022-07-23T09:05:17 INFO common.c: STM32F1xx_MD: 20 KiB SRAM, 128 KiB flash in at least 1 KiB pages.
file user/app.bin md5 checksum: 1e3bc73ae2b3cc6a26876b261f6ef48, stlink checksum: 0x0002486f
2022-07-23T09:05:17 INFO common_flash.c: Attempting to write 1808 (0x710) bytes to stm32 address: 134217728 (0x8000000)
-> Flash page at 0x8000000 erased (size: 0x400)
-> Flash page at 0x8000400 erased (size: 0x400)

2022-07-23T09:05:17 INFO flashloader.c: Starting Flash write for VL/F0/F3/F1_XL
2022-07-23T09:05:17 INFO flash_loader.c: Successfully loaded flash loader in sram
2022-07-23T09:05:17 INFO flash_loader.c: Clear DFSR
  2/  2 pages written
2022-07-23T09:05:17 INFO common_flash.c: Starting verification of write complete
2022-07-23T09:05:17 INFO common_flash.c: Flash written and verified! jolly good!
2022-07-23T09:05:17 WARN common.c: NRST is not connected
 *  Terminal will be reused by tasks, press any key to close it. 

posted on 2022-10-26 23:57  Milton  阅读(1001)  评论(0编辑  收藏  举报

导航