极海 APM32F072RB 开发指南 CubeMX Keil MDK 与 ST-LINK 全流程Geehy APM32F072RB Development Guide CubeMX Keil MDK and ST-LINK Full Flow


AI free token/AI免费积分

极海 APM32F072RB 开发指南 CubeMX Keil MDK 与 ST-LINK 全流程

极海APM32F072RB这颗料本质上就是冲着和STM32F072 pin-to-pin兼容来的。所以直接用STM32CubeMX来配工程、再用Keil MDK编译下载是完全可以走通的。我在实际项目里就是这么干的中间踩了不少坑尤其是ST-LINK这块几乎每个新手都会碰到。这篇就把整套流程从零开始捋一遍包括工具怎么配、工程怎么建、时钟树怎么调、烧录报错怎么解照着操作就能跑起来。1. 整体思路与方案选型1.1 为什么可以用STM32CubeMX开发极海芯片先说结论APM32F072RB是极海半导体推出的基于ARM Cortex-M0内核的通用MCU硬件上直接对标STM32F072RB引脚定义、外设映射、内存布局基本都是同一套。既然内核和寄存器层面跟意法半导体的芯片保持兼容那CubeMX在生成初始化代码、时钟配置、外设驱动的时候完全可以按STM32F072RB来生成然后烧录到APM32F072R

B上跑。有人会问CubeMX里根本没有极海芯片的选项会不会生成出来的代码用不了实际测试下来用STM32F072RB生成的工程只要不涉及极海额外增加的增值外设其余GPIO、UART、SPI、I2C、ADC、TIM这些常规功能都能在APM32F072RB上正常工作。毕竟Cortex-M0内核是ARM标准化的芯片厂商只是在上面挂了自己的外设IP而极海这颗料的外设IP设计时就是奔着兼容性去的。1.2 工具链选型CubeMX MDK ST-LINK的搭配逻辑这套组合里CubeMX负责图形化配置外设和时钟树Keil MDK负责编译、烧录和调试ST-LINK则是下载调试器。三个工具各管一段互相不冲突。CubeMX帮我省去了手写时钟树初始化、引脚复用表、中断向量配置这些繁琐重复的活MDK则提供了完整的编译环境和ULINK/CMSIS-DAP/ST-LINK的调试支持。ST-LINK在这个方案里扮演的角

色很关键。它既负责把编译好的hex文件烧进APM32F072RB的Flash也承担在线仿真调试功能包括断点、单步、变量监控等。而且ST-LINK功耗低、体积小、速度快性价比在淘宝上几十块钱就能买到适合学生、创客和刚接触嵌入式开发的工程师。把这三者串起来后开发流程就变成CubeMX配置生成MDK工程MDK编译生成固件ST-LINK下载烧录并调试。整条链路清晰任何一个环节出问题都能快速定位到具体工具。1.3 方案对比为什么不直接用官方SDK极海官方其实也提供了自己的SDK和例程甚至有自己的开发工具链配置方式。那为什么我首选还是STM32CubeMX原因有三点。一是生态成熟度CubeMX生成的代码结构规范、HAL库封装完善网上教程和案例多遇到问题一搜就有答案二是代码可迁移性强以后万一要换成STM32F072工程直接就能复用三是CubeMX在时钟树配置、引脚冲突检查上做得非常细致手写代码很容易犯的

低级错误比如引脚复用冲突、时钟源选择错误在CubeMX里基本不会发生。当然极海官方SDK也不是没用。当需要确认极海芯片特有外设的寄存器定义时翻一下官方SDK里的头文件和例程很有帮助。两个工具配合使用比单依赖某一个要稳妥得多。2. 环境搭建与工具安装2.1 软件获取途径与版本选择在动手之前先把三个核心软件准备好。每个软件的获取渠道和版本选择都有讲究直接决定后面会不会踩坑。STM32CubeMX是ST官方推出的图形化配置工具。下载地址是ST官网的CubeMX页面搜索STM32CubeMX就能找到。需要注意现在新版CubeMX是需要注册myST账号才能下载的注册流程比较简单邮箱验证通过后就能进下载页。版本选择上不用追最新版选择6.x系列的稳定版即可我目前用的6.9.0使用体验稳定。Keil MDK是ARM的集成开发环境在Keil官网下载MDK-ARM版本。这里有个重点MDK分社区版Communi

ty和标准版社区版免费但有代码大小限制32KB标准版需要购买License。编译APM32F072RB这个级别的工程代码量正常都在32KB以内社区版完全够用。版本方面我建议选5.36以上新版本对Cortex-M0内核的编译优化更好而且自带CMSIS版本也比较新。ST-LINK工具这边有两样东西一个是ST-LINK的USB驱动安装完MDK后一般会自动装上但如果设备管理器里能看到感叹号就要单独装另一个是STM32 ST-LINK Utility烧录工具这个工具用来单独烧录hex文件、查看Flash内容、配置选项字节都很方便推荐一起装上。注意这三个软件的安装路径最好不要包含中文、空格Keil默认安装路径C:\Keil_v5不适合修改到带中文的目录否则后面编译会报中文路径相关的错误。2.2 安装STM32CubeMX固件包的正确姿势CubeMX装好后第一次打开新建工程时会提示下载固件包。APM32

F072RB对应的是STM32F0系列固件包在CubeMX的Help-Manage embedded software packages里能看到。固件包的下载速度受网络影响较大如果卡在下载界面半天不动多半是网络问题。这里分享一个离线安装的方法。先从ST官网下载STM32CubeF0固件压缩包解压后把里面一个叫.stsdk的文件夹拷贝到本地仓库目录。这个仓库目录在CubeMX安装路径下的Repository文件夹比如C:\Users\你的用户名\STM32Cube\Repository。把.stsdk文件夹放进去后重新打开Manage embedded software packages就能看到固件包已经自动被识别、无需再联网下载。这个方法在离线环境、或者固件包反复下载失败时救命。固件包版本我推荐选择1.11.x或1.12.x太老的版本里HAL库实现可能跟APM32F072的寄存器存在细微差

异新版本则基本没有兼容性问题。2.3 让Keil MDK识别极海芯片安装Device PackMDK本身默认只带STM32的设备支持包Device Pack但极海的APM32F072RB因为兼容STM32F072RB所以MDK里选择STM32F072RB这颗芯片时编译出的启动文件、链接脚本都能正确工作不需要额外安装极海的设备支持包。这是我多次验证过的。2.4 ST-LINK驱动的校验与固件升级安装完所有软件后先把ST-LINK接到电脑上。打开设备管理器展开通用串行总线设备或通用串行总线控制器如果能看到STM32 STLink、STLink dongle之类的设备说明驱动正常。如果显示的是带黄色感叹号的未知设备需要手动安装ST-LINK驱动。ST-LINK的驱动安装包通常在MDK安装目录下的ARM\STLink文件夹里有也可以去ST官网搜索ST-LINK driver下载。安装驱动后如果还不

行试试换USB线。别小看USB线这个问题我之前就碰过品控很差的USB线里面只有电源线没有数据线导致ST-LINK在电脑上完全无法识别。用数据线连接成功后建议顺手用STM32 ST-LINK Utility或Keil的固件升级功能检查一下ST-LINK固件版本。ST-LINK的固件版本太旧会导致下载速度慢、不稳定升级到最新固件能解决大量莫名其妙的连接问题。3. 从CubeMX到Keil的详细配置流程3.1 新建工程CPU型号选择的两个方案打开STM32CubeMX点击New Project在Part Number搜索框输入STM32F072RB列表里会出现这颗芯片。选中后双击进入配置界面。但我的一般操作是如果确定用极海的APM32F072RB就在搜索框输入STM32F072RBT6选中的也是这颗。因为两者的Flash大小、RAM大小一致CubeMX生成的链接脚本分散加载文件能完美匹配。极海A

PM32F072RB的内存参数Flash 128KBRAM 16KB。确认CubeMX里选择的STM32F072RB也是Flash 128KB、RAM 16KB两者完全对应烧录和链接都没有问题。如果你手头板子上的PCB丝印、引脚定义跟STM32F072RB开发板完全一致这个替换过程就是零成本的。3.2 时钟树配置48MHz主频的达成路径APM32F072RB的时钟树设计跟STM32F072一样支持外部晶振HSE、内部高速RCHSI 8MHz、内部低速RCLSI 40kHz和外部低速晶振LSE。系统主频最高48MHz这也是APM32F072RB跟APM32F103系列最大的区别F0系列没有PLL倍频到72MHz的能力最大就是48MHz。进入Clock Configuration页面默认情况下使用的是HSI系统时钟是8MHz。如果板子上有8MHz外部晶振大多数开发板都有可以这样配置第一步在HS

E旁的下拉框中勾选Crystal/Ceramic Resonator表示使用外部晶振第二步把System Clock Mux的时钟源切到PLLCLK第三步设置PLL Source为HSEPLL Mul为68MHz外部晶振经过6倍频得到48MHz第四步在APB1 Prescaler里选择/1保持48MHz最后点击左侧的电源电压调节确认VDD范围是2.0~3.6V。完成后能看到右上角的SysClock显示48MHz绿色表示配置合法红色则提示配置冲突或超出范围。如果没有外部晶振就保持HSI配置PLL Source为HSI此时HSI是8MHz经过PLL Mul同样设置为6也能得到48MHz系统主频。PLL输入频率范围在2~16MHz之间所以8MHz的HSI或HSE都在合法范围内。3.3 外设配置LED、UART和按键的调试标配时钟配置完后就开始配外设。引出调试接口的操作在System Core下的

SYS页面。这里有个容易被忽略的点APM32F072RB默认的调试接口是SWDSerial Wire Debug只有两个引脚PA13和PA14。如果不小心把这两个引脚配置成普通GPIO或者复用功能ST-LINK连接就会崩溃表现为下载时报“No target connected”。调试接口务必选择Serial Wire。接下来做三个最常用的外设配置方便验证整条开发链路。Pinout Configuration页面里搜索PD2或者任意一个你板子上LED连接的引脚点击下拉框选择GPIO_Output这就是LED控制引脚。在GPIO设置里把GPIO output level设为HighLED初始状态就熄灭通常LED低电平点亮Maximum output speed设为LowPull-up/Pull-down保持No pull-up。然后配置串口。在Connectivity下找到USART1Mod

e选择Asynchronous异步通信默认引脚PA9TX、PA10RX不用改。Parameter Settings里把Baud Rate设为115200Word Length选8 BitsParity选NoneStop Bits选1。这些配置跟PC端串口终端保持一致即可。按键配置搜索PC13或任意一个接按键的引脚点击下拉框选择GPIO_Input。GPIO配置中如果按键一端接地、另一端接引脚就需要配置内部上拉Pull-up这样按键未按下时读到的电平为高按下后为低。3.4 工程生成设置不勾错这几个选项MISRA-C规范选项不用勾太严格了。考虑到代码阅读方便我习惯两个地方都勾上这样生成的代码里每个外设的实现不仅出现在主文件中还单独拆成外设名.c/.h文件模块化更清晰。最后Project Name填apm32_led_uartProject Location选一个纯英文路径比如D:\Work\a

pm32_demo。Toolchain/IDE选择MDK-ARM V5因为Keil MDK 5.x版本对应的是V5格式。在Code Generator页面里勾选Copy only the necessary library files这样生成的工程只包含用到的HAL库文件工程体积小、编译速度快。点击右上角GENERATE CODECubeMX开始生成工程。生成结束后点击Open ProjectKeil MDK会自动打开这个生成的工程。3.5 Keil MDK工程配置魔术棒里的关键选项Keil打开工程后第一件事是确认目标芯片。在Options for Target魔术棒图标的Device选项卡里应该已经自动选择了STM32F072RB如果没有就手动选择。这个选择直接决定了编译器使用哪个启动文件和哪个分散加载文件。然后是Output和Listing页签勾选Create HEX File。这一个

选项如果不勾生成结果只有axf文件ST-LINK Utility和串口烧录工具都无法直接烧录。平时在MDK里点击LOAD按钮不依赖HEX但很多第三方烧录工具必须要有hex文件。Debug页签里选择调试器。左侧下拉框选择ST-Link Debugger然后点击右侧Settings按钮。在Settings弹窗里确认两件事一是右侧Debug Adapter区域能识别出ST-LINK型号和序列号二是在Flash Download区域勾选了Reset and Run这样烧录结束后芯片会自动复位运行程序无需手动按复位键。C/C页签里的Define宏USE_HAL_DRIVER, STM32F072xB。其中STM32F072xB表示使用的是STM32F072系列128KB Flash型号这个宏在CubeMX生成时已自动填好。如果Define为空或写错编译会报出大量HAL库条件编译错误排查起来很头疼。3

.6 编译、烧录和验证第一把点亮LED准备工作做完先按F7编译。第一次编译会花点时间CubeMX生成的HAL库文件比较多大概几十秒到一两分钟。如果编译成功Build Output窗口会显示0 Error(s)0 Warning(s)。然后点击LOAD按钮或者F8Keil会调用ST-LINK把固件烧录到APM32F072RB。烧录成功后状态栏会出现Application running...的提示LED如果配置正确的话应该开始闪烁如果代码里写了循环翻转或按预设状态亮灭。如果一切正常说明从CubeMX配置到Keil编译下载的整条链路已经打通了。硬件看门狗没开、代码逻辑没问题的话芯片就会按你写的程序运行。4. ST-LINK避坑指南高频报错与处置办法4.1 连接失败No ST-LINK detected这个报错出现的原因很简单ST-LINK调试器根本没有被电脑识别。排查顺序是第一步确认USB线是

本文来源:http://www.lpqz.cn/news/106082
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。

Geehy APM32F072RB Development Guide CubeMX Keil MDK and ST-LINK Full Flow

The Geehy APM32F072RB is essentially designed from the outset to be pin-to-pin compatible with the STM32F072. Therefore, it is entirely feasible to configure the project directly with STM32CubeMX and then compile and download with Keil MDK. I did exactly this in a real project and ran into quite a few pitfalls along the way—especially with the ST-LINK, which almost every beginner encounters. This article walks through the whole process from scratch: how to configure the tools, how to create the project, how to tune the clock tree, and how to resolve programming errors—follow along and you'll get it running. 1. Overall Approach and Solution Selection 1.1 Why the STM32CubeMX Can Be Used to Develop Geehy Chips Let me start with the conclusion: the APM32F072RB is a general-purpose MCU based on the ARM Cortex-M0 core, launched by Geehy Semiconductor. In hardware it directly targets the STM32F072RB—the pin definitions, peripheral mapping, and memory layout are essentially the same. Since it stays compatible with STMicroelectronics' parts at the core and register level, CubeMX can generate initialization code, clock configuration, and peripheral drivers entirely based on the STM32F072RB, and then the result can be programmed onto the APM32F072RB to run.

Some may ask: CubeMX doesn't offer any Geehy chip option at all—won't the generated code be unusable? In actual testing, a project generated with the STM32F072RB works perfectly on the APM32F072RB for all the conventional functions—GPIO, UART, SPI, I2C, ADC, TIM, and so on—as long as you don't touch the extra value-added peripherals that Geehy added. After all, the Cortex-M0 core is an ARM standard, and chip vendors simply hang their own peripheral IPs on top of it; this Geehy part's peripheral IPs were designed with compatibility in mind from the very beginning. 1.2 Toolchain Selection: The Logic of Pairing CubeMX, MDK, and ST-LINK In this combination, CubeMX handles the graphical configuration of peripherals and the clock tree, Keil MDK handles compiling, programming, and debugging, and the ST-LINK acts as the download/debug probe. The three tools each cover their own stage and don't conflict with one another. CubeMX spares me the tedious, repetitive work of hand-writing clock tree initialization, pin multiplexing tables, and interrupt vector configuration, while MDK provides a complete compilation environment plus debugging support for ULINK/CMSIS-DAP/ST-LINK. The role the ST-LINK plays in this scheme is

crucial. It is responsible both for burning the compiled hex file into the Flash of the APM32F072RB and for providing in-circuit emulation and debugging, including breakpoints, single-stepping, variable watch, and the like. Moreover, the ST-LINK consumes little power, is compact, and is fast, offering excellent value—you can pick one up on Taobao for a few dozen yuan—which makes it suitable for students, makers, and engineers just getting started with embedded development. Once the three are chained together, the development flow becomes: CubeMX configures and generates the MDK project, MDK compiles the firmware, and the ST-LINK downloads, programs, and debugs it. The entire chain is transparent, so if any link fails you can quickly pinpoint the specific tool at fault. 1.3 Solution Comparison: Why Not Use the Official SDK Directly Geehy does provide its own SDK and example code, and even has its own toolchain configuration approach. So why do I still put STM32CubeMX first? There are three reasons. First, ecosystem maturity: the code structure generated by CubeMX is clean and standardized, the HAL library is well encapsulated, and there are plenty of tutorials and case studies online, so a quick search usually yields an answer when you hit a problem. Second, strong code portability: if you ever need to switch to an STM32F072 later, the project can be reused directly. Third, CubeMX is extremely thorough in clock tree configuration and pin-conflict checking; the low-level mistakes that are so easy to make when writing code by hand—

such as pin multiplexing conflicts and incorrect clock-source selection—basically never occur in CubeMX. Of course, Geehy's official SDK isn't useless. When you need to confirm the register definitions of Geehy-specific peripherals, browsing the header files and examples in the official SDK is very helpful. Using the two tools together is far more robust than depending on just one. 2. Environment Setup and Tool Installation 2.1 Software Sources and Version Choices Before getting hands-on, prepare the three core pieces of software first. Where you obtain each tool and which version you pick both matter, and they directly determine whether you'll hit pitfalls later on. STM32CubeMX is ST's official graphical configuration tool. You can get it from the CubeMX page on ST's website—just search for STM32CubeMX. Note that the current version of CubeMX requires a registered myST account to download; registration is simple, and once your email is verified you can access the download page. There's no need to chase the very latest release—a stable build in the 6.x series is fine; I currently use 6.9.0 and it has been stable. Keil MDK is ARM's integrated development environment; download the MDK-ARM version from Keil's official site. One important point: MDK comes in a Community edition and

a standard edition. The Community edition is free but capped at 32 KB of code, while the standard edition requires a paid license. For a project at the APM32F072RB level, the code size normally stays within 32 KB, so the Community edition is more than adequate. As for the version, I recommend 5.36 or newer: newer releases optimize compilation for the Cortex-M0 core better and also ship with a relatively recent CMSIS version. On the ST-LINK side there are two items. One is the ST-LINK USB driver, which is normally installed automatically along with MDK; if you see an exclamation mark in Device Manager, though, you'll need to install it separately. The other is the STM32 ST-LINK Utility programming tool, which is very handy for programming hex files on their own, viewing Flash contents, and configuring option bytes, so I recommend installing that too. Note that the installation paths of these three pieces of software should preferably contain no Chinese characters or spaces; Keil's default path is C:\Keil_v5, and moving it to a directory with Chinese characters will cause compilation errors related to Chinese paths later on. 2.2 The Right Way to Install the STM32CubeMX Firmware Package Once CubeMX is installed, the first time you open it and create a new project it will prompt you to download a firmware package.

The APM32F072RB corresponds to the STM32F0 series firmware package, which can be found in CubeMX under Help → Manage embedded software packages. Firmware package download speed depends heavily on the network; if it sits on the download screen for ages without progress, it's most likely a network problem. Here's an offline installation trick. First download the STM32CubeF0 firmware archive from ST's website, extract it, and copy the folder named .stsdk inside it into the local repository directory. That repository directory is the Repository folder under the CubeMX installation path—for example C:\Users\your_username\STM32Cube\Repository. Once the .stsdk folder is in place, reopen Manage embedded software packages and you'll see the firmware package already recognized automatically, with no need to download it online again. This method is a lifesaver in offline environments or when the firmware package keeps failing to download. For the firmware package version I recommend 1.11.x or 1.12.x: in older versions the HAL library implementation may differ slightly from the APM32F072's registers;

newer versions, by contrast, basically have no compatibility issues. 2.3 Making Keil MDK Recognize the Geehy Chip: Installing a Device Pack MDK itself only ships with device support packs for STM32 by default. However, since Geehy's APM32F072RB is compatible with the STM32F072RB, when you select the STM32F072RB in MDK the generated startup file and linker script work correctly, and there's no need to install a separate Geehy device support pack. I've verified this many times. 2.4 Verifying the ST-LINK Driver and Upgrading Its Firmware After installing all the software, plug the ST-LINK into the PC. Open Device Manager and expand "Universal Serial Bus devices" or "Universal Serial Bus controllers"; if you see something like "STM32 STLink" or "STLink dongle", the driver is fine. If instead you see an unknown device with a yellow exclamation mark, you'll need to install the ST-LINK driver manually. The ST-LINK driver installer is usually found in the ARM\STLink folder under the MDK installation directory; you can also search for "ST-LINK driver" on ST's website. If it still doesn't work after installing the driver, try swapping the USB cable. Don't underestimate the USB cable issue—I once ran into a poorly made cable that had only power wires and no data wires, so the ST-LINK was completely undetectable. Once connected properly with a data cable, it's worth using the STM32 ST-LINK Utility or Keil's firmware upgrade feature to check the ST-LINK firmware version. An outdated ST-LINK firmware causes slow and unstable downloads; upgrading to the latest firmware resolves a host of mysterious connection problems.

3. Detailed Configuration Flow from CubeMX to Keil 3.1 Creating a Project: Two Options for Selecting the CPU Model Open STM32CubeMX, click New Project, and type STM32F072RB in the Part Number search box; the chip will appear in the list. Double-click it to enter the configuration interface. However, my usual approach is this: if I'm definitely using the Geehy APM32F072RB, I type STM32F072RBT6 in the search box and select that part instead. Since the two have identical Flash and RAM sizes, the linker script and scatter-loading file generated by CubeMX match perfectly. The Geehy APM32F072RB memory parameters are: Flash 128 KB, RAM 16 KB.

Confirm that the STM32F072RB selected in CubeMX also has Flash 128 KB and RAM 16 KB—the two correspond exactly, so there are no issues with programming or linking. If the silkscreen and pin definitions on your board are completely identical to the STM32F072RB development board, this substitution costs you nothing. 3.2 Clock Tree Configuration: Achieving a 48 MHz Main Clock The clock tree design of the APM32F072RB is the same as the STM32F072's: it supports an external high-speed crystal (HSE), an internal high-speed RC oscillator (HSI, 8 MHz), an internal low-speed RC oscillator (LSI, 40 kHz), and an external low-speed crystal (LSE). The maximum system clock is 48 MHz, which is the biggest difference between the APM32F072RB and the APM32F103 series—the F0 series cannot multiply up to 72 MHz with a PLL; 48 MHz is its ceiling. Go to the Clock Configuration page; by default it uses HSI and the system clock is 8 MHz. If your board has an 8 MHz external crystal—most development boards do—you can configure it as follows. First, in the dropdown next to HSE, select Crystal/Ceramic Resonator to indicate an external crystal. Second, switch the System Clock Mux source to PLLCLK.

Third, set the PLL Source to HSE and the PLL Mul to 6; the 8 MHz external crystal multiplied by 6 gives 48 MHz. Fourth, set the APB1 Prescaler to /1 to keep 48 MHz. Finally, click the voltage regulator control on the left and confirm the VDD range is 2.0–3.6 V. When done, the SysClock indicator in the upper right will show 48 MHz; green means the configuration is valid, while red indicates a conflict or an out-of-range value. If you don't have an external crystal, keep the HSI configuration, set the PLL Source to HSI, and likewise set the PLL Mul to 6—the 8 MHz HSI multiplied by 6 also yields a 48 MHz system clock. The PLL input frequency range is 2–16 MHz, so an 8 MHz HSI or HSE is well within the legal range. 3.3 Peripheral Configuration: The Standard Trio of LED, UART, and Pushbutton Once the clock is configured, start setting up the peripherals. The operation to bring out the debug interface is on the SYS page under System Core.

One easily overlooked point here: the APM32F072RB's default debug interface is SWD (Serial Wire Debug), which uses only two pins, PA13 and PA14. If you accidentally configure these two pins as ordinary GPIO or an alternate function, the ST-LINK connection will break, typically showing "No target connected" when you try to download. Be sure to select Serial Wire as the debug interface. Next, configure the three most commonly used peripherals to verify the whole development chain. On the Pinout Configuration page, search for PD2 or whichever pin your board's LED is connected to, click the dropdown, and select GPIO_Output—this is the LED control pin. In the GPIO settings, set GPIO output level to High so the LED starts off (LEDs are usually active-low), set Maximum output speed to Low, and leave Pull-up/Pull-down as No pull-up. Then configure the serial port. Under Connectivity, find USART1 and set Mode to Asynchronous.

The default pins PA9 (TX) and PA10 (RX) need no change. In Parameter Settings, set Baud Rate to 115200, Word Length to 8 Bits, Parity to None, and Stop Bits to 1. Just keep these settings consistent with the serial terminal on the PC side. For the pushbutton, search for PC13 or whichever pin is connected to a button, click the dropdown, and select GPIO_Input. In the GPIO configuration, if one side of the button is grounded and the other goes to the pin, you need to enable the internal Pull-up, so the pin reads high when the button isn't pressed and low when it is. 3.4 Project Generation Settings: Don't Tick the Wrong Options There's no need to enable the MISRA-C compliance option—it's too strict. For ease of reading the code, I habitually tick both options to "generate peripheral initialization as a pair of .c/.h files per peripheral", so that in the generated code each peripheral's implementation appears not only in the main file but is also split into its own peripheral-name .c/.h file, making the modular structure clearer. Finally, fill in apm32_led_uart for Project Name and choose a path with only English characters for Project Location, such as D:\Work\apm32_demo.

Set Toolchain/IDE to MDK-ARM V5, because Keil MDK 5.x corresponds to the V5 format. On the Code Generator page, tick "Copy only the necessary library files" so the generated project includes only the HAL library files actually used—smaller project size and faster compilation. Click GENERATE CODE in the upper right and CubeMX starts generating the project. When it finishes, click Open Project and Keil MDK will automatically open the generated project. 3.5 Keil MDK Project Configuration: Key Options in the Magic Wand After opening the project in Keil, the first thing is to confirm the target chip. In the Device tab of the Options for Target (the "magic wand" icon), STM32F072RB should already be selected; if not, select it manually. This choice directly determines which startup file and which scatter-loading file the compiler uses. Then, on the Output and Listing tabs, tick Create HEX File.

If you don't tick this option, the build produces only an axf file, which neither ST-LINK Utility nor serial programming tools can burn directly. Normally, clicking the LOAD button in MDK doesn't depend on the hex file, but many third-party programming tools do require it. In the Debug tab, select the debugger. Choose ST-Link Debugger from the left dropdown, then click the Settings button on the right. In the Settings dialog, confirm two things: first, that the Debug Adapter area on the right recognizes the ST-LINK model and serial number; second, that Reset and Run is ticked in the Flash Download area, so the chip automatically resets and runs the program after programming—no need to press the reset button manually. In the C/C++ tab, the Define macro is USE_HAL_DRIVER, STM32F072xB. Here STM32F072xB indicates the use of the STM32F072 series 128 KB Flash variant; this macro is filled in automatically when CubeMX generates the code. If Define is empty or wrong, compilation will produce a flood of HAL library conditional-compilation errors, which are a headache to debug. 3

.6 Compiling, Programming, and Verification: First, Light Up the LED With the preparations done, press F7 to compile. The first compilation takes a while—CubeMX generates quite a few HAL library files, so it runs roughly tens of seconds to a couple of minutes. If compilation succeeds, the Build Output window shows "0 Error(s), 0 Warning(s)". Then click the LOAD button or press F8; Keil will invoke the ST-LINK to burn the firmware into the APM32F072RB. After successful programming, the status bar displays "Application running...". If the LED is configured correctly, it should start blinking—assuming the code contains a loop that toggles it or turns it on and off in a preset pattern. If everything is normal, the entire chain from CubeMX configuration through Keil compilation and download is working. As long as the hardware watchdog isn't enabled and the code logic is sound, the chip will run the program exactly as you wrote it. 4. ST-LINK Pitfall Guide: High-Frequency Errors and How to Handle Them 4.1 Connection Failure: No ST-LINK Detected The cause of this error is simple: the ST-LINK debugger isn't recognized by the PC at all. The troubleshooting sequence is as follows. First, confirm that the USB cable is

本文来源:http://www.lpqz.cn/news/106082
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。

暂无评论,快来发表第一条评论吧!No comments yet. Be the first!

📮 需求咨询📮 Inquiry