/******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** * File Name : main.c * Author : MCD Application Team * Version : V2.0.1 * Date : 06/13/2008 * Description : Main program body. ******************************************************************************** * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. *******************************************************************************/ /* Includes ------------------------------------------------------------------*/ #include "stm32f10x_lib.h" #include "platform_config.h"
/* Private functions ---------------------------------------------------------*/ /******************************************************************************* * Function Name : main * Description : Main program. * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { #ifdef DEBUG debug(); #endif
/* System Clocks Configuration */ RCC_Configuration();
/* GPIO configuration */ GPIO_Configuration();
/* Check if the system has resumed from WWDG reset */ if (RCC_GetFlagStatus(RCC_FLAG_WWDGRST) != RESET) { /* WWDGRST flag set */ /* Set GPIO_LED pin 6 */ GPIO_SetBits(GPIOB,GPIO_Pin_5|GPIO_Pin_8); //LED ON
/* Clear reset flags */ RCC_ClearFlag(); } else { /* WWDGRST flag is not set */ /* Reset GPIO_LED pin 6 */ GPIO_ResetBits(GPIOB,GPIO_Pin_5|GPIO_Pin_8); //LED OFF }
/* NVIC configuration */ NVIC_Configuration();
GPIO_ResetBits(GPIOB,GPIO_Pin_5|GPIO_Pin_8); //LED OFF Delay(700000);
GPIO_SetBits(GPIOB,GPIO_Pin_5|GPIO_Pin_8); //LED ON Delay(700000);
GPIO_ResetBits(GPIOB,GPIO_Pin_5|GPIO_Pin_8); //LED OFF Delay(700000);
GPIO_SetBits(GPIOB,GPIO_Pin_5|GPIO_Pin_8); //LED ON Delay(700000);
/* Select HSE as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);
/* Wait till HSE is used as system clock source */ while (RCC_GetSYSCLKSource() != 0x04) {} } /* GPIOA, GPIOB and SPI1 clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_SPI1, ENABLE); }
/******************************************************************************* * Function Name : GPIO_Configuration * Description : Configures the different GPIO ports. * Input : None * Output : None * Return : None *******************************************************************************/ void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure;
#ifdef VECT_TAB_RAM /* Set the Vector Table base location at 0x20000000 */ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */ /* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif
/* 2 bits for Preemption Priority and 2 bits for Sub Priority */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
/******************************************************************************* * Function Name : Delay * Description : Inserts a delay time. * Input : nCount: specifies the delay time length. * Output : None * Return : None *******************************************************************************/ void Delay(vu32 nCount) { for (; nCount != 0; nCount--); }
#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
", file, line) */
/* Infinite loop */ while (1) {} } #endif
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
/******************************************************************************* * Function Name : WWDG_IRQHandler * Description : This function handles WWDG interrupt request. * Input : None * Output : None * Return : None *******************************************************************************/ void WWDG_IRQHandler(void) { /* Update WWDG counter */ WWDG_SetCounter(0x7F); //注释这里不能造成STM32复位!!!!