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

📄 drv_init.c

📁 ARM_CORTEX-M3应用实例开发详解光盘
💻 C
字号:
/*****************************************************************************
* 文件名           : drv_init.c
* 功能描述     :设备驱动程序初始化

******************************************************************************/
#include <stdio.h>
#include <ucos_ii.h>
#include "drv_init.h"


/*=============================================================================
* 功能函数	: NVIC_Configuration
* 功能描述	: 中断向量表基址,优先组配置
* 输入	: 
* 输出	: 
* 返回  : 
=============================================================================*/
int NVIC_Configuration(void)
{
#ifdef  VECT_TAB_RAM  
	NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); 

#else  												
		NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0);   
#endif

	/* 配置1位抢占优先级 */
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

	return 0;
}

/*=============================================================================
* Function	: 
* Description	: 
* Input Para	: 
* Output Para	: 
* Return Value  : 
=============================================================================*/
int RCC_Configuration(void)
{

	ErrorStatus HSEStartUpStatus;

	/* 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_Div1); 

		/* PCLK1 = HCLK/2 */
		RCC_PCLK1Config(RCC_HCLK_Div2);

		/* Flash 2 wait state */
		FLASH_SetLatency(FLASH_Latency_2);
		/* Enable Prefetch Buffer */
		FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

		/* PLLCLK = 8MHz * 9 = 72 MHz */
		RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

		/* 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 PWR and BKP clocks */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

  /* Allow access to BKP Domain */
  PWR_BackupAccessCmd(ENABLE);

//  /* Reset Backup Domain */

  RCC_LSEConfig(RCC_LSE_ON);
  /* 等待LSE就绪 */
  while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
  {}

  /* 选择LSE作为RTC时钟 */
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);

  /* 使能RTC时钟 */
  RCC_RTCCLKCmd(ENABLE);  

	return 0;
}

/*=============================================================================
* 功能函数	: rfid_init
* 功能描述	: RFID初始化及寄存器初始化及状态输出提示信息
=============================================================================*/
int rfid_init(void) {
 	printf("\r\nfm1702_init(): ");
	if (fm1702_init() == FM1702_OK) {
		printf("OK");
	} else {
		printf("ERR");
	}

	printf("\r\nfm1702_reg_initial(): ");
	if (fm1702_reg_initial(1) == FM1702_OK) {
		printf("OK");
	} else {
		printf("ERR");
	}
	return 0;
}

/*=============================================================================
* 功能函数	:drv_all_init 
* 功能说明	: 所有设备初始化。
=============================================================================*/
int drv_all_init(void)
{
	ENABLE_IRQ();

	led_init();
	led_on(2);

	uart_init(udev_std);

	hwtm_init();

	dcodec_init();

	key_init();

	rtc_init();
	// SRAM_Init();

	/* LCD初始化 */
	STM3210E_LCD_Init();

	adc_init();

	FSMC_NAND_Init();

	uart2_init(STD_UART_BAUD);

	CDRS_Init();

	rfid_init();

	return 0;
}

/************************************END OF FILE******************************/

⌨️ 快捷键说明

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