添加串口操作类
This commit is contained in:
@@ -23,7 +23,8 @@ Mcu.IP4=NVIC
|
|||||||
Mcu.IP5=PWR
|
Mcu.IP5=PWR
|
||||||
Mcu.IP6=RCC
|
Mcu.IP6=RCC
|
||||||
Mcu.IP7=SYS
|
Mcu.IP7=SYS
|
||||||
Mcu.IPNb=9
|
Mcu.IP8=TIM7
|
||||||
|
Mcu.IPNb=10
|
||||||
Mcu.Name=STM32H563ZITx
|
Mcu.Name=STM32H563ZITx
|
||||||
Mcu.Package=LQFP144
|
Mcu.Package=LQFP144
|
||||||
Mcu.Pin0=PE2
|
Mcu.Pin0=PE2
|
||||||
@@ -56,20 +57,22 @@ Mcu.Pin32=PG13
|
|||||||
Mcu.Pin33=PB3(JTDO/TRACESWO)
|
Mcu.Pin33=PB3(JTDO/TRACESWO)
|
||||||
Mcu.Pin34=PB6
|
Mcu.Pin34=PB6
|
||||||
Mcu.Pin35=PB7
|
Mcu.Pin35=PB7
|
||||||
Mcu.Pin36=VP_PWR_VS_SECSignals
|
Mcu.Pin36=VP_CORTEX_M33_NS_VS_Hclk
|
||||||
Mcu.Pin37=VP_PWR_VS_LPOM
|
Mcu.Pin37=VP_PWR_VS_SECSignals
|
||||||
Mcu.Pin38=VP_PWR_VS_DBSignals
|
Mcu.Pin38=VP_PWR_VS_LPOM
|
||||||
Mcu.Pin39=VP_SYS_VS_Systick
|
Mcu.Pin39=VP_PWR_VS_DBSignals
|
||||||
Mcu.Pin4=PE6
|
Mcu.Pin4=PE6
|
||||||
Mcu.Pin40=VP_BOOTPATH_VS_BOOTPATH
|
Mcu.Pin40=VP_SYS_VS_Systick
|
||||||
Mcu.Pin41=VP_MEMORYMAP_VS_MEMORYMAP
|
Mcu.Pin41=VP_TIM7_VS_ClockSourceINT
|
||||||
Mcu.Pin42=VP_NUCLEO-H563ZI_VS_BSP_COMMON
|
Mcu.Pin42=VP_BOOTPATH_VS_BOOTPATH
|
||||||
|
Mcu.Pin43=VP_MEMORYMAP_VS_MEMORYMAP
|
||||||
|
Mcu.Pin44=VP_NUCLEO-H563ZI_VS_BSP_COMMON
|
||||||
Mcu.Pin5=PC13
|
Mcu.Pin5=PC13
|
||||||
Mcu.Pin6=PC14-OSC32_IN(OSC32_IN)
|
Mcu.Pin6=PC14-OSC32_IN(OSC32_IN)
|
||||||
Mcu.Pin7=PC15-OSC32_OUT(OSC32_OUT)
|
Mcu.Pin7=PC15-OSC32_OUT(OSC32_OUT)
|
||||||
Mcu.Pin8=PF4
|
Mcu.Pin8=PF4
|
||||||
Mcu.Pin9=PH0-OSC_IN(PH0)
|
Mcu.Pin9=PH0-OSC_IN(PH0)
|
||||||
Mcu.PinsNb=43
|
Mcu.PinsNb=45
|
||||||
Mcu.ThirdPartyNb=0
|
Mcu.ThirdPartyNb=0
|
||||||
Mcu.UserConstants=
|
Mcu.UserConstants=
|
||||||
Mcu.UserName=STM32H563ZITx
|
Mcu.UserName=STM32H563ZITx
|
||||||
@@ -273,8 +276,8 @@ ProjectManager.MainLocation=Core/Src
|
|||||||
ProjectManager.NoMain=false
|
ProjectManager.NoMain=false
|
||||||
ProjectManager.PreviousToolchain=
|
ProjectManager.PreviousToolchain=
|
||||||
ProjectManager.ProjectBuild=false
|
ProjectManager.ProjectBuild=false
|
||||||
ProjectManager.ProjectFileName=H563ZI-HAL-CMake-Template.ioc
|
ProjectManager.ProjectFileName=${REPO_NAME}.ioc
|
||||||
ProjectManager.ProjectName=H563ZI-HAL-CMake-Template
|
ProjectManager.ProjectName=${REPO_NAME}
|
||||||
ProjectManager.ProjectStructure=
|
ProjectManager.ProjectStructure=
|
||||||
ProjectManager.RegisterCallBack=
|
ProjectManager.RegisterCallBack=
|
||||||
ProjectManager.StackSize=0x400
|
ProjectManager.StackSize=0x400
|
||||||
@@ -283,7 +286,7 @@ ProjectManager.ToolChainLocation=
|
|||||||
ProjectManager.UAScriptAfterPath=
|
ProjectManager.UAScriptAfterPath=
|
||||||
ProjectManager.UAScriptBeforePath=
|
ProjectManager.UAScriptBeforePath=
|
||||||
ProjectManager.UnderRoot=false
|
ProjectManager.UnderRoot=false
|
||||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,false-0--NUCLEO-H563ZI-true-HAL-true,0-MX_CORTEX_M33_NS_Init-CORTEX_M33_NS-false-HAL-true,0-MX_PWR_Init-PWR-false-HAL-true
|
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,0-MX_CORTEX_M33_NS_Init-CORTEX_M33_NS-false-HAL-true,0-MX_PWR_Init-PWR-false-HAL-true,false-0--NUCLEO-H563ZI-true-HAL-true
|
||||||
RCC.ADCFreq_Value=250000000
|
RCC.ADCFreq_Value=250000000
|
||||||
RCC.AHBFreq_Value=250000000
|
RCC.AHBFreq_Value=250000000
|
||||||
RCC.APB1Freq_Value=250000000
|
RCC.APB1Freq_Value=250000000
|
||||||
@@ -376,8 +379,12 @@ SH.GPXTI13.0=GPIO_EXTI13
|
|||||||
SH.GPXTI13.ConfNb=1
|
SH.GPXTI13.ConfNb=1
|
||||||
SH.GPXTI7.0=GPIO_EXTI7
|
SH.GPXTI7.0=GPIO_EXTI7
|
||||||
SH.GPXTI7.ConfNb=1
|
SH.GPXTI7.ConfNb=1
|
||||||
|
TIM7.IPParameters=Prescaler
|
||||||
|
TIM7.Prescaler=249
|
||||||
VP_BOOTPATH_VS_BOOTPATH.Mode=BP_Activate
|
VP_BOOTPATH_VS_BOOTPATH.Mode=BP_Activate
|
||||||
VP_BOOTPATH_VS_BOOTPATH.Signal=BOOTPATH_VS_BOOTPATH
|
VP_BOOTPATH_VS_BOOTPATH.Signal=BOOTPATH_VS_BOOTPATH
|
||||||
|
VP_CORTEX_M33_NS_VS_Hclk.Mode=Hclk_Mode
|
||||||
|
VP_CORTEX_M33_NS_VS_Hclk.Signal=CORTEX_M33_NS_VS_Hclk
|
||||||
VP_MEMORYMAP_VS_MEMORYMAP.Mode=CurAppReg
|
VP_MEMORYMAP_VS_MEMORYMAP.Mode=CurAppReg
|
||||||
VP_MEMORYMAP_VS_MEMORYMAP.Signal=MEMORYMAP_VS_MEMORYMAP
|
VP_MEMORYMAP_VS_MEMORYMAP.Signal=MEMORYMAP_VS_MEMORYMAP
|
||||||
VP_NUCLEO-H563ZI_VS_BSP_COMMON.Mode=COMMON
|
VP_NUCLEO-H563ZI_VS_BSP_COMMON.Mode=COMMON
|
||||||
@@ -390,5 +397,7 @@ VP_PWR_VS_SECSignals.Mode=Security/Privilege
|
|||||||
VP_PWR_VS_SECSignals.Signal=PWR_VS_SECSignals
|
VP_PWR_VS_SECSignals.Signal=PWR_VS_SECSignals
|
||||||
VP_SYS_VS_Systick.Mode=SysTick
|
VP_SYS_VS_Systick.Mode=SysTick
|
||||||
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
|
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
|
||||||
|
VP_TIM7_VS_ClockSourceINT.Mode=Enable_Timer
|
||||||
|
VP_TIM7_VS_ClockSourceINT.Signal=TIM7_VS_ClockSourceINT
|
||||||
board=NUCLEO-H563ZI
|
board=NUCLEO-H563ZI
|
||||||
boardIOC=true
|
boardIOC=true
|
||||||
|
|||||||
34
.mxproject
34
.mxproject
File diff suppressed because one or more lines are too long
5
Core/App/Common/serial_port.cpp
Normal file
5
Core/App/Common/serial_port.cpp
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#include "serial_port.hpp"
|
||||||
|
|
||||||
|
extern "C" void HAL_UART_TxCpltCallback([[maybe_unused]] UART_HandleTypeDef* huart) {
|
||||||
|
SerialPort::isTransmitting = false;
|
||||||
|
}
|
||||||
118
Core/App/Common/serial_port.hpp
Normal file
118
Core/App/Common/serial_port.hpp
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "stm32h5xx_nucleo.h"
|
||||||
|
#include <cstdarg>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class SerialPort {
|
||||||
|
private:
|
||||||
|
static constexpr uint32_t kTransmitTimeout = 1000;
|
||||||
|
static constexpr auto* kHandle = &hcom_uart[COM1];
|
||||||
|
|
||||||
|
static inline char buffer[256] = {0};
|
||||||
|
|
||||||
|
friend void HAL_UART_TxCpltCallback(UART_HandleTypeDef* huart);
|
||||||
|
static inline volatile bool isTransmitting = false;
|
||||||
|
|
||||||
|
static void WaitTransmit() {
|
||||||
|
const auto tick = HAL_GetTick();
|
||||||
|
while (isTransmitting) {
|
||||||
|
if (HAL_GetTick() - tick > kTransmitTimeout) {
|
||||||
|
HAL_UART_AbortTransmit(kHandle);
|
||||||
|
isTransmitting = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
static uint8_t ReadByte() {
|
||||||
|
return kHandle->Instance->RDR;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string ReadLine() {
|
||||||
|
std::string result;
|
||||||
|
result.reserve(128);
|
||||||
|
char c;
|
||||||
|
ReadByte();
|
||||||
|
while (true) {
|
||||||
|
HAL_UART_Receive(kHandle, reinterpret_cast<uint8_t*>(&c), 1, HAL_MAX_DELAY);
|
||||||
|
if (c == '\n') {
|
||||||
|
if (!result.empty() && result.back() == '\r') {
|
||||||
|
result.pop_back();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
result.push_back(c);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void WriteLine(const char* format, ...) {
|
||||||
|
WaitTransmit();
|
||||||
|
isTransmitting = true;
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
int len = vsnprintf(buffer, sizeof(buffer) - 1, format, args);
|
||||||
|
va_end(args);
|
||||||
|
if (len < 0 || len > static_cast<int>(sizeof(buffer) - 1)) {
|
||||||
|
isTransmitting = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
buffer[len] = '\n';
|
||||||
|
len++;
|
||||||
|
HAL_UART_Transmit_DMA(kHandle, reinterpret_cast<uint8_t*>(buffer), len);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void WriteLineBlocking(const char* format, ...) {
|
||||||
|
WaitTransmit();
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
int len = vsnprintf(buffer, sizeof(buffer) - 1, format, args);
|
||||||
|
va_end(args);
|
||||||
|
if (len < 0 || len > static_cast<int>(sizeof(buffer) - 1)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
buffer[len] = '\n';
|
||||||
|
len++;
|
||||||
|
HAL_UART_Transmit(kHandle, reinterpret_cast<uint8_t*>(buffer), len, kTransmitTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Write(const char* format, ...) {
|
||||||
|
WaitTransmit();
|
||||||
|
isTransmitting = true;
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
auto len = vsnprintf(buffer, sizeof(buffer), format, args);
|
||||||
|
va_end(args);
|
||||||
|
if (len < 0 || len > static_cast<int>(sizeof(buffer))) {
|
||||||
|
isTransmitting = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
HAL_UART_Transmit_DMA(kHandle, reinterpret_cast<uint8_t*>(buffer), len);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void WriteBlocking(const char* format, ...) {
|
||||||
|
WaitTransmit();
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
auto len = vsnprintf(buffer, sizeof(buffer), format, args);
|
||||||
|
va_end(args);
|
||||||
|
if (len < 0 || len > static_cast<int>(sizeof(buffer))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
HAL_UART_Transmit(kHandle, reinterpret_cast<uint8_t*>(buffer), strlen(buffer), kTransmitTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void WriteBytes(const uint8_t* data, size_t size) {
|
||||||
|
WaitTransmit();
|
||||||
|
isTransmitting = true;
|
||||||
|
HAL_UART_Transmit_DMA(kHandle, const_cast<uint8_t*>(data), size);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void WriteBytesBlocking(const uint8_t* data, size_t size) {
|
||||||
|
WaitTransmit();
|
||||||
|
HAL_UART_Transmit(kHandle, const_cast<uint8_t*>(data), size, kTransmitTimeout);
|
||||||
|
}
|
||||||
|
};
|
||||||
29
Core/App/Helper/delay_helper.c
Normal file
29
Core/App/Helper/delay_helper.c
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
//
|
||||||
|
// Created by Engineer on 2024/1/11.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "delay_helper.h"
|
||||||
|
|
||||||
|
#include "tim.h"
|
||||||
|
|
||||||
|
void DelaySetup(void) {
|
||||||
|
HAL_TIM_Base_Start(&TIM_DELAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DelayUs(const uint16_t nus) {
|
||||||
|
__HAL_TIM_SET_COUNTER(&TIM_DELAY, 0);
|
||||||
|
while (__HAL_TIM_GET_COUNTER(&TIM_DELAY) < nus) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DelayMs(const uint32_t nms) {
|
||||||
|
for (uint32_t i = 0; i < nms; ++i) {
|
||||||
|
DelayUs(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DelayS(const uint32_t ns) {
|
||||||
|
for (uint32_t i = 0; i < ns; ++i) {
|
||||||
|
DelayMs(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
18
Core/App/Helper/delay_helper.h
Normal file
18
Core/App/Helper/delay_helper.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define TIM_DELAY htim7
|
||||||
|
|
||||||
|
void DelaySetup(void);
|
||||||
|
void DelayUs(uint16_t nus);
|
||||||
|
void DelayMs(uint32_t nms);
|
||||||
|
void DelayS(uint32_t ns);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
70
Core/App/Helper/gpio_helper.hpp
Normal file
70
Core/App/Helper/gpio_helper.hpp
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
#include <optional>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
class GpioHelper {
|
||||||
|
public:
|
||||||
|
struct Gpio {
|
||||||
|
GPIO_TypeDef* port;
|
||||||
|
uint16_t pin;
|
||||||
|
|
||||||
|
void Set() const {
|
||||||
|
port->BSRR = pin;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Reset() const {
|
||||||
|
port->BSRR = pin << 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Toggle() const {
|
||||||
|
port->ODR ^= pin;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] GPIO_PinState Read() const {
|
||||||
|
return port->IDR & pin ? GPIO_PIN_SET : GPIO_PIN_RESET;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct GpioPlus {
|
||||||
|
std::string_view name;
|
||||||
|
Gpio gpio;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void EnableAllGpioPeripheral() {
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Gpio GpioInit(GPIO_TypeDef* port, const uint16_t pin, const uint32_t mode, const uint32_t pull,
|
||||||
|
const std::optional<GPIO_PinState> state = std::nullopt) {
|
||||||
|
static GPIO_InitTypeDef o = {};
|
||||||
|
if (state.has_value()) {
|
||||||
|
HAL_GPIO_WritePin(port, pin, state.value());
|
||||||
|
}
|
||||||
|
o.Pin = pin;
|
||||||
|
o.Mode = mode;
|
||||||
|
o.Pull = pull;
|
||||||
|
o.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(port, &o);
|
||||||
|
return {port, pin};
|
||||||
|
}
|
||||||
|
|
||||||
|
static Gpio GpioInit(const Gpio& gpio, const uint32_t mode, const uint32_t pull, const GPIO_PinState state) {
|
||||||
|
return GpioInit(gpio.port, gpio.pin, mode, pull, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GpioDeInit(const Gpio& gpio) {
|
||||||
|
HAL_GPIO_DeInit(gpio.port, gpio.pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GpioDeInit(GPIO_TypeDef* port, const uint16_t pin) {
|
||||||
|
HAL_GPIO_DeInit(port, pin);
|
||||||
|
}
|
||||||
|
};
|
||||||
21
Core/App/app.cpp
Normal file
21
Core/App/app.cpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#include "Helper/delay_helper.h"
|
||||||
|
#include "stm32h563xx.h"
|
||||||
|
|
||||||
|
#include "Common/serial_port.hpp"
|
||||||
|
#include "Helper/gpio_helper.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
void Setup() {
|
||||||
|
GpioHelper::EnableAllGpioPeripheral();
|
||||||
|
DelaySetup();
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void AppStart() {
|
||||||
|
Setup();
|
||||||
|
auto gpio = GpioHelper::GpioInit(GPIOB, GPIO_PIN_0, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_PIN_SET);
|
||||||
|
while (true) {
|
||||||
|
gpio.Toggle();
|
||||||
|
SerialPort::WriteLine("LED is toggled,current state: %s", gpio.Read() ? "OFF" : "ON");
|
||||||
|
DelayS(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -78,7 +78,7 @@
|
|||||||
/*#define HAL_SMBUS_MODULE_ENABLED */
|
/*#define HAL_SMBUS_MODULE_ENABLED */
|
||||||
/*#define HAL_SPI_MODULE_ENABLED */
|
/*#define HAL_SPI_MODULE_ENABLED */
|
||||||
/*#define HAL_SRAM_MODULE_ENABLED */
|
/*#define HAL_SRAM_MODULE_ENABLED */
|
||||||
/*#define HAL_TIM_MODULE_ENABLED */
|
#define HAL_TIM_MODULE_ENABLED
|
||||||
/*#define HAL_RAMCFG_MODULE_ENABLED */
|
/*#define HAL_RAMCFG_MODULE_ENABLED */
|
||||||
#define HAL_UART_MODULE_ENABLED
|
#define HAL_UART_MODULE_ENABLED
|
||||||
/*#define HAL_USART_MODULE_ENABLED */
|
/*#define HAL_USART_MODULE_ENABLED */
|
||||||
|
|||||||
52
Core/Inc/tim.h
Normal file
52
Core/Inc/tim.h
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file tim.h
|
||||||
|
* @brief This file contains all the function prototypes for
|
||||||
|
* the tim.c file
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __TIM_H__
|
||||||
|
#define __TIM_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Includes */
|
||||||
|
|
||||||
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
extern TIM_HandleTypeDef htim7;
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Private defines */
|
||||||
|
|
||||||
|
/* USER CODE END Private defines */
|
||||||
|
|
||||||
|
void MX_TIM7_Init(void);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Prototypes */
|
||||||
|
|
||||||
|
/* USER CODE END Prototypes */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __TIM_H__ */
|
||||||
|
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "memorymap.h"
|
#include "memorymap.h"
|
||||||
|
#include "tim.h"
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
/* Private includes ----------------------------------------------------------*/
|
||||||
@@ -57,7 +58,7 @@ void SystemClock_Config(void);
|
|||||||
|
|
||||||
/* Private user code ---------------------------------------------------------*/
|
/* Private user code ---------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN 0 */
|
/* USER CODE BEGIN 0 */
|
||||||
|
extern void AppStart(void);
|
||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,6 +90,7 @@ int main(void)
|
|||||||
|
|
||||||
/* Initialize all configured peripherals */
|
/* Initialize all configured peripherals */
|
||||||
MX_GPIO_Init();
|
MX_GPIO_Init();
|
||||||
|
MX_TIM7_Init();
|
||||||
/* USER CODE BEGIN 2 */
|
/* USER CODE BEGIN 2 */
|
||||||
|
|
||||||
/* USER CODE END 2 */
|
/* USER CODE END 2 */
|
||||||
@@ -114,6 +116,7 @@ int main(void)
|
|||||||
|
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
/* USER CODE BEGIN WHILE */
|
/* USER CODE BEGIN WHILE */
|
||||||
|
AppStart();
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
97
Core/Src/tim.c
Normal file
97
Core/Src/tim.c
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file tim.c
|
||||||
|
* @brief This file provides code for the configuration
|
||||||
|
* of the TIM instances.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "tim.h"
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
TIM_HandleTypeDef htim7;
|
||||||
|
|
||||||
|
/* TIM7 init function */
|
||||||
|
void MX_TIM7_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM7_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM7_Init 0 */
|
||||||
|
|
||||||
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM7_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM7_Init 1 */
|
||||||
|
htim7.Instance = TIM7;
|
||||||
|
htim7.Init.Prescaler = 249;
|
||||||
|
htim7.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
|
htim7.Init.Period = 65535;
|
||||||
|
htim7.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||||
|
if (HAL_TIM_Base_Init(&htim7) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||||
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||||
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim7, &sMasterConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN TIM7_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM7_Init 2 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(tim_baseHandle->Instance==TIM7)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN TIM7_MspInit 0 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM7_MspInit 0 */
|
||||||
|
/* TIM7 clock enable */
|
||||||
|
__HAL_RCC_TIM7_CLK_ENABLE();
|
||||||
|
/* USER CODE BEGIN TIM7_MspInit 1 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM7_MspInit 1 */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(tim_baseHandle->Instance==TIM7)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN TIM7_MspDeInit 0 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM7_MspDeInit 0 */
|
||||||
|
/* Peripheral clock disable */
|
||||||
|
__HAL_RCC_TIM7_CLK_DISABLE();
|
||||||
|
/* USER CODE BEGIN TIM7_MspDeInit 1 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM7_MspDeInit 1 */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
|
/* USER CODE END 1 */
|
||||||
2537
Drivers/STM32H5xx_HAL_Driver/Inc/stm32h5xx_hal_tim.h
Normal file
2537
Drivers/STM32H5xx_HAL_Driver/Inc/stm32h5xx_hal_tim.h
Normal file
File diff suppressed because it is too large
Load Diff
1386
Drivers/STM32H5xx_HAL_Driver/Inc/stm32h5xx_hal_tim_ex.h
Normal file
1386
Drivers/STM32H5xx_HAL_Driver/Inc/stm32h5xx_hal_tim_ex.h
Normal file
File diff suppressed because it is too large
Load Diff
6571
Drivers/STM32H5xx_HAL_Driver/Inc/stm32h5xx_ll_tim.h
Normal file
6571
Drivers/STM32H5xx_HAL_Driver/Inc/stm32h5xx_ll_tim.h
Normal file
File diff suppressed because it is too large
Load Diff
8273
Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_tim.c
Normal file
8273
Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_tim.c
Normal file
File diff suppressed because it is too large
Load Diff
3474
Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_tim_ex.c
Normal file
3474
Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_tim_ex.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -24,6 +24,7 @@ set(MX_Application_Src
|
|||||||
${CMAKE_SOURCE_DIR}/Core/Src/main.c
|
${CMAKE_SOURCE_DIR}/Core/Src/main.c
|
||||||
${CMAKE_SOURCE_DIR}/Core/Src/gpio.c
|
${CMAKE_SOURCE_DIR}/Core/Src/gpio.c
|
||||||
${CMAKE_SOURCE_DIR}/Core/Src/memorymap.c
|
${CMAKE_SOURCE_DIR}/Core/Src/memorymap.c
|
||||||
|
${CMAKE_SOURCE_DIR}/Core/Src/tim.c
|
||||||
${CMAKE_SOURCE_DIR}/Core/Src/stm32h5xx_it.c
|
${CMAKE_SOURCE_DIR}/Core/Src/stm32h5xx_it.c
|
||||||
${CMAKE_SOURCE_DIR}/Core/Src/stm32h5xx_hal_msp.c
|
${CMAKE_SOURCE_DIR}/Core/Src/stm32h5xx_hal_msp.c
|
||||||
${CMAKE_SOURCE_DIR}/Core/Src/sysmem.c
|
${CMAKE_SOURCE_DIR}/Core/Src/sysmem.c
|
||||||
@@ -46,6 +47,8 @@ set(STM32_Drivers_Src
|
|||||||
${CMAKE_SOURCE_DIR}/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_pwr_ex.c
|
${CMAKE_SOURCE_DIR}/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_pwr_ex.c
|
||||||
${CMAKE_SOURCE_DIR}/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal.c
|
${CMAKE_SOURCE_DIR}/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal.c
|
||||||
${CMAKE_SOURCE_DIR}/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_exti.c
|
${CMAKE_SOURCE_DIR}/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_exti.c
|
||||||
|
${CMAKE_SOURCE_DIR}/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_tim.c
|
||||||
|
${CMAKE_SOURCE_DIR}/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_tim_ex.c
|
||||||
${CMAKE_SOURCE_DIR}/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_usart.c
|
${CMAKE_SOURCE_DIR}/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_usart.c
|
||||||
${CMAKE_SOURCE_DIR}/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_usart_ex.c
|
${CMAKE_SOURCE_DIR}/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_usart_ex.c
|
||||||
${CMAKE_SOURCE_DIR}/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_uart_ex.c
|
${CMAKE_SOURCE_DIR}/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_uart_ex.c
|
||||||
|
|||||||
Reference in New Issue
Block a user