惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
爱范儿
爱范儿
T
The Exploit Database - CXSecurity.com
量子位
T
Tailwind CSS Blog
T
Threatpost
The GitHub Blog
The GitHub Blog
AWS News Blog
AWS News Blog
云风的 BLOG
云风的 BLOG
K
Kaspersky official blog
P
Proofpoint News Feed
博客园 - 司徒正美
L
LangChain Blog
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
S
Secure Thoughts
The Last Watchdog
The Last Watchdog
Spread Privacy
Spread Privacy
H
Hacker News: Front Page
T
Troy Hunt's Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
W
WeLiveSecurity
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Proofpoint News Feed
T
Tor Project blog
T
The Blog of Author Tim Ferriss
I
Intezer
P
Privacy & Cybersecurity Law Blog
美团技术团队
N
Netflix TechBlog - Medium
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost
Application and Cybersecurity Blog
Application and Cybersecurity Blog
G
Google Developers Blog
Attack and Defense Labs
Attack and Defense Labs
T
Tenable Blog
月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
J
Java Code Geeks
腾讯CDC
Microsoft Security Blog
Microsoft Security Blog
A
About on SuperTechFans
Last Week in AI
Last Week in AI

阿方的博客

[已下线] 博客分布式电源管理系统已上线 - 阿方的博客 在 MCU 部署边缘 AI —— 以 RA6E2 天气预测为例 嘉立创双十一金豆活动秒杀脚本 - 阿方的博客 GD32VW553-IoT 实现 SoftAP 配网 - 阿方的博客 24MHz 8CH 开源逻辑分析仪指南 - 阿方的博客 从光谱到 RGB - 阿方的博客 记一次 XSS 攻击非法钓鱼网站 - 阿方的博客 DG-LAB APP 郊狼波形导出二维码的解析 - 阿方的博客 新头像!福瑞 OC! - 阿方的博客 【补档】从零开始制作一个矿石作物 Addon - 阿方的博客 关于我 - 阿方的博客
MM32:配置开发环境并点亮第一颗 LED - 阿方的博客
Fang_Zhijian · 2024-10-13 · via 阿方的博客

配置 MM32G0001 开发环境并点亮第一颗 LED

安装 KEIL PACK

https://www.mindmotion.com.cn/support/software/keil_pack/

下载 KEIL PACK 后找到 MindMotion.MM32G0001_DFP.1.0.1.pack 双击即可安装

https://drive.miri.site/?/upload_api/upload_plugin/blog/mm32.01.0001.png

获取官方库函数

https://www.mindmotion.com.cn/products/mm32mcu/value_line/mm32g_value/mm32g0001/

下载“MM32G0001 库函数与例程”,我们需要其中 Device 目录下的所有文件

然后随意进入一个例程,我们需要其中的 platform.cplatform.h

https://drive.miri.site/?/upload_api/upload_plugin/blog/mm32.01.0002.png

创建 KEIL 工程

此处使用的是 FTHR-G0001 开发板,所以创建 KEIL 工程时选择 MM32G0001A1TC

https://drive.miri.site/?/upload_api/upload_plugin/blog/mm32.01.0003.png

随后弹出的运行时管理界面直接选择 OK 即可

此时,创建了一个完全为空的项目

https://drive.miri.site/?/upload_api/upload_plugin/blog/mm32.01.0004.png

配置开发环境

首先,把刚刚从官方例程提取到的库丢到我们新建的目录下:

https://drive.miri.site/?/upload_api/upload_plugin/blog/mm32.01.0005.png

进入 Manage Project Items,我们将这些都添加到 KEIL 工程中

https://drive.miri.site/?/upload_api/upload_plugin/blog/mm32.01.0006.png

Target 1
 ├─ APP              // 在项目根目录下
 │   └─ platform.c
 ├─ HAL_LIB          // 在 \Device\MM32G0001\HAL_Lib\src
 │   ├─ hal_adc.c
 │   ├─ hal_crc.c
 │   ├─ hal_dbg.c
 │   ├─ hal_exti.c
 │   ├─ hal_flash.c
 │   ├─ hal_gpio.c
 │   ├─ hal_i2c.c
 │   ├─ hal_iwdg.c
 │   ├─ hal_misc.c
 │   ├─ hal_pwr.c
 │   ├─ hal_rcc.c
 │   ├─ hal_spi.c
 │   ├─ hal_syscfg.c
 │   ├─ hal_tim.c
 │   ├─ hal_uid.c
 │   └─ hal_usart.c
 └─ STARTUP
     ├─ system_mm32g0001.c        // 在 \Device\MM32G0001\Source
     └─ startup_mm32g0001_keil.s  // 在 \Device\MM32G0001\Source\KEIL_StartAsm

再进入 Configure target options,进入 C/C++ 选项卡,修改下面两项:

https://drive.miri.site/?/upload_api/upload_plugin/blog/mm32.01.0007.png
https://drive.miri.site/?/upload_api/upload_plugin/blog/mm32.01.0008.png

①:填写 USE_STDPERIPH_DRIVER

①:选择下图中的这些目录

https://drive.miri.site/?/upload_api/upload_plugin/blog/mm32.01.0009.png

转到 Asm 选项卡,Assembler Option 务必选择 armasm (Arm Syntax),否则会出现报错

https://drive.miri.site/?/upload_api/upload_plugin/blog/mm32.01.0010.png

转到 Debug 选项卡,将 Use 修改为 CMSIS-DAP Debugger,然后点击 Settings 按钮进入 Flash Download 选项卡勾选 Reset and Run

https://drive.miri.site/?/upload_api/upload_plugin/blog/mm32.01.0011.png

https://drive.miri.site/?/upload_api/upload_plugin/blog/mm32.01.0012.png

自此,开发环境配置完成,下面就可以点亮第一颗 LED 了!

点亮第一颗 LED

在 APP 下新建 led.cled.hmain.c

led.h 中 include 一些我们需要的库,以及编写函数原型:

#ifndef LED_H
#define LED_H

#include "hal_conf.h"

void LED_Init(void);
void LED_Toggle(unsigned int ms);

#endif // LED_H

led.c 中编写这些函数:

#include "platform.h"
#include "hal_gpio.h"
#include "hal_rcc.h"
#include "led.h"

void LED_Init(void)
{
    GPIO_InitTypeDef GPIO_InitStruct;

    RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOA, ENABLE);

    GPIO_StructInit(&GPIO_InitStruct);
    GPIO_InitStruct.GPIO_Pin   = GPIO_Pin_11;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_High;
    GPIO_InitStruct.GPIO_Mode  = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOA, &GPIO_InitStruct);

    GPIO_WriteBit(GPIOA, GPIO_Pin_11, Bit_SET);
}

void LED_Toggle(unsigned int ms)
{
    while(1)
    {
        GPIO_SetBits(GPIOA, GPIO_Pin_11);
        PLATFORM_DelayMS(ms);
        GPIO_ResetBits(GPIOA, GPIO_Pin_11);
        PLATFORM_DelayMS(ms);
    }
}

main.c 中调用 led.c 中的函数:

#include "platform.h"
#include "led.h"

void SysTick_Handler(void)
{
    if (0 != PLATFORM_DelayTick)
    {
        PLATFORM_DelayTick--;
    }
}

int main(void)
{
    PLATFORM_Init();
    LED_Init();

    while(1)
    {
        LED_Toggle(200);   // 可修改亮灭频率
    }
}

完成后点击 Rebuild 按钮编译,如果没有报错,恭喜你:你的环境配置无误!接下来就可以点击 Download 按钮下载程序了!

https://drive.miri.site/?/upload_api/upload_plugin/blog/mm32.01.0013.png

随后你将看到开发板 ATS 指示灯闪烁,当下载完成后 LED D2 开始按照你设定的延时闪烁!

https://drive.miri.site/?/upload_api/upload_plugin/blog/mm32.01.gif01.gif
https://drive.miri.site/?/upload_api/upload_plugin/blog/mm32.01.gif02.gif

工程下载

HelloMM32.zip
https://drive.miri.site/?/upload_api/upload_plugin/blog/HelloMM32.zip