Шаблон проекта с моей расширенной библиотекой MyLibs

This commit is contained in:
2025-12-25 10:36:35 +03:00
commit c6e1dc049f
69 changed files with 40782 additions and 0 deletions

68
Core/App/gpio.c Normal file
View File

@@ -0,0 +1,68 @@
/*==============================================================================
* Инициализация портов с использованием бибилотеки PLIB035
*------------------------------------------------------------------------------
* ЦНИИ СЭТ, Разваляев Алексей <wot890089@mail.ru>
*==============================================================================
* Конфигурация портов настраивается в gpio.h
* ЦНИИ СЭТ
*==============================================================================
*/
//-- Includes ------------------------------------------------------------------
#include "gpio.h"
//-- Defines -------------------------------------------------------------------
//-- Peripheral init functions -------------------------------------------------
void gpio_init(void)
{
RCU_AHBClkCmd(RCU_AHBClk_GPIOA, ENABLE);
RCU_AHBRstCmd(RCU_AHBRst_GPIOA, ENABLE);
/* Сброс пинов */
GPIO_DeInit(GPIOA);
GPIO_DeInit(GPIOB);
// Инициализируем порт A
for (int i = 0; i < sizeof(gpioa_config) / sizeof(gpioa_config[0]); i++)
{
GPIO_Init(GPIOA, &gpioa_config[i]);
}
// Инициализируем порт B
for (int i = 0; i < sizeof(gpiob_config) / sizeof(gpiob_config[0]); i++)
{
GPIO_Init(GPIOB, &gpiob_config[i]);
}
// GPIO_StructInit(&gpio_init);
// gpio_init.Digital = ENABLE;
// GPIO_Init(GPIOA, &gpio_init);
// GPIO_Init(GPIOB, &gpio_init);
//
// /* Инициализация выходных пинов Пуш-Пулл */
// gpio_init.Out = ENABLE;
// gpio_init.OutMode = GPIO_OutMode_PP;
//
// gpio_init.Pin = GPIO_OUT_PP_PA_PINS;
// GPIO_Init(GPIOA, &gpio_init);
// gpio_init.Pin = GPIO_OUT_PP_PB_PINS;
// GPIO_Init(GPIOB, &gpio_init);
//
// /* Инициализация выходных пинов Открытый сток */
// gpio_init.Out = ENABLE;
// gpio_init.OutMode = GPIO_OutMode_OD;
//
// gpio_init.Pin = GPIO_OUT_OD_PA_PINS;
// GPIO_Init(GPIOA, &gpio_init);
// gpio_init.Pin = GPIO_OUT_OD_PB_PINS;
// GPIO_Init(GPIOB, &gpio_init);
}

149
Core/App/gpio.h Normal file
View File

@@ -0,0 +1,149 @@
/*==============================================================================
* Конфигурация портов с использованием бибилотеки PLIB035
*------------------------------------------------------------------------------
* ЦНИИ СЭТ, Разваляев Алексей <wot890089@mail.ru>
*==============================================================================
* Реализация функций инициализации портов находится в gpio.c
* ЦНИИ СЭТ
*==============================================================================
*/
#ifndef __GPIO_H
#define __GPIO_H
//-- Includes ------------------------------------------------------------------
#include "main.h"
//-- Defines -------------------------------------------------------------------
// Дефайны для режима пина OutEnable, AltFuncEnable, DigitalEnable
#define GPIO_PinMode_Unused DISABLE, DISABLE, DISABLE
#define GPIO_PinMode_Input DISABLE, DISABLE, ENABLE
#define GPIO_PinMode_Output ENABLE, DISABLE, ENABLE
#define GPIO_PinMode_AltFunc DISABLE, ENABLE, ENABLE
//#define GPIO_PinMode_Analog DISABLE, DISABLE, DISABLE
static GPIO_Init_TypeDef gpioa_config[] = {
// Пин, Режим, Выходной режим, Входной режим, Подтяжка, Нагрузка/Скорость
{ GPIO_Pin_0, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_1, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_2, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_3, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_4, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_5, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_6, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_7, GPIO_PinMode_Output, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_8, GPIO_PinMode_Output, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_9, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_10, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_11, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_12, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_13, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_14, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_15, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
};
static GPIO_Init_TypeDef gpiob_config[] = {
{ GPIO_Pin_0, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_1, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_2, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_3, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_4, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_5, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_6, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_7, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_8, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_9, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_10, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_11, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_12, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_13, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_14, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
{ GPIO_Pin_15, GPIO_PinMode_Unused, GPIO_OutMode_PP, GPIO_InMode_Schmitt, GPIO_PullMode_Disable, GPIO_DriveMode_HighFast },
};
// Другой вариант
//#define GPIO_OUT_PP_PA_PINS /* GPIO_Pin_0 | */ \
// /* GPIO_Pin_1 | */ \
// /* GPIO_Pin_2 | */ \
// /* GPIO_Pin_3 | */ \
// /* GPIO_Pin_4 | */ \
// /* GPIO_Pin_5 | */ \
// /* GPIO_Pin_6 | */ \
// GPIO_Pin_7 | \
// GPIO_Pin_8 | \
// /* GPIO_Pin_9 | */ \
// /* GPIO_Pin_10 | */ \
// /* GPIO_Pin_11 | */ \
// /* GPIO_Pin_12 | */ \
// /* GPIO_Pin_13 | */ \
// /* GPIO_Pin_14 | */ \
// /* GPIO_Pin_15 | */ \
// 0
//#define GPIO_OUT_PP_PB_PINS /* GPIO_Pin_0 | */ \
// /* GPIO_Pin_1 | */ \
// /* GPIO_Pin_2 | */ \
// /* GPIO_Pin_3 | */ \
// /* GPIO_Pin_4 | */ \
// /* GPIO_Pin_5 | */ \
// /* GPIO_Pin_6 | */ \
// /* GPIO_Pin_7 | */ \
// /* GPIO_Pin_8 | */ \
// /* GPIO_Pin_9 | */ \
// /* GPIO_Pin_10 | */ \
// /* GPIO_Pin_11 | */ \
// /* GPIO_Pin_12 | */ \
// /* GPIO_Pin_13 | */ \
// /* GPIO_Pin_14 | */ \
// /* GPIO_Pin_15 | */ \
// 0
//
//
//#define GPIO_OUT_OD_PA_PINS /* GPIO_Pin_0 | */ \
// /* GPIO_Pin_1 | */ \
// /* GPIO_Pin_2 | */ \
// /* GPIO_Pin_3 | */ \
// /* GPIO_Pin_4 | */ \
// /* GPIO_Pin_5 | */ \
// /* GPIO_Pin_6 | */ \
// /* GPIO_Pin_7 | */ \
// /* GPIO_Pin_8 | */ \
// /* GPIO_Pin_9 | */ \
// /* GPIO_Pin_10 | */ \
// /* GPIO_Pin_11 | */ \
// /* GPIO_Pin_12 | */ \
// /* GPIO_Pin_13 | */ \
// /* GPIO_Pin_14 | */ \
// /* GPIO_Pin_15 | */ \
// 0
//
//#define GPIO_OUT_OD_PB_PINS /* GPIO_Pin_0 | */ \
// /* GPIO_Pin_1 | */ \
// /* GPIO_Pin_2 | */ \
// /* GPIO_Pin_3 | */ \
// /* GPIO_Pin_4 | */ \
// /* GPIO_Pin_5 | */ \
// /* GPIO_Pin_6 | */ \
// /* GPIO_Pin_7 | */ \
// /* GPIO_Pin_8 | */ \
// /* GPIO_Pin_9 | */ \
// /* GPIO_Pin_10 | */ \
// /* GPIO_Pin_11 | */ \
// /* GPIO_Pin_12 | */ \
// /* GPIO_Pin_13 | */ \
// /* GPIO_Pin_14 | */ \
// /* GPIO_Pin_15 | */ \
// 0
//-- Exported functions prototypes ---------------------------------------------
void gpio_init(void);
#endif /*__GPIO_H*/

68
Core/App/main.c Normal file
View File

@@ -0,0 +1,68 @@
/*==============================================================================
* Шаблон проекта для К1921ВК035 с использованием бибилотеки PLIB035
*------------------------------------------------------------------------------
* НИИЭТ, Богдан Колбов <kolbov@niiet.ru>
*==============================================================================
* ДАННОЕ ПРОГРАММНОЕ ОБЕСПЕЧЕНИЕ ПРЕДОСТАВЛЯЕТСЯ «КАК ЕСТЬ», БЕЗ КАКИХ-ЛИБО
* ГАРАНТИЙ, ЯВНО ВЫРАЖЕННЫХ ИЛИ ПОДРАЗУМЕВАЕМЫХ, ВКЛЮЧАЯ ГАРАНТИИ ТОВАРНОЙ
* ПРИГОДНОСТИ, СООТВЕТСТВИЯ ПО ЕГО КОНКРЕТНОМУ НАЗНАЧЕНИЮ И ОТСУТСТВИЯ
* НАРУШЕНИЙ, НО НЕ ОГРАНИЧИВАЯСЬ ИМИ. ДАННОЕ ПРОГРАММНОЕ ОБЕСПЕЧЕНИЕ
* ПРЕДНАЗНАЧЕНО ДЛЯ ОЗНАКОМИТЕЛЬНЫХ ЦЕЛЕЙ И НАПРАВЛЕНО ТОЛЬКО НА
* ПРЕДОСТАВЛЕНИЕ ДОПОЛНИТЕЛЬНОЙ ИНФОРМАЦИИ О ПРОДУКТЕ, С ЦЕЛЬЮ СОХРАНИТЬ ВРЕМЯ
* ПОТРЕБИТЕЛЮ. НИ В КАКОМ СЛУЧАЕ АВТОРЫ ИЛИ ПРАВООБЛАДАТЕЛИ НЕ НЕСУТ
* ОТВЕТСТВЕННОСТИ ПО КАКИМ-ЛИБО ИСКАМ, ЗА ПРЯМОЙ ИЛИ КОСВЕННЫЙ УЩЕРБ, ИЛИ
* ПО ИНЫМ ТРЕБОВАНИЯМ, ВОЗНИКШИМ ИЗ-ЗА ИСПОЛЬЗОВАНИЯ ПРОГРАММНОГО ОБЕСПЕЧЕНИЯ
* ИЛИ ИНЫХ ДЕЙСТВИЙ С ПРОГРАММНЫМ ОБЕСПЕЧЕНИЕМ.
*
* 2018 АО "НИИЭТ"
*==============================================================================
*/
//-- Includes ------------------------------------------------------------------
#include "main.h"
#include "rcu.h"
#include "gpio.h"
//-- Defines -------------------------------------------------------------------
//-- Peripheral init functions -------------------------------------------------
void periph_init()
{
SystemCoreClockUpdate();
sysclk_init();
gpio_init();
retarget_init();
printf("\nAll peripherals inited, SYSCLK = %3d MHz\n", (int)(SystemCoreClock / 1E6));
}
//-- Main ----------------------------------------------------------------------
int main()
{
periph_init();
while (1) {
};
//return 0;
}
//-- Assert --------------------------------------------------------------------
void Error_Handler(void)
{
__disable_irq();
while (1)
{
}
}
#if defined USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
printf("Assert failed: file %s on line %d\n", file, (int)line);
while (1) {
};
}
#endif /* USE_FULL_ASSERT */

35
Core/App/main.h Normal file
View File

@@ -0,0 +1,35 @@
/*==============================================================================
* Шаблон проекта для К1921ВК035 с использованием бибилотеки PLIB035
*------------------------------------------------------------------------------
* НИИЭТ, Богдан Колбов <kolbov@niiet.ru>
*==============================================================================
* ДАННОЕ ПРОГРАММНОЕ ОБЕСПЕЧЕНИЕ ПРЕДОСТАВЛЯЕТСЯ «КАК ЕСТЬ», БЕЗ КАКИХ-ЛИБО
* ГАРАНТИЙ, ЯВНО ВЫРАЖЕННЫХ ИЛИ ПОДРАЗУМЕВАЕМЫХ, ВКЛЮЧАЯ ГАРАНТИИ ТОВАРНОЙ
* ПРИГОДНОСТИ, СООТВЕТСТВИЯ ПО ЕГО КОНКРЕТНОМУ НАЗНАЧЕНИЮ И ОТСУТСТВИЯ
* НАРУШЕНИЙ, НО НЕ ОГРАНИЧИВАЯСЬ ИМИ. ДАННОЕ ПРОГРАММНОЕ ОБЕСПЕЧЕНИЕ
* ПРЕДНАЗНАЧЕНО ДЛЯ ОЗНАКОМИТЕЛЬНЫХ ЦЕЛЕЙ И НАПРАВЛЕНО ТОЛЬКО НА
* ПРЕДОСТАВЛЕНИЕ ДОПОЛНИТЕЛЬНОЙ ИНФОРМАЦИИ О ПРОДУКТЕ, С ЦЕЛЬЮ СОХРАНИТЬ ВРЕМЯ
* ПОТРЕБИТЕЛЮ. НИ В КАКОМ СЛУЧАЕ АВТОРЫ ИЛИ ПРАВООБЛАДАТЕЛИ НЕ НЕСУТ
* ОТВЕТСТВЕННОСТИ ПО КАКИМ-ЛИБО ИСКАМ, ЗА ПРЯМОЙ ИЛИ КОСВЕННЫЙ УЩЕРБ, ИЛИ
* ПО ИНЫМ ТРЕБОВАНИЯМ, ВОЗНИКШИМ ИЗ-ЗА ИСПОЛЬЗОВАНИЯ ПРОГРАММНОГО ОБЕСПЕЧЕНИЯ
* ИЛИ ИНЫХ ДЕЙСТВИЙ С ПРОГРАММНЫМ ОБЕСПЕЧЕНИЕМ.
*
* 2018 АО "НИИЭТ"
*==============================================================================
*/
#ifndef __MAIN_H
#define __MAIN_H
//-- Includes ------------------------------------------------------------------
#include "plib035.h"
#include "retarget_conf.h"
#include "mylibs_include.h"
//-- Defines -------------------------------------------------------------------
//-- Exported variables --------------------------------------------------------
//-- Exported functions prototypes ---------------------------------------------
void Error_Handler(void);
#endif /* __MAIN_H */

31
Core/App/rcu.c Normal file
View File

@@ -0,0 +1,31 @@
/*==============================================================================
* Инициализация тактирования с использованием бибилотеки PLIB035
*------------------------------------------------------------------------------
* ЦНИИ СЭТ, Разваляев Алексей <wot890089@mail.ru>
*==============================================================================
* ЦНИИ СЭТ
*==============================================================================
*/
//-- Includes ------------------------------------------------------------------
#include "rcu.h"
//-- Defines -------------------------------------------------------------------
//-- Peripheral init functions -------------------------------------------------
void sysclk_init(void)
{
OperationStatus status;
status = RCU_PLL_AutoConfig(MCU_CLOCK_MHZ*__MHZ, OS_Type);
if (status == ERROR)
{
Error_Handler();
}
SystemCoreClockUpdate();
RCU_ClkOutConfig(RCU_SysPeriphClk_PLLClk, 1, ENABLE);
RCU_ClkOutCmd(ENABLE);
/* Прерывание должно быть каждую миллисекунду:
Для тактирования N Гц это каждый N / 1000 тик */
SysTick_Config(MCU_CLOCK_MHZ*__MHZ/1000);
}

22
Core/App/rcu.h Normal file
View File

@@ -0,0 +1,22 @@
/*==============================================================================
* Инициализация тактирования с использованием бибилотеки PLIB035
*------------------------------------------------------------------------------
* ЦНИИ СЭТ, Разваляев Алексей <wot890089@mail.ru>
*==============================================================================
* ЦНИИ СЭТ
*==============================================================================
*/
#ifndef __RCU_H
#define __RCU_H
//-- Includes ------------------------------------------------------------------
#include "main.h"
//-- Defines -------------------------------------------------------------------
static RCU_PLL_Ref_TypeDef OS_Type = RCU_PLL_Ref_OSEClk;
#define MCU_CLOCK_MHZ 100
#define __MHZ 1000000
//-- Exported functions prototypes ---------------------------------------------
void sysclk_init(void);
#endif /*__RCU_H*/

106
Core/App/vk035_it.c Normal file
View File

@@ -0,0 +1,106 @@
/*==============================================================================
* Прерывания микроконтроллера 1921ВК035
*------------------------------------------------------------------------------
* ЦНИИ СЭТ, Разваляев Алексей <wot890089@mail.ru>
*==============================================================================
* ЦНИИ СЭТ
*==============================================================================
*/
//-- Includes ------------------------------------------------------------------
#include "main.h"
#include "plib035.h"
#include "retarget_conf.h"
/******************************************************************************/
/* STM32G4xx Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_stm32g4xx.s). */
/******************************************************************************/
/******************************************************************************/
/* Cortex-M4 Processor Interruption and Exception Handlers */
/******************************************************************************/
/**
* @brief This function handles Non maskable interrupt.
*/
void NMI_Handler(void)
{
while (1)
{
}
}
/**
* @brief This function handles Hard fault interrupt.
*/
void HardFault_Handler(void)
{
while (1)
{
}
}
/**
* @brief This function handles Memory management fault.
*/
void MemManage_Handler(void)
{
while (1)
{
}
}
/**
* @brief This function handles Prefetch fault, memory access fault.
*/
void BusFault_Handler(void)
{
while (1)
{
}
}
/**
* @brief This function handles Undefined instruction or illegal state.
*/
void UsageFault_Handler(void)
{
while (1)
{
}
}
/**
* @brief This function handles System service call via SWI instruction.
*/
void SVC_Handler(void)
{
}
/**
* @brief This function handles Debug monitor.
*/
void DebugMon_Handler(void)
{
}
/**
* @brief This function handles Pendable request for system service.
*/
void PendSV_Handler(void)
{
}
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
uwTick++;
}