河北水利局项目
This commit is contained in:
165
APP/Init.c
Normal file
165
APP/Init.c
Normal file
@@ -0,0 +1,165 @@
|
||||
/*——————————————————————————
|
||||
* 文 件 名:Init.c
|
||||
* 文件说明: 初始化源文件
|
||||
*
|
||||
* 当前版本:V8.0
|
||||
* 作 者:ZL
|
||||
* 开始日期:2013-12-30
|
||||
*———————————————————————————*/
|
||||
|
||||
#include "Init.h"
|
||||
|
||||
void RCC_Init(void)
|
||||
{
|
||||
/* Enable Clock Security System(CSS): this will generate an NMI exception
|
||||
when HSE clock fails */
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
NVIC_InitStructure.NVIC_IRQChannel = RCC_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
|
||||
RCC_ClockSecuritySystemCmd(ENABLE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void gpio_init(st_gpio_config ioconfig)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
RCC_APB2PeriphClockCmd(ioconfig.GPIO_clk, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = ioconfig.GPIO_Pin;
|
||||
GPIO_InitStructure.GPIO_Mode = ioconfig.GPIO_mode;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
|
||||
GPIO_Init(ioconfig.GPIO_port, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
/*—————————————————————————
|
||||
* 函 数 名:NVIC_Init
|
||||
* 输入参数:None
|
||||
* 输出参数:None
|
||||
* 返 回 值:None
|
||||
* 功能说明:中断向量初始化
|
||||
*——————————————————————————*/
|
||||
#define FLASH_APP_ADDRESS 0x08005000
|
||||
void Nvic_Init(void)
|
||||
{
|
||||
// NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
//NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);//重定义中断向量表的位置
|
||||
NVIC_SetVectorTable(NVIC_VectTab_FLASH,FLASH_APP_ADDRESS);
|
||||
//NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
|
||||
|
||||
|
||||
/* Enable and configure RCC global IRQ channel */
|
||||
/*
|
||||
NVIC_InitStructure.NVIC_IRQChannel = SysTick_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
*/
|
||||
|
||||
/* Enable and configure RCC global IRQ channel */
|
||||
|
||||
|
||||
/*
|
||||
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel7_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Channel4_5_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel2_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 6;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 6;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
*/
|
||||
}
|
||||
|
||||
/*——————————————————————————
|
||||
* 函 数 名:RCC_IRQHandler
|
||||
* 输入参数:None
|
||||
* 输出参数:None
|
||||
* 返 回 值:None
|
||||
* 功能说明:RCC中断服务函数
|
||||
*——————————————————————————*/
|
||||
void RCC_IRQHandler(void)
|
||||
{
|
||||
if(RCC_GetITStatus(RCC_IT_HSERDY) != RESET)
|
||||
{
|
||||
/* Clear HSERDY interrupt pending bit */
|
||||
RCC_ClearITPendingBit(RCC_IT_HSERDY);
|
||||
|
||||
/* Check if the HSE clock is still available */
|
||||
if (RCC_GetFlagStatus(RCC_FLAG_HSERDY) != RESET)
|
||||
{
|
||||
/* Enable PLL: once the PLL is ready the PLLRDY interrupt is generated */
|
||||
RCC_PLLCmd(ENABLE);
|
||||
}
|
||||
}
|
||||
|
||||
if(RCC_GetITStatus(RCC_IT_PLLRDY) != RESET)
|
||||
{
|
||||
/* Clear PLLRDY interrupt pending bit */
|
||||
RCC_ClearITPendingBit(RCC_IT_PLLRDY);
|
||||
|
||||
/* Check if the PLL is still locked */
|
||||
if (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) != RESET)
|
||||
{
|
||||
/* Select PLL as system clock source */
|
||||
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user