/** ******************************** STM32F10x ********************************* * @文件名 : bsp.c * @作者 : sun * @库版本 : V3.5.0 * @文件版本 : V1.0.0 * @日期 : 2016年05月09日 * @摘要 : BSP板级支持包源文件 ******************************************************************************/ /*---------------------------------------------------------------------------- 更新日志: 2016-05-09 V1.0.0:初始版本 ----------------------------------------------------------------------------*/ /* 包含的头文件 --------------------------------------------------------------*/ #include "bsp.h" #include "systick.h" #include "usart.h" #include "led.h" #include #include "AT24C128.h" #include "bsp.h" Device_version_info_t device_version_info; eeprom_first_info_t eeprom_first_info; /************************************************ 函数名称 : RCC_Configuration 功 能 : 时钟配置 参 数 : 无 返 回 值 : 无 作 者 : sun *************************************************/ void RCC_Configuration(void) { /* 使能APB2时钟 */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOF | RCC_APB2Periph_AFIO | RCC_APB2Periph_USART1 | RCC_APB2Periph_SPI1, ENABLE); /* 使能APB1时钟 */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2 | RCC_APB1Periph_UART4 | RCC_APB1Periph_TIM4, ENABLE); /* 使能APB时钟 */ /* CRC时钟 */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); //使能PWR和BKP外设时钟 PWR_BackupAccessCmd(ENABLE); //使能后备寄存器访问 } void GPIO_COMM_Init(u32 clk, GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIOMode_TypeDef mode, GPIOSpeed_TypeDef speed) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(clk, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin; GPIO_InitStructure.GPIO_Mode = mode; GPIO_InitStructure.GPIO_Speed = speed; GPIO_Init(GPIOx, &GPIO_InitStructure); GPIO_SetBits(GPIOx, GPIO_Pin); } /************************************************ 函数名称 : GPIO_Basic_Configuration 功 能 : 基本输入输出引脚配置 参 数 : 无 返 回 值 : 无 作 者 : sun *************************************************/ void GPIO_Basic_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = PIN_LED; //引脚 //频率(50M) GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //输出类型(推挽式输出) GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(PORT_LED, &GPIO_InitStructure); } /************************************************ 函数名称 : NVIC_Configuration 功 能 : NVIC配置 参 数 : 无 返 回 值 : 无 作 者 : sun *************************************************/ void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; /* 优先级分组 */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); /* 外设中断 */ NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /**/ NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } /************************************************ 函数名称 : System_Initializes 功 能 : 系统初始化 参 数 : 无 返 回 值 : 无 作 者 : sun *************************************************/ void System_Initializes(void) { LED_Init(); //初始化与LED连接的硬件接口 RCC_Configuration(); USART_Initializes(); I2C_init(); } /** *@brief STM32系统软复位函数 *@param 无 *@return 无 */ void SysReboot(void) { NVIC_SystemReset();// 复位 } /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// extern uint8_t updata_flag; uint8_t eeprom_buf[EECFG_NUM]={0}; uint8_t eeprom_erase_buf[64] = {0}; uint32_t eeprom_addr=0; #define EEPROM_PAGE_NUM 256 #define EEPROM_BUF_LEN 64 //eeprom上电初始化处理 void eeprom_init_handle(void) { // int i; //将eeprom存储的共有数据全部读出 AT24CXX_Read(EECFG_FIRST_INIT0,eeprom_buf,EECFG_NUM); // memcpy(&eeprom_first_info,eeprom_buf,sizeof(eeprom_first_info_t)); //读设备版本信息 memcpy(&device_version_info,&eeprom_buf[EECFG_BT_VER0],sizeof(Device_version_info_t)); // //擦除eeprom // if(eeprom_first_info.eeprom_first_init_flag != EEPROM_FIRST_INIT_FLAG) // { // memset(eeprom_erase_buf,0,sizeof(eeprom_erase_buf)); // for(i = 0; i < EEPROM_PAGE_NUM; i++) // { // AT24CXX_Write(eeprom_addr, eeprom_erase_buf, EEPROM_BUF_LEN); // eeprom_addr += EEPROM_BUF_LEN; // IWDG_ReloadCounter(); // } // } } //更新eeprom信息 void eeprom_info_updata(void) { // if(eeprom_first_info.eeprom_first_init_flag != EEPROM_FIRST_INIT_FLAG)//初次上电 // { // //写0x55AA,eeprom版本,复位次数 // eeprom_first_info.eeprom_first_init_flag = EEPROM_FIRST_INIT_FLAG; // eeprom_first_info.eeprom_ver = EEPROM_VER; // eeprom_first_info.reset_total_num = 1; // AT24CXX_Write(EECFG_FIRST_INIT0, (uint8_t *)&eeprom_first_info, 7); // // //写bt版本 // device_version_info.boot_ver = SOFTWARE_VERSION_BOOT; // AT24CXX_Write(EECFG_BT_VER0, (uint8_t *)&device_version_info.boot_ver, 4); // } // else//不是初次上电 { //写复位次数 eeprom_first_info.reset_total_num++; AT24CXX_Write(EECFG_RST_TIME0, (uint8_t *)&eeprom_first_info.reset_total_num, 4); //如果bt版本不对,写bt版本 if(device_version_info.boot_ver != SOFTWARE_VERSION_BOOT) { device_version_info.boot_ver = SOFTWARE_VERSION_BOOT; AT24CXX_Write(EECFG_BT_VER0, (uint8_t *)&device_version_info.boot_ver, 4); } //如果执行过升级或回退,写app1、2、3版本 if(updata_flag) { updata_flag = 0; AT24CXX_Write(EECFG_APP1_VER0, (uint8_t *)&device_version_info.APP1_ver, 12); } } } /**** Copyright (C)2016 sun. All Rights Reserved **** END OF FILE ****/