mirror of
https://github.com/xiaotianbc/AT32_BSPV1_Clion_Template.git
synced 2026-05-21 01:12:16 +00:00
init
This commit is contained in:
143
User/at32f4xx_it.c
Normal file
143
User/at32f4xx_it.c
Normal file
@@ -0,0 +1,143 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* File : Templates/at32f4xx_it.c
|
||||
* Version: V1.3.0
|
||||
* Date : 2021-03-18
|
||||
* Brief : Main Interrupt Service Routines.
|
||||
* This file provides template for all exceptions handler and peripherals
|
||||
* interrupt service routine.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "at32f4xx_it.h"
|
||||
/** @addtogroup AT32F403A_StdPeriph_Templates
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup GPIO_LED_Toggle
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This function handles NMI exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Hard Fault exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
/* Go to infinite loop when Hard Fault exception occurs */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Memory Manage exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void MemManage_Handler(void)
|
||||
{
|
||||
/* Go to infinite loop when Memory Manage exception occurs */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Bus Fault exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void BusFault_Handler(void)
|
||||
{
|
||||
/* Go to infinite loop when Bus Fault exception occurs */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Usage Fault exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void UsageFault_Handler(void)
|
||||
{
|
||||
/* Go to infinite loop when Usage Fault exception occurs */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles SVCall exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SVC_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Debug Monitor exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void DebugMon_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles PendSV_Handler exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void PendSV_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles SysTick Handler.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* at32f4xx Peripherals Interrupt Handlers */
|
||||
/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */
|
||||
/* available peripheral interrupt handler's name please refer to the startup */
|
||||
/* file (startup_at32f403_xx.s). */
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief This function handles PPP interrupt request.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
/*void PPP_IRQHandler(void)
|
||||
{
|
||||
}*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
36
User/inc/at32f4xx_it.h
Normal file
36
User/inc/at32f4xx_it.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* File : Templates/at32f4xx_it.h
|
||||
* Version: V1.3.0
|
||||
* Date : 2021-03-18
|
||||
* Brief : Main Interrupt Service Routines.
|
||||
* This file provides template for all exceptions handler and peripherals
|
||||
* interrupt service routine.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __AT32F4XX_IT_H
|
||||
#define __AT32F4XX_IT_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "at32f4xx.h"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
void NMI_Handler(void);
|
||||
void HardFault_Handler(void);
|
||||
void MemManage_Handler(void);
|
||||
void BusFault_Handler(void);
|
||||
void UsageFault_Handler(void);
|
||||
void SVC_Handler(void);
|
||||
void DebugMon_Handler(void);
|
||||
void PendSV_Handler(void);
|
||||
void SysTick_Handler(void);
|
||||
|
||||
#endif /* __AT32F4XX_IT_H */
|
||||
|
||||
177
User/main.c
Normal file
177
User/main.c
Normal file
@@ -0,0 +1,177 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* File : Templates/main.c
|
||||
* Version: V1.3.0
|
||||
* Date : 2021-03-18
|
||||
* Brief : Main program body
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include "at32f4xx.h"
|
||||
#include "at32_board.h"
|
||||
/** @addtogroup AT32F403A_StdPeriph_Templates
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup Template
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
#define DELAY 100
|
||||
#define FAST 1
|
||||
#define SLOW 4
|
||||
|
||||
/* Extern variables ---------------------------------------------------------*/
|
||||
extern GPIO_Type *BUTTON_GPIO_PORT[BUTTON_NUM];
|
||||
extern uint16_t BUTTON_GPIO_PIN[BUTTON_NUM];
|
||||
extern uint32_t BUTTON_GPIO_RCC_CLK[BUTTON_NUM];
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
uint16_t BUTTON_EXTI_LINE[BUTTON_NUM] = {EXTI_Line0, EXTI_Line13};
|
||||
uint16_t BUTTON_EXTI_IRQ[BUTTON_NUM] = {EXTI0_IRQn, EXTI15_10_IRQn};
|
||||
uint8_t BUTTON_EXTI_SOURCE_PORT[BUTTON_NUM] = {GPIO_PortSourceGPIOA, GPIO_PortSourceGPIOC};
|
||||
uint8_t BUTTON_EXTI_SOURCE_PIN[BUTTON_NUM] = {GPIO_PinsSource0, GPIO_PinsSource13};
|
||||
|
||||
BUTTON_Type gButtonType = BUTTON_WAKEUP;
|
||||
uint8_t gSpeed = FAST;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Config Clock Out Function.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void MCO_Config(void) {
|
||||
GPIO_InitType GPIO_InitStructure;
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_GPIOA, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pins = GPIO_Pins_8;
|
||||
GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
|
||||
/*PA8Êä³öPLL/4*/
|
||||
RCC_CLKOUTConfig(RCC_CLKOUT_PLL_Div4, RCC_MCOPRE_1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure Button EXTI
|
||||
* @param Button: Specifies the Button to be configured.
|
||||
* @retval None
|
||||
*/
|
||||
void BUTTON_EXTI_Init(BUTTON_Type button) {
|
||||
EXTI_InitType EXTI_InitStructure;
|
||||
NVIC_InitType NVIC_InitStructure;
|
||||
|
||||
GPIO_EXTILineConfig(BUTTON_EXTI_SOURCE_PORT[button], BUTTON_EXTI_SOURCE_PIN[button]);
|
||||
EXTI_StructInit(&EXTI_InitStructure);
|
||||
EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[button];
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
EXTI_InitStructure.EXTI_LineEnable = ENABLE;
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
|
||||
EXTI_Init(&EXTI_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = BUTTON_EXTI_IRQ[button];
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Button EXTI0 Interrupt Handler
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void EXTI0_IRQHandler(void) {
|
||||
Delay_ms(5);
|
||||
EXTI_ClearIntPendingBit(BUTTON_EXTI_LINE[gButtonType]);
|
||||
if ((GPIO_ReadInputData(BUTTON_GPIO_PORT[gButtonType]) & BUTTON_GPIO_PIN[gButtonType]) == \
|
||||
BUTTON_GPIO_PIN[gButtonType]) {
|
||||
if (gSpeed == SLOW)
|
||||
gSpeed = FAST;
|
||||
else
|
||||
gSpeed = SLOW;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Button EXTI13 Interrupt Handler
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void EXTI15_10_IRQHandler(void) {
|
||||
Delay_ms(5);
|
||||
EXTI_ClearIntPendingBit(BUTTON_EXTI_LINE[gButtonType]);
|
||||
if ((GPIO_ReadInputData(BUTTON_GPIO_PORT[gButtonType]) & BUTTON_GPIO_PIN[gButtonType]) == \
|
||||
BUTTON_GPIO_PIN[gButtonType]) {
|
||||
if (gSpeed == SLOW)
|
||||
gSpeed = FAST;
|
||||
else
|
||||
gSpeed = SLOW;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Main Function.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
int main(void) {
|
||||
gButtonType = BUTTON_WAKEUP;
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_AFIO, ENABLE);
|
||||
|
||||
AT32_Board_Init();
|
||||
|
||||
MCO_Config();
|
||||
|
||||
BUTTON_EXTI_Init(gButtonType);
|
||||
UART_Print_Init(115200);
|
||||
for (;;) {
|
||||
printf("Hello,true Linker,clion,test float! %f\r\n", 2.1f);
|
||||
AT32_LEDn_Toggle(LED2);
|
||||
Delay_ms(gSpeed * DELAY);
|
||||
AT32_LEDn_Toggle(LED3);
|
||||
Delay_ms(gSpeed * DELAY);
|
||||
AT32_LEDn_Toggle(LED4);
|
||||
Delay_ms(gSpeed * DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief Reports the name of the source file and the source line number
|
||||
* where the assert_param error has occurred.
|
||||
* @param file: pointer to the source file name
|
||||
* @param line: assert_param error line source number
|
||||
* @retval None
|
||||
*/
|
||||
void assert_failed(uint8_t* file, uint32_t line)
|
||||
{
|
||||
/* User can add his own implementation to report the file name and line number,
|
||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||
|
||||
/* Infinite loop */
|
||||
while (1)
|
||||
{}
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user