⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stm32f10x_target.c

📁 这个原例子是从网上收集的
💻 C
字号:
/****************************************Copyright (c)**********************************
**                                      
**                                          
**                                博格达科技有限公司
**
**                                 http://www.bogodtech.com
**
**--------------文件信息----------------------------------------------------------------
** 文 件 名: stm32f10x_target.c
** 创 建 人: 罗辉联(armgcc@foxmail.com, wyuyun@hotmail.com, lhlzjut@hotmail.com) 	
** 创建日期: 2007年12月10日
** 描    述: 目标板初始化函数
** 技术顾问: 楼东武(副教授)  浙江大学信电系
**
**---------- 版本信息-------------------------------------------------------------------
** 版    本: V1.0
** 说    明: 
**-------------------------------------------------------------------------------------*
****************************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include "config.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
ErrorStatus HSEStartUpStatus;

/* Public  variables ---------------------------------------------------------*/
/* Public  function  ---------------------------------------------------------*/

/***************************************************************************************
** 函数名称: RCC_Configuration
** 功能描述: stm32f10x时钟系统配置
** 参    数: None
** 返 回 值: None       
** 作   者: 罗辉联
** 日   期: 2007年11月28日
**--------------------------------------------------------------------------------------
** 修 改 人: 
** 日   期: 
**--------------------------------------------------------------------------------------
****************************************************************************************/
static void RCC_Configuration(void)	
{
	/* RCC system reset(for debug purpose) */
	RCC_DeInit();
	/* Enable HSE */
	RCC_HSEConfig(RCC_HSE_ON);
	/* Wait till HSE is ready */
	HSEStartUpStatus = RCC_WaitForHSEStartUp();
	if(HSEStartUpStatus == SUCCESS)
	{
		/* HCLK = SYSCLK */
		RCC_HCLKConfig(RCC_SYSCLK_Div1); 
		/* PCLK2 = HCLK */
		RCC_PCLK2Config(RCC_HCLK_Div2); 
		/* PCLK1 = HCLK/2 */
		RCC_PCLK1Config(RCC_HCLK_Div2);
		 /* ADCCLK = PCLK2/4 */
		RCC_ADCCLKConfig(RCC_PCLK2_Div4);
		
		/* Enable Prefetch Buffer */
		//FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
		/* Flash 2 wait state */
		FLASH_SetLatency(FLASH_Latency_2);
		 
		/* PLLCLK = 8MHz * 9 = 72 MHz */
		RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_7);
		/* Enable PLL */ 
		RCC_PLLCmd(ENABLE);
		/* Wait till PLL is ready */
		while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
		/* Select PLL as system clock source */
		RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
		/* Wait till PLL is used as system clock source */
		while(RCC_GetSYSCLKSource() != 0x08);
	}
	
	/* Enable GPIOx and AFIO clocks */
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | 
	                       RCC_APB2Periph_GPIOC , ENABLE);
	
}

/***************************************************************************************
** 函数名称: NVIC_Configuration
** 功能描述: stm32f10x配置基本向量中断
** 参    数: None
** 返 回 值: None       
** 作   者: 罗辉联
** 日   期: 2007年11月28日
**--------------------------------------------------------------------------------------
** 修 改 人: 
** 日   期: 
**--------------------------------------------------------------------------------------
****************************************************************************************/
static void NVIC_Configuration(void)
{ 
	NVIC_InitTypeDef NVIC_InitStructure;
	
	/* Set the Vector Table base location at 0x08000000 */ 
	NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);   
	
	/* Configure one bit for preemption priority */
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3);
	
	/* Enable the USART1 Interrupt */
	NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_Init(&NVIC_InitStructure);

	/* Enable the WDG Interrupt */
	NVIC_InitStructure.NVIC_IRQChannel = WWDG_IRQChannel;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
	NVIC_Init(&NVIC_InitStructure);
  
}

/***************************************************************************************
** 函数名称: GPIOX_Configuration
** 功能描述: 特殊的GPIO管脚配置
** 参    数: None
** 返 回 值: None       
** 作   者: 罗辉联
** 日   期: 2007年11月28日
**--------------------------------------------------------------------------------------
** 修 改 人: 
** 日   期: 
**--------------------------------------------------------------------------------------
****************************************************************************************/
static void GPIOX_Configuration(void)
{ 
  
}

/***************************************************************************************
** 函数名称: Target_Init
** 功能描述: 板级初始化函数
** 参    数: None
** 返 回 值: None       
** 作   者: 罗辉联
** 日   期: 2007年11月28日
**--------------------------------------------------------------------------------------
** 修 改 人: 
** 日   期: 
**--------------------------------------------------------------------------------------
****************************************************************************************/
void Target_Init (void)
{
	/* System Clocks Configuration */
	RCC_Configuration();

	NVIC_DeInit();
	      
	/* NVIC configuration */
	NVIC_Configuration();

	GPIOX_Configuration();
	
}

/***************************************************************************************
** 函数名称: Tmr_TickInit
** 功能描述: OS tick 初始化函数
** 参    数: None
** 返 回 值: None       
** 作   者: 罗辉联
** 日   期: 2007年11月28日
**--------------------------------------------------------------------------------------
** 修 改 人: 
** 日   期: 
**--------------------------------------------------------------------------------------
****************************************************************************************/
void Tmr_TickInit (void)
{
    /* SysTick end of count event each 1ms with input clock equal to 9MHz (HCLK/8, default) */
  	SysTick_SetReload(9000);
  	/* Enable SysTick interrupt */
  	SysTick_ITConfig(ENABLE);
  	/* Enable the SysTick Counter */
  	SysTick_CounterCmd(SysTick_Counter_Enable);	
}
/***************************************************************************************
** 函数名称: Wdg_Init
** 功能描述: 看门狗初始化函数
** 参    数: None
** 返 回 值: None       
** 作   者: 罗辉联
** 日   期: 2007年11月28日
**--------------------------------------------------------------------------------------
** 修 改 人: 
** 日   期: 
**--------------------------------------------------------------------------------------
****************************************************************************************/
void Wdg_Init(void)
{
	/* Enable WDG clocks */
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG , ENABLE);

	/* PCKL1: 36MHZ */
	/* WWDG clock counter = (PCLK1/4096)/8 = 488 Hz (~2 ms)  */
  	WWDG_SetPrescaler(WWDG_Prescaler_8);
  	/* Set Window value to 65 */
  	WWDG_SetWindowValue(65);
  	/* Enable WWDG and set counter value to 127, WWDG timeout = ~2 ms * 64 = 130 ms */
  	WWDG_Enable(127);

	/* Clear EWI flag */
  	WWDG_ClearFlag();

  	/* Enable EW interrupt */
  	WWDG_EnableIT();
}

/***************************************************************************************
** 函数名称: sleep
** 功能描述: 简单的延时函数
** 参    数: None
** 返 回 值: None       
** 作   者: 罗辉联
** 日   期: 2007年11月28日
**--------------------------------------------------------------------------------------
** 修 改 人: 
** 日   期: 
**--------------------------------------------------------------------------------------
****************************************************************************************/
void sleep(u32 cnt)
{
	u32 i = 0;

	for(i = 0; i < cnt; i++);
}



#ifdef  DEBUG
/*******************************************************************************
* Function Name  : assert_failed
* Description    : Reports the name of the source file and the source line number
*                  where the assert_param error has occurred.
* Input          : - file: pointer to the source file name
*                  - line: assert_param error line source number
* Output         : None
* Return         : None
*******************************************************************************/
void assert_failed(u8* file, u32 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

/****************** http://www.bogodtech.com *******End of file ******************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -