Симуляция генерации синусоидального шим и управление по модбас
note: - модбас не моделируется, в s-function просто передаются константы режимов. - лишние файлы убраны в outdate. - два канала одной фазы переключаются немного криво: на один такт симуляции проскакивает высокий уровень предыдущего канала и только потом включается текущий канал
This commit is contained in:
181
.outdate/Core_stm32f1/Src/adc.c
Normal file
181
.outdate/Core_stm32f1/Src/adc.c
Normal file
@@ -0,0 +1,181 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file adc.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the ADC instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 "adc.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
ADC_HandleTypeDef hadc1;
|
||||
|
||||
/* ADC1 init function */
|
||||
void MX_ADC1_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN ADC1_Init 0 */
|
||||
|
||||
/* USER CODE END ADC1_Init 0 */
|
||||
|
||||
ADC_AnalogWDGConfTypeDef AnalogWDGConfig = {0};
|
||||
ADC_InjectionConfTypeDef sConfigInjected = {0};
|
||||
|
||||
/* USER CODE BEGIN ADC1_Init 1 */
|
||||
|
||||
/* USER CODE END ADC1_Init 1 */
|
||||
|
||||
/** Common config
|
||||
*/
|
||||
hadc1.Instance = ADC1;
|
||||
hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
|
||||
hadc1.Init.ContinuousConvMode = ENABLE;
|
||||
hadc1.Init.DiscontinuousConvMode = DISABLE;
|
||||
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
||||
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
||||
hadc1.Init.NbrOfConversion = 1;
|
||||
if (HAL_ADC_Init(&hadc1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Configure Analog WatchDog 1
|
||||
*/
|
||||
AnalogWDGConfig.WatchdogMode = ADC_ANALOGWATCHDOG_SINGLE_INJEC;
|
||||
AnalogWDGConfig.HighThreshold = 4095;
|
||||
AnalogWDGConfig.LowThreshold = 3570;
|
||||
AnalogWDGConfig.Channel = ADC_CHANNEL_0;
|
||||
AnalogWDGConfig.ITMode = ENABLE;
|
||||
if (HAL_ADC_AnalogWDGConfig(&hadc1, &AnalogWDGConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Configure Injected Channel
|
||||
*/
|
||||
sConfigInjected.InjectedChannel = ADC_CHANNEL_0;
|
||||
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_1;
|
||||
sConfigInjected.InjectedNbrOfConversion = 2;
|
||||
sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_1CYCLE_5;
|
||||
sConfigInjected.ExternalTrigInjecConv = ADC_INJECTED_SOFTWARE_START;
|
||||
sConfigInjected.AutoInjectedConv = DISABLE;
|
||||
sConfigInjected.InjectedDiscontinuousConvMode = DISABLE;
|
||||
sConfigInjected.InjectedOffset = 0;
|
||||
if (HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Configure Injected Channel
|
||||
*/
|
||||
sConfigInjected.InjectedChannel = ADC_CHANNEL_1;
|
||||
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_2;
|
||||
if (HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN ADC1_Init 2 */
|
||||
|
||||
/* USER CODE END ADC1_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
|
||||
{
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(adcHandle->Instance==ADC1)
|
||||
{
|
||||
/* USER CODE BEGIN ADC1_MspInit 0 */
|
||||
|
||||
/* USER CODE END ADC1_MspInit 0 */
|
||||
/* ADC1 clock enable */
|
||||
__HAL_RCC_ADC1_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
/**ADC1 GPIO Configuration
|
||||
PA0-WKUP ------> ADC1_IN0
|
||||
PA1 ------> ADC1_IN1
|
||||
PA2 ------> ADC1_IN2
|
||||
PA3 ------> ADC1_IN3
|
||||
PA4 ------> ADC1_IN4
|
||||
PA5 ------> ADC1_IN5
|
||||
PA6 ------> ADC1_IN6
|
||||
PA7 ------> ADC1_IN7
|
||||
PB0 ------> ADC1_IN8
|
||||
PB1 ------> ADC1_IN9
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
|
||||
|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/* ADC1 interrupt Init */
|
||||
HAL_NVIC_SetPriority(ADC1_2_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(ADC1_2_IRQn);
|
||||
/* USER CODE BEGIN ADC1_MspInit 1 */
|
||||
|
||||
/* USER CODE END ADC1_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
|
||||
{
|
||||
|
||||
if(adcHandle->Instance==ADC1)
|
||||
{
|
||||
/* USER CODE BEGIN ADC1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END ADC1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_ADC1_CLK_DISABLE();
|
||||
|
||||
/**ADC1 GPIO Configuration
|
||||
PA0-WKUP ------> ADC1_IN0
|
||||
PA1 ------> ADC1_IN1
|
||||
PA2 ------> ADC1_IN2
|
||||
PA3 ------> ADC1_IN3
|
||||
PA4 ------> ADC1_IN4
|
||||
PA5 ------> ADC1_IN5
|
||||
PA6 ------> ADC1_IN6
|
||||
PA7 ------> ADC1_IN7
|
||||
PB0 ------> ADC1_IN8
|
||||
PB1 ------> ADC1_IN9
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
|
||||
|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
|
||||
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0|GPIO_PIN_1);
|
||||
|
||||
/* ADC1 interrupt Deinit */
|
||||
HAL_NVIC_DisableIRQ(ADC1_2_IRQn);
|
||||
/* USER CODE BEGIN ADC1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END ADC1_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
122
.outdate/Core_stm32f1/Src/can.c
Normal file
122
.outdate/Core_stm32f1/Src/can.c
Normal file
@@ -0,0 +1,122 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file can.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the CAN instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 "can.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
CAN_HandleTypeDef hcan;
|
||||
|
||||
/* CAN init function */
|
||||
void MX_CAN_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN CAN_Init 0 */
|
||||
|
||||
/* USER CODE END CAN_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN CAN_Init 1 */
|
||||
|
||||
/* USER CODE END CAN_Init 1 */
|
||||
hcan.Instance = CAN1;
|
||||
hcan.Init.Prescaler = 16;
|
||||
hcan.Init.Mode = CAN_MODE_NORMAL;
|
||||
hcan.Init.SyncJumpWidth = CAN_SJW_1TQ;
|
||||
hcan.Init.TimeSeg1 = CAN_BS1_15TQ;
|
||||
hcan.Init.TimeSeg2 = CAN_BS2_2TQ;
|
||||
hcan.Init.TimeTriggeredMode = DISABLE;
|
||||
hcan.Init.AutoBusOff = ENABLE;
|
||||
hcan.Init.AutoWakeUp = DISABLE;
|
||||
hcan.Init.AutoRetransmission = DISABLE;
|
||||
hcan.Init.ReceiveFifoLocked = DISABLE;
|
||||
hcan.Init.TransmitFifoPriority = ENABLE;
|
||||
if (HAL_CAN_Init(&hcan) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN CAN_Init 2 */
|
||||
|
||||
/* USER CODE END CAN_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
void HAL_CAN_MspInit(CAN_HandleTypeDef* canHandle)
|
||||
{
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(canHandle->Instance==CAN1)
|
||||
{
|
||||
/* USER CODE BEGIN CAN1_MspInit 0 */
|
||||
|
||||
/* USER CODE END CAN1_MspInit 0 */
|
||||
/* CAN1 clock enable */
|
||||
__HAL_RCC_CAN1_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
/**CAN GPIO Configuration
|
||||
PB8 ------> CAN_RX
|
||||
PB9 ------> CAN_TX
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_8;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_9;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
__HAL_AFIO_REMAP_CAN1_2();
|
||||
|
||||
/* USER CODE BEGIN CAN1_MspInit 1 */
|
||||
|
||||
/* USER CODE END CAN1_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_CAN_MspDeInit(CAN_HandleTypeDef* canHandle)
|
||||
{
|
||||
|
||||
if(canHandle->Instance==CAN1)
|
||||
{
|
||||
/* USER CODE BEGIN CAN1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END CAN1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_CAN1_CLK_DISABLE();
|
||||
|
||||
/**CAN GPIO Configuration
|
||||
PB8 ------> CAN_RX
|
||||
PB9 ------> CAN_TX
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9);
|
||||
|
||||
/* USER CODE BEGIN CAN1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END CAN1_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
261
.outdate/Core_stm32f1/Src/custom_ds18b20.c
Normal file
261
.outdate/Core_stm32f1/Src/custom_ds18b20.c
Normal file
@@ -0,0 +1,261 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : ds18b20.c
|
||||
* @brief : DS18B20 driver
|
||||
* @author : MicroTechnics (microtechnics.ru)
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "custom_ds18b20.h"
|
||||
#include "custom_onewire.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "usart.h"
|
||||
/* Declarations and definitions ----------------------------------------------*/
|
||||
// ROM commands
|
||||
static DS18B20_Command readRom = {.code = 0x33, .rxBytesNum = 8, .txBytesNum = 0};
|
||||
static DS18B20_Command skipRom = {.code = 0xCC, .rxBytesNum = 0, .txBytesNum = 0};
|
||||
// Function commands
|
||||
static DS18B20_Command readScratchpad = {.code = 0xBE, .rxBytesNum = 9, .txBytesNum = 0};
|
||||
static DS18B20_Command writeScratchpad = {.code = 0x4E, .rxBytesNum = 0, .txBytesNum = 3};
|
||||
static DS18B20_Command convertT = {.code = 0x44, .rxBytesNum = 0, .txBytesNum = 0};
|
||||
/* Functions -----------------------------------------------------------------*/
|
||||
extern UART_HandleTypeDef huart1;
|
||||
DS18B20 temperatureSensor;
|
||||
void InitRead_Sensors(void)
|
||||
{
|
||||
FirstStartDS18B(&temperatureSensor, &huart1);
|
||||
}
|
||||
void Read_Sensors(void)
|
||||
{
|
||||
Read_Temperature(&temperatureSensor, DS18B20_DELAY);
|
||||
}
|
||||
|
||||
void FirstStartDS18B(DS18B20 *sensor, UART_HandleTypeDef *huart)
|
||||
{
|
||||
DS18B20_Init(sensor, huart);
|
||||
DS18B20_InitializationCommand(sensor);
|
||||
DS18B20_ReadRom(sensor);
|
||||
DS18B20_ReadScratchpad(sensor);
|
||||
uint8_t settings[3];
|
||||
settings[0] = sensor->temperatureLimitHigh;
|
||||
settings[1] = sensor->temperatureLimitLow;
|
||||
settings[2] = DS18B20_12_BITS_CONFIG;
|
||||
DS18B20_InitializationCommand(sensor);
|
||||
DS18B20_SkipRom(sensor);
|
||||
DS18B20_WriteScratchpad(sensor, settings);
|
||||
}
|
||||
|
||||
void Read_Temperature(DS18B20 *sensor, DS18B20_WaitCondition waitCondition)
|
||||
{
|
||||
DS18B20_InitializationCommand(sensor);
|
||||
DS18B20_SkipRom(sensor);
|
||||
DS18B20_ConvertT(sensor, waitCondition);
|
||||
DS18B20_InitializationCommand(sensor);
|
||||
DS18B20_SkipRom(sensor);
|
||||
DS18B20_ReadScratchpad(sensor);
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static uint8_t CalculateChecksum(uint8_t *data, uint8_t length)
|
||||
{
|
||||
uint8_t checksum = 0;
|
||||
while (length--)
|
||||
{
|
||||
uint8_t currentByte = *data++;
|
||||
for (uint8_t i = 8; i; i--)
|
||||
{
|
||||
uint8_t temp = (checksum ^ currentByte) & 0x01;
|
||||
checksum >>= 1;
|
||||
if (temp)
|
||||
{
|
||||
checksum ^= 0x8C;
|
||||
}
|
||||
currentByte >>= 1;
|
||||
}
|
||||
}
|
||||
return checksum;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static DS18B20_Status ExecuteCommand(DS18B20 *sensor, DS18B20_Command command, uint8_t *data)
|
||||
{
|
||||
if (sensor->isConnected == 0)
|
||||
{
|
||||
return DS18B20_ERROR;
|
||||
}
|
||||
OneWire_ProcessByte(sensor->uart, command.code);
|
||||
if (command.rxBytesNum != 0)
|
||||
{
|
||||
for (uint8_t i = 0; i < command.rxBytesNum; i++)
|
||||
{
|
||||
data[i] = OneWire_ProcessByte(sensor->uart, 0xFF);
|
||||
}
|
||||
uint8_t checkSum = CalculateChecksum(data, command.rxBytesNum - 1);
|
||||
if (checkSum != data[command.rxBytesNum - 1])
|
||||
{
|
||||
return DS18B20_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (uint8_t i = 0; i < command.txBytesNum; i++)
|
||||
{
|
||||
OneWire_ProcessByte(sensor->uart, data[i]);
|
||||
}
|
||||
}
|
||||
return DS18B20_OK;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void WaitForConversionFinished(DS18B20 *sensor)
|
||||
{
|
||||
uint8_t data = OneWire_ProcessBit(sensor->uart, 1);
|
||||
while(data != 0xFF)
|
||||
{
|
||||
data = OneWire_ProcessBit(sensor->uart, 1);
|
||||
}
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
DS18B20_Status DS18B20_ConvertT(DS18B20 *sensor, DS18B20_WaitCondition waitCondition)
|
||||
{
|
||||
DS18B20_Status result;
|
||||
uint8_t rxDummyData;
|
||||
result = ExecuteCommand(sensor, convertT, &rxDummyData);
|
||||
if (waitCondition == DS18B20_DATA)
|
||||
{
|
||||
WaitForConversionFinished(sensor);
|
||||
}
|
||||
if (waitCondition == DS18B20_DELAY)
|
||||
{
|
||||
uint32_t delayValueMs = 0;
|
||||
switch (sensor->configRegister)
|
||||
{
|
||||
case DS18B20_9_BITS_CONFIG:
|
||||
delayValueMs = DS18B20_9_BITS_DELAY_MS;
|
||||
break;
|
||||
case DS18B20_10_BITS_CONFIG:
|
||||
delayValueMs = DS18B20_10_BITS_DELAY_MS;
|
||||
break;
|
||||
case DS18B20_11_BITS_CONFIG:
|
||||
delayValueMs = DS18B20_11_BITS_DELAY_MS;
|
||||
break;
|
||||
case DS18B20_12_BITS_CONFIG:
|
||||
delayValueMs = DS18B20_12_BITS_DELAY_MS;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
osDelay(delayValueMs);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
DS18B20_Status DS18B20_ReadScratchpad(DS18B20 *sensor)
|
||||
{
|
||||
DS18B20_Status result;
|
||||
uint8_t rxData[DS18B20_READ_SCRATCHPAD_RX_BYTES_NUM];
|
||||
result = ExecuteCommand(sensor, readScratchpad, rxData);
|
||||
if (result != DS18B20_OK)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
sensor->temperatureLimitHigh = rxData[DS18B20_SCRATCHPAD_T_LIMIT_H_BYTE_IDX];
|
||||
sensor->temperatureLimitLow = rxData[DS18B20_SCRATCHPAD_T_LIMIT_L_BYTE_IDX];
|
||||
sensor->configRegister = rxData[DS18B20_SCRATCHPAD_CONFIG_BYTE_IDX];
|
||||
uint16_t tRegValue = (rxData[DS18B20_SCRATCHPAD_T_MSB_BYTE_IDX] << 8) | rxData[DS18B20_SCRATCHPAD_T_LSB_BYTE_IDX];
|
||||
uint16_t sign = tRegValue & DS18B20_SIGN_MASK;
|
||||
if (sign != 0)
|
||||
{
|
||||
tRegValue = (0xFFFF - tRegValue + 1);
|
||||
}
|
||||
switch (sensor->configRegister)
|
||||
{
|
||||
case DS18B20_9_BITS_CONFIG:
|
||||
tRegValue &= DS18B20_9_BITS_DATA_MASK;
|
||||
break;
|
||||
case DS18B20_10_BITS_CONFIG:
|
||||
tRegValue &= DS18B20_10_BITS_DATA_MASK;
|
||||
break;
|
||||
case DS18B20_11_BITS_CONFIG:
|
||||
tRegValue &= DS18B20_11_BITS_DATA_MASK;
|
||||
break;
|
||||
case DS18B20_12_BITS_CONFIG:
|
||||
tRegValue &= DS18B20_12_BITS_DATA_MASK;
|
||||
break;
|
||||
default:
|
||||
tRegValue &= DS18B20_12_BITS_DATA_MASK;
|
||||
break;
|
||||
}
|
||||
sensor->temperature = (float)tRegValue * DS18B20_T_STEP;
|
||||
if (sign != 0)
|
||||
{
|
||||
sensor->temperature *= (-1);
|
||||
}
|
||||
return DS18B20_OK;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
DS18B20_Status DS18B20_WriteScratchpad(DS18B20 *sensor, uint8_t *data)
|
||||
{
|
||||
DS18B20_Status result;
|
||||
result = ExecuteCommand(sensor, writeScratchpad, data);
|
||||
if (result != DS18B20_OK)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
sensor->temperatureLimitHigh = data[0];
|
||||
sensor->temperatureLimitLow = data[1];
|
||||
sensor->configRegister = data[2];
|
||||
return result;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
DS18B20_Status DS18B20_InitializationCommand(DS18B20 *sensor)
|
||||
{
|
||||
if (sensor->isInitialized == 0)
|
||||
{
|
||||
return DS18B20_ERROR;
|
||||
}
|
||||
ONEWIRE_Status status = OneWire_Reset(sensor->uart);
|
||||
if (status == ONEWIRE_OK)
|
||||
{
|
||||
sensor->isConnected = 1;
|
||||
return DS18B20_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
sensor->isConnected = 0;
|
||||
return DS18B20_ERROR;
|
||||
}
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
DS18B20_Status DS18B20_ReadRom(DS18B20 *sensor)
|
||||
{
|
||||
DS18B20_Status result;
|
||||
uint8_t rxData[DS18B20_READ_ROM_RX_BYTES_NUM];
|
||||
result = ExecuteCommand(sensor, readRom, rxData);
|
||||
if (result != DS18B20_OK)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
for (uint8_t i = 0; i < DS18B20_SERIAL_NUMBER_LEN_BYTES; i++)
|
||||
{
|
||||
sensor->serialNumber[i] = rxData[DS18B20_SERIAL_NUMBER_OFFSET_BYTES + i];
|
||||
}
|
||||
return DS18B20_OK;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
DS18B20_Status DS18B20_SkipRom(DS18B20 *sensor)
|
||||
{
|
||||
DS18B20_Status result;
|
||||
uint8_t rxDummyData;
|
||||
result = ExecuteCommand(sensor, skipRom, &rxDummyData);
|
||||
if (result != DS18B20_OK)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
return DS18B20_OK;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void DS18B20_Init(DS18B20 *sensor, UART_HandleTypeDef *huart)
|
||||
{
|
||||
sensor->isConnected = 0;
|
||||
sensor->uart = huart;
|
||||
sensor->isInitialized = 1;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
3
.outdate/Core_stm32f1/Src/custom_flags.c
Normal file
3
.outdate/Core_stm32f1/Src/custom_flags.c
Normal file
@@ -0,0 +1,3 @@
|
||||
#include "custom_flags.h"
|
||||
|
||||
struct flags FLAGS;
|
||||
42
.outdate/Core_stm32f1/Src/custom_flash.c
Normal file
42
.outdate/Core_stm32f1/Src/custom_flash.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "custom_flash.h"
|
||||
FLASH_EraseInitTypeDef EraseInitStruct;
|
||||
//uint32_t PAGE_OFFSET = ((uint32_t)((4-1) * 0x0400));
|
||||
uint32_t PAGE_NUMB = 127;
|
||||
|
||||
|
||||
|
||||
|
||||
uint8_t *FLASH_Read(uint32_t add)
|
||||
{
|
||||
return (uint8_t *)add;
|
||||
}
|
||||
|
||||
void FLASH_Write_Data(void) //Куда записывать
|
||||
{
|
||||
HAL_StatusTypeDef res;
|
||||
|
||||
res = HAL_FLASH_Unlock();
|
||||
|
||||
res = HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, PAGE_NUMB, (uint32_t)(0x01234567));
|
||||
|
||||
|
||||
res = HAL_FLASH_Lock();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FLASH_Erase(void) //Что стирать
|
||||
{
|
||||
HAL_StatusTypeDef res;
|
||||
uint32_t PageError = 0x00;
|
||||
|
||||
res = HAL_FLASH_Unlock();
|
||||
|
||||
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;// erase pages
|
||||
EraseInitStruct.PageAddress = NVIC_VectTab_FLASH; //address
|
||||
EraseInitStruct.NbPages = 0x01;// num of erased pages
|
||||
|
||||
HAL_FLASHEx_Erase(&EraseInitStruct, &PageError);
|
||||
res = HAL_FLASH_Lock();
|
||||
}
|
||||
116
.outdate/Core_stm32f1/Src/custom_lcd.c
Normal file
116
.outdate/Core_stm32f1/Src/custom_lcd.c
Normal file
@@ -0,0 +1,116 @@
|
||||
#include "custom_lcd.h"
|
||||
#include "cmsis_os.h"
|
||||
#include <stdio.h>
|
||||
#include "iwdg.h"
|
||||
|
||||
extern unsigned tim1_cnt;
|
||||
extern I2C_HandleTypeDef hi2c1;
|
||||
uint16_t LCD_adr;
|
||||
|
||||
extern struct flags FLAGS;
|
||||
//extern struct var_result VAR_RESULT;
|
||||
//LCD Delays (Delay1 - )
|
||||
|
||||
void LCD_Reinit(void)
|
||||
{
|
||||
LCD_Init();
|
||||
FLAGS.LCD_REINIT=0;
|
||||
osDelay(1000);
|
||||
}
|
||||
void LCD_Check(void)
|
||||
{
|
||||
if(FLAGS.LCD_REINIT) LCD_Reinit();
|
||||
}
|
||||
|
||||
void LCD_Send_CMD (char cmd)
|
||||
{
|
||||
char data_up, data_low;
|
||||
uint8_t data_t[4];
|
||||
data_up = (cmd&0xf0);
|
||||
data_low=((cmd<<4)&0xf0);
|
||||
data_t[0]=data_up|0x0C; //en=1, rs=0
|
||||
data_t[1]=data_up|0x08; //en=0, rs=0
|
||||
data_t[2]=data_low|0x0C; //en=1, rs=0
|
||||
data_t[3]=data_low|0x08; //en=0, rs=0
|
||||
HAL_I2C_Master_Transmit(&hi2c1, LCD_adr, (uint8_t *)data_t, 4, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
void LCD_Send_DATA (char data)
|
||||
{
|
||||
char data_up, data_low;
|
||||
uint8_t data_t[4];
|
||||
data_up = (data&0xf0);
|
||||
data_low=((data<<4)&0xf0);
|
||||
data_t[0]=data_up|0x0D; //en=1, rs=1
|
||||
data_t[1]=data_up|0x09; //en=0, rs=1
|
||||
data_t[2]=data_low|0x0D; //en=1, rs=1
|
||||
data_t[3]=data_low|0x09; //en=0, rs=1
|
||||
HAL_I2C_Master_Transmit(&hi2c1, LCD_adr, (uint8_t *)data_t, 4, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
void LCD_Send_STRING(char *str)
|
||||
{
|
||||
while (*str) LCD_Send_DATA (*str++);
|
||||
}
|
||||
|
||||
void LCD_Send_INT(int int_to_string)
|
||||
{
|
||||
char string_from_int[10];
|
||||
snprintf(string_from_int, sizeof(string_from_int), "%d", int_to_string);
|
||||
LCD_Send_STRING(string_from_int);
|
||||
}
|
||||
|
||||
void LCD_Send_NUMB(float numb_to_string)
|
||||
{
|
||||
char string_from_numb[10];
|
||||
snprintf(string_from_numb, sizeof(string_from_numb), "%.3f", numb_to_string);
|
||||
LCD_Send_STRING(string_from_numb);
|
||||
}
|
||||
|
||||
|
||||
void LCD_Init(void)
|
||||
{
|
||||
for (LCD_adr = 0; LCD_adr < 128; LCD_adr++)
|
||||
{
|
||||
if(HAL_I2C_IsDeviceReady(&hi2c1, LCD_adr << 1, 1, HAL_MAX_DELAY)==HAL_OK) break; // scan i2c adresses
|
||||
}
|
||||
LCD_adr = LCD_adr << 1;
|
||||
|
||||
osDelay(500);
|
||||
LCD_Send_CMD(0x30);
|
||||
osDelay(5);
|
||||
LCD_Send_CMD(0x30);
|
||||
osDelay(1);
|
||||
LCD_Send_CMD(0x30);
|
||||
osDelay(10);
|
||||
LCD_Send_CMD(0x20); // 4bit mode
|
||||
osDelay(10);
|
||||
|
||||
//dislay initialisation
|
||||
LCD_Send_CMD(0x28); // display off
|
||||
osDelay(1);
|
||||
LCD_Send_CMD(0x08); // display off
|
||||
osDelay(50);
|
||||
LCD_Send_CMD(0x01); // clear display
|
||||
osDelay(10);
|
||||
osDelay(10);
|
||||
LCD_Send_CMD(0x06); // direction of cursor
|
||||
osDelay(1);
|
||||
LCD_Send_CMD(0x0C); // display on / cursor off
|
||||
}
|
||||
|
||||
void LCD_Start(void)
|
||||
{
|
||||
if(!(FLAGS.LCD_ON))
|
||||
{
|
||||
osDelay(3000);
|
||||
LCD_Init();
|
||||
MX_IWDG_Init();
|
||||
FLAGS.LCD_ON = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void LCD_IWDG_Reset(void)
|
||||
{
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
}
|
||||
70
.outdate/Core_stm32f1/Src/custom_led.c
Normal file
70
.outdate/Core_stm32f1/Src/custom_led.c
Normal file
@@ -0,0 +1,70 @@
|
||||
#include "custom_led.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "custom_flags.h"
|
||||
|
||||
extern struct flags FLAGS;
|
||||
|
||||
uint16_t UNDER_400V = 2500;
|
||||
void LED_Init(void)
|
||||
{
|
||||
GPIOC->ODR &= ~(1<<13);
|
||||
FLAGS.LED_WARNING_POSITION=1;
|
||||
}
|
||||
|
||||
void LED_Check(float R)
|
||||
{
|
||||
if(ADC1->JDR1>=3570) FLAGS.INSUFFICIENT_POWER_LEVEL=0;
|
||||
if(!(FLAGS.INSUFFICIENT_POWER_LEVEL)){
|
||||
if(R<500.0){ //Аварийный режим
|
||||
LED_EMERGENCY(FLAGS);
|
||||
}
|
||||
else if (toMega(R)<1.0){//Предупредительный режим
|
||||
LED_WARNING(FLAGS);
|
||||
}
|
||||
else {
|
||||
LED_STABLE(FLAGS);
|
||||
}}
|
||||
}
|
||||
void LED_Power_Less(void)
|
||||
{
|
||||
FLAGS.INSUFFICIENT_POWER_LEVEL=1;
|
||||
}
|
||||
uint16_t LED_Mode()
|
||||
{
|
||||
if (FLAGS.INSUFFICIENT_POWER_LEVEL)
|
||||
{
|
||||
GPIOC->ODR &= ~(1<<13);
|
||||
return 1000;
|
||||
}
|
||||
else if(FLAGS.LED_EMERGENCY_MODE)
|
||||
{
|
||||
GPIOC->ODR ^= 1<<13;
|
||||
FLAGS.LED_WARNING_POSITION=0;
|
||||
return 200;
|
||||
}
|
||||
else if(FLAGS.LED_WARNING_MODE){
|
||||
if(FLAGS.LED_WARNING_POSITION){
|
||||
GPIOC->ODR |= 1<<13;
|
||||
FLAGS.LED_WARNING_POSITION=0;
|
||||
return 1000;
|
||||
}
|
||||
else{
|
||||
GPIOC->ODR &= ~(1<<13);
|
||||
FLAGS.LED_WARNING_POSITION=1;
|
||||
return 1000;
|
||||
}
|
||||
}
|
||||
else{
|
||||
GPIOC->ODR |= 1<<13;
|
||||
FLAGS.LED_WARNING_POSITION=1;
|
||||
return 1000;
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc)
|
||||
{
|
||||
if(hadc->Instance == ADC1){
|
||||
LED_Power_Less();
|
||||
ADC1->LTR=UNDER_400V;
|
||||
}
|
||||
}
|
||||
89
.outdate/Core_stm32f1/Src/custom_onewire.c
Normal file
89
.outdate/Core_stm32f1/Src/custom_onewire.c
Normal file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : onewire.c
|
||||
* @brief : 1-Wire driver
|
||||
* @author : MicroTechnics (microtechnics.ru)
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "custom_onewire.h"
|
||||
#include "usart.h"
|
||||
/* Declarations and definitions ----------------------------------------------*/
|
||||
/* Functions -----------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void SetBaudrate(UART_HandleTypeDef *huart, uint32_t baudrate)
|
||||
{
|
||||
uint32_t pclk = 0;
|
||||
huart->Init.BaudRate = baudrate;
|
||||
#if defined(USART6) && defined(UART9) && defined(UART10)
|
||||
if ((huart->Instance == USART1) || (huart->Instance == USART6) ||
|
||||
(huart->Instance == UART9) || (huart->Instance == UART10))
|
||||
{
|
||||
pclk = HAL_RCC_GetPCLK2Freq();
|
||||
}
|
||||
#elif defined(USART6)
|
||||
if ((huart->Instance == USART1) || (huart->Instance == USART6))
|
||||
{
|
||||
pclk = HAL_RCC_GetPCLK2Freq();
|
||||
}
|
||||
#else
|
||||
if (huart->Instance == USART1)
|
||||
{
|
||||
pclk = HAL_RCC_GetPCLK2Freq();
|
||||
}
|
||||
#endif /* USART6 */
|
||||
else
|
||||
{
|
||||
pclk = HAL_RCC_GetPCLK1Freq();
|
||||
}
|
||||
|
||||
huart->Instance->BRR = UART_BRR_SAMPLING16(pclk, huart->Init.BaudRate);
|
||||
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
uint8_t OneWire_ProcessBit(UART_HandleTypeDef *huart, uint8_t bit)
|
||||
{
|
||||
uint8_t txData = 0xFF;
|
||||
uint8_t rxData = 0x00;
|
||||
if (bit == 0)
|
||||
{
|
||||
txData = 0x00;
|
||||
}
|
||||
HAL_UART_Transmit(huart, &txData, 1, ONEWIRE_UART_TIMEOUT);
|
||||
HAL_UART_Receive(huart, &rxData, 1, ONEWIRE_UART_TIMEOUT);
|
||||
return rxData;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
uint8_t OneWire_ProcessByte(UART_HandleTypeDef *huart, uint8_t byte)
|
||||
{
|
||||
uint8_t rxByte = 0x00;
|
||||
for (uint8_t i = 0; i < ONEWIRE_BITS_NUM; i++)
|
||||
{
|
||||
uint8_t txBit = (byte >> i) & 0x01;
|
||||
uint8_t rxBit = 0;
|
||||
uint8_t tempRxData = OneWire_ProcessBit(huart, txBit);
|
||||
if (tempRxData == 0xFF)
|
||||
{
|
||||
rxBit = 1;
|
||||
}
|
||||
rxByte |= (rxBit << i);
|
||||
}
|
||||
return rxByte;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
ONEWIRE_Status OneWire_Reset(UART_HandleTypeDef *huart)
|
||||
{
|
||||
ONEWIRE_Status status = ONEWIRE_OK;
|
||||
uint8_t txByte = ONEWIRE_RESET_BYTE;
|
||||
uint8_t rxByte = 0x00;
|
||||
SetBaudrate(huart, ONEWIRE_RESET_BAUDRATE);
|
||||
HAL_UART_Transmit(huart, &txByte, 1, ONEWIRE_UART_TIMEOUT);
|
||||
HAL_UART_Receive(huart, &rxByte, 1, ONEWIRE_UART_TIMEOUT);
|
||||
SetBaudrate(huart, ONEWIRE_BAUDRATE);
|
||||
if (rxByte == txByte)
|
||||
{
|
||||
status = ONEWIRE_ERROR;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
354
.outdate/Core_stm32f1/Src/custom_voltage_and_resistance.c
Normal file
354
.outdate/Core_stm32f1/Src/custom_voltage_and_resistance.c
Normal file
@@ -0,0 +1,354 @@
|
||||
#include "custom_voltage_and_resistance.h"
|
||||
#include "custom_led.h"
|
||||
#include "custom_lcd.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "custom_flags.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
extern ADC_HandleTypeDef hadc1;
|
||||
extern DMA_HandleTypeDef hdma_adc1;
|
||||
extern int cnt_adc_debug;
|
||||
unsigned ADC_Store;
|
||||
long long unsigned ADC_St;
|
||||
int adc_store_cnt;
|
||||
|
||||
int TimerDelay_1 = 1000;
|
||||
int TimerDelay_2 = 10;
|
||||
|
||||
|
||||
|
||||
unsigned ADC_Current_Position = 0;
|
||||
//Предупреждающий диапазон для разницы между средними значениями
|
||||
unsigned Warning_Range = 8; //8 - 30 sec, 7 - near 1 min
|
||||
//Аварийный диапазон для разницы между средними значениями
|
||||
unsigned Emergency_Range = 7;
|
||||
//(10/9 Emergency/Warning- probably stable range?) From calc (13/11 Emergency/Warning - extra stab) (13/12 last)
|
||||
|
||||
//Отладочная переменная-флаг для очистки счетчиков
|
||||
unsigned RedGreen_Erase = 0;
|
||||
//Счетчики некорректных показаний за пределами предупреждающим и аварийным диапазоном
|
||||
unsigned Warning_Range_Counter = 0;
|
||||
unsigned Emergency_Range_Counter = 0;
|
||||
|
||||
//Структура, в которой хранятся показания АЦП и сопутствующие обработке данные
|
||||
struct var_values VAR_VALUES;
|
||||
//Структура, в которой хранятся результаты вычисления напряжения и сопротивления
|
||||
struct var_result VAR_RESULT;
|
||||
//Структура, в которой хранится информация об ошибках и их количестве.
|
||||
struct error_of_voltage_and_resistance_calculation ERROR_OF_VAR;
|
||||
//Структура флагов проекта
|
||||
extern struct flags FLAGS;
|
||||
|
||||
unsigned ADC2_MN;
|
||||
unsigned ADC2_MX;
|
||||
unsigned ADC2_DELTA = 0;
|
||||
unsigned Pause_before_reading_ADC = 1;
|
||||
unsigned ADC1_MN;
|
||||
unsigned ADC1_MX;
|
||||
unsigned ADC1_DELTA = 0;
|
||||
long long unsigned Counter_of_opert = 0;
|
||||
unsigned ADC2_BEAST_MN=1999999;
|
||||
unsigned ADC2_BEAST_MX;
|
||||
unsigned ADC2_BEAST_DELTA = 0;
|
||||
|
||||
unsigned ADC1_BEAST_MN=138542385;
|
||||
unsigned ADC1_BEAST_MX;
|
||||
unsigned ADC1_BEAST_DELTA = 0;
|
||||
unsigned ZAMERKA_MN_MX_ADC = 0;
|
||||
|
||||
|
||||
// ADC2 при 7мОм 1443, то тогда U2_C = 88, U2_B = 0.8093, u1koef = 0.000860000087
|
||||
// ADC2 при 7мОм 1495, то тогда U2_c = 33.867, U2_B = 0.807, u1koef = 0.00085315
|
||||
float u1koef = (float) (0.000860000087); //0.00079869 0.00081425 old:000786139979 // 1mOhm 0.000824999996 0.000829999975
|
||||
float u2koef = (float) (0.0008);
|
||||
float u2shift = (float) (0.0700000077); //0.068 -> 0.0800000057. Last at 28.02 = 0.0700000077
|
||||
float err_delta = 0.1;
|
||||
float U2_A = 2; // 5
|
||||
float U2_B = 0.8093;//0.81848; //000817; //0.81848;//0,8093
|
||||
float U2_C = 88; //51.246; //0.0411;// 51.246;//42.409;//88
|
||||
float toMik = -0.000001;
|
||||
float Near_procent = 0.98;
|
||||
unsigned CounterofErrorOfJEOC = 0;
|
||||
|
||||
uint16_t VAR_Average(uint16_t *Arry_of_ADC_Values, uint16_t lenght)
|
||||
{
|
||||
//Функция принимает массив данных и его размер. После этого считает среднее значение и возвращает его.
|
||||
unsigned Average_Value = 0;
|
||||
|
||||
for(int i = 0; i<lenght; i++)
|
||||
{
|
||||
Average_Value+=Arry_of_ADC_Values[i];
|
||||
}
|
||||
|
||||
return (Average_Value/=lenght);
|
||||
}
|
||||
|
||||
void VAR_Average_Uint16(uint16_t *F, uint16_t *S)
|
||||
{
|
||||
// Average of two unsigned int
|
||||
uint16_t tmp = *F;
|
||||
*F = (*S+*F)/2;
|
||||
*S = tmp;
|
||||
}
|
||||
|
||||
void VAR_Cleaning_after_calculations(uint16_t *Arry_of_ADC_Values, uint16_t *lenght)
|
||||
{
|
||||
//Очищается массив
|
||||
for(int i = 0; i<(*lenght); i++)
|
||||
{
|
||||
Arry_of_ADC_Values[i]=0;
|
||||
}
|
||||
//Обнуляется количество элементов выборки
|
||||
*lenght=0;
|
||||
}
|
||||
|
||||
void VAR_Power_Turn_OnOff(void)
|
||||
{
|
||||
static int Buffer_Cleaning_Counter = 0;
|
||||
if(FLAGS.Power_Turn_On)
|
||||
{
|
||||
for(; Buffer_Cleaning_Counter < buffer_size; Buffer_Cleaning_Counter++)
|
||||
{
|
||||
VAR_VALUES.ADC1_[Buffer_Cleaning_Counter]=0;
|
||||
VAR_VALUES.ADC2_[Buffer_Cleaning_Counter]=0;
|
||||
VAR_VALUES.ADC1_Buff[Buffer_Cleaning_Counter]=0;
|
||||
VAR_VALUES.ADC2_Buff[Buffer_Cleaning_Counter]=0;
|
||||
ADC_Current_Position=0;
|
||||
}
|
||||
GPIOA->ODR &= ~(1<<11);
|
||||
osDelay(100);
|
||||
GPIOA->ODR |= (1<<12);
|
||||
}
|
||||
else
|
||||
{
|
||||
GPIOA->ODR &= ~(1<<12);
|
||||
osDelay(100);
|
||||
GPIOA->ODR |= (1<<11);
|
||||
Buffer_Cleaning_Counter=0;
|
||||
}
|
||||
}
|
||||
|
||||
void VAR_READ_ADC(void)
|
||||
{
|
||||
osDelay(Pause_before_reading_ADC);
|
||||
//Считываем значение первого инжектированного канала АЦП
|
||||
HAL_ADCEx_InjectedStart_IT(&hadc1);
|
||||
VAR_VALUES.ADC1_Buff[ADC_Current_Position] = ADC1->JDR1;
|
||||
//Считываем значение второго инжектированного канала АЦП
|
||||
osDelay(Pause_before_reading_ADC);
|
||||
HAL_ADCEx_InjectedStart_IT(&hadc1);
|
||||
VAR_VALUES.ADC2_Buff[ADC_Current_Position] = ADC1->JDR2;
|
||||
//Сдвигаем текущую позицию буффера на один шаг
|
||||
ADC_Current_Position++;
|
||||
|
||||
Counter_of_opert++;
|
||||
//Если буффер заполнен, то он проходит первичную обработку
|
||||
if(ADC_Current_Position==buffer_size)
|
||||
{
|
||||
//Вычисляем среднее значение по буфферу первого канала АЦП
|
||||
VAR_VALUES.ADC1_BUFF_MID_OLD = VAR_VALUES.ADC1_BUFF_MID;
|
||||
VAR_VALUES.ADC1_BUFF_MID = VAR_Average(VAR_VALUES.ADC1_Buff, ADC_Current_Position);
|
||||
VAR_Average_Uint16(&VAR_VALUES.ADC1_BUFF_MID, &VAR_VALUES.ADC1_BUFF_MID_OLD);
|
||||
//Вычисляем среднее значение по буфферу второго канала АЦП
|
||||
VAR_VALUES.ADC2_BUFF_MID_OLD = VAR_VALUES.ADC2_BUFF_MID;
|
||||
VAR_VALUES.ADC2_BUFF_MID = VAR_Average(VAR_VALUES.ADC2_Buff, ADC_Current_Position);
|
||||
VAR_Average_Uint16(&VAR_VALUES.ADC2_BUFF_MID, &VAR_VALUES.ADC2_BUFF_MID_OLD);
|
||||
//Проверяем стабильность показаний каналов АЦП
|
||||
VAR_Delta(&VAR_VALUES);
|
||||
//Если показания стабильны, то буффер проходит вторичную обработку
|
||||
if(FLAGS.STABLE_DELTA_CHECK || FLAGS.REFRESH_LCD_FROM_NONSTABLE_VALUE_ON)
|
||||
{
|
||||
//Формируем выборки по первому и второму каналам АЦП за исключением значений, выбивающихся из нормы
|
||||
for(int i = 0; i<ADC_Current_Position; i++)
|
||||
{
|
||||
//Первый канал АЦП
|
||||
if(abs(VAR_VALUES.ADC1_Buff[i]-VAR_VALUES.ADC1_BUFF_MID) <= VAR_VALUES.ADC1_BUFF_MID*err_delta)
|
||||
{
|
||||
VAR_VALUES.ADC1_[VAR_VALUES.ADC1_Correct_values_counter]=VAR_VALUES.ADC1_Buff[i];
|
||||
VAR_VALUES.ADC1_Correct_values_counter++;
|
||||
}
|
||||
/*
|
||||
else
|
||||
ERROR_OF_VAR.Count_of_incorrect_ADC_JDR1_value++;
|
||||
*/
|
||||
|
||||
//Второй канал АЦП
|
||||
if(abs(VAR_VALUES.ADC2_Buff[i]-VAR_VALUES.ADC2_BUFF_MID) <= VAR_VALUES.ADC2_BUFF_MID*err_delta)
|
||||
{
|
||||
VAR_VALUES.ADC2_[VAR_VALUES.ADC2_Correct_values_counter]=VAR_VALUES.ADC2_Buff[i];
|
||||
VAR_VALUES.ADC2_Correct_values_counter++;
|
||||
}
|
||||
/*
|
||||
else
|
||||
ERROR_OF_VAR.Count_of_incorrect_ADC_JDR2_value++;
|
||||
*/
|
||||
}
|
||||
//Расчитываем среднее значение выборки по первому каналу АЦП
|
||||
VAR_VALUES.ADC1_MID = VAR_Average(VAR_VALUES.ADC1_, VAR_VALUES.ADC1_Correct_values_counter);
|
||||
VAR_Average_Uint16(&VAR_VALUES.ADC1_MID, &VAR_VALUES.ADC1_MID_OLD);
|
||||
//Расчитываем среднее значение выборки по второму каналу АЦП
|
||||
VAR_VALUES.ADC2_MID = VAR_Average(VAR_VALUES.ADC2_, VAR_VALUES.ADC2_Correct_values_counter);
|
||||
VAR_Average_Uint16(&VAR_VALUES.ADC2_MID, &VAR_VALUES.ADC2_MID_OLD);
|
||||
//Производим вычисление напряжения и сопротивления
|
||||
VAR_Calculations(&VAR_VALUES, &VAR_RESULT);
|
||||
// //Производим очистку выборок
|
||||
// VAR_Cleaning_after_calculations(VAR_VALUES.ADC1_, &VAR_VALUES.ADC1_Correct_values_counter);
|
||||
// VAR_Cleaning_after_calculations(VAR_VALUES.ADC2_, &VAR_VALUES.ADC2_Correct_values_counter);
|
||||
}
|
||||
//Переходим к первым элементам буфферов
|
||||
ADC_Current_Position=0;
|
||||
|
||||
if (adc_store_cnt < 5000)
|
||||
{
|
||||
for (int i = 0; i < VAR_VALUES.ADC2_Correct_values_counter; i++)
|
||||
{
|
||||
ADC_St+=VAR_VALUES.ADC2_[i];
|
||||
//ADC_STORE[adc_store_cnt] = VAR_VALUES.ADC2_[i];
|
||||
adc_store_cnt++;
|
||||
|
||||
if(ADC2_MX<VAR_VALUES.ADC2_[i]) ADC2_MX = VAR_VALUES.ADC2_[i];
|
||||
if(ADC2_MN>VAR_VALUES.ADC2_[i]) ADC2_MN = VAR_VALUES.ADC2_[i];
|
||||
if (ADC2_MN == 0)
|
||||
{
|
||||
__ASM("");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ADC_Store=ADC_St/adc_store_cnt;
|
||||
ADC_St=0;
|
||||
adc_store_cnt=0;
|
||||
|
||||
|
||||
ADC2_DELTA=ADC2_MX-ADC2_MN;
|
||||
ADC2_MN=VAR_VALUES.ADC2_[0];
|
||||
ADC2_MX=VAR_VALUES.ADC2_[0];
|
||||
}
|
||||
|
||||
//Производим очистку выборок
|
||||
VAR_Cleaning_after_calculations(VAR_VALUES.ADC1_, &VAR_VALUES.ADC1_Correct_values_counter);
|
||||
VAR_Cleaning_after_calculations(VAR_VALUES.ADC2_, &VAR_VALUES.ADC2_Correct_values_counter);
|
||||
|
||||
// ADC_Current_Position&=~(buffer_size);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void VAR_Delta(struct var_values *VAR_VALUES)
|
||||
{
|
||||
//Сохраняем предыдущие значения разницы между двумя средними значениями
|
||||
VAR_VALUES->ADC1_DELTA_OLD = VAR_VALUES->ADC1_DELTA;
|
||||
VAR_VALUES->ADC2_DELTA_OLD = VAR_VALUES->ADC2_DELTA;
|
||||
//Вычисляем разницу между текущим средним значением и предыдущим
|
||||
VAR_VALUES->ADC1_DELTA=abs(VAR_VALUES->ADC1_BUFF_MID - VAR_VALUES->ADC1_BUFF_MID_OLD);
|
||||
VAR_VALUES->ADC2_DELTA=abs(VAR_VALUES->ADC2_BUFF_MID - VAR_VALUES->ADC2_BUFF_MID_OLD);
|
||||
//Функция обнуления счетчиков ошибок для отладки
|
||||
if(RedGreen_Erase) {
|
||||
Emergency_Range_Counter=0;
|
||||
Warning_Range_Counter=0;
|
||||
}
|
||||
//Если текущая разница отличается от прошлой на значение, выходящее за рамки аварийного диапазона
|
||||
if((VAR_VALUES->ADC2_DELTA + VAR_VALUES->ADC2_DELTA_OLD)/2 > Emergency_Range){
|
||||
//То сигнализируем о нестабильности показаний АЦП на втором канале
|
||||
FLAGS.STABLE_DELTA_CHECK=0;
|
||||
//Включаем красный светодиод
|
||||
GPIOC->ODR &= ~(1<<14);
|
||||
GPIOC->ODR |= (1<<15);
|
||||
//Увеличиваем счетчики некорректных показаний
|
||||
Emergency_Range_Counter++;
|
||||
Warning_Range_Counter++;
|
||||
|
||||
if(FLAGS.WAIT_TO_CALC_RANGE)
|
||||
Emergency_Range++;
|
||||
}
|
||||
//Иначе если текущая разница отличается от прошлой на значение, выходящее за рамки предупреждающего диапазона
|
||||
else if((VAR_VALUES->ADC2_DELTA + VAR_VALUES->ADC2_DELTA_OLD)/2 > Warning_Range){
|
||||
//Сигнализируем о нестабильности показаний АЦП на втором канале
|
||||
FLAGS.STABLE_DELTA_CHECK=0;
|
||||
//Включаем красный светодиод
|
||||
GPIOC->ODR &= ~(1<<14);
|
||||
GPIOC->ODR |= (1<<15);
|
||||
//Увеличиваем счетчик некорректных показаний
|
||||
Warning_Range_Counter++;
|
||||
|
||||
if(FLAGS.WAIT_TO_CALC_RANGE)
|
||||
Warning_Range++;
|
||||
}
|
||||
//Иначе сигнализируем о стабильном сигнале
|
||||
else{
|
||||
//Понижаем значение счетчика некорректных показаний
|
||||
if(Warning_Range_Counter>2)
|
||||
{
|
||||
Warning_Range_Counter-=3;
|
||||
}
|
||||
else if(Warning_Range_Counter>0)
|
||||
{
|
||||
Warning_Range_Counter--;
|
||||
}
|
||||
|
||||
if(Emergency_Range_Counter>0)
|
||||
{
|
||||
Emergency_Range_Counter--;
|
||||
}
|
||||
|
||||
//Если счетчик некорректных показаний принимает допустимое значение некорректных данных
|
||||
if(Warning_Range_Counter<3)
|
||||
{
|
||||
//Включаем зелёный светодиод
|
||||
GPIOC->ODR &= ~(1<<15 | 1<<14);
|
||||
GPIOC->ODR |= (1<<14);
|
||||
//Сигнализируем о стабильных показаниях АЦП на втором канале
|
||||
FLAGS.STABLE_DELTA_CHECK=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void VAR_Calculations(struct var_values *VAR_VALUES, struct var_result *VAR_RESULT)
|
||||
{
|
||||
// Store ADC measures
|
||||
VAR_VALUES->U1=(VAR_VALUES->ADC1_MID * u1koef); // U1 - Voltage on R1
|
||||
//VAR_VALUES->U2= u2koef * VAR_VALUES->ADC2_MID + u2shift; // U2 - Voltage for measure current
|
||||
//VAR_VALUES->U2= U2_A*toMik*VAR_VALUES->ADC2_MID*VAR_VALUES->ADC2_MID+U2_B*VAR_VALUES->ADC2_MID+U2_C;
|
||||
VAR_VALUES->U2=U2_B*VAR_VALUES->ADC2_MID+U2_C;
|
||||
VAR_VALUES->U2=VAR_VALUES->U2*Near_procent/1000;
|
||||
|
||||
VAR_RESULT->U_ALL_ADC = ((R1 + R2) * (VAR_VALUES->ADC1_MID)) / R1; // Total voltage //U_ALL_ADC
|
||||
VAR_RESULT->U_ALL = VAR_RESULT->U_ALL_ADC * u1koef;
|
||||
|
||||
VAR_RESULT->I = (VAR_VALUES->U2 )/ 35130; // Current
|
||||
|
||||
VAR_RESULT->R = VAR_RESULT->U_ALL / VAR_RESULT->I; // Total resistance
|
||||
|
||||
//VAR_RESULT->R-=((-0.0175*VAR_RESULT->R)+45309);
|
||||
|
||||
LED_Check(VAR_RESULT->R-4535000);
|
||||
}
|
||||
|
||||
void VAR_To_LCD(void)
|
||||
{
|
||||
LCD_Check();
|
||||
|
||||
LCD_Send_CMD(0x01); // clear display
|
||||
osDelay(TimerDelay_2);
|
||||
|
||||
LCD_Send_NUMB(VAR_RESULT.U_ALL);
|
||||
LCD_Send_STRING(" V");
|
||||
LCD_Send_CMD(0xC0);
|
||||
|
||||
// LED_Check(VAR_RESULT->R-4535000);
|
||||
|
||||
if((toMega(VAR_RESULT.R)-4.535)<0)
|
||||
LCD_Send_STRING("0.0");
|
||||
else if((toMega(VAR_RESULT.R)-4.535)>10)
|
||||
LCD_Send_STRING("INF");
|
||||
else
|
||||
LCD_Send_NUMB(toMega(VAR_RESULT.R)-4.535);
|
||||
|
||||
LCD_Send_STRING(" MOhm");
|
||||
LCD_IWDG_Reset();
|
||||
osDelay(TimerDelay_1);
|
||||
|
||||
}
|
||||
258
.outdate/Core_stm32f1/Src/freertos.c
Normal file
258
.outdate/Core_stm32f1/Src/freertos.c
Normal file
@@ -0,0 +1,258 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* File Name : freertos.c
|
||||
* Description : Code for freertos applications
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "main.h"
|
||||
#include "cmsis_os.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "custom_libs.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PTD */
|
||||
|
||||
/* USER CODE END PTD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Variables */
|
||||
|
||||
/* USER CODE END Variables */
|
||||
/* Definitions for ADC */
|
||||
osThreadId_t ADCHandle;
|
||||
const osThreadAttr_t ADC_attributes = {
|
||||
.name = "ADC",
|
||||
.stack_size = 128 * 4,
|
||||
.priority = (osPriority_t) osPriorityNormal,
|
||||
};
|
||||
/* Definitions for LED */
|
||||
osThreadId_t LEDHandle;
|
||||
const osThreadAttr_t LED_attributes = {
|
||||
.name = "LED",
|
||||
.stack_size = 128 * 4,
|
||||
.priority = (osPriority_t) osPriorityLow,
|
||||
};
|
||||
/* Definitions for CalcDisplay */
|
||||
osThreadId_t CalcDisplayHandle;
|
||||
const osThreadAttr_t CalcDisplay_attributes = {
|
||||
.name = "CalcDisplay",
|
||||
.stack_size = 128 * 4,
|
||||
.priority = (osPriority_t) osPriorityLow,
|
||||
};
|
||||
/* Definitions for Sensors */
|
||||
osThreadId_t SensorsHandle;
|
||||
const osThreadAttr_t Sensors_attributes = {
|
||||
.name = "Sensors",
|
||||
.stack_size = 128 * 4,
|
||||
.priority = (osPriority_t) osPriorityLow,
|
||||
};
|
||||
/* Definitions for LCD */
|
||||
osThreadId_t LCDHandle;
|
||||
const osThreadAttr_t LCD_attributes = {
|
||||
.name = "LCD",
|
||||
.stack_size = 128 * 4,
|
||||
.priority = (osPriority_t) osPriorityLow,
|
||||
};
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN FunctionPrototypes */
|
||||
|
||||
/* USER CODE END FunctionPrototypes */
|
||||
|
||||
void ADC_Task(void *argument);
|
||||
void LED_Task(void *argument);
|
||||
void Calculation_and_Display(void *argument);
|
||||
void Sensors_Task(void *argument);
|
||||
void LCD_Task(void *argument);
|
||||
|
||||
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
|
||||
|
||||
/**
|
||||
* @brief FreeRTOS initialization
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void MX_FREERTOS_Init(void) {
|
||||
/* USER CODE BEGIN Init */
|
||||
|
||||
/* USER CODE END Init */
|
||||
|
||||
/* USER CODE BEGIN RTOS_MUTEX */
|
||||
/* add mutexes, ... */
|
||||
/* USER CODE END RTOS_MUTEX */
|
||||
|
||||
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
||||
/* add semaphores, ... */
|
||||
/* USER CODE END RTOS_SEMAPHORES */
|
||||
|
||||
/* USER CODE BEGIN RTOS_TIMERS */
|
||||
/* start timers, add new ones, ... */
|
||||
/* USER CODE END RTOS_TIMERS */
|
||||
|
||||
/* USER CODE BEGIN RTOS_QUEUES */
|
||||
/* add queues, ... */
|
||||
/* USER CODE END RTOS_QUEUES */
|
||||
|
||||
/* Create the thread(s) */
|
||||
/* creation of ADC */
|
||||
ADCHandle = osThreadNew(ADC_Task, NULL, &ADC_attributes);
|
||||
|
||||
/* creation of LED */
|
||||
LEDHandle = osThreadNew(LED_Task, NULL, &LED_attributes);
|
||||
|
||||
/* creation of CalcDisplay */
|
||||
CalcDisplayHandle = osThreadNew(Calculation_and_Display, NULL, &CalcDisplay_attributes);
|
||||
|
||||
/* creation of Sensors */
|
||||
SensorsHandle = osThreadNew(Sensors_Task, NULL, &Sensors_attributes);
|
||||
|
||||
/* creation of LCD */
|
||||
LCDHandle = osThreadNew(LCD_Task, NULL, &LCD_attributes);
|
||||
|
||||
/* USER CODE BEGIN RTOS_THREADS */
|
||||
/* add threads, ... */
|
||||
/* USER CODE END RTOS_THREADS */
|
||||
|
||||
/* USER CODE BEGIN RTOS_EVENTS */
|
||||
/* add events, ... */
|
||||
/* USER CODE END RTOS_EVENTS */
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Header_ADC_Task */
|
||||
/**
|
||||
* @brief Function implementing the ADC thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_ADC_Task */
|
||||
void ADC_Task(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN ADC_Task */
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
//Сделать пропуск значений на 10% отлич. от среднего значению.
|
||||
VAR_READ_ADC();
|
||||
//osDelay(1);
|
||||
}
|
||||
/* USER CODE END ADC_Task */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Header_LED_Task */
|
||||
/**
|
||||
* @brief Function implementing the LED thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_LED_Task */
|
||||
void LED_Task(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN LED_Task */
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
osDelay(LED_Mode());
|
||||
}
|
||||
/* USER CODE END LED_Task */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Header_Calculation_and_Display */
|
||||
/**
|
||||
* @brief Function implementing the CalcDisplay thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_Calculation_and_Display */
|
||||
void Calculation_and_Display(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN Calculation_and_Display */
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
// osDelay(1);
|
||||
// if((ADC1->SR&ADC_SR_EOC)!=0)
|
||||
// {
|
||||
// GPIOC->ODR |= (1<<14);
|
||||
// __ASM("nop");
|
||||
// }
|
||||
VAR_Power_Turn_OnOff();
|
||||
osDelay(1);
|
||||
|
||||
}
|
||||
/* USER CODE END Calculation_and_Display */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Header_Sensors_Task */
|
||||
/**
|
||||
* @brief Function implementing the Sensors thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_Sensors_Task */
|
||||
void Sensors_Task(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN Sensors_Task */
|
||||
//InitRead_Sensors();
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
//Read_Sensors();
|
||||
osDelay(10);
|
||||
}
|
||||
/* USER CODE END Sensors_Task */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Header_LCD_Task */
|
||||
/**
|
||||
* @brief Function implementing the LCD thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_LCD_Task */
|
||||
void LCD_Task(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN LCD_Task */
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
LCD_Start();
|
||||
VAR_To_LCD();
|
||||
}
|
||||
/* USER CODE END LCD_Task */
|
||||
}
|
||||
|
||||
/* Private application code --------------------------------------------------*/
|
||||
/* USER CODE BEGIN Application */
|
||||
|
||||
/* USER CODE END Application */
|
||||
|
||||
102
.outdate/Core_stm32f1/Src/gpio.c
Normal file
102
.outdate/Core_stm32f1/Src/gpio.c
Normal file
@@ -0,0 +1,102 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file gpio.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of all used GPIO pins.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 "gpio.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Configure GPIO */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/** Configure pins as
|
||||
* Analog
|
||||
* Input
|
||||
* Output
|
||||
* EVENT_OUT
|
||||
* EXTI
|
||||
*/
|
||||
void MX_GPIO_Init(void)
|
||||
{
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin : PC13 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_13;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 2 */
|
||||
void CUSTOM_GPIO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin : PA11 and PA12 for Relay*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PC14 and PC15 for LED*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PB12 PB13 PB14 for control*/
|
||||
GPIO_InitStruct.Pin = SW_Reinit_Pin|SW_LCD_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
HAL_GPIO_Init(SW_Port, &GPIO_InitStruct);
|
||||
|
||||
|
||||
GPIO_InitStruct.Pin = SW_Power_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
HAL_GPIO_Init(SW_Port, &GPIO_InitStruct);
|
||||
|
||||
/* EXTI interrupt init*/
|
||||
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||
}
|
||||
/* USER CODE END 2 */
|
||||
123
.outdate/Core_stm32f1/Src/i2c.c
Normal file
123
.outdate/Core_stm32f1/Src/i2c.c
Normal file
@@ -0,0 +1,123 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file i2c.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the I2C instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 "i2c.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
I2C_HandleTypeDef hi2c1;
|
||||
|
||||
/* I2C1 init function */
|
||||
void MX_I2C1_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN I2C1_Init 0 */
|
||||
|
||||
/* USER CODE END I2C1_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN I2C1_Init 1 */
|
||||
|
||||
/* USER CODE END I2C1_Init 1 */
|
||||
hi2c1.Instance = I2C1;
|
||||
hi2c1.Init.ClockSpeed = 100000;
|
||||
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
||||
hi2c1.Init.OwnAddress1 = 0;
|
||||
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
||||
hi2c1.Init.OwnAddress2 = 0;
|
||||
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
||||
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
||||
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN I2C1_Init 2 */
|
||||
|
||||
/* USER CODE END I2C1_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle)
|
||||
{
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(i2cHandle->Instance==I2C1)
|
||||
{
|
||||
/* USER CODE BEGIN I2C1_MspInit 0 */
|
||||
|
||||
/* USER CODE END I2C1_MspInit 0 */
|
||||
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
/**I2C1 GPIO Configuration
|
||||
PB6 ------> I2C1_SCL
|
||||
PB7 ------> I2C1_SDA
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/* I2C1 clock enable */
|
||||
__HAL_RCC_I2C1_CLK_ENABLE();
|
||||
|
||||
/* I2C1 interrupt Init */
|
||||
HAL_NVIC_SetPriority(I2C1_EV_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(I2C1_EV_IRQn);
|
||||
HAL_NVIC_SetPriority(I2C1_ER_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(I2C1_ER_IRQn);
|
||||
/* USER CODE BEGIN I2C1_MspInit 1 */
|
||||
|
||||
/* USER CODE END I2C1_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_I2C_MspDeInit(I2C_HandleTypeDef* i2cHandle)
|
||||
{
|
||||
|
||||
if(i2cHandle->Instance==I2C1)
|
||||
{
|
||||
/* USER CODE BEGIN I2C1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END I2C1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_I2C1_CLK_DISABLE();
|
||||
|
||||
/**I2C1 GPIO Configuration
|
||||
PB6 ------> I2C1_SCL
|
||||
PB7 ------> I2C1_SDA
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6);
|
||||
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7);
|
||||
|
||||
/* I2C1 interrupt Deinit */
|
||||
HAL_NVIC_DisableIRQ(I2C1_EV_IRQn);
|
||||
HAL_NVIC_DisableIRQ(I2C1_ER_IRQn);
|
||||
/* USER CODE BEGIN I2C1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END I2C1_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
55
.outdate/Core_stm32f1/Src/iwdg.c
Normal file
55
.outdate/Core_stm32f1/Src/iwdg.c
Normal file
@@ -0,0 +1,55 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file iwdg.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the IWDG instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 "iwdg.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
IWDG_HandleTypeDef hiwdg;
|
||||
|
||||
/* IWDG init function */
|
||||
void MX_IWDG_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN IWDG_Init 0 */
|
||||
|
||||
/* USER CODE END IWDG_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN IWDG_Init 1 */
|
||||
|
||||
/* USER CODE END IWDG_Init 1 */
|
||||
hiwdg.Instance = IWDG;
|
||||
hiwdg.Init.Prescaler = IWDG_PRESCALER_64;
|
||||
hiwdg.Init.Reload = 1875;
|
||||
if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN IWDG_Init 2 */
|
||||
|
||||
/* USER CODE END IWDG_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
250
.outdate/Core_stm32f1/Src/main.c
Normal file
250
.outdate/Core_stm32f1/Src/main.c
Normal file
@@ -0,0 +1,250 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.c
|
||||
* @brief : Main program body
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 "main.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "adc.h"
|
||||
#include "can.h"
|
||||
#include "i2c.h"
|
||||
#include "iwdg.h"
|
||||
#include "rtc.h"
|
||||
#include "tim.h"
|
||||
#include "usart.h"
|
||||
#include "gpio.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
//int InitFlag = 0;
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PTD */
|
||||
extern struct flags FLAGS;
|
||||
/* USER CODE END PTD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void SystemClock_Config(void);
|
||||
void MX_FREERTOS_Init(void);
|
||||
/* USER CODE BEGIN PFP */
|
||||
extern DS18B20 temperatureSensor;
|
||||
extern DS18B20_Status res;
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
extern uint32_t PAGE_OFFSET;
|
||||
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
/* USER CODE BEGIN 1 */
|
||||
HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(USART1_IRQn);
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||
HAL_Init();
|
||||
|
||||
/* USER CODE BEGIN Init */
|
||||
|
||||
/* USER CODE END Init */
|
||||
|
||||
/* Configure the system clock */
|
||||
SystemClock_Config();
|
||||
|
||||
/* USER CODE BEGIN SysInit */
|
||||
/* USER CODE END SysInit */
|
||||
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
MX_USART1_UART_Init();
|
||||
MX_TIM1_Init();
|
||||
MX_TIM2_Init();
|
||||
MX_ADC1_Init();
|
||||
MX_I2C1_Init();
|
||||
MX_CAN_Init();
|
||||
//MX_IWDG_Init();
|
||||
MX_RTC_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
CUSTOM_GPIO_Init();
|
||||
HAL_TIM_Base_Start_IT(&htim1);
|
||||
HAL_ADCEx_InjectedStart_IT(&hadc1);
|
||||
FLAGS.Power_Turn_On=((SW_Port->IDR>>13)&1);
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Init scheduler */
|
||||
osKernelInitialize(); /* Call init function for freertos objects (in freertos.c) */
|
||||
MX_FREERTOS_Init();
|
||||
|
||||
/* Start scheduler */
|
||||
osKernelStart();
|
||||
/* We should never get here as control is now taken by the scheduler */
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
|
||||
while (1)
|
||||
{
|
||||
// uint8_t *res;
|
||||
// FLASH_Erase();
|
||||
// FLASH_Write_Data();
|
||||
// res = FLASH_Read(ADD_CURRENT_PAGE);
|
||||
//
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void)
|
||||
{
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
||||
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE
|
||||
|RCC_OSCILLATORTYPE_LSE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
|
||||
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_ADC;
|
||||
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
|
||||
PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
|
||||
/* USER CODE END 4 */
|
||||
|
||||
/**
|
||||
* @brief Period elapsed callback in non blocking mode
|
||||
* @note This function is called when TIM4 interrupt took place, inside
|
||||
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||
* a global variable "uwTick" used as application time base.
|
||||
* @param htim : TIM handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
/* USER CODE BEGIN Callback 0 */
|
||||
|
||||
/* USER CODE END Callback 0 */
|
||||
if (htim->Instance == TIM4) {
|
||||
HAL_IncTick();
|
||||
}
|
||||
/* USER CODE BEGIN Callback 1 */
|
||||
|
||||
/* USER CODE END Callback 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
*/
|
||||
void Error_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN Error_Handler_Debug */
|
||||
/* User can add his own implementation to report the HAL error return state */
|
||||
__disable_irq();
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief Reports the name of the source file and the source line number
|
||||
* where the assert_param error has occurred.
|
||||
* @param file: pointer to the source file name
|
||||
* @param line: assert_param error line source number
|
||||
* @retval None
|
||||
*/
|
||||
void assert_failed(uint8_t *file, uint32_t line)
|
||||
{
|
||||
/* USER CODE BEGIN 6 */
|
||||
/* User can add his own implementation to report the file name and line number,
|
||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||
/* USER CODE END 6 */
|
||||
}
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
120
.outdate/Core_stm32f1/Src/rtc.c
Normal file
120
.outdate/Core_stm32f1/Src/rtc.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rtc.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the RTC instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 "rtc.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
RTC_HandleTypeDef hrtc;
|
||||
|
||||
/* RTC init function */
|
||||
void MX_RTC_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN RTC_Init 0 */
|
||||
|
||||
/* USER CODE END RTC_Init 0 */
|
||||
|
||||
RTC_TimeTypeDef sTime = {0};
|
||||
RTC_DateTypeDef DateToUpdate = {0};
|
||||
|
||||
/* USER CODE BEGIN RTC_Init 1 */
|
||||
|
||||
/* USER CODE END RTC_Init 1 */
|
||||
|
||||
/** Initialize RTC Only
|
||||
*/
|
||||
hrtc.Instance = RTC;
|
||||
hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
|
||||
hrtc.Init.OutPut = RTC_OUTPUTSOURCE_NONE;
|
||||
if (HAL_RTC_Init(&hrtc) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Check_RTC_BKUP */
|
||||
|
||||
/* USER CODE END Check_RTC_BKUP */
|
||||
|
||||
/** Initialize RTC and set the Time and Date
|
||||
*/
|
||||
// sTime.Hours = 16;
|
||||
// sTime.Minutes = 0;
|
||||
// sTime.Seconds = 0;
|
||||
|
||||
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
// DateToUpdate.WeekDay = RTC_WEEKDAY_TUESDAY;
|
||||
// DateToUpdate.Month = RTC_MONTH_MARCH;
|
||||
// DateToUpdate.Date = 12;
|
||||
// DateToUpdate.Year = 54;
|
||||
|
||||
if (HAL_RTC_SetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BIN) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN RTC_Init 2 */
|
||||
|
||||
/* USER CODE END RTC_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)
|
||||
{
|
||||
|
||||
if(rtcHandle->Instance==RTC)
|
||||
{
|
||||
/* USER CODE BEGIN RTC_MspInit 0 */
|
||||
|
||||
/* USER CODE END RTC_MspInit 0 */
|
||||
HAL_PWR_EnableBkUpAccess();
|
||||
/* Enable BKP CLK enable for backup registers */
|
||||
__HAL_RCC_BKP_CLK_ENABLE();
|
||||
/* RTC clock enable */
|
||||
__HAL_RCC_RTC_ENABLE();
|
||||
/* USER CODE BEGIN RTC_MspInit 1 */
|
||||
|
||||
/* USER CODE END RTC_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_RTC_MspDeInit(RTC_HandleTypeDef* rtcHandle)
|
||||
{
|
||||
|
||||
if(rtcHandle->Instance==RTC)
|
||||
{
|
||||
/* USER CODE BEGIN RTC_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END RTC_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_RTC_DISABLE();
|
||||
/* USER CODE BEGIN RTC_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END RTC_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
87
.outdate/Core_stm32f1/Src/stm32f1xx_hal_msp.c
Normal file
87
.outdate/Core_stm32f1/Src/stm32f1xx_hal_msp.c
Normal file
@@ -0,0 +1,87 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f1xx_hal_msp.c
|
||||
* @brief This file provides code for the MSP Initialization
|
||||
* and de-Initialization codes.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 "main.h"
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN TD */
|
||||
|
||||
/* USER CODE END TD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Define */
|
||||
|
||||
/* USER CODE END Define */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Macro */
|
||||
|
||||
/* USER CODE END Macro */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* External functions --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ExternalFunctions */
|
||||
|
||||
/* USER CODE END ExternalFunctions */
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
/**
|
||||
* Initializes the Global MSP.
|
||||
*/
|
||||
void HAL_MspInit(void)
|
||||
{
|
||||
/* USER CODE BEGIN MspInit 0 */
|
||||
|
||||
/* USER CODE END MspInit 0 */
|
||||
|
||||
__HAL_RCC_AFIO_CLK_ENABLE();
|
||||
__HAL_RCC_PWR_CLK_ENABLE();
|
||||
|
||||
/* System interrupt init*/
|
||||
/* PendSV_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0);
|
||||
|
||||
/** NOJTAG: JTAG-DP Disabled and SW-DP Enabled
|
||||
*/
|
||||
__HAL_AFIO_REMAP_SWJ_NOJTAG();
|
||||
|
||||
/* USER CODE BEGIN MspInit 1 */
|
||||
|
||||
/* USER CODE END MspInit 1 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
138
.outdate/Core_stm32f1/Src/stm32f1xx_hal_timebase_tim.c
Normal file
138
.outdate/Core_stm32f1/Src/stm32f1xx_hal_timebase_tim.c
Normal file
@@ -0,0 +1,138 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f1xx_hal_timebase_TIM.c
|
||||
* @brief HAL time base based on the hardware TIM.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 "stm32f1xx_hal.h"
|
||||
#include "stm32f1xx_hal_tim.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
TIM_HandleTypeDef htim4;
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void TIM4_IRQHandler(void);
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief This function configures the TIM4 as a time base source.
|
||||
* The time source is configured to have 1ms time base with a dedicated
|
||||
* Tick interrupt priority.
|
||||
* @note This function is called automatically at the beginning of program after
|
||||
* reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig().
|
||||
* @param TickPriority: Tick interrupt priority.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||
{
|
||||
RCC_ClkInitTypeDef clkconfig;
|
||||
uint32_t uwTimclock, uwAPB1Prescaler = 0U;
|
||||
|
||||
uint32_t uwPrescalerValue = 0U;
|
||||
uint32_t pFLatency;
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Enable TIM4 clock */
|
||||
__HAL_RCC_TIM4_CLK_ENABLE();
|
||||
|
||||
/* Get clock configuration */
|
||||
HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
|
||||
|
||||
/* Get APB1 prescaler */
|
||||
uwAPB1Prescaler = clkconfig.APB1CLKDivider;
|
||||
/* Compute TIM4 clock */
|
||||
if (uwAPB1Prescaler == RCC_HCLK_DIV1)
|
||||
{
|
||||
uwTimclock = HAL_RCC_GetPCLK1Freq();
|
||||
}
|
||||
else
|
||||
{
|
||||
uwTimclock = 2UL * HAL_RCC_GetPCLK1Freq();
|
||||
}
|
||||
|
||||
/* Compute the prescaler value to have TIM4 counter clock equal to 1MHz */
|
||||
uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
|
||||
|
||||
/* Initialize TIM4 */
|
||||
htim4.Instance = TIM4;
|
||||
|
||||
/* Initialize TIMx peripheral as follow:
|
||||
|
||||
+ Period = [(TIM4CLK/1000) - 1]. to have a (1/1000) s time base.
|
||||
+ Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
|
||||
+ ClockDivision = 0
|
||||
+ Counter direction = Up
|
||||
*/
|
||||
htim4.Init.Period = (1000000U / 1000U) - 1U;
|
||||
htim4.Init.Prescaler = uwPrescalerValue;
|
||||
htim4.Init.ClockDivision = 0;
|
||||
htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
|
||||
status = HAL_TIM_Base_Init(&htim4);
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
/* Start the TIM time Base generation in interrupt mode */
|
||||
status = HAL_TIM_Base_Start_IT(&htim4);
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
/* Enable the TIM4 global Interrupt */
|
||||
HAL_NVIC_EnableIRQ(TIM4_IRQn);
|
||||
/* Configure the SysTick IRQ priority */
|
||||
if (TickPriority < (1UL << __NVIC_PRIO_BITS))
|
||||
{
|
||||
/* Configure the TIM IRQ priority */
|
||||
HAL_NVIC_SetPriority(TIM4_IRQn, TickPriority, 0U);
|
||||
uwTickPrio = TickPriority;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Return function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Suspend Tick increment.
|
||||
* @note Disable the tick increment by disabling TIM4 update interrupt.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SuspendTick(void)
|
||||
{
|
||||
/* Disable TIM4 update Interrupt */
|
||||
__HAL_TIM_DISABLE_IT(&htim4, TIM_IT_UPDATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resume Tick increment.
|
||||
* @note Enable the tick increment by Enabling TIM4 update interrupt.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ResumeTick(void)
|
||||
{
|
||||
/* Enable TIM4 Update interrupt */
|
||||
__HAL_TIM_ENABLE_IT(&htim4, TIM_IT_UPDATE);
|
||||
}
|
||||
|
||||
304
.outdate/Core_stm32f1/Src/stm32f1xx_it.c
Normal file
304
.outdate/Core_stm32f1/Src/stm32f1xx_it.c
Normal file
@@ -0,0 +1,304 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f1xx_it.c
|
||||
* @brief Interrupt Service Routines.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 "main.h"
|
||||
#include "stm32f1xx_it.h"
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "custom_led.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN TD */
|
||||
//Структура флагов проекта
|
||||
extern struct flags FLAGS;
|
||||
/* USER CODE END TD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
unsigned tim1_cnt = 0;
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
extern ADC_HandleTypeDef hadc1;
|
||||
extern I2C_HandleTypeDef hi2c1;
|
||||
extern TIM_HandleTypeDef htim1;
|
||||
extern TIM_HandleTypeDef htim2;
|
||||
extern UART_HandleTypeDef huart1;
|
||||
extern TIM_HandleTypeDef htim4;
|
||||
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
/* USER CODE END EV */
|
||||
|
||||
/******************************************************************************/
|
||||
/* Cortex-M3 Processor Interruption and Exception Handlers */
|
||||
/******************************************************************************/
|
||||
/**
|
||||
* @brief This function handles Non maskable interrupt.
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
|
||||
|
||||
/* USER CODE END NonMaskableInt_IRQn 0 */
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* USER CODE END NonMaskableInt_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Hard fault interrupt.
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN HardFault_IRQn 0 */
|
||||
/* USER CODE END HardFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
|
||||
return;
|
||||
/* USER CODE END W1_HardFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Memory management fault.
|
||||
*/
|
||||
void MemManage_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
|
||||
|
||||
/* USER CODE END MemoryManagement_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
|
||||
/* USER CODE END W1_MemoryManagement_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Prefetch fault, memory access fault.
|
||||
*/
|
||||
void BusFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN BusFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END BusFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_BusFault_IRQn 0 */
|
||||
/* USER CODE END W1_BusFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Undefined instruction or illegal state.
|
||||
*/
|
||||
void UsageFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN UsageFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END UsageFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_UsageFault_IRQn 0 */
|
||||
/* USER CODE END W1_UsageFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Debug monitor.
|
||||
*/
|
||||
void DebugMon_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
|
||||
|
||||
/* USER CODE END DebugMonitor_IRQn 0 */
|
||||
/* USER CODE BEGIN DebugMonitor_IRQn 1 */
|
||||
|
||||
/* USER CODE END DebugMonitor_IRQn 1 */
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* STM32F1xx Peripheral Interrupt Handlers */
|
||||
/* Add here the Interrupt Handlers for the used peripherals. */
|
||||
/* For the available peripheral interrupt handler names, */
|
||||
/* please refer to the startup file (startup_stm32f1xx.s). */
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief This function handles ADC1 and ADC2 global interrupts.
|
||||
*/
|
||||
void ADC1_2_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN ADC1_2_IRQn 0 */
|
||||
|
||||
/* USER CODE END ADC1_2_IRQn 0 */
|
||||
HAL_ADC_IRQHandler(&hadc1);
|
||||
/* USER CODE BEGIN ADC1_2_IRQn 1 */
|
||||
|
||||
/* USER CODE END ADC1_2_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM1 update interrupt.
|
||||
*/
|
||||
void TIM1_UP_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TIM1_UP_IRQn 0 */
|
||||
|
||||
/* USER CODE END TIM1_UP_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim1);
|
||||
/* USER CODE BEGIN TIM1_UP_IRQn 1 */
|
||||
|
||||
/* USER CODE END TIM1_UP_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM2 global interrupt.
|
||||
*/
|
||||
void TIM2_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TIM2_IRQn 0 */
|
||||
|
||||
/* USER CODE END TIM2_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim2);
|
||||
/* USER CODE BEGIN TIM2_IRQn 1 */
|
||||
|
||||
/* USER CODE END TIM2_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM4 global interrupt.
|
||||
*/
|
||||
void TIM4_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TIM4_IRQn 0 */
|
||||
|
||||
/* USER CODE END TIM4_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim4);
|
||||
/* USER CODE BEGIN TIM4_IRQn 1 */
|
||||
|
||||
/* USER CODE END TIM4_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles I2C1 event interrupt.
|
||||
*/
|
||||
void I2C1_EV_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN I2C1_EV_IRQn 0 */
|
||||
|
||||
/* USER CODE END I2C1_EV_IRQn 0 */
|
||||
HAL_I2C_EV_IRQHandler(&hi2c1);
|
||||
/* USER CODE BEGIN I2C1_EV_IRQn 1 */
|
||||
|
||||
/* USER CODE END I2C1_EV_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles I2C1 error interrupt.
|
||||
*/
|
||||
void I2C1_ER_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN I2C1_ER_IRQn 0 */
|
||||
|
||||
/* USER CODE END I2C1_ER_IRQn 0 */
|
||||
HAL_I2C_ER_IRQHandler(&hi2c1);
|
||||
/* USER CODE BEGIN I2C1_ER_IRQn 1 */
|
||||
|
||||
/* USER CODE END I2C1_ER_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles USART1 global interrupt.
|
||||
*/
|
||||
void USART1_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN USART1_IRQn 0 */
|
||||
|
||||
/* USER CODE END USART1_IRQn 0 */
|
||||
HAL_UART_IRQHandler(&huart1);
|
||||
/* USER CODE BEGIN USART1_IRQn 1 */
|
||||
|
||||
/* USER CODE END USART1_IRQn 1 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
void EXTI15_10_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN EXTI15_10_IRQn 0 */
|
||||
if(SW_Port->IDR & SW_Power_Pin)
|
||||
{
|
||||
FLAGS.Power_Turn_On = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
FLAGS.Power_Turn_On = 0;
|
||||
}
|
||||
|
||||
|
||||
if(SW_Port->IDR & SW_Reinit_Pin)
|
||||
{
|
||||
FLAGS.LCD_REINIT = 1;
|
||||
}
|
||||
|
||||
|
||||
if(SW_Port->IDR & SW_LCD_Pin)
|
||||
{
|
||||
FLAGS.REFRESH_LCD_FROM_NONSTABLE_VALUE_ON ^= 1;
|
||||
}
|
||||
/* USER CODE END EXTI15_10_IRQn 0 */
|
||||
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_12);
|
||||
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);
|
||||
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_14);
|
||||
/* USER CODE BEGIN EXTI15_10_IRQn 1 */
|
||||
|
||||
/* USER CODE END EXTI15_10_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles EXTI line[15:10] interrupts.
|
||||
*/
|
||||
/* USER CODE END 1 */
|
||||
408
.outdate/Core_stm32f1/Src/system_stm32f1xx.c
Normal file
408
.outdate/Core_stm32f1/Src/system_stm32f1xx.c
Normal file
@@ -0,0 +1,408 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file system_stm32f1xx.c
|
||||
* @author MCD Application Team
|
||||
* @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.
|
||||
*
|
||||
* 1. This file provides two functions and one global variable to be called from
|
||||
* user application:
|
||||
* - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
|
||||
* factors, AHB/APBx prescalers and Flash settings).
|
||||
* This function is called at startup just after reset and
|
||||
* before branch to main program. This call is made inside
|
||||
* the "startup_stm32f1xx_xx.s" file.
|
||||
*
|
||||
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
|
||||
* by the user application to setup the SysTick
|
||||
* timer or configure other parameters.
|
||||
*
|
||||
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
|
||||
* be called whenever the core clock is changed
|
||||
* during program execution.
|
||||
*
|
||||
* 2. After each device reset the HSI (8 MHz) is used as system clock source.
|
||||
* Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to
|
||||
* configure the system clock before to branch to main program.
|
||||
*
|
||||
* 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on
|
||||
* the product used), refer to "HSE_VALUE".
|
||||
* When HSE is used as system clock source, directly or through PLL, and you
|
||||
* are using different crystal you have to adapt the HSE value to your own
|
||||
* configuration.
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/** @addtogroup CMSIS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup stm32f1xx_system
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_Includes
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "stm32f1xx.h"
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if !defined (HSE_VALUE)
|
||||
#define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz.
|
||||
This value can be provided and adapted by the user application. */
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
#if !defined (HSI_VALUE)
|
||||
#define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz.
|
||||
This value can be provided and adapted by the user application. */
|
||||
#endif /* HSI_VALUE */
|
||||
|
||||
/*!< Uncomment the following line if you need to use external SRAM */
|
||||
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||
/* #define DATA_IN_ExtSRAM */
|
||||
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
|
||||
|
||||
/* Note: Following vector table addresses must be defined in line with linker
|
||||
configuration. */
|
||||
/*!< Uncomment the following line if you need to relocate the vector table
|
||||
anywhere in Flash or Sram, else the vector table is kept at the automatic
|
||||
remap of boot address selected */
|
||||
/* #define USER_VECT_TAB_ADDRESS */
|
||||
|
||||
#if defined(USER_VECT_TAB_ADDRESS)
|
||||
/*!< Uncomment the following line if you need to relocate your vector Table
|
||||
in Sram else user remap will be done in Flash. */
|
||||
/* #define VECT_TAB_SRAM */
|
||||
#if defined(VECT_TAB_SRAM)
|
||||
#define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#else
|
||||
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#endif /* VECT_TAB_SRAM */
|
||||
#endif /* USER_VECT_TAB_ADDRESS */
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* This variable is updated in three ways:
|
||||
1) by calling CMSIS function SystemCoreClockUpdate()
|
||||
2) by calling HAL API function HAL_RCC_GetHCLKFreq()
|
||||
3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
|
||||
Note: If you use this function to configure the system clock; then there
|
||||
is no need to call the 2 first functions listed above, since SystemCoreClock
|
||||
variable is updated automatically.
|
||||
*/
|
||||
uint32_t SystemCoreClock = 16000000;
|
||||
const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||
const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
static void SystemInit_ExtMemCtl(void);
|
||||
#endif /* DATA_IN_ExtSRAM */
|
||||
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Setup the microcontroller system
|
||||
* Initialize the Embedded Flash Interface, the PLL and update the
|
||||
* SystemCoreClock variable.
|
||||
* @note This function should be used only after reset.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemInit (void)
|
||||
{
|
||||
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
SystemInit_ExtMemCtl();
|
||||
#endif /* DATA_IN_ExtSRAM */
|
||||
#endif
|
||||
|
||||
/* Configure the Vector Table location -------------------------------------*/
|
||||
#if defined(USER_VECT_TAB_ADDRESS)
|
||||
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
|
||||
#endif /* USER_VECT_TAB_ADDRESS */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update SystemCoreClock variable according to Clock Register Values.
|
||||
* The SystemCoreClock variable contains the core clock (HCLK), it can
|
||||
* be used by the user application to setup the SysTick timer or configure
|
||||
* other parameters.
|
||||
*
|
||||
* @note Each time the core clock (HCLK) changes, this function must be called
|
||||
* to update SystemCoreClock variable value. Otherwise, any configuration
|
||||
* based on this variable will be incorrect.
|
||||
*
|
||||
* @note - The system frequency computed by this function is not the real
|
||||
* frequency in the chip. It is calculated based on the predefined
|
||||
* constant and the selected clock source:
|
||||
*
|
||||
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
|
||||
*
|
||||
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
|
||||
*
|
||||
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
|
||||
* or HSI_VALUE(*) multiplied by the PLL factors.
|
||||
*
|
||||
* (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value
|
||||
* 8 MHz) but the real value may vary depending on the variations
|
||||
* in voltage and temperature.
|
||||
*
|
||||
* (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value
|
||||
* 8 MHz or 25 MHz, depending on the product used), user has to ensure
|
||||
* that HSE_VALUE is same as the real frequency of the crystal used.
|
||||
* Otherwise, this function may have wrong result.
|
||||
*
|
||||
* - The result of this function could be not correct when using fractional
|
||||
* value for HSE crystal.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemCoreClockUpdate (void)
|
||||
{
|
||||
uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U;
|
||||
|
||||
#if defined(STM32F105xC) || defined(STM32F107xC)
|
||||
uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U;
|
||||
#endif /* STM32F105xC */
|
||||
|
||||
#if defined(STM32F100xB) || defined(STM32F100xE)
|
||||
uint32_t prediv1factor = 0U;
|
||||
#endif /* STM32F100xB or STM32F100xE */
|
||||
|
||||
/* Get SYSCLK source -------------------------------------------------------*/
|
||||
tmp = RCC->CFGR & RCC_CFGR_SWS;
|
||||
|
||||
switch (tmp)
|
||||
{
|
||||
case 0x00U: /* HSI used as system clock */
|
||||
SystemCoreClock = HSI_VALUE;
|
||||
break;
|
||||
case 0x04U: /* HSE used as system clock */
|
||||
SystemCoreClock = HSE_VALUE;
|
||||
break;
|
||||
case 0x08U: /* PLL used as system clock */
|
||||
|
||||
/* Get PLL clock source and multiplication factor ----------------------*/
|
||||
pllmull = RCC->CFGR & RCC_CFGR_PLLMULL;
|
||||
pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
|
||||
|
||||
#if !defined(STM32F105xC) && !defined(STM32F107xC)
|
||||
pllmull = ( pllmull >> 18U) + 2U;
|
||||
|
||||
if (pllsource == 0x00U)
|
||||
{
|
||||
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
|
||||
SystemCoreClock = (HSI_VALUE >> 1U) * pllmull;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(STM32F100xB) || defined(STM32F100xE)
|
||||
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
|
||||
/* HSE oscillator clock selected as PREDIV1 clock entry */
|
||||
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
|
||||
#else
|
||||
/* HSE selected as PLL clock entry */
|
||||
if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET)
|
||||
{/* HSE oscillator clock divided by 2 */
|
||||
SystemCoreClock = (HSE_VALUE >> 1U) * pllmull;
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemCoreClock = HSE_VALUE * pllmull;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
pllmull = pllmull >> 18U;
|
||||
|
||||
if (pllmull != 0x0DU)
|
||||
{
|
||||
pllmull += 2U;
|
||||
}
|
||||
else
|
||||
{ /* PLL multiplication factor = PLL input clock * 6.5 */
|
||||
pllmull = 13U / 2U;
|
||||
}
|
||||
|
||||
if (pllsource == 0x00U)
|
||||
{
|
||||
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
|
||||
SystemCoreClock = (HSI_VALUE >> 1U) * pllmull;
|
||||
}
|
||||
else
|
||||
{/* PREDIV1 selected as PLL clock entry */
|
||||
|
||||
/* Get PREDIV1 clock source and division factor */
|
||||
prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC;
|
||||
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
|
||||
|
||||
if (prediv1source == 0U)
|
||||
{
|
||||
/* HSE oscillator clock selected as PREDIV1 clock entry */
|
||||
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
|
||||
}
|
||||
else
|
||||
{/* PLL2 clock selected as PREDIV1 clock entry */
|
||||
|
||||
/* Get PREDIV2 division factor and PLL2 multiplication factor */
|
||||
prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U;
|
||||
pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U;
|
||||
SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull;
|
||||
}
|
||||
}
|
||||
#endif /* STM32F105xC */
|
||||
break;
|
||||
|
||||
default:
|
||||
SystemCoreClock = HSI_VALUE;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Compute HCLK clock frequency ----------------*/
|
||||
/* Get HCLK prescaler */
|
||||
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)];
|
||||
/* HCLK clock frequency */
|
||||
SystemCoreClock >>= tmp;
|
||||
}
|
||||
|
||||
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||
/**
|
||||
* @brief Setup the external memory controller. Called in startup_stm32f1xx.s
|
||||
* before jump to __main
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
/**
|
||||
* @brief Setup the external memory controller.
|
||||
* Called in startup_stm32f1xx_xx.s/.c before jump to main.
|
||||
* This function configures the external SRAM mounted on STM3210E-EVAL
|
||||
* board (STM32 High density devices). This SRAM will be used as program
|
||||
* data memory (including heap and stack).
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemInit_ExtMemCtl(void)
|
||||
{
|
||||
__IO uint32_t tmpreg;
|
||||
/*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is
|
||||
required, then adjust the Register Addresses */
|
||||
|
||||
/* Enable FSMC clock */
|
||||
RCC->AHBENR = 0x00000114U;
|
||||
|
||||
/* Delay after an RCC peripheral clock enabling */
|
||||
tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN);
|
||||
|
||||
/* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */
|
||||
RCC->APB2ENR = 0x000001E0U;
|
||||
|
||||
/* Delay after an RCC peripheral clock enabling */
|
||||
tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN);
|
||||
|
||||
(void)(tmpreg);
|
||||
|
||||
/* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/
|
||||
/*---------------- SRAM Address lines configuration -------------------------*/
|
||||
/*---------------- NOE and NWE configuration --------------------------------*/
|
||||
/*---------------- NE3 configuration ----------------------------------------*/
|
||||
/*---------------- NBL0, NBL1 configuration ---------------------------------*/
|
||||
|
||||
GPIOD->CRL = 0x44BB44BBU;
|
||||
GPIOD->CRH = 0xBBBBBBBBU;
|
||||
|
||||
GPIOE->CRL = 0xB44444BBU;
|
||||
GPIOE->CRH = 0xBBBBBBBBU;
|
||||
|
||||
GPIOF->CRL = 0x44BBBBBBU;
|
||||
GPIOF->CRH = 0xBBBB4444U;
|
||||
|
||||
GPIOG->CRL = 0x44BBBBBBU;
|
||||
GPIOG->CRH = 0x444B4B44U;
|
||||
|
||||
/*---------------- FSMC Configuration ---------------------------------------*/
|
||||
/*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/
|
||||
|
||||
FSMC_Bank1->BTCR[4U] = 0x00001091U;
|
||||
FSMC_Bank1->BTCR[5U] = 0x00110212U;
|
||||
}
|
||||
#endif /* DATA_IN_ExtSRAM */
|
||||
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
182
.outdate/Core_stm32f1/Src/tim.c
Normal file
182
.outdate/Core_stm32f1/Src/tim.c
Normal file
@@ -0,0 +1,182 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file tim.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the TIM instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 htim2;
|
||||
|
||||
/* TIM1 init function */
|
||||
void MX_TIM1_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN TIM1_Init 0 */
|
||||
|
||||
/* USER CODE END TIM1_Init 0 */
|
||||
|
||||
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||
|
||||
/* USER CODE BEGIN TIM1_Init 1 */
|
||||
|
||||
/* USER CODE END TIM1_Init 1 */
|
||||
htim1.Instance = TIM1;
|
||||
htim1.Init.Prescaler = 7200-1;
|
||||
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim1.Init.Period = 10-1;
|
||||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim1.Init.RepetitionCounter = 0;
|
||||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM1_Init 2 */
|
||||
|
||||
/* USER CODE END TIM1_Init 2 */
|
||||
|
||||
}
|
||||
/* TIM2 init function */
|
||||
void MX_TIM2_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN TIM2_Init 0 */
|
||||
|
||||
/* USER CODE END TIM2_Init 0 */
|
||||
|
||||
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||
|
||||
/* USER CODE BEGIN TIM2_Init 1 */
|
||||
|
||||
/* USER CODE END TIM2_Init 1 */
|
||||
htim2.Instance = TIM2;
|
||||
htim2.Init.Prescaler = 36-1;
|
||||
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim2.Init.Period = 10-1;
|
||||
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM2_Init 2 */
|
||||
|
||||
/* USER CODE END TIM2_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
|
||||
{
|
||||
|
||||
if(tim_baseHandle->Instance==TIM1)
|
||||
{
|
||||
/* USER CODE BEGIN TIM1_MspInit 0 */
|
||||
|
||||
/* USER CODE END TIM1_MspInit 0 */
|
||||
/* TIM1 clock enable */
|
||||
__HAL_RCC_TIM1_CLK_ENABLE();
|
||||
|
||||
/* TIM1 interrupt Init */
|
||||
HAL_NVIC_SetPriority(TIM1_UP_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(TIM1_UP_IRQn);
|
||||
/* USER CODE BEGIN TIM1_MspInit 1 */
|
||||
|
||||
/* USER CODE END TIM1_MspInit 1 */
|
||||
}
|
||||
else if(tim_baseHandle->Instance==TIM2)
|
||||
{
|
||||
/* USER CODE BEGIN TIM2_MspInit 0 */
|
||||
|
||||
/* USER CODE END TIM2_MspInit 0 */
|
||||
/* TIM2 clock enable */
|
||||
__HAL_RCC_TIM2_CLK_ENABLE();
|
||||
|
||||
/* TIM2 interrupt Init */
|
||||
HAL_NVIC_SetPriority(TIM2_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(TIM2_IRQn);
|
||||
/* USER CODE BEGIN TIM2_MspInit 1 */
|
||||
|
||||
/* USER CODE END TIM2_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
|
||||
{
|
||||
|
||||
if(tim_baseHandle->Instance==TIM1)
|
||||
{
|
||||
/* USER CODE BEGIN TIM1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END TIM1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_TIM1_CLK_DISABLE();
|
||||
|
||||
/* TIM1 interrupt Deinit */
|
||||
HAL_NVIC_DisableIRQ(TIM1_UP_IRQn);
|
||||
/* USER CODE BEGIN TIM1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END TIM1_MspDeInit 1 */
|
||||
}
|
||||
else if(tim_baseHandle->Instance==TIM2)
|
||||
{
|
||||
/* USER CODE BEGIN TIM2_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END TIM2_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_TIM2_CLK_DISABLE();
|
||||
|
||||
/* TIM2 interrupt Deinit */
|
||||
HAL_NVIC_DisableIRQ(TIM2_IRQn);
|
||||
/* USER CODE BEGIN TIM2_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END TIM2_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
115
.outdate/Core_stm32f1/Src/usart.c
Normal file
115
.outdate/Core_stm32f1/Src/usart.c
Normal file
@@ -0,0 +1,115 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usart.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the USART instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 "usart.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
UART_HandleTypeDef huart1;
|
||||
|
||||
/* USART1 init function */
|
||||
|
||||
void MX_USART1_UART_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN USART1_Init 0 */
|
||||
|
||||
/* USER CODE END USART1_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN USART1_Init 1 */
|
||||
|
||||
/* USER CODE END USART1_Init 1 */
|
||||
huart1.Instance = USART1;
|
||||
huart1.Init.BaudRate = 115200;
|
||||
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
huart1.Init.StopBits = UART_STOPBITS_1;
|
||||
huart1.Init.Parity = UART_PARITY_NONE;
|
||||
huart1.Init.Mode = UART_MODE_TX_RX;
|
||||
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||
if (HAL_HalfDuplex_Init(&huart1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN USART1_Init 2 */
|
||||
|
||||
/* USER CODE END USART1_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
|
||||
{
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(uartHandle->Instance==USART1)
|
||||
{
|
||||
/* USER CODE BEGIN USART1_MspInit 0 */
|
||||
|
||||
/* USER CODE END USART1_MspInit 0 */
|
||||
/* USART1 clock enable */
|
||||
__HAL_RCC_USART1_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/**USART1 GPIO Configuration
|
||||
PA9 ------> USART1_TX
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_9;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* USART1 interrupt Init */
|
||||
HAL_NVIC_SetPriority(USART1_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(USART1_IRQn);
|
||||
/* USER CODE BEGIN USART1_MspInit 1 */
|
||||
|
||||
/* USER CODE END USART1_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
|
||||
{
|
||||
|
||||
if(uartHandle->Instance==USART1)
|
||||
{
|
||||
/* USER CODE BEGIN USART1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END USART1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_USART1_CLK_DISABLE();
|
||||
|
||||
/**USART1 GPIO Configuration
|
||||
PA9 ------> USART1_TX
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9);
|
||||
|
||||
/* USART1 interrupt Deinit */
|
||||
HAL_NVIC_DisableIRQ(USART1_IRQn);
|
||||
/* USER CODE BEGIN USART1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END USART1_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
Reference in New Issue
Block a user