1. 程式人生 > >STM32F207ZG型號gpio配置

STM32F207ZG型號gpio配置


#include "main.h"
#include "stm32f2xx.h"
#include "stm322xg_eval.h"
#include <stdio.h>
#define MESSAGE1   "     STM32F2xx      "
#define MESSAGE2   " Device running on  "
#define MESSAGE3   "   STM322xG-EVAL    "
static __IO uint32_t TimingDelay;
USART_InitTypeDef USART_InitStructure;
#ifdef __GNUC__
  /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
     set to 'Yes') calls __io_putchar() */
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
#define EVAL_COM1                        USART3
#define EVAL_COM1_CLK                    RCC_APB1Periph_USART3
#define EVAL_COM1_TX_PIN                 GPIO_Pin_10
#define EVAL_COM1_TX_GPIO_PORT           GPIOC
#define EVAL_COM1_TX_GPIO_CLK            RCC_AHB1Periph_GPIOC
#define EVAL_COM1_TX_SOURCE              GPIO_PinSource10
#define EVAL_COM1_TX_AF                  GPIO_AF_USART3
#define EVAL_COM1_RX_PIN                 GPIO_Pin_11
#define EVAL_COM1_RX_GPIO_PORT           GPIOC
#define EVAL_COM1_RX_GPIO_CLK            RCC_AHB1Periph_GPIOC
#define EVAL_COM1_RX_SOURCE              GPIO_PinSource11
#define EVAL_COM1_RX_AF                  GPIO_AF_USART3
#define EVAL_COM1_IRQn                   USART3_IRQn void dely(int i)
{
int a=0;
int z=0;
for(;a<i;a++) 
{
 for(;z<100;z++)
 {}
}
} void STM_EVAL_LEDInit1()
{
  GPIO_InitTypeDef  GPIO_InitStructure;
 
  /* Enable the GPIO_LED Clock */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
  /* Configure the GPIO_LED pin */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void STM_EVAL_LEDInit2()
{
  GPIO_InitTypeDef  GPIO_InitStructure;
 
  /* Enable the GPIO_LED Clock */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
  /* Configure the GPIO_LED pin */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
}
int main(void)
{
  RCC_ClocksTypeDef RCC_Clocks;
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);
 STM_EVAL_LEDInit1();
 STM_EVAL_LEDInit2();
 //GPIO_ResetBits(GPIOC,GPIO_Pin_7);
 GPIO_SetBits(GPIOC,GPIO_Pin_7);
 GPIO_SetBits(GPIOC,GPIO_Pin_6);
 GPIO_ResetBits(GPIOC,GPIO_Pin_7);
 GPIO_ResetBits(GPIOC,GPIO_Pin_6);
  USART_InitStructure.USART_BaudRate = 115200;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
 STM_EVAL_COMInit(COM1, &USART_InitStructure);
 printf("\n\rUSART Printf Example: retarget the C library printf function to the USART\n\r");   while (1)
  {
  }
 /*
 for(;;){
  GPIO_SetBits(GPIOC,GPIO_Pin_6); //置為1
dely(1000000);//延時1s,自己實現的,暫不說明
  GPIO_ResetBits(GPIOC,GPIO_Pin_6); //置為0
dely(1000000); //延時1s
}*/
 
}
void Delay(__IO uint32_t nTime)
{
  TimingDelay = nTime;   while(TimingDelay!= 0);
}
void TimingDelay_Decrement(void)
{
  if (TimingDelay!= 0x00)
  {
    TimingDelay--;
  }
} PUTCHAR_PROTOTYPE
{
  /* Place your implementation of fputc here */
  /* e.g. write a character to the USART */
  USART_SendData(EVAL_COM1, (uint8_t) ch);   /* Loop until the end of transmission */
  while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
  {}   return ch;
}
#ifdef  USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t 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 /**
  * @}
  */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/