本次活动我选的是NUCLEO-C562RE开发板,想体验一下mx2
开发环境选择官方推荐的vscode +cubemx2
vscode里面要安装官方插件 stm32cubeide
我在cubemx2中是选择board创建项目的

选择stm32c562re开发板

根据开发板的原理图,led连接到了pa5上面,低电平点亮

选择pa5,右键能对pa5进行设置

下面代码每500ms翻转led,并且通过串口2输出eepw let is do
/**
******************************************************************************
* file : main.c
* brief : Main program body
* Calls target system initialization then loop in main.
******************************************************************************
*
* Copyright (c) 2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "mx_gpio_default.h"
#include <stdio.h> /* C library input/output functions */
#include <string.h> /* importing memcmp and memset functions */
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define RX_TIMEOUT 10000U
#define TX_TIMEOUT 1000U
#define MAX_BUFFER_SIZE 26U
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
uint8_t RxBuffer[MAX_BUFFER_SIZE]; /* Reception buffer */
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private functions prototype -----------------------------------------------*/
int __io_getchar(void) {
uint8_t ch = 0;
HAL_UART_Receive(mx_usart2_uart_gethandle(), (uint8_t *)&ch, 1, 10000);
return ch;
}
int __io_putchar(int ch) {
HAL_UART_Transmit(mx_usart2_uart_gethandle(), (uint8_t *)&ch, 1, 100);
return ch;
}
/**
* brief: The application entry point.
* retval: none but we specify int to comply with C99 standard
*/
int main(void)
{
/** System Init: this code placed in targets folder initializes your system.
* It calls the initialization (and sets the initial configuration) of the peripherals.
* You can use STM32CubeMX to generate and call this code or not in this project.
* It also contains the HAL initialization and the initial clock configuration.
*/
if (mx_system_init() != SYSTEM_OK)
{
return (-1);
}
else
{
/*
* You can start your application code here
*/
while (1) {
HAL_GPIO_TogglePin(LED_PORT, LED_PIN);
HAL_Delay(500);
printf("eepw let is do!\r\n");
}
}
} /* end main */下面是串口输出的内容

我要赚赏金
