Compare commits
15 Commits
b4305e8296
...
py32_dalla
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ba89a0f52 | ||
|
|
bef05f2773 | ||
|
|
016efe4a05 | ||
|
|
570a11a37f | ||
|
|
4c987be8e7 | ||
|
|
15134a549a | ||
|
|
dbc9388f67 | ||
|
|
fad121a9fd | ||
|
|
424ca121f8 | ||
|
|
1d6ccdbef3 | ||
|
|
8d44a1a153 | ||
|
|
b59da11afc | ||
|
|
1633a224f3 | ||
|
|
54c8a663e4 | ||
|
|
458d2d77c9 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -47,3 +47,6 @@ JLinkLog.txt
|
|||||||
|
|
||||||
/MDK-ARM/DebugConfig/
|
/MDK-ARM/DebugConfig/
|
||||||
/MDK-ARM/Output/
|
/MDK-ARM/Output/
|
||||||
|
/~$ds18b20_locations.xlsx
|
||||||
|
/~$PY32F002A_Pins.xlsx
|
||||||
|
/~$PY32F002B_Pins.xlsx
|
||||||
|
|||||||
@@ -1,249 +0,0 @@
|
|||||||
/**
|
|
||||||
**************************************************************************
|
|
||||||
* @file mylibs_defs.h
|
|
||||||
* @brief Заголочный файл для дефайнов библиотеки MyLibsGeneral.
|
|
||||||
**************************************************************************
|
|
||||||
* @defgroup BIT_ACCESS_DEFINES Bit access defines
|
|
||||||
* @ingroup MYLIBS_DEFINES
|
|
||||||
* @brief Всякое для доступа к битам в unsigned
|
|
||||||
*************************************************************************/
|
|
||||||
#ifndef __BIT_ACCESS_H_
|
|
||||||
#define __BIT_ACCESS_H_
|
|
||||||
#include "mylibs_defs.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @addtogroup BIT_ACCESS_TYPEDEF Byte access typedefs
|
|
||||||
* @ingroup BIT_ACCESS_DEFINES
|
|
||||||
* @brief Дефайны юнионов для обращения к битам.
|
|
||||||
@{
|
|
||||||
*/
|
|
||||||
typedef union
|
|
||||||
{
|
|
||||||
uint8_t all;
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
unsigned bit0:1;
|
|
||||||
unsigned bit1:1;
|
|
||||||
unsigned bit2:1;
|
|
||||||
unsigned bit3:1;
|
|
||||||
unsigned reserved:4;
|
|
||||||
}bit;
|
|
||||||
}uint4_BitTypeDef;
|
|
||||||
|
|
||||||
typedef union
|
|
||||||
{
|
|
||||||
uint8_t all;
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
unsigned bit0:1;
|
|
||||||
unsigned bit1:1;
|
|
||||||
unsigned bit2:1;
|
|
||||||
unsigned bit3:1;
|
|
||||||
unsigned bit4:1;
|
|
||||||
unsigned reserved:3;
|
|
||||||
}bit;
|
|
||||||
}uint5_BitTypeDef;
|
|
||||||
|
|
||||||
typedef union
|
|
||||||
{
|
|
||||||
uint8_t all;
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
unsigned bit0:1;
|
|
||||||
unsigned bit1:1;
|
|
||||||
unsigned bit2:1;
|
|
||||||
unsigned bit3:1;
|
|
||||||
unsigned bit4:1;
|
|
||||||
unsigned bit5:1;
|
|
||||||
unsigned reserved:2;
|
|
||||||
}bit;
|
|
||||||
}uint6_BitTypeDef;
|
|
||||||
|
|
||||||
typedef union
|
|
||||||
{
|
|
||||||
uint8_t all;
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
unsigned bit0:1;
|
|
||||||
unsigned bit1:1;
|
|
||||||
unsigned bit2:1;
|
|
||||||
unsigned bit3:1;
|
|
||||||
unsigned bit4:1;
|
|
||||||
unsigned bit5:1;
|
|
||||||
unsigned bit6:1;
|
|
||||||
unsigned reserved:1;
|
|
||||||
}bit;
|
|
||||||
}uint7_BitTypeDef;
|
|
||||||
|
|
||||||
typedef union
|
|
||||||
{
|
|
||||||
uint8_t all;
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
unsigned bit0:1;
|
|
||||||
unsigned bit1:1;
|
|
||||||
unsigned bit2:1;
|
|
||||||
unsigned bit3:1;
|
|
||||||
unsigned bit4:1;
|
|
||||||
unsigned bit5:1;
|
|
||||||
unsigned bit6:1;
|
|
||||||
unsigned bit7:1;
|
|
||||||
}bit;
|
|
||||||
}uint8_BitTypeDef;
|
|
||||||
|
|
||||||
typedef union
|
|
||||||
{
|
|
||||||
uint16_t all;
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
unsigned bit0:1;
|
|
||||||
unsigned bit1:1;
|
|
||||||
unsigned bit2:1;
|
|
||||||
unsigned bit3:1;
|
|
||||||
unsigned bit4:1;
|
|
||||||
unsigned bit5:1;
|
|
||||||
unsigned bit6:1;
|
|
||||||
unsigned bit7:1;
|
|
||||||
unsigned bit8:1;
|
|
||||||
unsigned bit9:1;
|
|
||||||
unsigned bit10:1;
|
|
||||||
unsigned bit11:1;
|
|
||||||
unsigned bit12:1;
|
|
||||||
unsigned bit13:1;
|
|
||||||
unsigned bit14:1;
|
|
||||||
unsigned bit15:1;
|
|
||||||
}bit;
|
|
||||||
}uint16_BitTypeDef;
|
|
||||||
|
|
||||||
|
|
||||||
typedef union
|
|
||||||
{
|
|
||||||
uint32_t all;
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
unsigned bit0:1;
|
|
||||||
unsigned bit1:1;
|
|
||||||
unsigned bit2:1;
|
|
||||||
unsigned bit3:1;
|
|
||||||
unsigned bit4:1;
|
|
||||||
unsigned bit5:1;
|
|
||||||
unsigned bit6:1;
|
|
||||||
unsigned bit7:1;
|
|
||||||
unsigned bit8:1;
|
|
||||||
unsigned bit9:1;
|
|
||||||
unsigned bit10:1;
|
|
||||||
unsigned bit11:1;
|
|
||||||
unsigned bit12:1;
|
|
||||||
unsigned bit13:1;
|
|
||||||
unsigned bit14:1;
|
|
||||||
unsigned bit15:1;
|
|
||||||
unsigned bit16:1;
|
|
||||||
unsigned bit17:1;
|
|
||||||
unsigned bit18:1;
|
|
||||||
unsigned bit19:1;
|
|
||||||
unsigned bit20:1;
|
|
||||||
unsigned bit21:1;
|
|
||||||
unsigned bit22:1;
|
|
||||||
unsigned bit23:1;
|
|
||||||
unsigned bit24:1;
|
|
||||||
unsigned bit25:1;
|
|
||||||
unsigned bit26:1;
|
|
||||||
unsigned bit27:1;
|
|
||||||
unsigned bit28:1;
|
|
||||||
unsigned bit29:1;
|
|
||||||
unsigned bit30:1;
|
|
||||||
unsigned bit31:1;
|
|
||||||
}bit;
|
|
||||||
}uint32_BitTypeDef;
|
|
||||||
|
|
||||||
|
|
||||||
typedef union
|
|
||||||
{
|
|
||||||
uint64_t all;
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
unsigned bit0:1;
|
|
||||||
unsigned bit1:1;
|
|
||||||
unsigned bit2:1;
|
|
||||||
unsigned bit3:1;
|
|
||||||
unsigned bit4:1;
|
|
||||||
unsigned bit5:1;
|
|
||||||
unsigned bit6:1;
|
|
||||||
unsigned bit7:1;
|
|
||||||
unsigned bit8:1;
|
|
||||||
unsigned bit9:1;
|
|
||||||
unsigned bit10:1;
|
|
||||||
unsigned bit11:1;
|
|
||||||
unsigned bit12:1;
|
|
||||||
unsigned bit13:1;
|
|
||||||
unsigned bit14:1;
|
|
||||||
unsigned bit15:1;
|
|
||||||
unsigned bit16:1;
|
|
||||||
unsigned bit17:1;
|
|
||||||
unsigned bit18:1;
|
|
||||||
unsigned bit19:1;
|
|
||||||
unsigned bit20:1;
|
|
||||||
unsigned bit21:1;
|
|
||||||
unsigned bit22:1;
|
|
||||||
unsigned bit23:1;
|
|
||||||
unsigned bit24:1;
|
|
||||||
unsigned bit25:1;
|
|
||||||
unsigned bit26:1;
|
|
||||||
unsigned bit27:1;
|
|
||||||
unsigned bit28:1;
|
|
||||||
unsigned bit29:1;
|
|
||||||
unsigned bit30:1;
|
|
||||||
unsigned bit31:1;
|
|
||||||
unsigned bit32:1;
|
|
||||||
unsigned bit33:1;
|
|
||||||
unsigned bit34:1;
|
|
||||||
unsigned bit35:1;
|
|
||||||
unsigned bit36:1;
|
|
||||||
unsigned bit37:1;
|
|
||||||
unsigned bit38:1;
|
|
||||||
unsigned bit39:1;
|
|
||||||
unsigned bit40:1;
|
|
||||||
unsigned bit41:1;
|
|
||||||
unsigned bit42:1;
|
|
||||||
unsigned bit43:1;
|
|
||||||
unsigned bit44:1;
|
|
||||||
unsigned bit45:1;
|
|
||||||
unsigned bit46:1;
|
|
||||||
unsigned bit47:1;
|
|
||||||
unsigned bit48:1;
|
|
||||||
unsigned bit49:1;
|
|
||||||
unsigned bit50:1;
|
|
||||||
unsigned bit51:1;
|
|
||||||
unsigned bit52:1;
|
|
||||||
unsigned bit53:1;
|
|
||||||
unsigned bit54:1;
|
|
||||||
unsigned bit55:1;
|
|
||||||
unsigned bit56:1;
|
|
||||||
unsigned bit57:1;
|
|
||||||
unsigned bit58:1;
|
|
||||||
unsigned bit59:1;
|
|
||||||
unsigned bit60:1;
|
|
||||||
unsigned bit61:1;
|
|
||||||
unsigned bit62:1;
|
|
||||||
unsigned bit63:1;
|
|
||||||
}bit;
|
|
||||||
}uint64_BitTypeDef;
|
|
||||||
/** BIT_ACCESS_TYPEDEF
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @addtogroup BIT_ACCESS_FUNCTIONS Byte access functions
|
|
||||||
* @ingroup BIT_ACCESS_DEFINES
|
|
||||||
* @brief Дефайны для обращения к битам в unsigned.
|
|
||||||
@{
|
|
||||||
*/
|
|
||||||
#define uint8_bit(_uint8_, _bit_) (*(uint8_BitTypeDef *)(&(_uint8_))).bit.bit##_bit_
|
|
||||||
#define uint16_bit(_uint8_, _bit_) (*(uint16_BitTypeDef *)(&(_uint8_))).bit.bit##_bit_
|
|
||||||
#define uint32_bit(_uint8_, _bit_) (*(uint32_BitTypeDef *)(&(_uint8_))).bit.bit##_bit_
|
|
||||||
#define uint64_bit(_uint8_, _bit_) (*(uint64_BitTypeDef *)(&(_uint8_))).bit.bit##_bit_
|
|
||||||
|
|
||||||
/** BIT_ACCESS_FUNCTIONS
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
#endif //__BIT_ACCESS_H_
|
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
/**
|
|
||||||
**************************************************************************
|
|
||||||
* @file general_gpio.c
|
|
||||||
* @brief Модуль для инициализации портов.
|
|
||||||
**************************************************************************
|
|
||||||
@verbatim
|
|
||||||
//-------------------Функции-------------------//
|
|
||||||
Functions: users
|
|
||||||
- GPIO_Clock_Enable Инициализация тактирования порта
|
|
||||||
@endverbatim
|
|
||||||
***************************************************************************/
|
|
||||||
#include "general_gpio.h"
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
//------------------------GPIO INIT FUNCTIONS------------------------
|
|
||||||
|
|
||||||
HAL_StatusTypeDef GPIO_Clock_Enable(GPIO_TypeDef *GPIOx)
|
|
||||||
{
|
|
||||||
HAL_StatusTypeDef status = HAL_OK;
|
|
||||||
// choose port for enable clock
|
|
||||||
if (GPIOx==GPIOA)
|
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
||||||
else if (GPIOx==GPIOB)
|
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
||||||
else if (GPIOx==GPIOC)
|
|
||||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
||||||
#ifdef GPIOD
|
|
||||||
else if (GPIOx==GPIOD)
|
|
||||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#ifdef GPIOE
|
|
||||||
else if (GPIOx==GPIOE)
|
|
||||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
else
|
|
||||||
status = HAL_ERROR;
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------GPIO INIT FUNCTIONS------------------------
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
//------------------------GPIO LED FUNCTIONS-------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Включить светодиод
|
|
||||||
*/
|
|
||||||
void GPIO_LED_On(GPIO_LEDTypeDef *led)
|
|
||||||
{
|
|
||||||
led->state = LED_IS_ON;
|
|
||||||
HAL_GPIO_WritePin(led->LED_Port, led->LED_Pin, LED_ON);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @brief Выключить светодиод
|
|
||||||
*/
|
|
||||||
void GPIO_LED_Off(GPIO_LEDTypeDef *led)
|
|
||||||
{
|
|
||||||
led->state = LED_IS_OFF;
|
|
||||||
HAL_GPIO_WritePin(led->LED_Port, led->LED_Pin, LED_OFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Активировать моргание светодиодом
|
|
||||||
*/
|
|
||||||
void GPIO_LED_Blink_Start(GPIO_LEDTypeDef *led, uint32_t period)
|
|
||||||
{
|
|
||||||
led->state = LED_IS_BLINKING;
|
|
||||||
led->LED_Period = period;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Моргание светодиодом
|
|
||||||
*/
|
|
||||||
void GPIO_LED_Blink_Handle(GPIO_LEDTypeDef *led)
|
|
||||||
{
|
|
||||||
if(led->state == LED_IS_BLINKING)
|
|
||||||
{
|
|
||||||
uint32_t tickcurrent = HAL_GetTick();
|
|
||||||
if((tickcurrent - led->tickprev) > led->LED_Period)
|
|
||||||
{
|
|
||||||
HAL_GPIO_TogglePin(led->LED_Port, led->LED_Pin);
|
|
||||||
led->tickprev = tickcurrent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//------------------------GPIO LED FUNCTIONS-------------------------
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
//------------------------GPIO SW FUNCTIONS-------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Считать состоянии кнопки запуска
|
|
||||||
*/
|
|
||||||
uint8_t GPIO_Read_Swich(GPIO_SwitchTypeDef *sw)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(HAL_GPIO_ReadPin(sw->Sw_Port, sw->Sw_Pin) == SW_ON)
|
|
||||||
{
|
|
||||||
sw->Sw_PrevState = 1;
|
|
||||||
|
|
||||||
if(sw->tickprev == 0)
|
|
||||||
sw->tickprev = HAL_GetTick();
|
|
||||||
|
|
||||||
if((HAL_GetTick() - sw->tickprev) > sw->Sw_FilterDelay)
|
|
||||||
{
|
|
||||||
if(HAL_GPIO_ReadPin(sw->Sw_Port, sw->Sw_Pin) == SW_ON)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sw->tickprev = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sw->Sw_PrevState = 0;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
//------------------------GPIO SW FUNCTIONS-------------------------
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
/**
|
|
||||||
**************************************************************************
|
|
||||||
* @file general_gpio.h
|
|
||||||
* @brief Заголовочный файл для модуля инициализации портов.
|
|
||||||
*************************************************************************/
|
|
||||||
#ifndef __GPIO_GENERAL_H_
|
|
||||||
#define __GPIO_GENERAL_H_
|
|
||||||
|
|
||||||
#include "mylibs_defs.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define SPI_Alternate_Mapping(INSTANCE) ((((INSTANCE) == TIM1) || ((INSTANCE) == TIM2))? GPIO_AF1_TIM1: \
|
|
||||||
(((INSTANCE) == TIM3) || ((INSTANCE) == TIM4) || ((INSTANCE) == TIM5))? GPIO_AF2_TIM3: \
|
|
||||||
(((INSTANCE) == TIM8) || ((INSTANCE) == TIM9) || ((INSTANCE) == TIM10) || ((INSTANCE) == TIM11))? GPIO_AF3_TIM8: \
|
|
||||||
(((INSTANCE) == TIM12) || ((INSTANCE) == TIM13) || ((INSTANCE) == TIM14))? GPIO_AF9_TIM12: \
|
|
||||||
(0))
|
|
||||||
|
|
||||||
|
|
||||||
#define TIM_Alternate_Mapping(INSTANCE) ((((INSTANCE) == TIM1) || ((INSTANCE) == TIM2))? GPIO_AF1_TIM1: \
|
|
||||||
(((INSTANCE) == TIM3) || ((INSTANCE) == TIM4) || ((INSTANCE) == TIM5))? GPIO_AF2_TIM3: \
|
|
||||||
(((INSTANCE) == TIM8) || ((INSTANCE) == TIM9) || ((INSTANCE) == TIM10) || ((INSTANCE) == TIM11))? GPIO_AF3_TIM8: \
|
|
||||||
(((INSTANCE) == TIM12) || ((INSTANCE) == TIM13) || ((INSTANCE) == TIM14))? GPIO_AF9_TIM12: \
|
|
||||||
(0))
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
LED_IS_OFF = 0,
|
|
||||||
LED_IS_ON = 1,
|
|
||||||
LED_IS_BLINKING = 2,
|
|
||||||
LED_IS_FADING = 3,
|
|
||||||
}GPIO_LEDStateTypeDef;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
GPIO_LEDStateTypeDef state;
|
|
||||||
|
|
||||||
GPIO_TypeDef *LED_Port;
|
|
||||||
uint32_t LED_Pin;
|
|
||||||
|
|
||||||
uint32_t LED_Period;
|
|
||||||
uint32_t tickprev;
|
|
||||||
}GPIO_LEDTypeDef;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
GPIO_TypeDef *Sw_Port;
|
|
||||||
uint32_t Sw_Pin;
|
|
||||||
|
|
||||||
uint32_t Sw_PrevState;
|
|
||||||
uint32_t Sw_FilterDelay;
|
|
||||||
uint32_t tickprev;
|
|
||||||
}GPIO_SwitchTypeDef;
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
|
||||||
///////////////////////////---FUNCTIONS---///////////////////////////
|
|
||||||
HAL_StatusTypeDef GPIO_Clock_Enable(GPIO_TypeDef *GPIOx);
|
|
||||||
|
|
||||||
/* Считать состоянии кнопки запуска */
|
|
||||||
uint8_t GPIO_Read_Swich(GPIO_SwitchTypeDef *swstart);
|
|
||||||
/* Включить светодиод */
|
|
||||||
void GPIO_LED_On(GPIO_LEDTypeDef *led);
|
|
||||||
/* Выключить светодиод */
|
|
||||||
void GPIO_LED_Off(GPIO_LEDTypeDef *led);
|
|
||||||
/* Активировать моргание светодиодом */
|
|
||||||
void GPIO_LED_Blink_Start(GPIO_LEDTypeDef *led, uint32_t period);
|
|
||||||
/* Моргание светодиодом */
|
|
||||||
void GPIO_LED_Blink_Handle(GPIO_LEDTypeDef *led);
|
|
||||||
///////////////////////////---FUNCTIONS---///////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef LED_ON
|
|
||||||
#define LED_ON 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef LED_0FF
|
|
||||||
#define LED_OFF 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef SW_ON
|
|
||||||
#define SW_ON 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef SW_0FF
|
|
||||||
#define SW_OFF 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // __GPIO_GENERAL_H_
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
/**
|
|
||||||
**************************************************************************
|
|
||||||
* @file mylibs_config.h
|
|
||||||
* @brief Конфигурации для библиотек MyLibs
|
|
||||||
**************************************************************************
|
|
||||||
* @defgroup MYLIBS_CONFIG Configs My Libs
|
|
||||||
* @ingroup MYLIBS_ALL
|
|
||||||
* @brief Конфигурации для библиотек MyLibs
|
|
||||||
@{
|
|
||||||
*************************************************************************/
|
|
||||||
#ifndef __MYLIBS_CONFIG_H_
|
|
||||||
#define __MYLIBS_CONFIG_H_
|
|
||||||
|
|
||||||
#include "py32f0xx_hal.h"
|
|
||||||
|
|
||||||
// user includes
|
|
||||||
#include "interface_config.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define RS_USER_VARS_NUMB 0
|
|
||||||
#define ADC_USER_VARS_NUMB 0
|
|
||||||
#define ADC_CH_USER_VARS_NUMB 0
|
|
||||||
|
|
||||||
|
|
||||||
#define INCLUDE_BIT_ACCESS_LIB
|
|
||||||
#define INCLUDE_TRACKERS_LIB
|
|
||||||
#define INCLUDE_TRACE_LIB
|
|
||||||
//#define INCLUDE_GENERAL_PERIPH_LIBS
|
|
||||||
//#define FREERTOS_DELAY
|
|
||||||
|
|
||||||
|
|
||||||
/** MYLIBS_CONFIG
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
#endif //__MYLIBS_CONFIG_H_
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
/**
|
|
||||||
**************************************************************************
|
|
||||||
* @file mylibs_defs.h
|
|
||||||
* @brief Заголочный файл для дефайнов библиотеки MyLibsGeneral.
|
|
||||||
**************************************************************************
|
|
||||||
* @defgroup MYLIBS_DEFINES My Libs defines
|
|
||||||
* @brief Базовые дефайны для всего проекта
|
|
||||||
*
|
|
||||||
*************************************************************************/
|
|
||||||
#ifndef __MYLIBS_DEFINES_H_
|
|
||||||
#define __MYLIBS_DEFINES_H_
|
|
||||||
|
|
||||||
#include "mylibs_config.h"
|
|
||||||
|
|
||||||
/***************************************************************************
|
|
||||||
******************************ERROR_HANDLER********************************/
|
|
||||||
/**
|
|
||||||
* @addtogroup ERROR_HANDLER_DEFINES Error Handler defines
|
|
||||||
* @ingroup MYLIBS_DEFINES
|
|
||||||
* @brief Дефайны для определения функции обработки ошибок
|
|
||||||
@{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* extern Error_Handler from main.h */
|
|
||||||
extern void Error_Handler(void);
|
|
||||||
|
|
||||||
/* Define error handler for MyLibs */
|
|
||||||
#define MyLibs_Error_Handler(_params_) Error_Handler(_params_)
|
|
||||||
/* If error handler not defined - set void */
|
|
||||||
#ifndef MyLibs_Error_Handler
|
|
||||||
#define ((void)0U)
|
|
||||||
#endif // MyLibs_Error_Handler
|
|
||||||
|
|
||||||
/** ERROR_HANDLER_DEFINES
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
|
||||||
********************************ACCESS_DEFINES*****************************/
|
|
||||||
|
|
||||||
#define ClearStruct(_struct_) memset(&(_struct_), 0, sizeof(_struct_))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
|
||||||
******************************DELAYS_DEFINES*******************************/
|
|
||||||
/**
|
|
||||||
* @addtogroup DELAYS_DEFINES Delays defines
|
|
||||||
* @ingroup MYLIBS_DEFINES
|
|
||||||
* @brief Дефайны для реализации задержек
|
|
||||||
@{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef FREERTOS_DELAY
|
|
||||||
#define msDelay(_ms_) osDelay(_ms_)
|
|
||||||
#else
|
|
||||||
#define msDelay(_ms_) if(_ms_ != 0) HAL_Delay(_ms_-1)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** DELAYS_DEFINES
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
|
||||||
*******************************MATH_DEFINES********************************/
|
|
||||||
/**
|
|
||||||
* @addtogroup MATH_DEFINES Math defines
|
|
||||||
* @ingroup MYLIBS_DEFINES
|
|
||||||
* @brief Дефайны для различных математических функций
|
|
||||||
@{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Calc dividing including remainder
|
|
||||||
* @param _val_ - делимое.
|
|
||||||
* @param _div_ - делитель.
|
|
||||||
* @details Если результат деления без остатка: он возвращается как есть
|
|
||||||
Если с остатком - округляется вверх
|
|
||||||
*/
|
|
||||||
//#define Divide_Up(_val_, _div_) (((_val_)%(_div_))? (_val_)/(_div_)+1 : (_val_)/_div_) /* через тернарный оператор */
|
|
||||||
#define Divide_Up(_val_, _div_) ((_val_ - 1) / _div_) + 1 /* через мат выражение */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Swap between Little Endian and Big Endian
|
|
||||||
* @param v - Переменная для свапа.
|
|
||||||
* @return v (new) - Свапнутая переменная.
|
|
||||||
* @details Переключения между двумя типами хранения слова: HI-LO байты и LO-HI байты.
|
|
||||||
*/
|
|
||||||
#define ByteSwap16(v) (((v&0xFF00) >> (8)) | ((v&0x00FF) << (8)))
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Absolute
|
|
||||||
* @param x - Переменная для модудя.
|
|
||||||
* @return x (new) - Число по модулю.
|
|
||||||
* @details Берет число по модулю. Хз как работает библиотечный abs в stdlib.h, мб это быстрее, но вряд ли конечно.
|
|
||||||
*/
|
|
||||||
#define ABS(x) ( ((x) > 0)? (x) : -(x))?
|
|
||||||
|
|
||||||
/** MATH_DEFINES
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#endif //__MYLIBS_DEFINES_H_
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
/**
|
|
||||||
**************************************************************************
|
|
||||||
* @file mylibs_include.h
|
|
||||||
* @brief Заголочный файл для всех библиотек
|
|
||||||
**************************************************************************
|
|
||||||
@details
|
|
||||||
Здесь нужно собрать библиотеки и дефайны, которые должны быть видны во всем проекте,
|
|
||||||
чтобы не подключать 100 инклюдов в каждом ".c" файле
|
|
||||||
**************************************************************************
|
|
||||||
* @defgroup MYLIBS_ALL My Libs
|
|
||||||
* @brief Все используемые MyLibs библиотеки
|
|
||||||
*
|
|
||||||
*************************************************************************/
|
|
||||||
#ifndef __MYLIBS_INCLUDE_H_
|
|
||||||
#define __MYLIBS_INCLUDE_H_
|
|
||||||
|
|
||||||
#include "mylibs_defs.h"
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef ARM_MATH_CM4
|
|
||||||
#include "arm_math.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef INCLUDE_BIT_ACCESS_LIB
|
|
||||||
#include "bit_access.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef INCLUDE_TRACKERS_LIB
|
|
||||||
#include "trackers.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef INCLUDE_TRACE_LIB
|
|
||||||
#include "trace.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERAL_PERIPH_LIBS
|
|
||||||
|
|
||||||
#include "general_flash.h"
|
|
||||||
#include "general_gpio.h"
|
|
||||||
#ifdef HAL_SPI_MODULE_ENABLED
|
|
||||||
#include "general_spi.h"
|
|
||||||
#endif
|
|
||||||
#ifdef HAL_UART_MODULE_ENABLED
|
|
||||||
#include "general_uart.h"
|
|
||||||
#endif
|
|
||||||
#ifdef HAL_TIM_MODULE_ENABLED
|
|
||||||
#include "general_tim.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif //INCLUDE_GENERAL_PERIPH_LIBS
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////---USER SETTINGS---/////////////////////////
|
|
||||||
// user includes
|
|
||||||
#include "stdlib.h"
|
|
||||||
#include "string.h"
|
|
||||||
#include "stdio.h"
|
|
||||||
#include "math.h"
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "modbus_data.h"
|
|
||||||
#include "general_gpio.h"
|
|
||||||
|
|
||||||
/** @brief Struct for trackers for Measure */
|
|
||||||
/** @brief Struct for trackers for RS */
|
|
||||||
typedef TrackerTypeDef(RS_USER_VARS_NUMB) RS_TrackerTypeDef;
|
|
||||||
/** @brief Struct for trackers for ADC */
|
|
||||||
typedef TrackerTypeDef(ADC_USER_VARS_NUMB) ADC_TrackerTypeDef;
|
|
||||||
/** @brief Struct for trackers for ADC Channel */
|
|
||||||
typedef TrackerTypeDef(ADC_CH_USER_VARS_NUMB) ADCChannel_TrackerTypeDef;
|
|
||||||
/////////////////////////---USER SETTINGS---/////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
#endif // __MYLIBS_INCLUDE_H_
|
|
||||||
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
/**
|
|
||||||
**************************************************************************
|
|
||||||
* @file trace.h
|
|
||||||
* @brief Заголочный файл для работы с трассировкой.
|
|
||||||
**************************************************************************
|
|
||||||
* @addtogroup TRACE Trace defines
|
|
||||||
* @ingroup MYLIBS_DEFINES
|
|
||||||
* @brief Дефайны для работы с трассировкой
|
|
||||||
*************************************************************************/
|
|
||||||
#ifndef __TRACE_H_
|
|
||||||
#define __TRACE_H_
|
|
||||||
#include "mylibs_defs.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @addtogroup TRACE_SERIAL Serial trace defines
|
|
||||||
* @ingroup TRACE
|
|
||||||
* @brief Дефайны для работы с serial трассировкой
|
|
||||||
* @details Определяется дефайн my_printf() для работы с serial трассировкой:
|
|
||||||
- для RTT это будет вызов функции SEGGER_RTT_printf(), с подключением библиотеки SEGGER_RTT.h
|
|
||||||
- для SWO это будет просто printf(), но библиотеку STDOUT надо подключить самостоятельно:
|
|
||||||
|
|
||||||
@verbatim
|
|
||||||
Manage Run-Time Environment -> Compiler -> I/O -> STDOUT
|
|
||||||
@endverbatim
|
|
||||||
|
|
||||||
- Если трассировка отключена, то все дефайны определяются как 'ничего' и на производительность кода не влияют
|
|
||||||
@{
|
|
||||||
*/
|
|
||||||
/* Выбор какой serial trace использовать */
|
|
||||||
#ifdef SERIAL_TRACE_ENABLE
|
|
||||||
|
|
||||||
#if defined(RTT_TRACE_ENABLE)
|
|
||||||
#undef SWO_TRACE_ENABLE
|
|
||||||
#include "SEGGER_RTT.h"
|
|
||||||
#define my_printf(...) SEGGER_RTT_printf(0, __VA_ARGS__)
|
|
||||||
#elif defined(SWO_TRACE_ENABLE)
|
|
||||||
#undef RTT_TRACE_ENABLE
|
|
||||||
#define my_printf(...) printf(__VA_ARGS__)
|
|
||||||
#else // NO_TRACE
|
|
||||||
#define my_printf(...)
|
|
||||||
#warning No trace is selected. Serial debug wont work.
|
|
||||||
#endif // RTT_TRACE_ENABLE/SWO_TRACE_ENABLE/NO_TRACE
|
|
||||||
#else //SERIAL_TRACE_ENABLE
|
|
||||||
#define my_printf(...)
|
|
||||||
#undef RTT_TRACE_ENABLE
|
|
||||||
#undef SWO_TRACE_ENABLE
|
|
||||||
|
|
||||||
#endif //SERIAL_TRACE_ENABLE
|
|
||||||
|
|
||||||
/** TRACE_SERIAL
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @addtogroup TRACE_GPIO GPIO trace defines
|
|
||||||
* @ingroup TRACE
|
|
||||||
* @brief Дефайны для работы с GPIO трассировкой
|
|
||||||
* @details Определяется дефайны для работы с GPIO трассировкой:
|
|
||||||
- TRACE_GPIO_RESET() - для сброса ножки GPIO (через BSRR)
|
|
||||||
- TRACE_GPIO_SET() - для выставления ножки GPIO (через BSRR)
|
|
||||||
|
|
||||||
- Если трассировка отключена, то все дефайны определяются как 'ничего' и на производительность кода не влияют
|
|
||||||
@{
|
|
||||||
*/
|
|
||||||
#ifndef GPIO_TRACE_ENABLE
|
|
||||||
#define TRACE_GPIO_RESET(_gpio_,_pin_)
|
|
||||||
#define TRACE_GPIO_SET(_gpio_,_pin_)
|
|
||||||
#else
|
|
||||||
#define TRACE_GPIO_RESET(_gpio_,_pin_) (_gpio_)->BSRR = ((_pin_)<<16)
|
|
||||||
#define TRACE_GPIO_SET(_gpio_,_pin_) (_gpio_)->BSRR = (((_pin_)))
|
|
||||||
#endif //GPIO_TRACE_ENABLE
|
|
||||||
|
|
||||||
|
|
||||||
/** TRACE_GPIO
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#endif //__TRACE_H_
|
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
/**
|
|
||||||
**************************************************************************
|
|
||||||
* @file mylibs_defs.h
|
|
||||||
* @brief Заголочный файл для дефайнов библиотеки MyLibsGeneral.
|
|
||||||
**************************************************************************
|
|
||||||
* @defgroup MYLIBS_DEFINES My Libs defines
|
|
||||||
* @brief Базовые дефайны для всего проекта
|
|
||||||
*
|
|
||||||
*************************************************************************/
|
|
||||||
#ifndef __TRACKERS_H_
|
|
||||||
#define __TRACKERS_H_
|
|
||||||
#include "mylibs_defs.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @addtogroup TRACKERS Trackers defines
|
|
||||||
* @ingroup MYLIBS_DEFINES
|
|
||||||
* @brief Дефайны для работы с трекерами
|
|
||||||
* @details Есть дефайн для объявления структуры трекера: TrackerTypeDef(num_user_vars).
|
|
||||||
Структура состоит из следующих элементов:
|
|
||||||
- cnt_ok
|
|
||||||
- cnt_err
|
|
||||||
- cnt_warn
|
|
||||||
- user[num_user_vars]
|
|
||||||
Также есть ряд функций (дефайнов) для обращения к элементам этой структуры.
|
|
||||||
|
|
||||||
|
|
||||||
Если трассировка отключена, то все дефайны определяются как ничего и на производительность кода не влияют
|
|
||||||
|
|
||||||
@par Пример:
|
|
||||||
Определяем typedef трекера измерений @ref Measure_TrackerTypeDef
|
|
||||||
|
|
||||||
@verbatim
|
|
||||||
typedef TrackerTypeDef(MEASURE_USER_VARS_NUMB) Measure_TrackerTypeDef;
|
|
||||||
@endverbatim
|
|
||||||
|
|
||||||
И через @ref Measure_TrackerTypeDef структура подключается в @ref TESTER_MeasureHandleTypeDef, а также
|
|
||||||
если необхожимо в другие структуру, например в структуру всех ошибок через указатель @ref TESTER_TrackerTypeDef
|
|
||||||
|
|
||||||
@{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef TRACKERS_ENABLE
|
|
||||||
/**
|
|
||||||
* @brief Структура для счетчиков отладки
|
|
||||||
* @param num_user_vars - количество пользовательских счетчиков
|
|
||||||
* @details Содержит счетчик для успешных событый (cnt_ok),
|
|
||||||
* счетчик для ошибок (cnt_err), счетчик для предупреждений (cnt_warn).
|
|
||||||
*
|
|
||||||
* Также есть возможность объявить пользовательские счетчики в
|
|
||||||
* количестве <num_user_vars> штук.
|
|
||||||
*
|
|
||||||
* Для работы с структурой можно использовать функции:
|
|
||||||
* - TrackerCnt_Ok()
|
|
||||||
* - TrackerCnt_Err()
|
|
||||||
* - TrackerCnt_Warn()
|
|
||||||
* - TrackerCnt_User()
|
|
||||||
* - TrackerWrite_User()
|
|
||||||
* - TrackerClear_All()
|
|
||||||
* - TrackerClear_Ok()
|
|
||||||
* - TrackerClear_Err()
|
|
||||||
* - TrackerClear_Warn()
|
|
||||||
* - TrackerClear_User()
|
|
||||||
* - TrackerClear_UserAll()
|
|
||||||
*/
|
|
||||||
#define TrackerTypeDef(num_user_vars) \
|
|
||||||
struct \
|
|
||||||
{ \
|
|
||||||
uint32_t cnt_ok; \
|
|
||||||
uint32_t cnt_err; \
|
|
||||||
uint32_t cnt_warn; \
|
|
||||||
uint32_t user[num_user_vars]; \
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @brief Получить количетство пользовательских переменных */
|
|
||||||
#define num_of_usercnts(_user_) (sizeof(_user_) / sizeof(_user_[0]))
|
|
||||||
/** @brief Проверка существует ли указанная пользовательская переменная */
|
|
||||||
#define assert_usertracker(_cntstruct_, _uservarnumb_) ((_uservarnumb_) < num_of_usercnts((_cntstruct_).user))
|
|
||||||
/** @brief Условие для проверки существует ли указанная пользовательская переменная */
|
|
||||||
#define if_assert_usertracker(_cntstruct_, _uservarnumb_) if(assert_usertracker(_cntstruct_, _uservarnumb_))
|
|
||||||
/** @brief Тернарный оператор для проверки существует ли указанная пользовательская переменная */
|
|
||||||
#define tern_assert_usertracker(_cntstruct_, _uservarnumb_) (assert_usertracker(_cntstruct_, _uservarnumb_)) ? _uservarnumb_ : 0
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Запись числа в пользовательскую переменную
|
|
||||||
* @note Здесь нет проверки - существует ли пользовательская переменная!
|
|
||||||
* Есть возможность выйти за границы структуры!!!
|
|
||||||
* Чтобы этого избежать используете дефайн #ref assert_usertracker()
|
|
||||||
*/
|
|
||||||
#define TrackerGet_User(_cntstruct_, _uservarnumb_) (_cntstruct_).user[tern_assert_usertracker(_cntstruct_, _uservarnumb_)]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** @brief Инкрементирование счетчика успешных событий */
|
|
||||||
#define TrackerCnt_Ok(_cntstruct_) (_cntstruct_).cnt_ok++
|
|
||||||
/** @brief Инкрементирование счетчика ошибок */
|
|
||||||
#define TrackerCnt_Err(_cntstruct_) (_cntstruct_).cnt_err++
|
|
||||||
/** @brief Инкрементирование счетчика предупреждений */
|
|
||||||
#define TrackerCnt_Warn(_cntstruct_) (_cntstruct_).cnt_warn++
|
|
||||||
/** @brief Инкрементирование пользовательской переменной */
|
|
||||||
#define TrackerCnt_User(_cntstruct_, _uservarnumb_) if_assert_usertracker(_cntstruct_, _uservarnumb_) (_cntstruct_).user[_uservarnumb_]++;
|
|
||||||
/** @brief Запись числа в пользовательскую переменную */
|
|
||||||
#define TrackerWrite_User(_cntstruct_, _uservarnumb_, _val_) if_assert_usertracker(_cntstruct_, _uservarnumb_) (_cntstruct_).user[_uservarnumb_] = (_val_)
|
|
||||||
|
|
||||||
/** @brief Очистка всей структуры */
|
|
||||||
#define TrackerClear_All(_cntstruct_) memset(&(_cntstruct_), 0, sizeof(_cntstruct_))
|
|
||||||
/** @brief Очистка счетчика успешных событий */
|
|
||||||
#define TrackerClear_Ok(_cntstruct_) (_cntstruct_).cnt_ok = 0
|
|
||||||
/** @brief Очистка счетчика ошибок */
|
|
||||||
#define TrackerClear_Err(_cntstruct_) (_cntstruct_).cnt_err = 0
|
|
||||||
/** @brief Очистка счетчика предупреждений */
|
|
||||||
#define TrackerClear_Warn(_cntstruct_) (_cntstruct_).cnt_warn = 0
|
|
||||||
/** @brief Очистка пользовательской переменной */
|
|
||||||
#define TrackerClear_User(_cntstruct_, _uservarnumb_) if_assert_usertracker(_cntstruct_, _uservarnumb_) (_cntstruct_).user[_uservarnumb_] = 0;
|
|
||||||
/** @brief Очистка всех пользовательских переменных */
|
|
||||||
#define TrackerClear_UserAll(_cntstruct_) memset(&(_cntstruct_).user, 0, sizeof((_cntstruct_).user))
|
|
||||||
|
|
||||||
#else //TRACKERS_ENABLE
|
|
||||||
#define TrackerTypeDef(num_user_vars) void *
|
|
||||||
|
|
||||||
#define num_of_usercnts(_user_)
|
|
||||||
#define assert_tracecnt(_cntstruct_, _uservarnumb_)
|
|
||||||
|
|
||||||
#define TrackerCnt_Ok(_cntstruct_)
|
|
||||||
#define TrackerCnt_Err(_cntstruct_)
|
|
||||||
#define TrackerCnt_Warn(_cntstruct_)
|
|
||||||
#define TrackerCnt_User(_cntstruct_, _uservarnumb_)
|
|
||||||
#define TrackerWrite_User(_cntstruct_, _uservarnumb_, _val_)
|
|
||||||
|
|
||||||
/** @brief Очистка всей структуры */
|
|
||||||
#define TrackerClear_All(_cntstruct_)
|
|
||||||
#define TrackerClear_Ok(_cntstruct_)
|
|
||||||
#define TrackerClear_Err(_cntstruct_)
|
|
||||||
#define TrackerClear_Warn(_cntstruct_)
|
|
||||||
#define TrackerClear_User(_cntstruct_)
|
|
||||||
#define TrackerClear_UserAll(_cntstruct_)
|
|
||||||
|
|
||||||
#endif //TRACKERS_ENABLE
|
|
||||||
|
|
||||||
#endif //__TRACKERS_H_
|
|
||||||
141
Core/Src/main.c
141
Core/Src/main.c
@@ -1,141 +0,0 @@
|
|||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file main.c
|
|
||||||
* @author MCU Application Team
|
|
||||||
* @brief Main program body
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* <h2><center>© Copyright (c) Puya Semiconductor Co.
|
|
||||||
* All rights reserved.</center></h2>
|
|
||||||
*
|
|
||||||
* <h2><center>© Copyright (c) 2016 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
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "main.h"
|
|
||||||
#include "gpio.h"
|
|
||||||
#include "tim.h"
|
|
||||||
#include "usart.h"
|
|
||||||
#include "iwdg.h"
|
|
||||||
#include "PY32module_main.h"
|
|
||||||
|
|
||||||
/* Private define ------------------------------------------------------------*/
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
|
||||||
/* Private user code ---------------------------------------------------------*/
|
|
||||||
/* Private macro -------------------------------------------------------------*/
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
|
||||||
static void APP_SystemClockConfig(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Application Entry Function.
|
|
||||||
* @retval int
|
|
||||||
*/
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
__HAL_DBGMCU_FREEZE_IWDG();
|
|
||||||
__HAL_DBGMCU_FREEZE_TIM1();
|
|
||||||
__HAL_DBGMCU_FREEZE_TIM14();
|
|
||||||
/* Reset of all peripherals, Initializes the Systick. */
|
|
||||||
HAL_Init();
|
|
||||||
|
|
||||||
/* System clock configuration */
|
|
||||||
APP_SystemClockConfig();
|
|
||||||
|
|
||||||
// MX_IWDG_Init();
|
|
||||||
MX_GPIO_Init();
|
|
||||||
MX_TIM1_Init();
|
|
||||||
MX_TIM14_Init();
|
|
||||||
MX_USART1_UART_Init();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PYModule_FirstInit();
|
|
||||||
/* infinite loop */
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
PYModule_main();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief System clock configuration function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void APP_SystemClockConfig(void)
|
|
||||||
{
|
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|
||||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|
||||||
|
|
||||||
/* Oscillator configuration */
|
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE; /* Select oscillator HSE, HSI, LSI, LSE */
|
|
||||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON; /* Enable HSI */
|
|
||||||
RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; /* HSI 1 frequency division */
|
|
||||||
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_24MHz; /* Configure HSI clock 24MHz */
|
|
||||||
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS_DISABLE; /* Close HSE bypass */
|
|
||||||
RCC_OscInitStruct.LSIState = RCC_LSI_OFF; /* Close LSI */
|
|
||||||
/*RCC_OscInitStruct.LSICalibrationValue = RCC_LSICALIBRATION_32768Hz;*/
|
|
||||||
RCC_OscInitStruct.LSEState = RCC_LSE_OFF; /* Close LSE */
|
|
||||||
/*RCC_OscInitStruct.LSEDriver = RCC_LSEDRIVE_MEDIUM;*/
|
|
||||||
/* Configure oscillator */
|
|
||||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Clock source configuration */
|
|
||||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1; /* Choose to configure clock HCLK, SYSCLK, PCLK1 */
|
|
||||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSISYS; /* Select HSISYS as the system clock */
|
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; /* AHB clock 1 division */
|
|
||||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; /* APB clock 1 division */
|
|
||||||
/* Configure clock source */
|
|
||||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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)
|
|
||||||
{
|
|
||||||
/* Users can add their own printing information as needed,
|
|
||||||
for example: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|
||||||
/* Infinite loop */
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* USE_FULL_ASSERT */
|
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT Puya *****END OF FILE******************/
|
|
||||||
@@ -1,694 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
|
||||||
<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_projx.xsd">
|
|
||||||
|
|
||||||
<SchemaVersion>2.1</SchemaVersion>
|
|
||||||
|
|
||||||
<Header>### uVision Project, (C) Keil Software</Header>
|
|
||||||
|
|
||||||
<Targets>
|
|
||||||
<Target>
|
|
||||||
<TargetName>PY32F002Bx5_Project</TargetName>
|
|
||||||
<ToolsetNumber>0x4</ToolsetNumber>
|
|
||||||
<ToolsetName>ARM-ADS</ToolsetName>
|
|
||||||
<pArmCC>6190000::V6.19::ARMCLANG</pArmCC>
|
|
||||||
<pCCUsed>6190000::V6.19::ARMCLANG</pCCUsed>
|
|
||||||
<uAC6>1</uAC6>
|
|
||||||
<TargetOption>
|
|
||||||
<TargetCommonOption>
|
|
||||||
<Device>PY32F002Bx5</Device>
|
|
||||||
<Vendor>Puya</Vendor>
|
|
||||||
<PackID>Puya.PY32F0xx_DFP.1.2.2</PackID>
|
|
||||||
<PackURL>https://www.puyasemi.com/uploadfiles/</PackURL>
|
|
||||||
<Cpu>IRAM(0x20000000,0x00000C00) IROM(0x08000000,0x00006000) CPUTYPE("Cortex-M0+") CLOCK(12000000) ELITTLE</Cpu>
|
|
||||||
<FlashUtilSpec></FlashUtilSpec>
|
|
||||||
<StartupFile></StartupFile>
|
|
||||||
<FlashDriverDll>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC800 -FN1 -FF0PY32F002Bxx_24 -FS08000000 -FL06000 -FP0($$Device:PY32F002Bx5$Flash\PY32F002Bxx_24.FLM))</FlashDriverDll>
|
|
||||||
<DeviceId>0</DeviceId>
|
|
||||||
<RegisterFile>$$Device:PY32F002Bx5$Device\Include\py32f0xx.h</RegisterFile>
|
|
||||||
<MemoryEnv></MemoryEnv>
|
|
||||||
<Cmp></Cmp>
|
|
||||||
<Asm></Asm>
|
|
||||||
<Linker></Linker>
|
|
||||||
<OHString></OHString>
|
|
||||||
<InfinionOptionDll></InfinionOptionDll>
|
|
||||||
<SLE66CMisc></SLE66CMisc>
|
|
||||||
<SLE66AMisc></SLE66AMisc>
|
|
||||||
<SLE66LinkerMisc></SLE66LinkerMisc>
|
|
||||||
<SFDFile>$$Device:PY32F002Bx5$SVD\py32f002bxx.svd</SFDFile>
|
|
||||||
<bCustSvd>0</bCustSvd>
|
|
||||||
<UseEnv>0</UseEnv>
|
|
||||||
<BinPath></BinPath>
|
|
||||||
<IncludePath></IncludePath>
|
|
||||||
<LibPath></LibPath>
|
|
||||||
<RegisterFilePath></RegisterFilePath>
|
|
||||||
<DBRegisterFilePath></DBRegisterFilePath>
|
|
||||||
<TargetStatus>
|
|
||||||
<Error>0</Error>
|
|
||||||
<ExitCodeStop>0</ExitCodeStop>
|
|
||||||
<ButtonStop>0</ButtonStop>
|
|
||||||
<NotGenerated>0</NotGenerated>
|
|
||||||
<InvalidFlash>1</InvalidFlash>
|
|
||||||
</TargetStatus>
|
|
||||||
<OutputDirectory>.\Output\</OutputDirectory>
|
|
||||||
<OutputName>Project</OutputName>
|
|
||||||
<CreateExecutable>1</CreateExecutable>
|
|
||||||
<CreateLib>0</CreateLib>
|
|
||||||
<CreateHexFile>1</CreateHexFile>
|
|
||||||
<DebugInformation>1</DebugInformation>
|
|
||||||
<BrowseInformation>1</BrowseInformation>
|
|
||||||
<ListingPath>.\Output\</ListingPath>
|
|
||||||
<HexFormatSelection>1</HexFormatSelection>
|
|
||||||
<Merge32K>0</Merge32K>
|
|
||||||
<CreateBatchFile>0</CreateBatchFile>
|
|
||||||
<BeforeCompile>
|
|
||||||
<RunUserProg1>0</RunUserProg1>
|
|
||||||
<RunUserProg2>0</RunUserProg2>
|
|
||||||
<UserProg1Name></UserProg1Name>
|
|
||||||
<UserProg2Name></UserProg2Name>
|
|
||||||
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
|
|
||||||
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
|
|
||||||
<nStopU1X>0</nStopU1X>
|
|
||||||
<nStopU2X>0</nStopU2X>
|
|
||||||
</BeforeCompile>
|
|
||||||
<BeforeMake>
|
|
||||||
<RunUserProg1>0</RunUserProg1>
|
|
||||||
<RunUserProg2>0</RunUserProg2>
|
|
||||||
<UserProg1Name></UserProg1Name>
|
|
||||||
<UserProg2Name></UserProg2Name>
|
|
||||||
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
|
|
||||||
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
|
|
||||||
<nStopB1X>0</nStopB1X>
|
|
||||||
<nStopB2X>0</nStopB2X>
|
|
||||||
</BeforeMake>
|
|
||||||
<AfterMake>
|
|
||||||
<RunUserProg1>0</RunUserProg1>
|
|
||||||
<RunUserProg2>0</RunUserProg2>
|
|
||||||
<UserProg1Name></UserProg1Name>
|
|
||||||
<UserProg2Name></UserProg2Name>
|
|
||||||
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
|
|
||||||
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
|
|
||||||
<nStopA1X>0</nStopA1X>
|
|
||||||
<nStopA2X>0</nStopA2X>
|
|
||||||
</AfterMake>
|
|
||||||
<SelectedForBatchBuild>0</SelectedForBatchBuild>
|
|
||||||
<SVCSIdString></SVCSIdString>
|
|
||||||
</TargetCommonOption>
|
|
||||||
<CommonProperty>
|
|
||||||
<UseCPPCompiler>0</UseCPPCompiler>
|
|
||||||
<RVCTCodeConst>0</RVCTCodeConst>
|
|
||||||
<RVCTZI>0</RVCTZI>
|
|
||||||
<RVCTOtherData>0</RVCTOtherData>
|
|
||||||
<ModuleSelection>0</ModuleSelection>
|
|
||||||
<IncludeInBuild>1</IncludeInBuild>
|
|
||||||
<AlwaysBuild>0</AlwaysBuild>
|
|
||||||
<GenerateAssemblyFile>0</GenerateAssemblyFile>
|
|
||||||
<AssembleAssemblyFile>0</AssembleAssemblyFile>
|
|
||||||
<PublicsOnly>0</PublicsOnly>
|
|
||||||
<StopOnExitCode>3</StopOnExitCode>
|
|
||||||
<CustomArgument></CustomArgument>
|
|
||||||
<IncludeLibraryModules></IncludeLibraryModules>
|
|
||||||
<ComprImg>1</ComprImg>
|
|
||||||
</CommonProperty>
|
|
||||||
<DllOption>
|
|
||||||
<SimDllName>SARMCM3.DLL</SimDllName>
|
|
||||||
<SimDllArguments> -REMAP </SimDllArguments>
|
|
||||||
<SimDlgDll>DARMCM1.DLL</SimDlgDll>
|
|
||||||
<SimDlgDllArguments>-pCM0+</SimDlgDllArguments>
|
|
||||||
<TargetDllName>SARMCM3.DLL</TargetDllName>
|
|
||||||
<TargetDllArguments> </TargetDllArguments>
|
|
||||||
<TargetDlgDll>TARMCM1.DLL</TargetDlgDll>
|
|
||||||
<TargetDlgDllArguments>-pCM0+</TargetDlgDllArguments>
|
|
||||||
</DllOption>
|
|
||||||
<DebugOption>
|
|
||||||
<OPTHX>
|
|
||||||
<HexSelection>1</HexSelection>
|
|
||||||
<HexRangeLowAddress>0</HexRangeLowAddress>
|
|
||||||
<HexRangeHighAddress>0</HexRangeHighAddress>
|
|
||||||
<HexOffset>0</HexOffset>
|
|
||||||
<Oh166RecLen>16</Oh166RecLen>
|
|
||||||
</OPTHX>
|
|
||||||
</DebugOption>
|
|
||||||
<Utilities>
|
|
||||||
<Flash1>
|
|
||||||
<UseTargetDll>1</UseTargetDll>
|
|
||||||
<UseExternalTool>0</UseExternalTool>
|
|
||||||
<RunIndependent>0</RunIndependent>
|
|
||||||
<UpdateFlashBeforeDebugging>1</UpdateFlashBeforeDebugging>
|
|
||||||
<Capability>1</Capability>
|
|
||||||
<DriverSelection>4096</DriverSelection>
|
|
||||||
</Flash1>
|
|
||||||
<bUseTDR>1</bUseTDR>
|
|
||||||
<Flash2>BIN\UL2CM3.DLL</Flash2>
|
|
||||||
<Flash3>"" ()</Flash3>
|
|
||||||
<Flash4></Flash4>
|
|
||||||
<pFcarmOut></pFcarmOut>
|
|
||||||
<pFcarmGrp></pFcarmGrp>
|
|
||||||
<pFcArmRoot></pFcArmRoot>
|
|
||||||
<FcArmLst>0</FcArmLst>
|
|
||||||
</Utilities>
|
|
||||||
<TargetArmAds>
|
|
||||||
<ArmAdsMisc>
|
|
||||||
<GenerateListings>0</GenerateListings>
|
|
||||||
<asHll>1</asHll>
|
|
||||||
<asAsm>1</asAsm>
|
|
||||||
<asMacX>1</asMacX>
|
|
||||||
<asSyms>1</asSyms>
|
|
||||||
<asFals>1</asFals>
|
|
||||||
<asDbgD>1</asDbgD>
|
|
||||||
<asForm>1</asForm>
|
|
||||||
<ldLst>0</ldLst>
|
|
||||||
<ldmm>1</ldmm>
|
|
||||||
<ldXref>1</ldXref>
|
|
||||||
<BigEnd>0</BigEnd>
|
|
||||||
<AdsALst>1</AdsALst>
|
|
||||||
<AdsACrf>1</AdsACrf>
|
|
||||||
<AdsANop>0</AdsANop>
|
|
||||||
<AdsANot>0</AdsANot>
|
|
||||||
<AdsLLst>1</AdsLLst>
|
|
||||||
<AdsLmap>1</AdsLmap>
|
|
||||||
<AdsLcgr>1</AdsLcgr>
|
|
||||||
<AdsLsym>1</AdsLsym>
|
|
||||||
<AdsLszi>1</AdsLszi>
|
|
||||||
<AdsLtoi>1</AdsLtoi>
|
|
||||||
<AdsLsun>1</AdsLsun>
|
|
||||||
<AdsLven>1</AdsLven>
|
|
||||||
<AdsLsxf>1</AdsLsxf>
|
|
||||||
<RvctClst>0</RvctClst>
|
|
||||||
<GenPPlst>0</GenPPlst>
|
|
||||||
<AdsCpuType>"Cortex-M0+"</AdsCpuType>
|
|
||||||
<RvctDeviceName></RvctDeviceName>
|
|
||||||
<mOS>0</mOS>
|
|
||||||
<uocRom>0</uocRom>
|
|
||||||
<uocRam>0</uocRam>
|
|
||||||
<hadIROM>1</hadIROM>
|
|
||||||
<hadIRAM>1</hadIRAM>
|
|
||||||
<hadXRAM>0</hadXRAM>
|
|
||||||
<uocXRam>0</uocXRam>
|
|
||||||
<RvdsVP>0</RvdsVP>
|
|
||||||
<RvdsMve>0</RvdsMve>
|
|
||||||
<RvdsCdeCp>0</RvdsCdeCp>
|
|
||||||
<nBranchProt>0</nBranchProt>
|
|
||||||
<hadIRAM2>0</hadIRAM2>
|
|
||||||
<hadIROM2>0</hadIROM2>
|
|
||||||
<StupSel>8</StupSel>
|
|
||||||
<useUlib>1</useUlib>
|
|
||||||
<EndSel>0</EndSel>
|
|
||||||
<uLtcg>0</uLtcg>
|
|
||||||
<nSecure>0</nSecure>
|
|
||||||
<RoSelD>3</RoSelD>
|
|
||||||
<RwSelD>3</RwSelD>
|
|
||||||
<CodeSel>0</CodeSel>
|
|
||||||
<OptFeed>0</OptFeed>
|
|
||||||
<NoZi1>0</NoZi1>
|
|
||||||
<NoZi2>0</NoZi2>
|
|
||||||
<NoZi3>0</NoZi3>
|
|
||||||
<NoZi4>0</NoZi4>
|
|
||||||
<NoZi5>0</NoZi5>
|
|
||||||
<Ro1Chk>0</Ro1Chk>
|
|
||||||
<Ro2Chk>0</Ro2Chk>
|
|
||||||
<Ro3Chk>0</Ro3Chk>
|
|
||||||
<Ir1Chk>1</Ir1Chk>
|
|
||||||
<Ir2Chk>0</Ir2Chk>
|
|
||||||
<Ra1Chk>0</Ra1Chk>
|
|
||||||
<Ra2Chk>0</Ra2Chk>
|
|
||||||
<Ra3Chk>0</Ra3Chk>
|
|
||||||
<Im1Chk>1</Im1Chk>
|
|
||||||
<Im2Chk>0</Im2Chk>
|
|
||||||
<OnChipMemories>
|
|
||||||
<Ocm1>
|
|
||||||
<Type>0</Type>
|
|
||||||
<StartAddress>0x0</StartAddress>
|
|
||||||
<Size>0x0</Size>
|
|
||||||
</Ocm1>
|
|
||||||
<Ocm2>
|
|
||||||
<Type>0</Type>
|
|
||||||
<StartAddress>0x0</StartAddress>
|
|
||||||
<Size>0x0</Size>
|
|
||||||
</Ocm2>
|
|
||||||
<Ocm3>
|
|
||||||
<Type>0</Type>
|
|
||||||
<StartAddress>0x0</StartAddress>
|
|
||||||
<Size>0x0</Size>
|
|
||||||
</Ocm3>
|
|
||||||
<Ocm4>
|
|
||||||
<Type>0</Type>
|
|
||||||
<StartAddress>0x0</StartAddress>
|
|
||||||
<Size>0x0</Size>
|
|
||||||
</Ocm4>
|
|
||||||
<Ocm5>
|
|
||||||
<Type>0</Type>
|
|
||||||
<StartAddress>0x0</StartAddress>
|
|
||||||
<Size>0x0</Size>
|
|
||||||
</Ocm5>
|
|
||||||
<Ocm6>
|
|
||||||
<Type>0</Type>
|
|
||||||
<StartAddress>0x0</StartAddress>
|
|
||||||
<Size>0x0</Size>
|
|
||||||
</Ocm6>
|
|
||||||
<IRAM>
|
|
||||||
<Type>0</Type>
|
|
||||||
<StartAddress>0x20000000</StartAddress>
|
|
||||||
<Size>0xc00</Size>
|
|
||||||
</IRAM>
|
|
||||||
<IROM>
|
|
||||||
<Type>1</Type>
|
|
||||||
<StartAddress>0x8000000</StartAddress>
|
|
||||||
<Size>0x6000</Size>
|
|
||||||
</IROM>
|
|
||||||
<XRAM>
|
|
||||||
<Type>0</Type>
|
|
||||||
<StartAddress>0x0</StartAddress>
|
|
||||||
<Size>0x0</Size>
|
|
||||||
</XRAM>
|
|
||||||
<OCR_RVCT1>
|
|
||||||
<Type>1</Type>
|
|
||||||
<StartAddress>0x0</StartAddress>
|
|
||||||
<Size>0x0</Size>
|
|
||||||
</OCR_RVCT1>
|
|
||||||
<OCR_RVCT2>
|
|
||||||
<Type>1</Type>
|
|
||||||
<StartAddress>0x0</StartAddress>
|
|
||||||
<Size>0x0</Size>
|
|
||||||
</OCR_RVCT2>
|
|
||||||
<OCR_RVCT3>
|
|
||||||
<Type>1</Type>
|
|
||||||
<StartAddress>0x0</StartAddress>
|
|
||||||
<Size>0x0</Size>
|
|
||||||
</OCR_RVCT3>
|
|
||||||
<OCR_RVCT4>
|
|
||||||
<Type>1</Type>
|
|
||||||
<StartAddress>0x8000000</StartAddress>
|
|
||||||
<Size>0x6000</Size>
|
|
||||||
</OCR_RVCT4>
|
|
||||||
<OCR_RVCT5>
|
|
||||||
<Type>1</Type>
|
|
||||||
<StartAddress>0x0</StartAddress>
|
|
||||||
<Size>0x0</Size>
|
|
||||||
</OCR_RVCT5>
|
|
||||||
<OCR_RVCT6>
|
|
||||||
<Type>0</Type>
|
|
||||||
<StartAddress>0x0</StartAddress>
|
|
||||||
<Size>0x0</Size>
|
|
||||||
</OCR_RVCT6>
|
|
||||||
<OCR_RVCT7>
|
|
||||||
<Type>0</Type>
|
|
||||||
<StartAddress>0x0</StartAddress>
|
|
||||||
<Size>0x0</Size>
|
|
||||||
</OCR_RVCT7>
|
|
||||||
<OCR_RVCT8>
|
|
||||||
<Type>0</Type>
|
|
||||||
<StartAddress>0x0</StartAddress>
|
|
||||||
<Size>0x0</Size>
|
|
||||||
</OCR_RVCT8>
|
|
||||||
<OCR_RVCT9>
|
|
||||||
<Type>0</Type>
|
|
||||||
<StartAddress>0x20000000</StartAddress>
|
|
||||||
<Size>0xc00</Size>
|
|
||||||
</OCR_RVCT9>
|
|
||||||
<OCR_RVCT10>
|
|
||||||
<Type>0</Type>
|
|
||||||
<StartAddress>0x0</StartAddress>
|
|
||||||
<Size>0x0</Size>
|
|
||||||
</OCR_RVCT10>
|
|
||||||
</OnChipMemories>
|
|
||||||
<RvctStartVector></RvctStartVector>
|
|
||||||
</ArmAdsMisc>
|
|
||||||
<Cads>
|
|
||||||
<interw>1</interw>
|
|
||||||
<Optim>1</Optim>
|
|
||||||
<oTime>0</oTime>
|
|
||||||
<SplitLS>0</SplitLS>
|
|
||||||
<OneElfS>1</OneElfS>
|
|
||||||
<Strict>0</Strict>
|
|
||||||
<EnumInt>0</EnumInt>
|
|
||||||
<PlainCh>0</PlainCh>
|
|
||||||
<Ropi>0</Ropi>
|
|
||||||
<Rwpi>0</Rwpi>
|
|
||||||
<wLevel>3</wLevel>
|
|
||||||
<uThumb>0</uThumb>
|
|
||||||
<uSurpInc>0</uSurpInc>
|
|
||||||
<uC99>1</uC99>
|
|
||||||
<uGnu>0</uGnu>
|
|
||||||
<useXO>0</useXO>
|
|
||||||
<v6Lang>3</v6Lang>
|
|
||||||
<v6LangP>5</v6LangP>
|
|
||||||
<vShortEn>1</vShortEn>
|
|
||||||
<vShortWch>1</vShortWch>
|
|
||||||
<v6Lto>0</v6Lto>
|
|
||||||
<v6WtE>0</v6WtE>
|
|
||||||
<v6Rtti>0</v6Rtti>
|
|
||||||
<VariousControls>
|
|
||||||
<MiscControls></MiscControls>
|
|
||||||
<Define>USE_HAL_DRIVER,PY32F002Bx5</Define>
|
|
||||||
<Undefine></Undefine>
|
|
||||||
<IncludePath>..\Core\Inc;..\Drivers\CMSIS\Include;..\Drivers\CMSIS\Device\PY32F0xx\Include;..\Drivers\PY32F002B_HAL_Driver\Inc;..\Core\Dallas;..\Core\Modbus;..\Core\MyLibs;..\Core\PY32Module</IncludePath>
|
|
||||||
</VariousControls>
|
|
||||||
</Cads>
|
|
||||||
<Aads>
|
|
||||||
<interw>1</interw>
|
|
||||||
<Ropi>0</Ropi>
|
|
||||||
<Rwpi>0</Rwpi>
|
|
||||||
<thumb>0</thumb>
|
|
||||||
<SplitLS>0</SplitLS>
|
|
||||||
<SwStkChk>0</SwStkChk>
|
|
||||||
<NoWarn>0</NoWarn>
|
|
||||||
<uSurpInc>0</uSurpInc>
|
|
||||||
<useXO>0</useXO>
|
|
||||||
<ClangAsOpt>4</ClangAsOpt>
|
|
||||||
<VariousControls>
|
|
||||||
<MiscControls></MiscControls>
|
|
||||||
<Define></Define>
|
|
||||||
<Undefine></Undefine>
|
|
||||||
<IncludePath></IncludePath>
|
|
||||||
</VariousControls>
|
|
||||||
</Aads>
|
|
||||||
<LDads>
|
|
||||||
<umfTarg>1</umfTarg>
|
|
||||||
<Ropi>0</Ropi>
|
|
||||||
<Rwpi>0</Rwpi>
|
|
||||||
<noStLib>0</noStLib>
|
|
||||||
<RepFail>1</RepFail>
|
|
||||||
<useFile>0</useFile>
|
|
||||||
<TextAddressRange>0x00000000</TextAddressRange>
|
|
||||||
<DataAddressRange>0x20000000</DataAddressRange>
|
|
||||||
<pXoBase></pXoBase>
|
|
||||||
<ScatterFile>.\Objects\Project.sct</ScatterFile>
|
|
||||||
<IncludeLibs></IncludeLibs>
|
|
||||||
<IncludeLibsPath></IncludeLibsPath>
|
|
||||||
<Misc></Misc>
|
|
||||||
<LinkerInputFile></LinkerInputFile>
|
|
||||||
<DisabledWarnings></DisabledWarnings>
|
|
||||||
</LDads>
|
|
||||||
</TargetArmAds>
|
|
||||||
</TargetOption>
|
|
||||||
<Groups>
|
|
||||||
<Group>
|
|
||||||
<GroupName>Common</GroupName>
|
|
||||||
<Files>
|
|
||||||
<File>
|
|
||||||
<FileName>startup_py32f002bxx.s</FileName>
|
|
||||||
<FileType>2</FileType>
|
|
||||||
<FilePath>.\startup_py32f002bxx.s</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>system_py32f002b.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Core\Src\system_py32f002b.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>interface_config.h</FileName>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<FilePath>..\Core\Modbus\interface_config.h</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>modbus_data.h</FileName>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<FilePath>..\Core\Modbus\modbus_data.h</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>py32f002b_hal_conf.h</FileName>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<FilePath>..\Core\Inc\py32f002b_hal_conf.h</FilePath>
|
|
||||||
</File>
|
|
||||||
</Files>
|
|
||||||
</Group>
|
|
||||||
<Group>
|
|
||||||
<GroupName>PY32Module</GroupName>
|
|
||||||
<Files>
|
|
||||||
<File>
|
|
||||||
<FileName>PY32module_main.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Core\PY32Module\PY32module_main.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>PY32module_main.h</FileName>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<FilePath>..\Core\PY32Module\PY32module_main.h</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>pch_sensors.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Core\PY32Module\pch_sensors.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>pch_sensors.h</FileName>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<FilePath>..\Core\PY32Module\pch_sensors.h</FilePath>
|
|
||||||
</File>
|
|
||||||
</Files>
|
|
||||||
</Group>
|
|
||||||
<Group>
|
|
||||||
<GroupName>Dallas</GroupName>
|
|
||||||
<Files>
|
|
||||||
<File>
|
|
||||||
<FileName>dallas_tools.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Core\Dallas\dallas_tools.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>dallas_tools.h</FileName>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<FilePath>..\Core\Dallas\dallas_tools.h</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>ds18b20_driver.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Core\Dallas\ds18b20_driver.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>ds18b20_driver.h</FileName>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<FilePath>..\Core\Dallas\ds18b20_driver.h</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>onewire.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Core\Dallas\onewire.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>onewire.h</FileName>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<FilePath>..\Core\Dallas\onewire.h</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>ow_port.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Core\Dallas\ow_port.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>ow_port.h</FileName>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<FilePath>..\Core\Dallas\ow_port.h</FilePath>
|
|
||||||
</File>
|
|
||||||
</Files>
|
|
||||||
</Group>
|
|
||||||
<Group>
|
|
||||||
<GroupName>Modbus</GroupName>
|
|
||||||
<Files>
|
|
||||||
<File>
|
|
||||||
<FileName>crc_algs.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Core\Modbus\crc_algs.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>crc_algs.h</FileName>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<FilePath>..\Core\Modbus\crc_algs.h</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>modbus.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Core\Modbus\modbus.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>modbus.h</FileName>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<FilePath>..\Core\Modbus\modbus.h</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>rs_message.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Core\Modbus\rs_message.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>rs_message.h</FileName>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<FilePath>..\Core\Modbus\rs_message.h</FilePath>
|
|
||||||
</File>
|
|
||||||
</Files>
|
|
||||||
</Group>
|
|
||||||
<Group>
|
|
||||||
<GroupName>Application/User</GroupName>
|
|
||||||
<Files>
|
|
||||||
<File>
|
|
||||||
<FileName>main.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Core\Src\main.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>gpio.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Core\Src\gpio.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>tim.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Core\Src\tim.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>usart.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Core\Src\usart.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>iwdg.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Core\Src\iwdg.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>py32f002b_it.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Core\Src\py32f002b_it.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>py32f002b_hal_msp.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Core\Src\py32f002b_hal_msp.c</FilePath>
|
|
||||||
</File>
|
|
||||||
</Files>
|
|
||||||
</Group>
|
|
||||||
<Group>
|
|
||||||
<GroupName>MyLibs</GroupName>
|
|
||||||
<Files>
|
|
||||||
<File>
|
|
||||||
<FileName>bit_access.h</FileName>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<FilePath>..\Core\MyLibs\bit_access.h</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>general_gpio.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Core\MyLibs\general_gpio.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>general_gpio.h</FileName>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<FilePath>..\Core\MyLibs\general_gpio.h</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>mylibs_config.h</FileName>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<FilePath>..\Core\MyLibs\mylibs_config.h</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>mylibs_defs.h</FileName>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<FilePath>..\Core\MyLibs\mylibs_defs.h</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>mylibs_include.h</FileName>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<FilePath>..\Core\MyLibs\mylibs_include.h</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>trace.h</FileName>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<FilePath>..\Core\MyLibs\trace.h</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>trackers.h</FileName>
|
|
||||||
<FileType>5</FileType>
|
|
||||||
<FilePath>..\Core\MyLibs\trackers.h</FilePath>
|
|
||||||
</File>
|
|
||||||
</Files>
|
|
||||||
</Group>
|
|
||||||
<Group>
|
|
||||||
<GroupName>Drivers/PY32F002B_HAL_Driver</GroupName>
|
|
||||||
<Files>
|
|
||||||
<File>
|
|
||||||
<FileName>py32f002b_hal.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Drivers\PY32F002B_HAL_Driver\Src\py32f002b_hal.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>py32f002b_hal_rcc.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Drivers\PY32F002B_HAL_Driver\Src\py32f002b_hal_rcc.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>py32f002b_hal_rcc_ex.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Drivers\PY32F002B_HAL_Driver\Src\py32f002b_hal_rcc_ex.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>py32f002b_hal_cortex.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Drivers\PY32F002B_HAL_Driver\Src\py32f002b_hal_cortex.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>py32f002b_hal_gpio.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Drivers\PY32F002B_HAL_Driver\Src\py32f002b_hal_gpio.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>py32f002b_hal_pwr.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Drivers\PY32F002B_HAL_Driver\Src\py32f002b_hal_pwr.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>py32f002b_hal_usart.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Drivers\PY32F002B_HAL_Driver\Src\py32f002b_hal_usart.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>py32f002b_hal_tim.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Drivers\PY32F002B_HAL_Driver\Src\py32f002b_hal_tim.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>py32f002b_hal_tim_ex.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Drivers\PY32F002B_HAL_Driver\Src\py32f002b_hal_tim_ex.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>py32f002b_hal_uart.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Drivers\PY32F002B_HAL_Driver\Src\py32f002b_hal_uart.c</FilePath>
|
|
||||||
</File>
|
|
||||||
<File>
|
|
||||||
<FileName>py32f002b_hal_iwdg.c</FileName>
|
|
||||||
<FileType>1</FileType>
|
|
||||||
<FilePath>..\Drivers\PY32F002B_HAL_Driver\Src\py32f002b_hal_iwdg.c</FilePath>
|
|
||||||
</File>
|
|
||||||
</Files>
|
|
||||||
</Group>
|
|
||||||
<Group>
|
|
||||||
<GroupName>::CMSIS</GroupName>
|
|
||||||
</Group>
|
|
||||||
</Groups>
|
|
||||||
</Target>
|
|
||||||
</Targets>
|
|
||||||
|
|
||||||
<RTE>
|
|
||||||
<apis/>
|
|
||||||
<components>
|
|
||||||
<component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="5.6.0" condition="ARMv6_7_8-M Device">
|
|
||||||
<package name="CMSIS" schemaVersion="1.7.7" url="http://www.keil.com/pack/" vendor="ARM" version="5.9.0"/>
|
|
||||||
<targetInfos>
|
|
||||||
<targetInfo name="PY32F002Bx5_Project"/>
|
|
||||||
</targetInfos>
|
|
||||||
</component>
|
|
||||||
</components>
|
|
||||||
<files/>
|
|
||||||
</RTE>
|
|
||||||
|
|
||||||
<LayerInfo>
|
|
||||||
<Layers>
|
|
||||||
<Layer>
|
|
||||||
<LayName>PY32Dallas</LayName>
|
|
||||||
<LayPrjMark>1</LayPrjMark>
|
|
||||||
</Layer>
|
|
||||||
</Layers>
|
|
||||||
</LayerInfo>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
BIN
PY32F002A_Pins.xlsx
Normal file
BIN
PY32F002A_Pins.xlsx
Normal file
Binary file not shown.
BIN
PY32F002B_Pins.xlsx
Normal file
BIN
PY32F002B_Pins.xlsx
Normal file
Binary file not shown.
@@ -38,7 +38,7 @@ HAL_StatusTypeDef Dallas_ReplaceLostedSensor(DALLAS_SensorHandleTypeDef *sensor)
|
|||||||
|
|
||||||
if(sensor->isLost)
|
if(sensor->isLost)
|
||||||
{
|
{
|
||||||
if(DS18B20_Search(&DS, &OW) != HAL_OK)
|
if(DS18B20_Search(sensor->hdallas->ds_devices, sensor->hdallas->onewire) != HAL_OK)
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
|
|
||||||
if(sensor->Init.init_func(sensor->hdallas, sensor) != HAL_OK)
|
if(sensor->Init.init_func(sensor->hdallas, sensor) != HAL_OK)
|
||||||
@@ -287,11 +287,12 @@ HAL_StatusTypeDef Dallas_SensorDeInit(DALLAS_SensorHandleTypeDef *sensor)
|
|||||||
if(sensor == NULL)
|
if(sensor == NULL)
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
|
|
||||||
DALLAS_InitStructTypeDef initbuff = sensor->Init;
|
memset(&sensor->f, 0, sizeof(sensor->f));
|
||||||
|
sensor->isConnected = 0;
|
||||||
memset(sensor, 0, sizeof(DALLAS_SensorHandleTypeDef));
|
sensor->isInitialized = 0;
|
||||||
|
sensor->isLost = 0;
|
||||||
sensor->Init = initbuff;
|
sensor->temperature = 0;
|
||||||
|
sensor->sensROM = 0;
|
||||||
|
|
||||||
return HAL_OK;
|
return HAL_OK;
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "ds18b20_driver.h"
|
#include "ds18b20_driver.h"
|
||||||
|
|
||||||
DS18B20_Drv_t DS;
|
DS18B20_Drv_t *DS;
|
||||||
OneWire_t OW;
|
OneWire_t OW;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -593,6 +593,12 @@ HAL_StatusTypeDef DS18B20_Search(DS18B20_Drv_t *DS, OneWire_t *OW)
|
|||||||
|
|
||||||
OW->RomCnt++;
|
OW->RomCnt++;
|
||||||
}
|
}
|
||||||
|
for(int i = OW->RomCnt; i < DS18B20_DEVICE_AMOUNT; i++)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < 8; j++)
|
||||||
|
DS->DevAddr[i][j] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if(OW->RomCnt > 0)
|
if(OW->RomCnt > 0)
|
||||||
return HAL_OK;
|
return HAL_OK;
|
||||||
@@ -22,8 +22,14 @@
|
|||||||
#include "onewire.h"
|
#include "onewire.h"
|
||||||
|
|
||||||
/* I/O Port ------------------------------------------------------------------*/
|
/* I/O Port ------------------------------------------------------------------*/
|
||||||
|
#ifdef PY32F002Bx5
|
||||||
#define DS_Pin GPIO_PIN_0
|
#define DS_Pin GPIO_PIN_0
|
||||||
#define DS_GPIO_Port GPIOB
|
#define DS_GPIO_Port GPIOB
|
||||||
|
#endif
|
||||||
|
#ifdef PY32F002Ax5
|
||||||
|
#define DS_Pin GPIO_PIN_3
|
||||||
|
#define DS_GPIO_Port GPIOA
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Data Structure ------------------------------------------------------------*/
|
/* Data Structure ------------------------------------------------------------*/
|
||||||
#define DS18B20_DEVICE_AMOUNT 30
|
#define DS18B20_DEVICE_AMOUNT 30
|
||||||
@@ -78,7 +84,7 @@ typedef struct
|
|||||||
{
|
{
|
||||||
uint8_t DevAddr[DS18B20_DEVICE_AMOUNT][8];
|
uint8_t DevAddr[DS18B20_DEVICE_AMOUNT][8];
|
||||||
} DS18B20_Drv_t;
|
} DS18B20_Drv_t;
|
||||||
extern DS18B20_Drv_t DS;
|
extern DS18B20_Drv_t *DS;;
|
||||||
extern OneWire_t OW;
|
extern OneWire_t OW;
|
||||||
|
|
||||||
/* External Function ---------------------------------------------------------*/
|
/* External Function ---------------------------------------------------------*/
|
||||||
@@ -8,6 +8,13 @@
|
|||||||
#include "onewire.h"
|
#include "onewire.h"
|
||||||
#include "tim.h"
|
#include "tim.h"
|
||||||
|
|
||||||
|
#ifdef PY32F002Bx5
|
||||||
|
#define PIN_NUMB 0
|
||||||
|
#endif
|
||||||
|
#ifdef PY32F002Ax5
|
||||||
|
#define PIN_NUMB 3
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The internal function is used as gpio pin mode
|
* @brief The internal function is used as gpio pin mode
|
||||||
* @param OW OneWire HandleTypedef
|
* @param OW OneWire HandleTypedef
|
||||||
@@ -16,30 +23,13 @@
|
|||||||
void OneWire_Pin_Mode(OneWire_t* OW, PinMode Mode)
|
void OneWire_Pin_Mode(OneWire_t* OW, PinMode Mode)
|
||||||
{
|
{
|
||||||
#ifdef CMSIS_Driver
|
#ifdef CMSIS_Driver
|
||||||
static uint32_t pin_cr_numb = 0;
|
|
||||||
static int get_pin_numb = 1;
|
|
||||||
|
|
||||||
if(get_pin_numb)
|
|
||||||
{
|
|
||||||
get_pin_numb = 0;
|
|
||||||
for(int i = 0; i < 8; i++)
|
|
||||||
{
|
|
||||||
if((OW->DataPin >> i) == 0x1)
|
|
||||||
pin_cr_numb = i*4;
|
|
||||||
}
|
|
||||||
for(int i = 8; i < 16; i++)
|
|
||||||
{
|
|
||||||
if((OW->DataPin >> i) == 0x1)
|
|
||||||
pin_cr_numb = (i-8)*4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(Mode == Input)
|
if(Mode == Input)
|
||||||
{
|
{
|
||||||
OW->DataPort->MODER &= ~((GPIO_MODER_MODE0_Msk) << pin_cr_numb);
|
OW->DataPort->MODER &= ~((GPIO_MODER_MODE0_Msk) << PIN_NUMB);
|
||||||
OW->DataPort->MODER |= (GPIO_MODE_INPUT << (pin_cr_numb+2));
|
OW->DataPort->MODER |= (GPIO_MODE_INPUT << (PIN_NUMB));
|
||||||
}else{
|
}else{
|
||||||
OW->DataPort->MODER &= ~((GPIO_MODER_MODE0_Msk) << pin_cr_numb);
|
OW->DataPort->MODER &= ~((GPIO_MODER_MODE0_Msk) << PIN_NUMB);
|
||||||
OW->DataPort->MODER |= (GPIO_MODE_OUTPUT_PP << pin_cr_numb);
|
OW->DataPort->MODER |= (GPIO_MODE_OUTPUT_PP << PIN_NUMB);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#ifdef LL_Driver
|
#ifdef LL_Driver
|
||||||
@@ -38,6 +38,22 @@ extern "C" {
|
|||||||
#define GPIO_LED_3 GPIO_PIN_5
|
#define GPIO_LED_3 GPIO_PIN_5
|
||||||
#define GPIO_LED_4 GPIO_PIN_4
|
#define GPIO_LED_4 GPIO_PIN_4
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef PY32F002Bx5
|
||||||
|
#define TIM_MB TIM14
|
||||||
|
#define __HAL_DBGMCU_FREEZE_TIM_MB __HAL_DBGMCU_FREEZE_TIM14
|
||||||
|
#define __HAL_RCC_TIM_MB_CLK_ENABLE __HAL_RCC_TIM14_CLK_ENABLE
|
||||||
|
#define TIM_MB_IRQn TIM14_IRQn
|
||||||
|
#define TIM_MB_IRQHandler TIM14_IRQHandler
|
||||||
|
#endif
|
||||||
|
#ifdef PY32F002Ax5
|
||||||
|
#define TIM_MB TIM16
|
||||||
|
#define __HAL_DBGMCU_FREEZE_TIM_MB __HAL_DBGMCU_FREEZE_TIM16
|
||||||
|
#define __HAL_RCC_TIM_MB_CLK_ENABLE __HAL_RCC_TIM16_CLK_ENABLE
|
||||||
|
#define TIM_MB_IRQn TIM16_IRQn
|
||||||
|
#define TIM_MB_IRQHandler TIM16_IRQHandler
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Exported variables prototypes ---------------------------------------------*/
|
/* Exported variables prototypes ---------------------------------------------*/
|
||||||
/* Exported functions prototypes ---------------------------------------------*/
|
/* Exported functions prototypes ---------------------------------------------*/
|
||||||
void Error_Handler(void);
|
void Error_Handler(void);
|
||||||
222
py_project/Core/Inc/py32f0xx_hal_conf.h
Normal file
222
py_project/Core/Inc/py32f0xx_hal_conf.h
Normal file
@@ -0,0 +1,222 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file py32f0xx_hal_conf.h
|
||||||
|
* @author MCU Application Team
|
||||||
|
* @Version V1.0.0
|
||||||
|
* @Date
|
||||||
|
* @brief HAL configuration file.
|
||||||
|
******************************************************************************
|
||||||
|
**/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __PY32F0xx_HAL_CONF_H
|
||||||
|
#define __PY32F0xx_HAL_CONF_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Exported types ------------------------------------------------------------*/
|
||||||
|
/* Exported constants --------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* ########################## Module Selection ############################## */
|
||||||
|
/**
|
||||||
|
* @brief This is the list of modules to be used in the HAL driver
|
||||||
|
*/
|
||||||
|
#define HAL_MODULE_ENABLED
|
||||||
|
#define HAL_RCC_MODULE_ENABLED
|
||||||
|
//#define HAL_ADC_MODULE_ENABLED
|
||||||
|
//#define HAL_CRC_MODULE_ENABLED
|
||||||
|
//#define HAL_COMP_MODULE_ENABLED
|
||||||
|
#define HAL_FLASH_MODULE_ENABLED
|
||||||
|
#define HAL_GPIO_MODULE_ENABLED
|
||||||
|
#define HAL_IWDG_MODULE_ENABLED
|
||||||
|
#define HAL_TIM_MODULE_ENABLED
|
||||||
|
//#define HAL_LPTIM_MODULE_ENABLED
|
||||||
|
#define HAL_PWR_MODULE_ENABLED
|
||||||
|
//#define HAL_I2C_MODULE_ENABLED
|
||||||
|
#define HAL_UART_MODULE_ENABLED
|
||||||
|
#define HAL_USART_MODULE_ENABLED
|
||||||
|
//#define HAL_SPI_MODULE_ENABLED
|
||||||
|
//#define HAL_EXTI_MODULE_ENABLED
|
||||||
|
#define HAL_CORTEX_MODULE_ENABLED
|
||||||
|
|
||||||
|
/* ########################## Oscillator Values adaptation ####################*/
|
||||||
|
|
||||||
|
#if !defined (HSI_VALUE)
|
||||||
|
#define HSI_VALUE ((uint32_t)8000000) /*!< Value of the Internal oscillator in Hz */
|
||||||
|
#endif /* HSI_VALUE */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adjust the value of External High Speed oscillator (HXT) used in your application.
|
||||||
|
* This value is used by the RCC HAL module to compute the system frequency
|
||||||
|
*/
|
||||||
|
#if !defined (HSE_VALUE)
|
||||||
|
#define HSE_VALUE ((uint32_t)24000000) /*!< Value of the External oscillator in Hz */
|
||||||
|
#endif /* HSE_VALUE */
|
||||||
|
|
||||||
|
#if !defined (HSE_STARTUP_TIMEOUT)
|
||||||
|
#define HSE_STARTUP_TIMEOUT ((uint32_t)200) /*!< Time out for HXT start up, in ms */
|
||||||
|
#endif /* HSE_STARTUP_TIMEOUT */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Internal Low Speed Internal oscillator (LIRC) value.
|
||||||
|
*/
|
||||||
|
#if !defined (LSI_VALUE)
|
||||||
|
#define LSI_VALUE 32768U /*!< LIRC Typical Value in Hz */
|
||||||
|
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
|
||||||
|
The real value may vary depending on the variations
|
||||||
|
in voltage and temperature. */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adjust the value of External Low Speed oscillator (LXT) used in your application.
|
||||||
|
* This value is used by the RCC HAL module to compute the system frequency
|
||||||
|
*/
|
||||||
|
#if !defined (LSE_VALUE)
|
||||||
|
#define LSE_VALUE ((uint32_t)32768) /*!< Value of the External oscillator in Hz*/
|
||||||
|
#endif /* LSE_VALUE */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined (LSE_STARTUP_TIMEOUT)
|
||||||
|
#define LSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for LXT start up, in ms */
|
||||||
|
#endif /* LSE_STARTUP_TIMEOUT */
|
||||||
|
|
||||||
|
/* Tip: To avoid modifying this file each time you need to use different HSE,
|
||||||
|
=== you can define the HSE value in your toolchain compiler preprocessor. */
|
||||||
|
|
||||||
|
/* ########################### System Configuration ######################### */
|
||||||
|
/**
|
||||||
|
* @brief This is the HAL system configuration section
|
||||||
|
*/
|
||||||
|
#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */
|
||||||
|
#define PRIORITY_HIGHEST 0
|
||||||
|
#define PRIORITY_HIGH 1
|
||||||
|
#define PRIORITY_LOW 2
|
||||||
|
#define PRIORITY_LOWEST 3
|
||||||
|
#define TICK_INT_PRIORITY ((uint32_t)PRIORITY_LOWEST) /*!< tick interrupt priority (lowest by default) */
|
||||||
|
#define USE_RTOS 0
|
||||||
|
#define PREFETCH_ENABLE 1
|
||||||
|
|
||||||
|
/* ########################## Assert Selection ############################## */
|
||||||
|
/**
|
||||||
|
* @brief Uncomment the line below to expanse the "assert_param" macro in the
|
||||||
|
* HAL drivers code
|
||||||
|
*/
|
||||||
|
/* #define USE_FULL_ASSERT 1U */
|
||||||
|
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* @brief Include module's header file
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAL_MODULE_ENABLED
|
||||||
|
#include "py32f0xx_hal.h"
|
||||||
|
#endif /* HAL_MODULE_ENABLED */
|
||||||
|
|
||||||
|
#ifdef HAL_RCC_MODULE_ENABLED
|
||||||
|
#include "py32f0xx_hal_rcc.h"
|
||||||
|
#endif /* HAL_RCC_MODULE_ENABLED */
|
||||||
|
|
||||||
|
#ifdef HAL_EXTI_MODULE_ENABLED
|
||||||
|
#include "py32f0xx_hal_exti.h"
|
||||||
|
#endif /* HAL_EXTI_MODULE_ENABLED */
|
||||||
|
|
||||||
|
#ifdef HAL_GPIO_MODULE_ENABLED
|
||||||
|
#include "py32f0xx_hal_gpio.h"
|
||||||
|
#endif /* HAL_GPIO_MODULE_ENABLED */
|
||||||
|
|
||||||
|
#ifdef HAL_CORTEX_MODULE_ENABLED
|
||||||
|
#include "py32f0xx_hal_cortex.h"
|
||||||
|
#endif /* HAL_CORTEX_MODULE_ENABLED */
|
||||||
|
|
||||||
|
#ifdef HAL_DMA_MODULE_ENABLED
|
||||||
|
#include "py32f0xx_hal_dma.h"
|
||||||
|
#endif /* HAL_DMA_MODULE_ENABLED */
|
||||||
|
|
||||||
|
#ifdef HAL_ADC_MODULE_ENABLED
|
||||||
|
#include "py32f0xx_hal_adc.h"
|
||||||
|
#endif /* HAL_ADC_MODULE_ENABLED */
|
||||||
|
|
||||||
|
#ifdef HAL_CRC_MODULE_ENABLED
|
||||||
|
#include "py32f0xx_hal_crc.h"
|
||||||
|
#endif /* HAL_CRC_MODULE_ENABLED */
|
||||||
|
|
||||||
|
#ifdef HAL_COMP_MODULE_ENABLED
|
||||||
|
#include "py32f0xx_hal_comp.h"
|
||||||
|
#endif /* HAL_COMP_MODULE_ENABLED */
|
||||||
|
|
||||||
|
#ifdef HAL_FLASH_MODULE_ENABLED
|
||||||
|
#include "py32f0xx_hal_flash.h"
|
||||||
|
#endif /* HAL_FLASH_MODULE_ENABLED */
|
||||||
|
|
||||||
|
#ifdef HAL_I2C_MODULE_ENABLED
|
||||||
|
#include "py32f0xx_hal_i2c.h"
|
||||||
|
#endif /* HAL_I2C_MODULE_ENABLED */
|
||||||
|
|
||||||
|
#ifdef HAL_IWDG_MODULE_ENABLED
|
||||||
|
#include "py32f0xx_hal_iwdg.h"
|
||||||
|
#endif /* HAL_IWDG_MODULE_ENABLED */
|
||||||
|
|
||||||
|
#ifdef HAL_PWR_MODULE_ENABLED
|
||||||
|
#include "py32f0xx_hal_pwr.h"
|
||||||
|
#endif /* HAL_PWR_MODULE_ENABLED */
|
||||||
|
|
||||||
|
#ifdef HAL_RTC_MODULE_ENABLED
|
||||||
|
#include "py32f0xx_hal_rtc.h"
|
||||||
|
#endif /* HAL_RTC_MODULE_ENABLED */
|
||||||
|
|
||||||
|
#ifdef HAL_SPI_MODULE_ENABLED
|
||||||
|
#include "py32f0xx_hal_spi.h"
|
||||||
|
#endif /* HAL_SPI_MODULE_ENABLED */
|
||||||
|
|
||||||
|
#ifdef HAL_TIM_MODULE_ENABLED
|
||||||
|
#include "py32f0xx_hal_tim.h"
|
||||||
|
#endif /* HAL_TIM_MODULE_ENABLED */
|
||||||
|
|
||||||
|
#ifdef HAL_LPTIM_MODULE_ENABLED
|
||||||
|
#include "py32f0xx_hal_lptim.h"
|
||||||
|
#endif /* HAL_LPTIM_MODULE_ENABLED */
|
||||||
|
|
||||||
|
#ifdef HAL_UART_MODULE_ENABLED
|
||||||
|
#include "py32f0xx_hal_uart.h"
|
||||||
|
#endif /* HAL_UART_MODULE_ENABLED */
|
||||||
|
|
||||||
|
#ifdef HAL_WWDG_MODULE_ENABLED
|
||||||
|
#include "py32f0xx_hal_wwdg.h"
|
||||||
|
#endif /* HAL_WWDG_MODULE_ENABLED */
|
||||||
|
|
||||||
|
#ifdef HAL_LED_MODULE_ENABLED
|
||||||
|
#include "py32f0xx_hal_led.h"
|
||||||
|
#endif /* HAL_LED_MODULE_ENABLED */
|
||||||
|
|
||||||
|
#ifdef HAL_USART_MODULE_ENABLED
|
||||||
|
#include "py32f0xx_hal_usart.h"
|
||||||
|
#endif /* HAL_USART_MODULE_ENABLED */
|
||||||
|
|
||||||
|
/* Exported macro ------------------------------------------------------------*/
|
||||||
|
#ifdef USE_FULL_ASSERT
|
||||||
|
/**
|
||||||
|
* @brief The assert_param macro is used for function's parameters check.
|
||||||
|
* @param expr: If expr is false, it calls assert_failed function
|
||||||
|
* which reports the name of the source file and the source
|
||||||
|
* line number of the call that failed.
|
||||||
|
* If expr is true, it returns no value.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
|
||||||
|
/* Exported functions ------------------------------------------------------- */
|
||||||
|
void assert_failed(uint8_t* file, uint32_t line);
|
||||||
|
#else
|
||||||
|
#define assert_param(expr) ((void)0U)
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __PY32F0xx_HAL_CONF_H */
|
||||||
|
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ extern TIM_HandleTypeDef htim14;
|
|||||||
/* USER CODE END Private defines */
|
/* USER CODE END Private defines */
|
||||||
|
|
||||||
void MX_TIM1_Init(void);
|
void MX_TIM1_Init(void);
|
||||||
void MX_TIM14_Init(void);
|
void MX_TIMMB_Init(void);
|
||||||
|
|
||||||
/* USER CODE BEGIN Prototypes */
|
/* USER CODE BEGIN Prototypes */
|
||||||
|
|
||||||
@@ -1,13 +1,6 @@
|
|||||||
#include "crc_algs.h"
|
#include "crc_algs.h"
|
||||||
|
|
||||||
|
|
||||||
uint32_t CRC_calc;
|
|
||||||
uint32_t CRC_ref;
|
|
||||||
|
|
||||||
//uint16_t CRC_calc;
|
|
||||||
//uint16_t CRC_ref;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*Table of CRC values for high order byte*/
|
/*Table of CRC values for high order byte*/
|
||||||
const unsigned char auchCRCHi[]=
|
const unsigned char auchCRCHi[]=
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "mylibs_include.h"
|
#include "main.h"
|
||||||
|
|
||||||
// extern here to use in bootloader.c
|
// extern here to use in bootloader.c
|
||||||
extern uint32_t CRC_calc;
|
extern uint32_t CRC_calc;
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
#define MODBUS_VENDOR_NAME "NIO-12"
|
#define MODBUS_VENDOR_NAME "NIO-12"
|
||||||
#define MODBUS_PRODUCT_CODE "12345"
|
#define MODBUS_PRODUCT_CODE "12345"
|
||||||
#define MODBUS_REVISION "Ver. 1.0"
|
#define MODBUS_REVISION "Ver. 1.0"
|
||||||
#define MODBUS_VENDOR_URL "https://git.arktika.cyou/set506/DS18B20_Library/src/branch/py32f002b_dallas"
|
#define MODBUS_VENDOR_URL "https://git.arktika.cyou/set506/DS18B20_Library/"
|
||||||
#define MODBUS_PRODUCT_NAME "Dallas Driver"
|
#define MODBUS_PRODUCT_NAME "Dallas Driver"
|
||||||
#define MODBUS_MODEL_NAME "PY32F002B"
|
#define MODBUS_MODEL_NAME "PY32F002B"
|
||||||
#define MODBUS_USER_APPLICATION_NAME "PY32Dallas"
|
#define MODBUS_USER_APPLICATION_NAME "PY32Dallas"
|
||||||
@@ -39,6 +39,9 @@
|
|||||||
#define RS_TIM_DeInit HAL_TIM_Base_MspDeInit
|
#define RS_TIM_DeInit HAL_TIM_Base_MspDeInit
|
||||||
#define rs_huart huart1
|
#define rs_huart huart1
|
||||||
#define rs_htim htim14
|
#define rs_htim htim14
|
||||||
|
|
||||||
|
#define RS_EnableReceive() GPIOB->ODR |= GPIO_PIN_3
|
||||||
|
#define RS_EnableTransmit() GPIOB->ODR &= ~GPIO_PIN_3
|
||||||
/**
|
/**
|
||||||
* @brief Поменять комманды 0x03 и 0x04 местами (для LabView терминалки от двигателей)
|
* @brief Поменять комманды 0x03 и 0x04 местами (для LabView терминалки от двигателей)
|
||||||
* @details Терминалка от двигателей использует для чтения регистров комманду R_HOLD_REGS вместо R_IN_REGS
|
* @details Терминалка от двигателей использует для чтения регистров комманду R_HOLD_REGS вместо R_IN_REGS
|
||||||
@@ -81,14 +81,13 @@ EXAMPLE: INIT SLAVE RECEIVE
|
|||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
#include "rs_message.h"
|
#include "rs_message.h"
|
||||||
uint32_t dbg_temp, dbg_temp2, dbg_temp3; // for debug
|
|
||||||
/* MODBUS HANDLES */
|
/* MODBUS HANDLES */
|
||||||
#ifdef INCLUDE_GENERAL_PERIPH_LIBS
|
#ifdef INCLUDE_GENERAL_PERIPH_LIBS
|
||||||
UART_SettingsTypeDef modbus1_suart;
|
UART_SettingsTypeDef modbus1_suart;
|
||||||
TIM_SettingsTypeDef modbus1_stim;
|
TIM_SettingsTypeDef modbus1_stim;
|
||||||
#else
|
#else
|
||||||
extern UART_HandleTypeDef rs_huart;
|
extern UART_HandleTypeDef rs_huart;
|
||||||
extern TIM_HandleTypeDef rs_htim;
|
//extern TIM_HandleTypeDef rs_htim;
|
||||||
#endif
|
#endif
|
||||||
RS_HandleTypeDef hmodbus1;
|
RS_HandleTypeDef hmodbus1;
|
||||||
|
|
||||||
@@ -136,7 +135,7 @@ void MODBUS_FirstInit(void)
|
|||||||
#ifdef INCLUDE_GENERAL_PERIPH_LIBS
|
#ifdef INCLUDE_GENERAL_PERIPH_LIBS
|
||||||
hmodbus1.RS_STATUS = RS_Init(&hmodbus1, &modbus1_suart, &modbus1_stim, 0);
|
hmodbus1.RS_STATUS = RS_Init(&hmodbus1, &modbus1_suart, &modbus1_stim, 0);
|
||||||
#else
|
#else
|
||||||
hmodbus1.RS_STATUS = RS_Init(&hmodbus1, &rs_huart, &rs_htim, 0);
|
hmodbus1.RS_STATUS = RS_Init(&hmodbus1, &rs_huart, NULL, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RS_EnableReceive();
|
RS_EnableReceive();
|
||||||
@@ -291,6 +290,11 @@ MB_ExceptionTypeDef MB_DefineRegistersAddress(uint16_t **pRegs, uint16_t Addr, u
|
|||||||
extern void PYModule_IncrementScanSensor(void);
|
extern void PYModule_IncrementScanSensor(void);
|
||||||
PYModule_IncrementScanSensor();
|
PYModule_IncrementScanSensor();
|
||||||
}
|
}
|
||||||
|
// Все найденные ROM на линии
|
||||||
|
else if(MB_Check_Address_For_Arr(Addr, Qnt, R_ALL_ROMS_ADDR, R_ALL_ROMS_QNT) == NO_ERRORS)
|
||||||
|
{
|
||||||
|
*pRegs = MB_Set_Register_Ptr(&MB_DATA.InRegs, Addr); // начало регистров хранения/входных
|
||||||
|
}
|
||||||
// if address doesnt match any array - return illegal data address response
|
// if address doesnt match any array - return illegal data address response
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -733,12 +737,12 @@ RS_StatusTypeDef RS_Response(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef *modbus_ms
|
|||||||
|
|
||||||
if(hmodbus->f.MessageHandled == 0)
|
if(hmodbus->f.MessageHandled == 0)
|
||||||
{
|
{
|
||||||
TrackerCnt_Err(hmodbus->rs_err);
|
|
||||||
modbus_msg->Func_Code += ERR_VALUES_START;
|
modbus_msg->Func_Code += ERR_VALUES_START;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TrackerCnt_Ok(hmodbus->rs_err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -793,7 +797,7 @@ RS_StatusTypeDef RS_Collect_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef *mo
|
|||||||
|
|
||||||
if (modbus_msg->ByteCnt > DATA_SIZE*2) // if ByteCnt less than DATA_SIZE
|
if (modbus_msg->ByteCnt > DATA_SIZE*2) // if ByteCnt less than DATA_SIZE
|
||||||
{
|
{
|
||||||
TrackerCnt_Err(hmodbus->rs_err);
|
|
||||||
return RS_COLLECT_MSG_ERR;
|
return RS_COLLECT_MSG_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -815,7 +819,7 @@ RS_StatusTypeDef RS_Collect_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef *mo
|
|||||||
modbus_uart_buff[ind++] = modbus_msg->ByteCnt;
|
modbus_uart_buff[ind++] = modbus_msg->ByteCnt;
|
||||||
else // otherwise return data_size err
|
else // otherwise return data_size err
|
||||||
{
|
{
|
||||||
TrackerCnt_Err(hmodbus->rs_err);
|
|
||||||
return RS_COLLECT_MSG_ERR;
|
return RS_COLLECT_MSG_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -903,7 +907,7 @@ RS_StatusTypeDef RS_Parse_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef *modb
|
|||||||
//check that data size is correct
|
//check that data size is correct
|
||||||
if (modbus_msg->ByteCnt > DATA_SIZE*2)
|
if (modbus_msg->ByteCnt > DATA_SIZE*2)
|
||||||
{
|
{
|
||||||
TrackerCnt_Err(hmodbus->rs_err);
|
|
||||||
modbus_msg->Func_Code += ERR_VALUES_START;
|
modbus_msg->Func_Code += ERR_VALUES_START;
|
||||||
return RS_PARSE_MSG_ERR;
|
return RS_PARSE_MSG_ERR;
|
||||||
}
|
}
|
||||||
@@ -930,7 +934,7 @@ RS_StatusTypeDef RS_Parse_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef *modb
|
|||||||
// compare crc
|
// compare crc
|
||||||
if (modbus_msg->MB_CRC != CRC_VALUE)
|
if (modbus_msg->MB_CRC != CRC_VALUE)
|
||||||
{
|
{
|
||||||
TrackerCnt_Err(hmodbus->rs_err);
|
|
||||||
modbus_msg->Func_Code += ERR_VALUES_START;
|
modbus_msg->Func_Code += ERR_VALUES_START;
|
||||||
}
|
}
|
||||||
// hmodbus->MB_RESPONSE = MB_CRC_ERR; // set func code - error about wrong crc
|
// hmodbus->MB_RESPONSE = MB_CRC_ERR; // set func code - error about wrong crc
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
#ifndef __MODBUS_H_
|
#ifndef __MODBUS_H_
|
||||||
#define __MODBUS_H_
|
#define __MODBUS_H_
|
||||||
|
|
||||||
#include "mylibs_include.h"
|
#include "main.h"
|
||||||
#include "modbus_data.h"
|
#include "modbus_data.h"
|
||||||
//#include "settings.h" // for modbus settings
|
//#include "settings.h" // for modbus settings
|
||||||
|
|
||||||
@@ -330,7 +330,44 @@ uint8_t MB_Write_Miltuple_Regs(RS_MsgTypeDef *modbus_msg);
|
|||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
/////////////////////////---FUNCTIONS---/////////////////////////////
|
/////////////////////////---FUNCTIONS---/////////////////////////////
|
||||||
|
/***************************************************************************
|
||||||
|
*******************************MATH_DEFINES********************************/
|
||||||
|
/**
|
||||||
|
* @addtogroup MATH_DEFINES Math defines
|
||||||
|
* @ingroup MYLIBS_DEFINES
|
||||||
|
* @brief Дефайны для различных математических функций
|
||||||
|
@{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Calc dividing including remainder
|
||||||
|
* @param _val_ - делимое.
|
||||||
|
* @param _div_ - делитель.
|
||||||
|
* @details Если результат деления без остатка: он возвращается как есть
|
||||||
|
Если с остатком - округляется вверх
|
||||||
|
*/
|
||||||
|
//#define Divide_Up(_val_, _div_) (((_val_)%(_div_))? (_val_)/(_div_)+1 : (_val_)/_div_) /* через тернарный оператор */
|
||||||
|
#define Divide_Up(_val_, _div_) ((_val_ - 1) / _div_) + 1 /* через мат выражение */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Swap between Little Endian and Big Endian
|
||||||
|
* @param v - Переменная для свапа.
|
||||||
|
* @return v (new) - Свапнутая переменная.
|
||||||
|
* @details Переключения между двумя типами хранения слова: HI-LO байты и LO-HI байты.
|
||||||
|
*/
|
||||||
|
#define ByteSwap16(v) (((v&0xFF00) >> (8)) | ((v&0x00FF) << (8)))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Absolute
|
||||||
|
* @param x - Переменная для модудя.
|
||||||
|
* @return x (new) - Число по модулю.
|
||||||
|
* @details Берет число по модулю. Хз как работает библиотечный abs в stdlib.h, мб это быстрее, но вряд ли конечно.
|
||||||
|
*/
|
||||||
|
#define ABS(x) ( ((x) > 0)? (x) : -(x))?
|
||||||
|
|
||||||
|
/** MATH_DEFINES
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
@@ -54,6 +54,8 @@ typedef struct //MB_DataInRegsTypeDef
|
|||||||
{
|
{
|
||||||
uint16_t SensTemperature[DS18B20_DEVICE_AMOUNT];
|
uint16_t SensTemperature[DS18B20_DEVICE_AMOUNT];
|
||||||
MB_SensorParamsTypeDef Response;
|
MB_SensorParamsTypeDef Response;
|
||||||
|
uint16_t reserved;
|
||||||
|
uint16_t AllROMs[DS18B20_DEVICE_AMOUNT][4];
|
||||||
}MB_DataInRegsTypeDef;
|
}MB_DataInRegsTypeDef;
|
||||||
|
|
||||||
|
|
||||||
@@ -69,8 +71,10 @@ typedef struct //MB_DataInRegsTypeDef
|
|||||||
// DEFINES FOR INPUT REGISTERS ARRAYS
|
// DEFINES FOR INPUT REGISTERS ARRAYS
|
||||||
#define R_TEMPERATURE_ADDR (0)
|
#define R_TEMPERATURE_ADDR (0)
|
||||||
#define R_TEMPERATURE_QNT (DS18B20_DEVICE_AMOUNT)
|
#define R_TEMPERATURE_QNT (DS18B20_DEVICE_AMOUNT)
|
||||||
#define R_SENS_PARAMS_ADDR (DS18B20_DEVICE_AMOUNT)
|
#define R_SENS_PARAMS_ADDR (DS18B20_DEVICE_AMOUNT) // 30
|
||||||
#define R_SENS_PARAMS_QNT (sizeof(MB_SensorParamsTypeDef)/sizeof(uint16_t))
|
#define R_SENS_PARAMS_QNT (sizeof(MB_SensorParamsTypeDef)/sizeof(uint16_t)) // 7
|
||||||
|
#define R_ALL_ROMS_ADDR (R_SENS_PARAMS_ADDR+R_SENS_PARAMS_QNT + 1) // 38
|
||||||
|
#define R_ALL_ROMS_QNT (DS18B20_DEVICE_AMOUNT*4)
|
||||||
|
|
||||||
// DEFINES FOR HOLDING REGISTERS ARRAYS
|
// DEFINES FOR HOLDING REGISTERS ARRAYS
|
||||||
#define R_SENS_INIT_ADDR (0)
|
#define R_SENS_INIT_ADDR (0)
|
||||||
@@ -119,14 +123,15 @@ typedef struct //MB_DataCoilsTypeDef
|
|||||||
/* reg 2 - settings */
|
/* reg 2 - settings */
|
||||||
unsigned ConvertionDone:1;
|
unsigned ConvertionDone:1;
|
||||||
unsigned LostedSensors:1;
|
unsigned LostedSensors:1;
|
||||||
|
unsigned reserved2:11;
|
||||||
}MB_DataCoilsTypeDef;
|
}MB_DataCoilsTypeDef;
|
||||||
|
|
||||||
// DEFINES FOR COIL ARRAYS
|
// DEFINES FOR COIL ARRAYS
|
||||||
#define C_CONTROL_ADDR 0
|
#define C_CONTROL_ADDR 0
|
||||||
#define C_CONTROL_QNT 3
|
#define C_CONTROL_QNT 5
|
||||||
|
|
||||||
#define C_FLAGS_ADDR 16
|
#define C_FLAGS_ADDR 16
|
||||||
#define C_FLAGS_QNT 2
|
#define C_FLAGS_QNT 10
|
||||||
|
|
||||||
/** MODBUS_DATA_COILS_DEFINES
|
/** MODBUS_DATA_COILS_DEFINES
|
||||||
* @}
|
* @}
|
||||||
@@ -82,13 +82,13 @@ RS_StatusTypeDef RS_Receive_IT(RS_HandleTypeDef *hRS, RS_MsgTypeDef *RS_msg)
|
|||||||
{
|
{
|
||||||
RS_RES = RS_Abort(hRS, ABORT_RS);
|
RS_RES = RS_Abort(hRS, ABORT_RS);
|
||||||
printf_rs_err("\n%d: Error RS: Failed to start RS receiving...", uwTick);
|
printf_rs_err("\n%d: Error RS: Failed to start RS receiving...", uwTick);
|
||||||
TrackerCnt_Err(hRS->rs_err);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RS_RES = RS_OK;
|
RS_RES = RS_OK;
|
||||||
printf_rs("\n%d: RS: Start Receiving...", uwTick);
|
printf_rs("\n%d: RS: Start Receiving...", uwTick);
|
||||||
TrackerCnt_Ok(hRS->rs_err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hRS->RS_STATUS = RS_RES;
|
hRS->RS_STATUS = RS_RES;
|
||||||
@@ -138,13 +138,13 @@ RS_StatusTypeDef RS_Transmit_IT(RS_HandleTypeDef *hRS, RS_MsgTypeDef *RS_msg)
|
|||||||
{
|
{
|
||||||
RS_RES = RS_Abort(hRS, ABORT_RS);
|
RS_RES = RS_Abort(hRS, ABORT_RS);
|
||||||
printf_rs_err("\n%d: Error RS: Failed to start RS transmitting...", uwTick);
|
printf_rs_err("\n%d: Error RS: Failed to start RS transmitting...", uwTick);
|
||||||
TrackerCnt_Err(hRS->rs_err);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RS_RES = RS_OK;
|
RS_RES = RS_OK;
|
||||||
printf_rs("\n%d: RS: Start Transmitting...", uwTick);
|
printf_rs("\n%d: RS: Start Transmitting...", uwTick);
|
||||||
TrackerCnt_Ok(hRS->rs_err);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,9 +288,9 @@ RS_StatusTypeDef RS_Abort(RS_HandleTypeDef *hRS, RS_AbortTypeDef AbortMode)
|
|||||||
|
|
||||||
if(hRS->sRS_Timeout) // if timeout setted
|
if(hRS->sRS_Timeout) // if timeout setted
|
||||||
{
|
{
|
||||||
TIM14->DIER &= ~(TIM_IT_UPDATE);
|
TIM_MB->DIER &= ~(TIM_IT_UPDATE);
|
||||||
/* Disable the Peripheral */
|
/* Disable the Peripheral */
|
||||||
TIM14->CR1 &= ~(TIM_CR1_CEN);
|
TIM_MB->CR1 &= ~(TIM_CR1_CEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((AbortMode&ABORT_RS) == 0x00)
|
if((AbortMode&ABORT_RS) == 0x00)
|
||||||
@@ -345,7 +345,7 @@ RS_StatusTypeDef RS_Handle_Receive_Start(RS_HandleTypeDef *hRS, RS_MsgTypeDef *R
|
|||||||
|
|
||||||
if(RS_RES != RS_OK)
|
if(RS_RES != RS_OK)
|
||||||
{
|
{
|
||||||
TrackerCnt_Err(hRS->rs_err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return RS_RES;
|
return RS_RES;
|
||||||
@@ -369,7 +369,7 @@ RS_StatusTypeDef RS_Handle_Transmit_Start(RS_HandleTypeDef *hRS, RS_MsgTypeDef *
|
|||||||
}
|
}
|
||||||
if(RS_RES != RS_OK)
|
if(RS_RES != RS_OK)
|
||||||
{
|
{
|
||||||
TrackerCnt_Err(hRS->rs_err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return RS_RES;
|
return RS_RES;
|
||||||
@@ -398,7 +398,7 @@ RS_StatusTypeDef RS_UART_RxCpltCallback(RS_HandleTypeDef *hRS)
|
|||||||
// if we need to skip this message - restart receive
|
// if we need to skip this message - restart receive
|
||||||
if(RS_RES == RS_SKIP || NuRS_of_Rest_Bytes == 0xFFFF)
|
if(RS_RES == RS_SKIP || NuRS_of_Rest_Bytes == 0xFFFF)
|
||||||
{
|
{
|
||||||
TrackerCnt_Err(hRS->rs_err);
|
|
||||||
RS_Abort(hRS, ABORT_RX);
|
RS_Abort(hRS, ABORT_RX);
|
||||||
RS_RES = RS_Handle_Receive_Start(hRS, hRS->pMessagePtr);
|
RS_RES = RS_Handle_Receive_Start(hRS, hRS->pMessagePtr);
|
||||||
return RS_RES;
|
return RS_RES;
|
||||||
@@ -414,9 +414,9 @@ RS_StatusTypeDef RS_UART_RxCpltCallback(RS_HandleTypeDef *hRS)
|
|||||||
|
|
||||||
if(hRS->sRS_Timeout) // if timeout setted
|
if(hRS->sRS_Timeout) // if timeout setted
|
||||||
{
|
{
|
||||||
TIM14->DIER &= ~(TIM_IT_UPDATE);
|
TIM_MB->DIER &= ~(TIM_IT_UPDATE);
|
||||||
/* Disable the Peripheral */
|
/* Disable the Peripheral */
|
||||||
TIM14->CR1 &= ~(TIM_CR1_CEN);
|
TIM_MB->CR1 &= ~(TIM_CR1_CEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse received data
|
// parse received data
|
||||||
@@ -433,7 +433,6 @@ RS_StatusTypeDef RS_UART_RxCpltCallback(RS_HandleTypeDef *hRS)
|
|||||||
|
|
||||||
if(uart_res != HAL_OK)
|
if(uart_res != HAL_OK)
|
||||||
{// need uart status, so doesnt write abort to RS_RES
|
{// need uart status, so doesnt write abort to RS_RES
|
||||||
TrackerCnt_Err(hRS->rs_err);
|
|
||||||
RS_RES = RS_Abort(hRS, ABORT_RS);
|
RS_RES = RS_Abort(hRS, ABORT_RS);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -448,9 +447,9 @@ RS_StatusTypeDef RS_UART_RxCpltCallback(RS_HandleTypeDef *hRS)
|
|||||||
|
|
||||||
if(hRS->sRS_Timeout) // if timeout setted
|
if(hRS->sRS_Timeout) // if timeout setted
|
||||||
{
|
{
|
||||||
TIM14->DIER &= ~(TIM_IT_UPDATE);
|
TIM_MB->DIER &= ~(TIM_IT_UPDATE);
|
||||||
/* Disable the Peripheral */
|
/* Disable the Peripheral */
|
||||||
TIM14->CR1 &= ~(TIM_CR1_CEN);
|
TIM_MB->CR1 &= ~(TIM_CR1_CEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse received data
|
// parse received data
|
||||||
@@ -504,9 +503,9 @@ void RS_UART_Handler(RS_HandleTypeDef *hRS)
|
|||||||
if(hRS->sRS_Timeout) // if timeout setted
|
if(hRS->sRS_Timeout) // if timeout setted
|
||||||
if((hRS->huart->RxXferCount+1 == hRS->huart->RxXferSize) && RS_Is_RX_Busy(hRS)) // if first byte is received and receive is active
|
if((hRS->huart->RxXferCount+1 == hRS->huart->RxXferSize) && RS_Is_RX_Busy(hRS)) // if first byte is received and receive is active
|
||||||
{
|
{
|
||||||
TIM14->DIER |= (TIM_IT_UPDATE);
|
TIM_MB->DIER |= (TIM_IT_UPDATE);
|
||||||
/* Disable the Peripheral */
|
/* Disable the Peripheral */
|
||||||
TIM14->CR1 |= (TIM_CR1_CEN);
|
TIM_MB->CR1 |= (TIM_CR1_CEN);
|
||||||
RS_Set_RX_Active_Flags(hRS);
|
RS_Set_RX_Active_Flags(hRS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -523,7 +522,7 @@ void RS_UART_Handler(RS_HandleTypeDef *hRS)
|
|||||||
//----------------ERRORS HANDLER----------------
|
//----------------ERRORS HANDLER----------------
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TrackerCnt_Err(hRS->rs_err);
|
|
||||||
/* de-init uart transfer */
|
/* de-init uart transfer */
|
||||||
RS_Abort(hRS, ABORT_RS);
|
RS_Abort(hRS, ABORT_RS);
|
||||||
RS_Handle_Receive_Start(hRS, hRS->pMessagePtr);
|
RS_Handle_Receive_Start(hRS, hRS->pMessagePtr);
|
||||||
@@ -541,11 +540,11 @@ void RS_UART_Handler(RS_HandleTypeDef *hRS)
|
|||||||
*/
|
*/
|
||||||
void RS_TIM_Handler(RS_HandleTypeDef *hRS)
|
void RS_TIM_Handler(RS_HandleTypeDef *hRS)
|
||||||
{
|
{
|
||||||
TIM14->SR = ~(TIM_IT_UPDATE);
|
TIM_MB->SR = ~(TIM_IT_UPDATE);
|
||||||
/* Disable the TIM Update interrupt */
|
/* Disable the TIM Update interrupt */
|
||||||
TIM14->DIER &= ~(TIM_IT_UPDATE);
|
TIM_MB->DIER &= ~(TIM_IT_UPDATE);
|
||||||
/* Disable the Peripheral */
|
/* Disable the Peripheral */
|
||||||
TIM14->CR1 &= ~(TIM_CR1_CEN);
|
TIM_MB->CR1 &= ~(TIM_CR1_CEN);
|
||||||
|
|
||||||
RS_Abort(hRS, ABORT_RS);
|
RS_Abort(hRS, ABORT_RS);
|
||||||
|
|
||||||
@@ -27,7 +27,6 @@
|
|||||||
|
|
||||||
#include "modbus.h"
|
#include "modbus.h"
|
||||||
|
|
||||||
#include "mylibs_include.h"
|
|
||||||
#include "crc_algs.h"
|
#include "crc_algs.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -187,7 +186,6 @@ typedef struct // RS_HandleTypeDef
|
|||||||
|
|
||||||
/* RS STATUS */
|
/* RS STATUS */
|
||||||
RS_StatusTypeDef RS_STATUS; ///< RS status
|
RS_StatusTypeDef RS_STATUS; ///< RS status
|
||||||
RS_TrackerTypeDef rs_err;
|
|
||||||
}RS_HandleTypeDef;
|
}RS_HandleTypeDef;
|
||||||
extern RS_HandleTypeDef hmodbus1;
|
extern RS_HandleTypeDef hmodbus1;
|
||||||
|
|
||||||
@@ -27,19 +27,32 @@ void PYModule_main(void)
|
|||||||
{
|
{
|
||||||
if(DS18B20_WaitForEndConvertion_NonBlocking(hdallas1.onewire) == HAL_OK)
|
if(DS18B20_WaitForEndConvertion_NonBlocking(hdallas1.onewire) == HAL_OK)
|
||||||
{
|
{
|
||||||
|
PCHSens_ModuleReadTemperature(&pchsens.module1);
|
||||||
|
// PCHSens_ModuleReadTemperature(&pchsens.module2);
|
||||||
|
// PCHSens_ModuleReadTemperature(&pchsens.module3);
|
||||||
|
// PCHSens_ModuleReadTemperature(&pchsens.module4);
|
||||||
|
// PCHSens_ModuleReadTemperature(&pchsens.module5);
|
||||||
|
// PCHSens_ModuleReadTemperature(&pchsens.module6);
|
||||||
|
|
||||||
|
PYModule_StoreModbus(&pchsens);
|
||||||
PCHSens_StartCovert(&DallasBus);
|
PCHSens_StartCovert(&DallasBus);
|
||||||
GPIOA->ODR ^= GPIO_LED_2;
|
GPIOA->ODR ^= GPIO_LED_2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(MB_DATA.Coils.ScanSensors)
|
if(MB_DATA.Coils.ReadSensor)
|
||||||
{
|
{
|
||||||
PYModule_ScanSensor(&DallasBus);
|
PYModule_ReadSensor(&hdallas1, &pchsens);
|
||||||
}
|
MB_DATA.Coils.ReadSensor = 0;
|
||||||
else
|
|
||||||
{
|
|
||||||
scan_cnt = 0;
|
|
||||||
}
|
}
|
||||||
|
// if(MB_DATA.Coils.ScanSensors)
|
||||||
|
// {
|
||||||
|
// PYModule_ScanSensor(&DallasBus);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// scan_cnt = 0;
|
||||||
|
// }
|
||||||
|
|
||||||
if(MB_DATA.Coils.InitSensor)
|
if(MB_DATA.Coils.InitSensor)
|
||||||
{
|
{
|
||||||
@@ -55,21 +68,6 @@ void PYModule_main(void)
|
|||||||
|
|
||||||
PYModule_CheckLosted(&pchsens);
|
PYModule_CheckLosted(&pchsens);
|
||||||
|
|
||||||
if(MB_DATA.Coils.RunConvertions)
|
|
||||||
{
|
|
||||||
if(DS18B20_WaitForEndConvertion_NonBlocking(hdallas1.onewire) == HAL_OK)
|
|
||||||
{
|
|
||||||
PCHSens_ModuleReadTemperature(&pchsens.module1);
|
|
||||||
// PCHSens_ModuleReadTemperature(&pchsens.module2);
|
|
||||||
// PCHSens_ModuleReadTemperature(&pchsens.module3);
|
|
||||||
// PCHSens_ModuleReadTemperature(&pchsens.module4);
|
|
||||||
// PCHSens_ModuleReadTemperature(&pchsens.module5);
|
|
||||||
// PCHSens_ModuleReadTemperature(&pchsens.module6);
|
|
||||||
|
|
||||||
PYModule_StoreModbus(&pchsens);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -79,8 +77,9 @@ void PYModule_FirstInit(void)
|
|||||||
OW.DataPort = DS_GPIO_Port;
|
OW.DataPort = DS_GPIO_Port;
|
||||||
|
|
||||||
/* Инициализация onewire и поиск датчиков*/
|
/* Инициализация onewire и поиск датчиков*/
|
||||||
|
DS = (DS18B20_Drv_t *)&MB_DATA.InRegs.AllROMs;
|
||||||
OneWire_Init(&OW);
|
OneWire_Init(&OW);
|
||||||
DS18B20_Search(&DS, &OW);
|
DS18B20_Search(DS, &OW);
|
||||||
|
|
||||||
|
|
||||||
/* Инициализация modbus */
|
/* Инициализация modbus */
|
||||||
@@ -90,13 +89,13 @@ void PYModule_FirstInit(void)
|
|||||||
/* Инициализация структур датчиков ПЧ */
|
/* Инициализация структур датчиков ПЧ */
|
||||||
DallasBus.hdallas = &hdallas1;
|
DallasBus.hdallas = &hdallas1;
|
||||||
DallasBus.hdallas->onewire = &OW;
|
DallasBus.hdallas->onewire = &OW;
|
||||||
DallasBus.hdallas->ds_devices = &DS;
|
DallasBus.hdallas->ds_devices = DS;
|
||||||
PCHSens_InitModule(&hdallas1, &pchsens.module1, REG_PCH_NUMB_11|REG_PCH_DIODE_NUMB_1);
|
PCHSens_InitModule(&hdallas1, &pchsens.module1, REG_PCH_NUMB_11|REG_PCH_DIODE_NUMB_1);
|
||||||
PCHSens_InitModule(&hdallas1, &pchsens.module2, REG_PCH_NUMB_12|REG_PCH_DIODE_NUMB_1);
|
// PCHSens_InitModule(&hdallas1, &pchsens.module2, REG_PCH_NUMB_12|REG_PCH_DIODE_NUMB_1);
|
||||||
PCHSens_InitModule(&hdallas1, &pchsens.module3, REG_PCH_NUMB_21|REG_PCH_DIODE_NUMB_1);
|
// PCHSens_InitModule(&hdallas1, &pchsens.module3, REG_PCH_NUMB_21|REG_PCH_DIODE_NUMB_1);
|
||||||
PCHSens_InitModule(&hdallas1, &pchsens.module4, REG_PCH_NUMB_22|REG_PCH_DIODE_NUMB_1);
|
// PCHSens_InitModule(&hdallas1, &pchsens.module4, REG_PCH_NUMB_22|REG_PCH_DIODE_NUMB_1);
|
||||||
PCHSens_InitModule(&hdallas1, &pchsens.module5, REG_PCH_NUMB_31|REG_PCH_DIODE_NUMB_1);
|
// PCHSens_InitModule(&hdallas1, &pchsens.module5, REG_PCH_NUMB_31|REG_PCH_DIODE_NUMB_1);
|
||||||
PCHSens_InitModule(&hdallas1, &pchsens.module6, REG_PCH_NUMB_32|REG_PCH_DIODE_NUMB_1);
|
// PCHSens_InitModule(&hdallas1, &pchsens.module6, REG_PCH_NUMB_32|REG_PCH_DIODE_NUMB_1);
|
||||||
|
|
||||||
/* Поиск неизвестных сенсоров */
|
/* Поиск неизвестных сенсоров */
|
||||||
PCHSens_FindUnknownSensors(&DallasBus);
|
PCHSens_FindUnknownSensors(&DallasBus);
|
||||||
@@ -183,10 +182,11 @@ void PYModule_InitSensor(PCHSens_TypeDef *pchsens)
|
|||||||
if(PCHSens_GetSensorByLocation(pchsens, (PCHSens_LocationTypeDef)MB_DATA.HoldRegs.InitStruct.Location, &sensor) != HAL_OK)
|
if(PCHSens_GetSensorByLocation(pchsens, (PCHSens_LocationTypeDef)MB_DATA.HoldRegs.InitStruct.Location, &sensor) != HAL_OK)
|
||||||
return;
|
return;
|
||||||
uint64_t connectROM = 0;
|
uint64_t connectROM = 0;
|
||||||
connectROM = ((uint64_t)(MB_DATA.HoldRegs.InitStruct.ROM[0]))<<48;
|
connectROM = ((uint64_t)(__REV16(MB_DATA.HoldRegs.InitStruct.ROM[0])))<<48;
|
||||||
connectROM |= ((uint64_t)(MB_DATA.HoldRegs.InitStruct.ROM[1]))<<32;
|
connectROM |= ((uint64_t)(__REV16(MB_DATA.HoldRegs.InitStruct.ROM[1])))<<32;
|
||||||
connectROM |= ((uint64_t)(MB_DATA.HoldRegs.InitStruct.ROM[2]))<<16;
|
connectROM |= ((uint64_t)(__REV16(MB_DATA.HoldRegs.InitStruct.ROM[2])))<<16;
|
||||||
connectROM |= ((uint64_t)(MB_DATA.HoldRegs.InitStruct.ROM[3]));
|
connectROM |= ((uint64_t)(__REV16(MB_DATA.HoldRegs.InitStruct.ROM[3])));
|
||||||
|
|
||||||
if(PCHSens_InitNewSensor(&hdallas1, sensor, connectROM) == HAL_OK)
|
if(PCHSens_InitNewSensor(&hdallas1, sensor, connectROM) == HAL_OK)
|
||||||
{
|
{
|
||||||
PYModule_FillResponse(sensor, STATUS_OK);
|
PYModule_FillResponse(sensor, STATUS_OK);
|
||||||
@@ -207,7 +207,7 @@ void PYModule_DeInitSensor(PCHSens_TypeDef *pchsens)
|
|||||||
if(PCHSens_GetSensorByLocation(pchsens, (PCHSens_LocationTypeDef)MB_DATA.HoldRegs.InitStruct.Location, &sensor) != HAL_OK)
|
if(PCHSens_GetSensorByLocation(pchsens, (PCHSens_LocationTypeDef)MB_DATA.HoldRegs.InitStruct.Location, &sensor) != HAL_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(PCHSens_UndefineSensor(sensor) != HAL_OK)
|
if(PCHSens_UndefineSensor(sensor) == HAL_OK)
|
||||||
{
|
{
|
||||||
PYModule_FillResponse(sensor, STATUS_OK);
|
PYModule_FillResponse(sensor, STATUS_OK);
|
||||||
}
|
}
|
||||||
@@ -199,7 +199,7 @@ HAL_StatusTypeDef PCHSens_FindUnknownSensors(PCHSens_DallasBusHandle *hbus)
|
|||||||
for(int i = 0; i < hbus->hdallas->onewire->RomCnt; i++)
|
for(int i = 0; i < hbus->hdallas->onewire->RomCnt; i++)
|
||||||
{
|
{
|
||||||
/* Проверка присутствует ли выбранный датчик на линии */
|
/* Проверка присутствует ли выбранный датчик на линии */
|
||||||
result = DS18B20_ReadScratchpad(hbus->hdallas->onewire, (uint8_t *)&DS.DevAddr[i], (uint8_t *)&hbus->hdallas->scratchpad);
|
result = DS18B20_ReadScratchpad(hbus->hdallas->onewire, (uint8_t *)&hbus->hdallas->ds_devices->DevAddr[i], (uint8_t *)&hbus->hdallas->scratchpad);
|
||||||
if(result != HAL_OK)
|
if(result != HAL_OK)
|
||||||
__NOP();
|
__NOP();
|
||||||
|
|
||||||
@@ -43,22 +43,37 @@ void MX_GPIO_Init(void)
|
|||||||
/* GPIO Ports Clock Enable */
|
/* GPIO Ports Clock Enable */
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
||||||
|
|
||||||
|
|
||||||
/*Configure LED GPIO pin : PB0 (OneWire) */
|
/* Íàñòðîéêà ïèíà PB0 (OneWire) */
|
||||||
GPIO_InitStruct.Pin = DS_Pin;
|
DS_GPIO_Port->MODER &= ~(GPIO_MODER_MODE0);
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
DS_GPIO_Port->MODER |= (GPIO_MODE_OUTPUT_PP << GPIO_MODER_MODE0_Pos);
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
DS_GPIO_Port->PUPDR &= ~(GPIO_PUPDR_PUPD0);
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
DS_GPIO_Port->PUPDR |= (GPIO_NOPULL << GPIO_PUPDR_PUPD0_Pos);
|
||||||
HAL_GPIO_Init(DS_GPIO_Port, &GPIO_InitStruct);
|
DS_GPIO_Port->OSPEEDR |= (GPIO_SPEED_FREQ_VERY_HIGH << GPIO_OSPEEDR_OSPEED0_Pos);
|
||||||
|
|
||||||
|
/* Óñòàíîâêà PA1, PA4, PA5 â âûñîêèé óðîâåíü */
|
||||||
|
GPIOA->BSRR = GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5;
|
||||||
|
|
||||||
/*Configure LED GPIO pin : PA1 PA4 PA5 */
|
/*Configure LED GPIO pin : PA1 PA4 PA5 */
|
||||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5, GPIO_PIN_SET);
|
/* Íàñòðîéêà ïèíîâ PA1, PA4, PA5 */
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5;
|
GPIOA->MODER &= ~(GPIO_MODER_MODE1 | GPIO_MODER_MODE4 | GPIO_MODER_MODE5);
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
GPIOA->MODER |= (GPIO_MODE_OUTPUT_PP << GPIO_MODER_MODE1_Pos) |
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
(GPIO_MODE_OUTPUT_PP << GPIO_MODER_MODE4_Pos) |
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
(GPIO_MODE_OUTPUT_PP << GPIO_MODER_MODE5_Pos);
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
GPIOA->PUPDR &= ~(GPIO_PUPDR_PUPD1 | GPIO_PUPDR_PUPD4 | GPIO_PUPDR_PUPD5);
|
||||||
|
GPIOA->PUPDR |= (GPIO_NOPULL << GPIO_PUPDR_PUPD1_Pos) |
|
||||||
|
(GPIO_NOPULL << GPIO_PUPDR_PUPD4_Pos) |
|
||||||
|
(GPIO_NOPULL << GPIO_PUPDR_PUPD5_Pos);
|
||||||
|
GPIOA->OSPEEDR |= (GPIO_SPEED_FREQ_LOW << GPIO_OSPEEDR_OSPEED1_Pos) |
|
||||||
|
(GPIO_SPEED_FREQ_LOW << GPIO_OSPEEDR_OSPEED4_Pos) |
|
||||||
|
(GPIO_SPEED_FREQ_LOW << GPIO_OSPEEDR_OSPEED5_Pos);
|
||||||
|
|
||||||
|
/*Configure LED GPIO pin : PB3 (Receive Enable) */
|
||||||
|
GPIOB->MODER &= ~(GPIO_MODER_MODE3);
|
||||||
|
GPIOB->MODER |= (GPIO_MODE_OUTPUT_PP << GPIO_MODER_MODE3_Pos);
|
||||||
|
GPIOB->PUPDR &= ~(GPIO_PUPDR_PUPD3);
|
||||||
|
GPIOB->PUPDR |= (GPIO_NOPULL << GPIO_PUPDR_PUPD3_Pos);
|
||||||
|
GPIOB->OSPEEDR |= (GPIO_SPEED_FREQ_HIGH << GPIO_OSPEEDR_OSPEED3_Pos);
|
||||||
}
|
}
|
||||||
/************************ (C) COPYRIGHT Puya *****END OF FILE******************/
|
/************************ (C) COPYRIGHT Puya *****END OF FILE******************/
|
||||||
185
py_project/Core/Src/main.c
Normal file
185
py_project/Core/Src/main.c
Normal file
@@ -0,0 +1,185 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file main.c
|
||||||
|
* @author MCU Application Team
|
||||||
|
* @brief Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* <h2><center>© Copyright (c) Puya Semiconductor Co.
|
||||||
|
* All rights reserved.</center></h2>
|
||||||
|
*
|
||||||
|
* <h2><center>© Copyright (c) 2016 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
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
#include "gpio.h"
|
||||||
|
#include "tim.h"
|
||||||
|
#include "usart.h"
|
||||||
|
#include "iwdg.h"
|
||||||
|
#include "PY32module_main.h"
|
||||||
|
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
static void APP_SystemClockConfig(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Application Entry Function.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
__HAL_DBGMCU_FREEZE_IWDG();
|
||||||
|
__HAL_DBGMCU_FREEZE_TIM1();
|
||||||
|
__HAL_DBGMCU_FREEZE_TIM_MB();
|
||||||
|
/* Reset of all peripherals, Initializes the Systick. */
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* System clock configuration */
|
||||||
|
APP_SystemClockConfig();
|
||||||
|
|
||||||
|
// MX_IWDG_Init();
|
||||||
|
MX_GPIO_Init();
|
||||||
|
MX_TIM1_Init();
|
||||||
|
MX_TIMMB_Init();
|
||||||
|
MX_USART1_UART_Init();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PYModule_FirstInit();
|
||||||
|
/* infinite loop */
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
PYModule_main();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System clock configuration function
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
static void APP_SystemClockConfig(void)
|
||||||
|
{
|
||||||
|
// RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
// RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
// /* Oscillator configuration */
|
||||||
|
// RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE; /* Select oscillator HSE, HSI, LSI, LSE */
|
||||||
|
// RCC_OscInitStruct.HSIState = RCC_HSI_ON; /* Enable HSI */
|
||||||
|
// RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; /* HSI 1 frequency division */
|
||||||
|
// RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_24MHz; /* Configure HSI clock 24MHz */
|
||||||
|
// RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS_DISABLE; /* Close HSE bypass */
|
||||||
|
// RCC_OscInitStruct.LSIState = RCC_LSI_OFF; /* Close LSI */
|
||||||
|
// /*RCC_OscInitStruct.LSICalibrationValue = RCC_LSICALIBRATION_32768Hz;*/
|
||||||
|
// RCC_OscInitStruct.LSEState = RCC_LSE_OFF; /* Close LSE */
|
||||||
|
// /*RCC_OscInitStruct.LSEDriver = RCC_LSEDRIVE_MEDIUM;*/
|
||||||
|
// /* Configure oscillator */
|
||||||
|
// if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
// {
|
||||||
|
// Error_Handler();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// /* Clock source configuration */
|
||||||
|
// RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1; /* Choose to configure clock HCLK, SYSCLK, PCLK1 */
|
||||||
|
// RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSISYS; /* Select HSISYS as the system clock */
|
||||||
|
// RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; /* AHB clock 1 division */
|
||||||
|
// RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; /* APB clock 1 division */
|
||||||
|
// /* Configure clock source */
|
||||||
|
// if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||||
|
// {
|
||||||
|
// Error_Handler();
|
||||||
|
// }
|
||||||
|
/* Âêëþ÷åíèå HSI */
|
||||||
|
RCC->CR |= RCC_CR_HSION;
|
||||||
|
while (!(RCC->CR & RCC_CR_HSIRDY));
|
||||||
|
|
||||||
|
/* Íàñòðîéêà äåëèòåëÿ HSI */
|
||||||
|
RCC->CR &= ~RCC_CR_HSIDIV;
|
||||||
|
RCC->CR |= RCC_HSI_DIV1;
|
||||||
|
|
||||||
|
/* Êàëèáðîâêà HSI */
|
||||||
|
RCC->ICSCR &= ~RCC_ICSCR_HSI_TRIM;
|
||||||
|
RCC->ICSCR |= (RCC_HSICALIBRATION_24MHz << RCC_ICSCR_HSI_TRIM_Pos);
|
||||||
|
|
||||||
|
/* Îòêëþ÷åíèå LSI è LSE */
|
||||||
|
#ifdef RCC_LSE_SUPPORT
|
||||||
|
RCC->CSR &= ~RCC_CSR_LSION;
|
||||||
|
RCC->BDCR &= ~RCC_BDCR_LSEON;
|
||||||
|
#endif
|
||||||
|
/* Îòêëþ÷åíèå áàéïàñà HSE */
|
||||||
|
RCC->CR &= ~0x00000000U;
|
||||||
|
|
||||||
|
/* Óñòàíîâêà èñòî÷íèêà ñèñòåìíîé òàêòîâîé ÷àñòîòû */
|
||||||
|
RCC->CFGR &= ~RCC_CFGR_SW;
|
||||||
|
#ifdef PY32F002Bx5
|
||||||
|
RCC->CFGR |= RCC_SYSCLKSOURCE_HSISYS;
|
||||||
|
while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_SYSCLKSOURCE_HSISYS);
|
||||||
|
#endif
|
||||||
|
#ifdef PY32F002Ax5
|
||||||
|
RCC->CFGR |= RCC_SYSCLKSOURCE_HSI;
|
||||||
|
while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_SYSCLKSOURCE_HSI);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Óñòàíîâêà äåëèòåëåé */
|
||||||
|
RCC->CFGR &= ~(RCC_CFGR_HPRE | RCC_CFGR_PPRE_1);
|
||||||
|
RCC->CFGR |= RCC_SYSCLK_DIV1 | RCC_HCLK_DIV1;
|
||||||
|
|
||||||
|
/* Íàñòðîéêà çàäåðæêè ôëåø-ïàìÿòè */
|
||||||
|
FLASH->ACR &= ~FLASH_ACR_LATENCY;
|
||||||
|
FLASH->ACR |= FLASH_LATENCY_0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t HAL_RCC_GetPCLK1Freq(void)
|
||||||
|
{
|
||||||
|
/* Get HCLK source and Compute PCLK1 frequency ---------------------------*/
|
||||||
|
return (uint32_t)((SystemCoreClock) >> (APBPrescTable[(RCC->CFGR & RCC_CFGR_PPRE) >> RCC_CFGR_PPRE_Pos] & 0x1FU));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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)
|
||||||
|
{
|
||||||
|
/* Users can add their own printing information as needed,
|
||||||
|
for example: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* Infinite loop */
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
|
|
||||||
|
/************************ (C) COPYRIGHT Puya *****END OF FILE******************/
|
||||||
@@ -88,7 +88,7 @@ void USART1_IRQHandler(void)
|
|||||||
/**
|
/**
|
||||||
* @brief This function handles TIM2 global interrupt.
|
* @brief This function handles TIM2 global interrupt.
|
||||||
*/
|
*/
|
||||||
void TIM14_IRQHandler(void)
|
void TIM_MB_IRQHandler(void)
|
||||||
{
|
{
|
||||||
/* USER CODE BEGIN TIM2_IRQn 0 */
|
/* USER CODE BEGIN TIM2_IRQn 0 */
|
||||||
RS_TIM_Handler(&hmodbus1);
|
RS_TIM_Handler(&hmodbus1);
|
||||||
173
py_project/Core/Src/system_py32f0xx.c
Normal file
173
py_project/Core/Src/system_py32f0xx.c
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file system_py32f0xx.c
|
||||||
|
* @author MCU Application Team
|
||||||
|
* @Version V1.0.0
|
||||||
|
* @Date 2020-10-19
|
||||||
|
* @brief CMSIS Cortex-M0+ Device Peripheral Access Layer System Source File.
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "py32f0xx.h"
|
||||||
|
|
||||||
|
#if !defined (HSE_VALUE)
|
||||||
|
#define HSE_VALUE 24000000U /*!< Value of the External oscillator in Hz */
|
||||||
|
#endif /* HSE_VALUE */
|
||||||
|
|
||||||
|
#if !defined (HSI_VALUE)
|
||||||
|
#define HSI_VALUE 8000000U /*!< Value of the Internal oscillator in Hz*/
|
||||||
|
#endif /* HSI_VALUE */
|
||||||
|
|
||||||
|
#if !defined (LSI_VALUE)
|
||||||
|
#define LSI_VALUE 32768U /*!< Value of LSI in Hz*/
|
||||||
|
#endif /* LSI_VALUE */
|
||||||
|
|
||||||
|
#if !defined (LSE_VALUE)
|
||||||
|
#define LSE_VALUE 32768U /*!< Value of LSE in Hz*/
|
||||||
|
#endif /* LSE_VALUE */
|
||||||
|
|
||||||
|
|
||||||
|
/************************* Miscellaneous Configuration ************************/
|
||||||
|
/*!< Uncomment the following line if you need to relocate your vector Table in
|
||||||
|
Internal SRAM. */
|
||||||
|
/* #define FORBID_VECT_TAB_MIGRATION */
|
||||||
|
/* #define VECT_TAB_SRAM */
|
||||||
|
#define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field.
|
||||||
|
This value must be a multiple of 0x100. */
|
||||||
|
/******************************************************************************/
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
Clock Variable definitions
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
/* 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 = HSI_VALUE;
|
||||||
|
|
||||||
|
const uint32_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||||
|
const uint32_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
|
||||||
|
const uint32_t HSIFreqTable[8] = {4000000U, 8000000U, 16000000U, 22120000U, 24000000U, 4000000U, 4000000U, 4000000U};
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
Clock functions
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
void SystemCoreClockUpdate(void) /* Get Core Clock Frequency */
|
||||||
|
{
|
||||||
|
uint32_t tmp;
|
||||||
|
uint32_t hsidiv;
|
||||||
|
uint32_t hsifs;
|
||||||
|
|
||||||
|
/* Get SYSCLK source -------------------------------------------------------*/
|
||||||
|
switch (RCC->CFGR & RCC_CFGR_SWS)
|
||||||
|
{
|
||||||
|
case RCC_CFGR_SWS_0: /* HSE used as system clock */
|
||||||
|
SystemCoreClock = HSE_VALUE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case (RCC_CFGR_SWS_1 | RCC_CFGR_SWS_0): /* LSI used as system clock */
|
||||||
|
SystemCoreClock = LSI_VALUE;
|
||||||
|
break;
|
||||||
|
#if defined(RCC_LSE_SUPPORT)
|
||||||
|
case RCC_CFGR_SWS_2: /* LSE used as system clock */
|
||||||
|
SystemCoreClock = LSE_VALUE;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
#if defined(RCC_PLL_SUPPORT)
|
||||||
|
case RCC_CFGR_SWS_1: /* PLL used as system clock */
|
||||||
|
if ((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLCFGR_PLLSRC_HSI) /* HSI used as PLL clock source */
|
||||||
|
{
|
||||||
|
hsifs = ((READ_BIT(RCC->ICSCR, RCC_ICSCR_HSI_FS)) >> RCC_ICSCR_HSI_FS_Pos);
|
||||||
|
SystemCoreClock = 2 * (HSIFreqTable[hsifs]);
|
||||||
|
}
|
||||||
|
else /* HSE used as PLL clock source */
|
||||||
|
{
|
||||||
|
SystemCoreClock = 2 * HSE_VALUE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
case 0x00000000U: /* HSI used as system clock */
|
||||||
|
default: /* HSI used as system clock */
|
||||||
|
hsifs = ((READ_BIT(RCC->ICSCR, RCC_ICSCR_HSI_FS)) >> RCC_ICSCR_HSI_FS_Pos);
|
||||||
|
hsidiv = (1UL << ((READ_BIT(RCC->CR, RCC_CR_HSIDIV)) >> RCC_CR_HSIDIV_Pos));
|
||||||
|
SystemCoreClock = (HSIFreqTable[hsifs] / hsidiv);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* Compute HCLK clock frequency --------------------------------------------*/
|
||||||
|
/* Get HCLK prescaler */
|
||||||
|
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> RCC_CFGR_HPRE_Pos)];
|
||||||
|
/* HCLK clock frequency */
|
||||||
|
SystemCoreClock >>= tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the system
|
||||||
|
*
|
||||||
|
* @param none
|
||||||
|
* @return none
|
||||||
|
*
|
||||||
|
* @brief Setup the microcontroller system.
|
||||||
|
* Initialize the System.
|
||||||
|
*/
|
||||||
|
void SystemInit(void)
|
||||||
|
{
|
||||||
|
//Set the HSI clock to 8MHz by default
|
||||||
|
RCC->ICSCR = (RCC->ICSCR & 0xFFFF0000) | (0x1 << 13) | *(uint32_t *)(0x1fff0f04);
|
||||||
|
|
||||||
|
/* Configure the Vector Table location add offset address ------------------*/
|
||||||
|
#ifdef VECT_TAB_SRAM
|
||||||
|
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
|
||||||
|
#else
|
||||||
|
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef FORBID_VECT_TAB_MIGRATION
|
||||||
|
#ifndef VECT_TAB_SRAM
|
||||||
|
#if (defined (__CC_ARM)) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))
|
||||||
|
extern int32_t $Super$$main(void);
|
||||||
|
uint32_t VECT_SRAM_TAB[48]__attribute__((section(".ARM.__at_0x20000000")));
|
||||||
|
|
||||||
|
/* re-define main function */
|
||||||
|
int $Sub$$main(void)
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
uint32_t *pFmcVect = (uint32_t *)(FLASH_BASE | VECT_TAB_OFFSET);
|
||||||
|
for (i = 0; i < 48; i++)
|
||||||
|
{
|
||||||
|
VECT_SRAM_TAB[i] = pFmcVect[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
SCB->VTOR = SRAM_BASE;
|
||||||
|
|
||||||
|
$Super$$main();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#elif defined(__ICCARM__)
|
||||||
|
extern int32_t main(void);
|
||||||
|
/* __low_level_init will auto called by IAR cstartup */
|
||||||
|
extern void __iar_data_init3(void);
|
||||||
|
uint32_t VECT_SRAM_TAB[48] @SRAM_BASE;
|
||||||
|
int __low_level_init(void)
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
uint32_t *pFmcVect = (uint32_t *)(FLASH_BASE | VECT_TAB_OFFSET);
|
||||||
|
// call IAR table copy function.
|
||||||
|
__iar_data_init3();
|
||||||
|
|
||||||
|
for (i = 0; i < 48; i++)
|
||||||
|
{
|
||||||
|
VECT_SRAM_TAB[i] = pFmcVect[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
SCB->VTOR = SRAM_BASE;
|
||||||
|
|
||||||
|
main();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user