Files
HBshuiwuConcentrator/APP/Init.c
2025-12-15 16:07:49 +08:00

166 lines
5.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*——————————————————————————
* 文 件 名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);
}
}
}