【STM32C0评测】1、开箱、环境搭建、按键点灯
**一、开箱**这次真的开箱,不像传统包装方式,使用的是环保纸盒+自封防静电袋方式包装。
![包装.jpg](data/attachment/forum/202403/08/103326kbxd9v5vc3tdglgb.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "包装.jpg")
NUCLEO-C031C6基板
型号:MB1717B,[电路原理图](https://www.st.com/resource/en/schematic_pack/mb1717-c031c6-b02_schematic.pdf)
接口:板上自带ST-LINK
V2.1,MicroUSB接口
板上资源:一个按钮接PC13,一个LED灯接PA5
MCU:STM32C031C6T6U,48Mhz,12kSram,32kFlash,带I2C,SPI,USART,I2S,12Bit-ADC。
![功能框图.jpg](data/attachment/forum/202403/08/103316gdmwz50u77vedw77.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "功能框图.jpg")
STM32C0系列相关技术文档[下载地址](https://www.stmcu.com.cn/Product/pro_detail/STM32C0/product)。
**二、免费环境搭建**
方式一、STM32CubeIDE
这是STM官方免费提供的STM32集成开发环境,是一种高级C/C++开发平台,具有STM32微控制器和微处理器的外设配置、代码生成、代码编译和调试功能,并且集成了STM32CubeMX的STM32配置与项目创建功能,以便提供一体化工具体验,并节省安装与开发时间。([下载地址](https://www.st.com/zh/development-tools/stm32cubeide.html))
1、安装STM32CubeIDE后安装STM32C0的Pack,这一步也可以略过,如果没有安装生成代码时也会要求下载。
![下载PACK.jpg](data/attachment/forum/202403/08/103410f8jbzbqj8yjzzayb.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "下载PACK.jpg")
2、新建项目
![新建项目.jpg](data/attachment/forum/202403/08/103627acus060pjpp0dzrz.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "新建项目.jpg")
因使用的是nucleo板可以选择芯片或板卡开始配置。
注意:选择芯片时,选STM32C031C6T6与STM32C031C6T6TR都可以,区别在于有TR的为卷带包装,无的是管装或托盘包装。
![选择1.jpg](data/attachment/forum/202403/08/104146qvvx1njdhjv2x2th.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "选择1.jpg")
我选择板卡
![选择板件型号.jpg](data/attachment/forum/202403/08/104909xcdai66azkooy6os.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "选择板件型号.jpg")
输入项目名称
![项目设置.jpg](data/attachment/forum/202403/08/104955hevj3jorjmvtgho2.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "项目设置.jpg")
GPIO和时钟配置,因选择板卡,不需要设置直接跳过
![配置GPIO.jpg](data/attachment/forum/202403/08/105039v6ppjbj66zi96vd5.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "配置GPIO.jpg")
![时钟设置.jpg](data/attachment/forum/202403/08/105145ictbrz8c9rftk93k.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "时钟设置.jpg")
代码配置
![生成代码设置.jpg](data/attachment/forum/202403/08/105617p1u21ukq0kzk2qa0.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "生成代码设置.jpg")
生成代码
![生成代码.jpg](data/attachment/forum/202403/08/105649p3tt7ngb00zt6tyt.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "生成代码.jpg")
方式二、STM32CubeMX + Keil5
STM32CubeMX([下载地址](https://www.st.com/zh/development-tools/stm32cubemx.html))
Keil5不是免费,但面向STM32C0、STM32F0、STM32L0和STM32G0的Keil MDK免费提供(Keil[下载注册地址](https://arm-sc10xp1-pre-prod-cd.azurewebsites.net/tools-and-software/embedded/keil-mdk/buy/stmicroelectronics))。Keil5的STM32packs下载方式参考这帖子:(https://blog.csdn.net/weixin_54221349/article/details/131691178)
也可以到网盘下载:[百度网盘](https://pan.baidu.com/s/1g0B1aPYsdYmlpmuHo_XELg%20:pws=6666)链接:https://pan.baidu.com/s/1g0B1aPYsdYmlpmuHo_XELg :pws=6666 提取码:6666
预先安装好STM32CubeMX和Keil5
STM32CubeMX配置方式与STM32CubeIDE差不多,但还是用差异,同样选择板子,GPIO功能只做了预留,配置要重新配一下。
!(data/attachment/forum/202403/08/112154xoobebkir66bb2oc.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "MxGPIO.jpg")
![项目配置.jpg](data/attachment/forum/202403/08/112612ot5hhplfe7o0fide.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "项目配置.jpg")
选择Generate Code生成代码
![项目配置_副本.jpg](data/attachment/forum/202403/08/112933wbkwbzdyrogzc4d4.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "项目配置_副本.jpg")
生成后选择打开项目,会自动加载keil5,如果没装stm32c0的pack,会自动转去下载安装。
**三、通过按键点灯**
程序要写在/* USER CODE BEGIN xxxx */ 和 /* USER CODE END xxxx */之间,这样重新配置再生成代码就不会覆盖已编写的程序。
![程序1.jpg](data/attachment/forum/202403/08/122012lxaa8eey35bbogn3.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "程序1.jpg")
本例使用gpio-按键中断方式控制LED的亮和灭
1、查看电路原理图,当PA5高电平,T2导通,LD4亮,根据这个在main.h添加预定义
![灯电路图.jpg](data/attachment/forum/202403/08/122832g3tgwmmgzwttf5t4.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "灯电路图.jpg")
#define LED_ON HAL_GPIO_WritePin(Led_GPIO_Port, Led_Pin, GPIO_PIN_SET)
#define LED_OFF HAL_GPIO_WritePin(Led_GPIO_Port, Led_Pin, GPIO_PIN_RESET)
#define LED_TOGGLE HAL_GPIO_TogglePin(Led_GPIO_Port, Led_Pin)
![程序2.jpg](data/attachment/forum/202403/08/122439mms0hbzd3m36y4d4.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "程序2.jpg")
2、在gpio.c中增加中断回调函数
根据设置为上升沿触发中断
![配置.jpg](data/attachment/forum/202403/08/123447dvdg4ivvkigqx0j9.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "配置.jpg")
打开库文件stm32c0xx_hal.gpio.c查看回调函数的形式,编写回调函数
![程序4.jpg](data/attachment/forum/202403/08/123518ywp22h5pwei0k24w.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "程序4.jpg")
void HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin)
{
if (GPIO_Pin == User_Button_Pin)
{
LED_TOGGLE;
}
}
3、使用MicroUSB数据线连接板子,运行代码
![运行.jpg](data/attachment/forum/202403/08/123946o2zlyxcy2xxvyzzv.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "运行.jpg")
或
![批注2024-03-08123910.jpg](data/attachment/forum/202403/08/123957mil5ljrxlk5isijj.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "批注 2024-03-08 123910.jpg")
四、程序运行效果:
不会上视频,只能截屏了
![效果1.jpg](data/attachment/forum/202403/08/124428sz1yyqhmqzjjqoic.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "效果1.jpg")![效果2.jpg](data/attachment/forum/202403/08/124428bhomx6mgxx111bjx.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "效果2.jpg")
发布在这个位置哈,STM32团队
STMCU-管管 发表于 2024-3-8 14:08
发布在这个位置哈,STM32团队
能帮转过去吗?
老哥,STM32CubeIDE装好了,STM32C0这个找不到咋回事
!(data/attachment/forum/202403/20/083549cjougnn9yqx0o3yj.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
背影101 发表于 2024-3-20 08:35
老哥,STM32CubeIDE装好了,STM32C0这个找不到咋回事
!(data/attachment/forum/202403/20/083549cjoug ...
你的IDE是什么版本?
网络孤客 发表于 2024-3-20 18:23
你的IDE是什么版本?
版本问题,已经解决了
页:
[1]