15 changed files with 937 additions and 369 deletions
-
3.gitmodules
-
26app/.mxproject
-
2app/Core/Inc/stm32f4xx_hal_conf.h
-
57app/Core/Inc/tim.h
-
12app/Core/Src/gpio.c
-
69app/Core/Src/main.c
-
224app/Core/Src/tim.c
-
224app/MDK-ARM/app.uvguix.29643
-
316app/MDK-ARM/app.uvoptx
-
88app/MDK-ARM/app.uvprojx
-
42app/app.ioc
-
160src/port.c
-
58src/port.h
-
1src/usermain.c
-
24src/zboard.h
@ -0,0 +1,3 @@ |
|||
[submodule "iflytop_microcontroller"] |
|||
path = iflytop_microcontroller |
|||
url = zwsd@192.168.1.3:z2nd_lib/iflytop_microcontroller.git |
26
app/.mxproject
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,57 @@ |
|||
/* USER CODE BEGIN Header */ |
|||
/** |
|||
****************************************************************************** |
|||
* @file tim.h |
|||
* @brief This file contains all the function prototypes for |
|||
* the tim.c file |
|||
****************************************************************************** |
|||
* @attention |
|||
* |
|||
* Copyright (c) 2023 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 htim1; |
|||
|
|||
extern TIM_HandleTypeDef htim4; |
|||
|
|||
/* USER CODE BEGIN Private defines */ |
|||
|
|||
/* USER CODE END Private defines */ |
|||
|
|||
void MX_TIM1_Init(void); |
|||
void MX_TIM4_Init(void); |
|||
|
|||
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); |
|||
|
|||
/* USER CODE BEGIN Prototypes */ |
|||
|
|||
/* USER CODE END Prototypes */ |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
|||
|
|||
#endif /* __TIM_H__ */ |
|||
|
@ -0,0 +1,224 @@ |
|||
/* USER CODE BEGIN Header */ |
|||
/** |
|||
****************************************************************************** |
|||
* @file tim.c |
|||
* @brief This file provides code for the configuration |
|||
* of the TIM instances. |
|||
****************************************************************************** |
|||
* @attention |
|||
* |
|||
* Copyright (c) 2023 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 htim1; |
|||
TIM_HandleTypeDef htim4; |
|||
|
|||
/* TIM1 init function */ |
|||
void MX_TIM1_Init(void) |
|||
{ |
|||
|
|||
/* USER CODE BEGIN TIM1_Init 0 */ |
|||
|
|||
/* USER CODE END TIM1_Init 0 */ |
|||
|
|||
TIM_MasterConfigTypeDef sMasterConfig = {0}; |
|||
TIM_OC_InitTypeDef sConfigOC = {0}; |
|||
TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0}; |
|||
|
|||
/* USER CODE BEGIN TIM1_Init 1 */ |
|||
|
|||
/* USER CODE END TIM1_Init 1 */ |
|||
htim1.Instance = TIM1; |
|||
htim1.Init.Prescaler = 0; |
|||
htim1.Init.CounterMode = TIM_COUNTERMODE_UP; |
|||
htim1.Init.Period = 65535; |
|||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
|||
htim1.Init.RepetitionCounter = 0; |
|||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
|||
if (HAL_TIM_PWM_Init(&htim1) != HAL_OK) |
|||
{ |
|||
Error_Handler(); |
|||
} |
|||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; |
|||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
|||
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK) |
|||
{ |
|||
Error_Handler(); |
|||
} |
|||
sConfigOC.OCMode = TIM_OCMODE_PWM1; |
|||
sConfigOC.Pulse = 0; |
|||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; |
|||
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH; |
|||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; |
|||
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET; |
|||
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET; |
|||
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) |
|||
{ |
|||
Error_Handler(); |
|||
} |
|||
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE; |
|||
sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE; |
|||
sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF; |
|||
sBreakDeadTimeConfig.DeadTime = 0; |
|||
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE; |
|||
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH; |
|||
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE; |
|||
if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK) |
|||
{ |
|||
Error_Handler(); |
|||
} |
|||
/* USER CODE BEGIN TIM1_Init 2 */ |
|||
|
|||
/* USER CODE END TIM1_Init 2 */ |
|||
HAL_TIM_MspPostInit(&htim1); |
|||
|
|||
} |
|||
/* TIM4 init function */ |
|||
void MX_TIM4_Init(void) |
|||
{ |
|||
|
|||
/* USER CODE BEGIN TIM4_Init 0 */ |
|||
|
|||
/* USER CODE END TIM4_Init 0 */ |
|||
|
|||
TIM_ClockConfigTypeDef sClockSourceConfig = {0}; |
|||
TIM_MasterConfigTypeDef sMasterConfig = {0}; |
|||
|
|||
/* USER CODE BEGIN TIM4_Init 1 */ |
|||
|
|||
/* USER CODE END TIM4_Init 1 */ |
|||
htim4.Instance = TIM4; |
|||
htim4.Init.Prescaler = 168-1; |
|||
htim4.Init.CounterMode = TIM_COUNTERMODE_UP; |
|||
htim4.Init.Period = 65535; |
|||
htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
|||
htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
|||
if (HAL_TIM_Base_Init(&htim4) != HAL_OK) |
|||
{ |
|||
Error_Handler(); |
|||
} |
|||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; |
|||
if (HAL_TIM_ConfigClockSource(&htim4, &sClockSourceConfig) != HAL_OK) |
|||
{ |
|||
Error_Handler(); |
|||
} |
|||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; |
|||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
|||
if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK) |
|||
{ |
|||
Error_Handler(); |
|||
} |
|||
/* USER CODE BEGIN TIM4_Init 2 */ |
|||
|
|||
/* USER CODE END TIM4_Init 2 */ |
|||
|
|||
} |
|||
|
|||
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* tim_pwmHandle) |
|||
{ |
|||
|
|||
if(tim_pwmHandle->Instance==TIM1) |
|||
{ |
|||
/* USER CODE BEGIN TIM1_MspInit 0 */ |
|||
|
|||
/* USER CODE END TIM1_MspInit 0 */ |
|||
/* TIM1 clock enable */ |
|||
__HAL_RCC_TIM1_CLK_ENABLE(); |
|||
/* USER CODE BEGIN TIM1_MspInit 1 */ |
|||
|
|||
/* USER CODE END TIM1_MspInit 1 */ |
|||
} |
|||
} |
|||
|
|||
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) |
|||
{ |
|||
|
|||
if(tim_baseHandle->Instance==TIM4) |
|||
{ |
|||
/* USER CODE BEGIN TIM4_MspInit 0 */ |
|||
|
|||
/* USER CODE END TIM4_MspInit 0 */ |
|||
/* TIM4 clock enable */ |
|||
__HAL_RCC_TIM4_CLK_ENABLE(); |
|||
/* USER CODE BEGIN TIM4_MspInit 1 */ |
|||
|
|||
/* USER CODE END TIM4_MspInit 1 */ |
|||
} |
|||
} |
|||
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle) |
|||
{ |
|||
|
|||
GPIO_InitTypeDef GPIO_InitStruct = {0}; |
|||
if(timHandle->Instance==TIM1) |
|||
{ |
|||
/* USER CODE BEGIN TIM1_MspPostInit 0 */ |
|||
|
|||
/* USER CODE END TIM1_MspPostInit 0 */ |
|||
|
|||
__HAL_RCC_GPIOE_CLK_ENABLE(); |
|||
/**TIM1 GPIO Configuration |
|||
PE9 ------> TIM1_CH1 |
|||
*/ |
|||
GPIO_InitStruct.Pin = GPIO_PIN_9; |
|||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
|||
GPIO_InitStruct.Pull = GPIO_NOPULL; |
|||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
|||
GPIO_InitStruct.Alternate = GPIO_AF1_TIM1; |
|||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); |
|||
|
|||
/* USER CODE BEGIN TIM1_MspPostInit 1 */ |
|||
|
|||
/* USER CODE END TIM1_MspPostInit 1 */ |
|||
} |
|||
|
|||
} |
|||
|
|||
void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* tim_pwmHandle) |
|||
{ |
|||
|
|||
if(tim_pwmHandle->Instance==TIM1) |
|||
{ |
|||
/* USER CODE BEGIN TIM1_MspDeInit 0 */ |
|||
|
|||
/* USER CODE END TIM1_MspDeInit 0 */ |
|||
/* Peripheral clock disable */ |
|||
__HAL_RCC_TIM1_CLK_DISABLE(); |
|||
/* USER CODE BEGIN TIM1_MspDeInit 1 */ |
|||
|
|||
/* USER CODE END TIM1_MspDeInit 1 */ |
|||
} |
|||
} |
|||
|
|||
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) |
|||
{ |
|||
|
|||
if(tim_baseHandle->Instance==TIM4) |
|||
{ |
|||
/* USER CODE BEGIN TIM4_MspDeInit 0 */ |
|||
|
|||
/* USER CODE END TIM4_MspDeInit 0 */ |
|||
/* Peripheral clock disable */ |
|||
__HAL_RCC_TIM4_CLK_DISABLE(); |
|||
/* USER CODE BEGIN TIM4_MspDeInit 1 */ |
|||
|
|||
/* USER CODE END TIM4_MspDeInit 1 */ |
|||
} |
|||
} |
|||
|
|||
/* USER CODE BEGIN 1 */ |
|||
|
|||
/* USER CODE END 1 */ |
224
app/MDK-ARM/app.uvguix.29643
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
316
app/MDK-ARM/app.uvoptx
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -1,79 +1,87 @@ |
|||
// #include "port.h" |
|||
// #include <stdint.h> |
|||
// #include <stdio.h> |
|||
// #include "main.h" |
|||
// // #include "modbus_processer.h" |
|||
// #include "port.h" |
|||
// // #include "tim.h" |
|||
// #include "usart.h" |
|||
// // |
|||
// /********************************************************************************************************************** |
|||
// * ===================================================printf重定向=================================================== * |
|||
// **********************************************************************************************************************/ |
|||
// int fputc(int ch, FILE* stream) { |
|||
// uint8_t c = ch; |
|||
// HAL_UART_Transmit(&DEBUG_UART, &c, 1, 100); |
|||
// return ch; |
|||
// } |
|||
// /*********************************************************************************************************************** |
|||
// * ====================================================调试指示灯===================================================== * |
|||
// ***********************************************************************************************************************/ |
|||
// void port_do_debug_light_state(void) { |
|||
// static uint32_t lastprocess = 0; |
|||
// if (sys_haspassedms(lastprocess) > 300) { |
|||
// lastprocess = HAL_GetTick(); |
|||
// HAL_GPIO_TogglePin(DEBUG_LIGHT_PORT, DEBUG_LIGHT_PIN); |
|||
// } |
|||
// } |
|||
// /*********************************************************************************************************************** |
|||
// * =====================================================串口相关====================================================== * |
|||
// ***********************************************************************************************************************/ |
|||
#include "port.h" |
|||
|
|||
// static uart_t m_uarts[] = { |
|||
// {&DEBUG_UART, 0}, |
|||
// // {&MODBUS_UART, 0}, |
|||
// }; |
|||
// __weak void port_mock_on_uart_rx(uart_t* uart) {} |
|||
// static void uarts_start_receive(uart_t* uart) { HAL_UART_Receive_IT(uart->uarthandler, &uart->rxbuf, 1); } |
|||
// void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart) { |
|||
// for (size_t i = 0; i < sizeof(m_uarts) / sizeof(uart_t); i++) { |
|||
// if (m_uarts[i].uarthandler == huart) { |
|||
// port_mock_on_uart_rx(&m_uarts[i]); |
|||
// uarts_start_receive(&m_uarts[i]); |
|||
// return; |
|||
// } |
|||
// } |
|||
// } |
|||
// void HAL_UART_ErrorCallback(UART_HandleTypeDef* huart) { |
|||
// for (size_t i = 0; i < sizeof(m_uarts) / sizeof(uart_t); i++) { |
|||
// if (m_uarts[i].uarthandler == huart) { |
|||
// uarts_start_receive(&m_uarts[i]); |
|||
// return; |
|||
// } |
|||
// } |
|||
// } |
|||
// // export |
|||
// void port_uart_start_all_uart_receive(void) { |
|||
// for (size_t i = 0; i < sizeof(m_uarts) / sizeof(uart_t); i++) { |
|||
// uarts_start_receive(&m_uarts[i]); |
|||
// } |
|||
// } |
|||
#include <stdint.h> |
|||
#include <stdio.h> |
|||
|
|||
// bool port_electric_relay_get_state(int relayindex) { |
|||
// /* |
|||
// example: |
|||
// if (relayindex == 1) { |
|||
// return GPIO_GET(C, 8, !!); |
|||
// } |
|||
// */ |
|||
#include "main.h" |
|||
// #include "modbus_processer.h" |
|||
#include "port.h" |
|||
#include "tim.h" |
|||
#include "usart.h" |
|||
|
|||
// return false; |
|||
// } |
|||
// void port_electric_relay_set_state(int relayindex, bool state) { |
|||
// /* |
|||
// example: |
|||
// if (relayindex == 1) { |
|||
// GPIO_SET(C, 8, !!, state); |
|||
// } |
|||
// */ |
|||
// } |
|||
// |
|||
#include "../../../iflytop_microcontroller/sdk/stm32/pwm.h" |
|||
#include "../../../iflytop_microcontroller/sdk/stm32/stm32sdk.h" |
|||
#include "../iflytop_microcontroller/sdk/stm32/pwm.h" |
|||
#include "../iflytop_microcontroller/sdk/stm32/stm32sdk.h" |
|||
|
|||
/********************************************************************************************************************** |
|||
* ===================================================printf重定向=================================================== * |
|||
**********************************************************************************************************************/ |
|||
int fputc(int ch, FILE* stream) { |
|||
uint8_t c = ch; |
|||
HAL_UART_Transmit(&DEBUG_UART, &c, 1, 100); |
|||
return ch; |
|||
} |
|||
/*********************************************************************************************************************** |
|||
* ====================================================调试指示灯===================================================== * |
|||
***********************************************************************************************************************/ |
|||
void port_do_debug_light_state(void) { |
|||
static uint32_t lastprocess = 0; |
|||
if (sys_haspassedms(lastprocess) > 300) { |
|||
lastprocess = HAL_GetTick(); |
|||
HAL_GPIO_TogglePin(DEBUG_LIGHT_PORT, DEBUG_LIGHT_PIN); |
|||
} |
|||
} |
|||
/*********************************************************************************************************************** |
|||
* =====================================================串口相关====================================================== * |
|||
***********************************************************************************************************************/ |
|||
|
|||
static uart_t m_uarts[] = { |
|||
{&DEBUG_UART, 0}, |
|||
// {&MODBUS_UART, 0}, |
|||
}; |
|||
__weak void port_mock_on_uart_rx(uart_t* uart) {} |
|||
static void uarts_start_receive(uart_t* uart) { HAL_UART_Receive_IT(uart->uarthandler, &uart->rxbuf, 1); } |
|||
void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart) { |
|||
for (size_t i = 0; i < sizeof(m_uarts) / sizeof(uart_t); i++) { |
|||
if (m_uarts[i].uarthandler == huart) { |
|||
port_mock_on_uart_rx(&m_uarts[i]); |
|||
uarts_start_receive(&m_uarts[i]); |
|||
return; |
|||
} |
|||
} |
|||
} |
|||
void HAL_UART_ErrorCallback(UART_HandleTypeDef* huart) { |
|||
for (size_t i = 0; i < sizeof(m_uarts) / sizeof(uart_t); i++) { |
|||
if (m_uarts[i].uarthandler == huart) { |
|||
uarts_start_receive(&m_uarts[i]); |
|||
return; |
|||
} |
|||
} |
|||
} |
|||
// export |
|||
void port_uart_start_all_uart_receive(void) { |
|||
for (size_t i = 0; i < sizeof(m_uarts) / sizeof(uart_t); i++) { |
|||
uarts_start_receive(&m_uarts[i]); |
|||
} |
|||
} |
|||
|
|||
bool port_electric_relay_get_state(int relayindex) { |
|||
/* |
|||
example: |
|||
if (relayindex == 1) { |
|||
return GPIO_GET(C, 8, !!); |
|||
} |
|||
*/ |
|||
|
|||
return false; |
|||
} |
|||
void port_electric_relay_set_state(int relayindex, bool state) { |
|||
/* |
|||
example: |
|||
if (relayindex == 1) { |
|||
GPIO_SET(C, 8, !!, state); |
|||
} |
|||
*/ |
|||
} |
@ -1,29 +1,35 @@ |
|||
// #pragma once |
|||
// #include <stdbool.h> |
|||
// #include <stdint.h> |
|||
// #include <stdio.h> |
|||
// // #include "tim.h" |
|||
// #include "usart.h" |
|||
// #include "zboard.h" |
|||
// #define GPIO_SET(port, pin, mirror, _state) \ |
|||
// HAL_GPIO_WritePin(GPIO##port, GPIO_PIN_##pin, mirror _state ? GPIO_PIN_SET : GPIO_PIN_RESET); |
|||
// #define GPIO_GET(port, pin, mirror) (mirror(HAL_GPIO_ReadPin(GPIO##port, GPIO_PIN_##pin) == GPIO_PIN_SET)) |
|||
// /*********************************************************************************************************************** |
|||
// * ====================================================调试指示灯===================================================== * |
|||
// ***********************************************************************************************************************/ |
|||
// void port_do_debug_light_state(void); |
|||
#pragma once |
|||
#include <stdbool.h> |
|||
#include <stdint.h> |
|||
#include <stdio.h> |
|||
|
|||
// /*********************************************************************************************************************** |
|||
// * =======================================================UART======================================================== * |
|||
// ***********************************************************************************************************************/ |
|||
// typedef struct { |
|||
// UART_HandleTypeDef* uarthandler; |
|||
// uint8_t rxbuf; |
|||
// } uart_t; |
|||
// void port_mock_on_uart_rx(uart_t* uart); |
|||
// void port_uart_start_all_uart_receive(void); |
|||
#include "tim.h" |
|||
#include "usart.h" |
|||
#include "zboard.h" |
|||
|
|||
// bool port_electric_relay_get_state(int relayindex); |
|||
// void port_electric_relay_set_state(int relayindex, bool state); |
|||
#define GPIO_SET(port, pin, mirror, _state) \ |
|||
HAL_GPIO_WritePin(GPIO##port, GPIO_PIN_##pin, mirror _state ? GPIO_PIN_SET : GPIO_PIN_RESET); |
|||
|
|||
// static inline bool port_get_gpio_int(int index) { return false; } |
|||
#define GPIO_GET(port, pin, mirror) (mirror(HAL_GPIO_ReadPin(GPIO##port, GPIO_PIN_##pin) == GPIO_PIN_SET)) |
|||
|
|||
/*********************************************************************************************************************** |
|||
* ====================================================调试指示灯===================================================== * |
|||
***********************************************************************************************************************/ |
|||
void port_do_debug_light_state(void); |
|||
|
|||
/*********************************************************************************************************************** |
|||
* =======================================================UART======================================================== * |
|||
***********************************************************************************************************************/ |
|||
typedef struct { |
|||
UART_HandleTypeDef* uarthandler; |
|||
uint8_t rxbuf; |
|||
} uart_t; |
|||
void port_mock_on_uart_rx(uart_t* uart); |
|||
void port_uart_start_all_uart_receive(void); |
|||
|
|||
bool port_electric_relay_get_state(int relayindex); |
|||
void port_electric_relay_set_state(int relayindex, bool state); |
|||
|
|||
static inline bool port_get_gpio_int(int index) { |
|||
return false; |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue