如何在没有 IDE 的情况下使用 CMSIS? [英] How do you use CMSIS without an IDE?

查看:46
本文介绍了如何在没有 IDE 的情况下使用 CMSIS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 STM32F103C8T6 并想使用 CMSIS,本质上只是寄存器定义,没有代码,让我的生活更轻松,同时仍然保持在低水平.问题是我不知道如何使用 Makefile 安装库以在命令行上使用.所有文档似乎都与供应商特定的 IDE(如 STM32CubeIDE)绑定.

I am working with STM32F103C8T6 and would like to use CMSIS, which is essentially just register definitions and no code, to make my life easier while still staying at a low level. The problem is that I have no idea how to install the library for use on the command line with Makefile. All documentation seems to be bound with a vendor-specific IDE like STM32CubeIDE.

我想首先要做的是下载我在 GitHub 上找到的 CMSIS 库.但是,在解压 ARM.CMSIS.5.6.0.pack 后,我没有找到名为 stm32f10x.h 的文件.我花了更多时间,找到了一个CMSIS包对于我正在使用的特定 MCU,但它不包含 core_cm3.h,但它出现在 ARM.CMSIS.5.6.0.pack 中.文档 说我需要将两者都包含在我的项目,那么我需要把从不同地方下载的文件复制到我的项目中,还是什么?

I suppose the first thing to do is to download the CMSIS library, which I found on GitHub. However, after unzipping ARM.CMSIS.5.6.0.pack I found no files named stm32f10x.h. I spend some more time and found a CMSIS pack for the specific MCU I'm using, but it doesn't contain core_cm3.h, which however presents in ARM.CMSIS.5.6.0.pack. The document says I need to include both to my project, so do I need to copy the files downloaded from different places to my project, or what?

作为附加问题:CMSIS 和 Keli 之间是什么关系?特定于设备的 CMSIS 包是从 www.keil.com 下载的,但我现在不想使用 Keil MDK,因为它似乎是一个商业产品,而 GNU Arm 工具链是很好地为我服务.

As a bonus question: what is the relationship between CMSIS and Keli? The device-specific CMSIS pack is downloaded from www.keil.com, but I don't want to use Keil MDK for now, as it appears to be a commercial product, and the GNU Arm toolchain is serving me pretty well.

我应该从一开始就更具体,但现在让我们专注于如何构建 基本 CMSIS 示例 作为最小、完整和可验证的示例.

I should have been more specific from the beginning, but now let's focus on how to build the Basic CMSIS Example as a minimal, complete and verifiable example.

我做了什么:

  1. 将 CMSIS-Core 和 CMSIS-DFP 下载并解压缩到 /Users/nalzok/Developer/CMSIS/ARM.CMSIS.5.6.0//Users/nalzok/Developer/CMSIS/Packs/Keil.STM32F1xx_DFP.2.3.0/,分别.
  2. 创建一个名为main.c的文件,复制基本示例.
  3. 在第一行添加#define STM32F10X_MD来指定芯片.
  4. 修正拼写错误:将第 31 行的 : 替换为 ;,并将第 33 行替换为 timer1_init (42);.
  5. 构建并出现错误
  1. Download and unzip CMSIS-Core and CMSIS-DFP to /Users/nalzok/Developer/CMSIS/ARM.CMSIS.5.6.0/ and /Users/nalzok/Developer/CMSIS/Packs/Keil.STM32F1xx_DFP.2.3.0/, respectively.
  2. Create a file named main.c, and copy the content of the basic example to it.
  3. Add #define STM32F10X_MD on the very first line to specify the chip.
  4. Fix typos: replace the : on line 31 to ;, and replace line 33 to timer1_init (42);.
  5. Build and get an error


/tmp $ arm-none-eabi-gcc -I/Users/nalzok/Developer/CMSIS/ARM.CMSIS.5.6.0/CMSIS/Include/ -I/Users/nalzok/Developer/CMSIS/Packs/Keil.STM32F1xx_DFP.2.3.0/Device/Include/ main.c
main.c: In function 'main':
main.c:42:5: warning: implicit declaration of function 'Get_InputValues' [-Wimplicit-function-declaration]
   42 |     Get_InputValues ();                          // Read Values
      |     ^~~~~~~~~~~~~~~
main.c:44:5: warning: implicit declaration of function 'Calculation_Response' [-Wimplicit-function-declaration]
   44 |     Calculation_Response ();                     // Calculate Results
      |     ^~~~~~~~~~~~~~~~~~~~
main.c:45:5: warning: implicit declaration of function 'Output_Response' [-Wimplicit-function-declaration]
   45 |     Output_Response ();                          // Output Results
      |     ^~~~~~~~~~~~~~~
/var/folders/m4/7my6q_kj6pxgzb1b7pxyhp0h0000gn/T//cc1ZVBaH.s: Assembler messages:
/var/folders/m4/7my6q_kj6pxgzb1b7pxyhp0h0000gn/T//cc1ZVBaH.s:197: Error: selected processor does not support `wfe' in ARM mode
/var/folders/m4/7my6q_kj6pxgzb1b7pxyhp0h0000gn/T//cc1ZVBaH.s:310: Error: selected processor does not support `cpsid i' in ARM mode
/var/folders/m4/7my6q_kj6pxgzb1b7pxyhp0h0000gn/T//cc1ZVBaH.s:318: Error: selected processor does not support `cpsie i' in ARM mode

根据下面@KamilCuk 的评论,我添加了更多选项并注释掉了函数 Get_InputValuesCalculation_ResponseOutput_Response,但现在我我有一些不同的错误.

As per @KamilCuk's comment below, I added more options and commented out the functions Get_InputValues, Calculation_Response, and Output_Response, but now I am having some different errors.

/tmp $ arm-none-eabi-gcc -I/Users/nalzok/Developer/CMSIS/ARM.CMSIS.5.6.0/CMSIS/Include/ -I/Users/nalzok/Developer/CMSIS/Packs/Keil.STM32F1xx_DFP.2.3.0/Device/Include/ -D STM32F1 -D STM32F103x6 -mthumb -mcpu=cortex-m3 main.c
/Users/nalzok/opt/xPacks/arm-none-eabi-gcc/9.2.1-1.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: /Users/nalzok/opt/xPacks/arm-none-eabi-gcc/9.2.1-1.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/lib/thumb/v7-m/nofp/libc.a(lib_a-exit.o): in function `exit':
exit.c:(.text.exit+0x16): undefined reference to `_exit'
/Users/nalzok/opt/xPacks/arm-none-eabi-gcc/9.2.1-1.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: /var/folders/m4/7my6q_kj6pxgzb1b7pxyhp0h0000gn/T//ccqfC5LA.o: in function `Device_Initialization':
main.c:(.text+0x164): undefined reference to `SystemCoreClock'
collect2: error: ld returned 1 exit status

推荐答案

对于最新的设备头文件,我建议从 ST 网站下载 STM32CubeF1 包.除其他外(中间件、HAL 等),此包在 /Drivers/CMSIS/Device 文件夹中包含所需的设备标头.您需要为 stm32f1xx.h 标头定义的 STM32F103xB 符号才能正常工作.

For the latest device headers, I suggest downloading STM32CubeF1 package from the ST website. Among other things (Middlewares, HAL etc.), this package contains the required device headers in /Drivers/CMSIS/Device folder. You need STM32F103xB symbol defined for stm32f1xx.h header to work correctly.

当然,STM32CubeF1 包也包含 CMSIS 库,但它们通常有点过时.我更喜欢从您提到的 github 存储库中将它们下载为 .pack 文件.您至少需要 /CMSIS/Core 中的标头.如果您愿意,您可以添加 CMSIS 的其他部分.其中一些(如 DSP)可能还需要您添加 /Lib 文件夹中提供的静态库.

Of course, STM32CubeF1 package also contains CMSIS libraries but they are generally a little bit outdated. I prefer to download them as .pack files from the github repo you mentioned. You need the headers in /CMSIS/Core at least. You may add additional parts of the CMSIS if you wish. Some of them (like DSP) may also need you to add static libraries provided in /Lib folders.

请注意,如果您从 github 克隆 CMSIS 存储库而不是下载 .pack 文件,您最终会得到静态库的占位符版本,因为该项目使用 git LFS.您不能直接使用这些静态库文件(.a 文件),因为它们只是某种指针.我不熟悉 git LFS,但我想您需要一些 git 命令(可能是 checkout)来告诉您的 PC 下载实际的 .a 文件.

Please be aware that if you clone the CMSIS repo from github instead of downloading the .pack file, you end up with placeholder versions of the static libraries, as the project uses git LFS. You can't use these static library files (.a files) directly as they are just some kind of pointers. I'm not familiar with git LFS, but I guess you need some git commands (maybe checkout) to tell your PC to download the actual .a files.

另请注意,有时 CMSIS 文件夹结构会因版本而异.您在 STM32CubeF1 中获得的文件夹结构可能与您从官方 CMSIS 存储库下载的不同.

Also note that sometimes CMSIS folder structure changes from version to version. The folder structure you get in STM32CubeF1 may be different from the one you download from the official CMSIS repo.

我忘了说:除了CMSIS和ST设备头文件,你还需要以下文件:

I forgot to mention: Other than CMSIS and ST device headers, you also need the following files:

  • system_stm32f1xx.c(STM32CubeF1/Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates 文件夹)
  • startup_stm32f103xb.s(STM32CubeF1/Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/gcc 文件夹)
  • 来自 STM32CubeF1/Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/gcc/linker 文件夹中的链接器脚本.奇怪的是,STM32F103x8 没有,所以你可能需要选择 STM32F103xB 并修改它.我使用 IDE 生成的.
  • system_stm32f1xx.c (STM32CubeF1 package /Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates folder)
  • startup_stm32f103xb.s (STM32CubeF1 package /Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/gcc folder)
  • A linker script from STM32CubeF1 package /Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/gcc/linker folder. Strangely, there is none for STM32F103x8, so you probably need to pick STM32F103xB and modify it. I use an IDE generated one.

更新:

此处您可以找到在 STM32CubeIDE 中创建的最小项目.我创建了一个空的 C 项目.IDE 提供了一个链接器脚本和一个启动文件 (.s),但我删除了它们并使用了 STM32CubeF1 包中包含的那些.我还从/Drivers/Device/ST/STM32F1xx/Include 目录中删除了不相关的头文件.但是我没有触及/Drivers/CMSIS/Core/Include 中的那些,尽管那里有很多不相关的文件,因为很难确定哪些需要哪些不需要.

Here you can find a minimal project created in STM32CubeIDE. I created an empty C project. The IDE provides a linker script and a startup file (.s) but I deleted them and used the ones included in the STM32CubeF1 package. I also deleted unrelated header files from the /Drivers/Device/ST/STM32F1xx/Include directory. But I didn't touched the ones in the /Drivers/CMSIS/Core/Include although there are lots of unrelated files there, as it's harder to determine which ones are needed and which ones are not.

我知道您在寻找没有 IDE 的解决方案,但我认为这个示例项目至少可以为您提供一些有关所需文件和项目结构的线索.

I know that you look for a solution without an IDE, but I think this example project can at least give you some clues about the required files and the project structure.

注意:示例项目名称是 blinky.cube 但项目中没有 Cube.我使用这个命名约定只是为了指定我使用的 IDE,在本例中是 STM32CubeIDE.

Note: The example project name is blinky.cube but there is no Cube in the project. I use this naming convention just to specify the IDE I use, which is STM32CubeIDE in this case.

这篇关于如何在没有 IDE 的情况下使用 CMSIS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆