bsp.c
上传用户:yj_qqy
上传日期:2017-01-28
资源大小:2911k
文件大小:28k
- /*
- *********************************************************************************************************
- * MICIRUM BOARD SUPPORT PACKAGE
- *
- * (c) Copyright 2007; Micrium, Inc.; Weston, FL
- *
- * All rights reserved. Protected by international copyright laws.
- * Knowledge of the source code may NOT be used to develop a similar product.
- * Please help us continue to provide the Embedded community with the finest
- * software available. Your honesty is greatly appreciated.
- *********************************************************************************************************
- */
- /*
- *********************************************************************************************************
- *
- * BOARD SUPPORT PACKAGE
- *
- * ST Microelectronics STM32
- * with the
- * STM3210B-EVAL Evaluation Board
- *
- * Filename : bsp.c
- * Version : V1.10
- * Programmer(s) : BAN
- *********************************************************************************************************
- */
- /*
- *********************************************************************************************************
- * INCLUDE FILES
- *********************************************************************************************************
- */
- #define BSP_MODULE
- #include <bsp.h>
- /*
- *********************************************************************************************************
- * LOCAL DEFINES
- *********************************************************************************************************
- */
- /* -------------------- GPIOA PINS -------------------- */
- #define BSP_GPIOA_UART2_TX DEF_BIT_02
- #define BSP_GPIOA_UART2_RX DEF_BIT_03
- #define BSP_GPIOA_UART1_TX DEF_BIT_09
- #define BSP_GPIOA_UART1_RX DEF_BIT_10
- /* -------------------- GPIOB PINS -------------------- */
- /* -------------------- GPIOC PINS -------------------- */
- #define BSP_GPIOC_LED_RED DEF_BIT_06
- #define BSP_GPIOC_LED_GRN DEF_BIT_07
- #define BSP_GPIOC_USB_DISCONNECT DEF_BIT_09
- /*
- *********************************************************************************************************
- * LOCAL CONSTANTS
- *********************************************************************************************************
- */
- /*
- *********************************************************************************************************
- * LOCAL DATA TYPES
- *********************************************************************************************************
- */
- /*
- *********************************************************************************************************
- * LOCAL TABLES
- *********************************************************************************************************
- */
- /*
- *********************************************************************************************************
- * LOCAL GLOBAL VARIABLES
- *********************************************************************************************************
- */
- /*
- *********************************************************************************************************
- * LOCAL FUNCTION PROTOTYPES
- *********************************************************************************************************
- */
- static void BSP_ADC_Init (void);
- static void BSP_LED_Init (void);
- #if DEBUG_MODULE == DEF_ENABLED
- static void Debug_InitTarget (void);
- #endif
- static void ADC_RCVTabISRHandler (void);
- INT8U ADC_CurConvCount = 0;
- INT32S ADC_ValueMux[ADC_RCVTab_SIZE] = {0,0,0,0,0,0,0,0};
- INT32S ADC_Mittelwert[ADC_RCVTab_SIZE] = {0,0,0,0,0,0,0,0};
- INT32S ADC_Neutral[ADC_RCVTab_SIZE] = {0,0,0,0,0,0,0,0};
- /*
- *********************************************************************************************************
- * LOCAL CONFIGURATION ERRORS
- *********************************************************************************************************
- */
- /*
- *********************************************************************************************************
- * BSP_Init()
- *
- * Description : Initialize the Board Support Package (BSP).
- *
- * Argument(s) : none.
- *
- * Return(s) : none.
- *
- * Caller(s) : Application.
- *
- * Note(s) : (1) This function SHOULD be called before any other BSP function is called.
- *********************************************************************************************************
- */
- void BSP_Init (void)
- {
- //BSP_IntInit();
- RCC_DeInit();
- RCC_HSEConfig(RCC_HSE_ON);
- if(RCC_WaitForHSEStartUp() == SUCCESS)
- {
- RCC_HCLKConfig(RCC_SYSCLK_Div1);
- RCC_PCLK2Config(RCC_HCLK_Div1);
- RCC_PCLK1Config(RCC_HCLK_Div2);
- RCC_ADCCLKConfig(RCC_PCLK2_Div6);
- FLASH_SetLatency(FLASH_Latency_2);
- FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
- RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
- RCC_PLLCmd(ENABLE);
-
- while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
-
- RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
-
- while (RCC_GetSYSCLKSource() != 0x08);
- }
- BSP_ADC_Init(); /* Initialize the I/Os for the ADC controls. */
- BSP_LED_Init(); /* Initialize the I/Os for the LED controls. */
- #if (DEBUG_MODULE == DEF_ENABLED)
- Debug_InitTarget();
- #endif
- }
- /*
- *********************************************************************************************************
- * BSP_CPU_ClkFreq()
- *
- * Description : Read CPU registers to determine the CPU clock frequency of the chip.
- *
- * Argument(s) : none.
- *
- * Return(s) : The CPU clock frequency, in Hz.
- *
- * Caller(s) : Application.
- *
- * Note(s) : none.
- *********************************************************************************************************
- */
- CPU_INT32U BSP_CPU_ClkFreq (void)
- {
- RCC_ClocksTypeDef rcc_clocks;
- RCC_GetClocksFreq(&rcc_clocks);
- return ((CPU_INT32U)rcc_clocks.SYSCLK_Frequency);
- }
- /*
- *********************************************************************************************************
- *********************************************************************************************************
- * OS CORTEX-M3 FUNCTIONS
- *********************************************************************************************************
- *********************************************************************************************************
- */
- /*
- *********************************************************************************************************
- * OS_CPU_SysTickClkFreq()
- *
- * Description : Get system tick clock frequency.
- *
- * Argument(s) : none.
- *
- * Return(s) : Clock frequency (of system tick).
- *
- * Caller(s) : BSP_Init().
- *
- * Note(s) : none.
- *********************************************************************************************************
- */
- INT32U OS_CPU_SysTickClkFreq (void)
- {
- INT32U freq;
- freq = BSP_CPU_ClkFreq();
- return (freq);
- }
- /*
- *********************************************************************************************************
- *********************************************************************************************************
- * ADC FUNCTIONS
- *********************************************************************************************************
- *********************************************************************************************************
- */
- /*
- *********************************************************************************************************
- * BSP_ADC_Init()
- *
- * Description : Initialize the board's ADC
- *
- * Argument(s) : none.
- *
- * Return(s) : none.
- *
- * Caller(s) : BSP_Init().
- *
- * Note(s) : none.
- *********************************************************************************************************
- */
- static void BSP_ADC_Init (void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- /* Enable peripheral clocks --------------------------------------------------*/
- BSP_PeriphEn(BSP_PERIPH_ID_IOPA);
- BSP_PeriphEn(BSP_PERIPH_ID_IOPC);
- BSP_PeriphEn(BSP_PERIPH_ID_ADC1);
- BSP_PeriphEn(BSP_PERIPH_ID_DMA1);
-
- /* Enable clock */
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
-
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
-
- /* DMA1 channel1 configuration ----------------------------------------------*/
- DMA_DeInit(DMA1_Channel1);
- DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; //外设地址
- DMA_InitStructure.DMA_MemoryBaseAddr = (INT32U)&ADC_RCVTab; //内存地址
- DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //DMA传输方向单向
- DMA_InitStructure.DMA_BufferSize = ADC_RCVTab_SIZE; //设置DMA在传输时缓冲区的长度 WORD
- DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //设置DMA的外设递增模式, 一个外设
- DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //设置DMA的内存递增模式
- DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; //外设数据字长
- DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //内存数据字长
- DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //设置DMA的传输模式:Circular循环模式/Normal普通模式
- DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; //设置DMA的优先级别
- DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //设置DMA的2个memory中的变量互相访问
- DMA_Init(DMA1_Channel1, &DMA_InitStructure);
-
- BSP_IntVectSet(BSP_INT_ID_DMA1_CH1, ADC_RCVTabISRHandler);
- BSP_IntEn(BSP_INT_ID_DMA1_CH1);
-
- /* Enable DMA DMA1_Channel1 complete transfer interrupt */
- DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);
-
- /* Enable DMA1 channel1 */
- DMA_Cmd(DMA1_Channel1, ENABLE);
-
- /* ADC1 configuration ------------------------------------------------------*/
- ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; //独立工作模式
- ADC_InitStructure.ADC_ScanConvMode = ENABLE; //扫描方式
- ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //连续转换关闭
- ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //外部触发禁止
- ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //数据右对齐
- ADC_InitStructure.ADC_NbrOfChannel = ADC_RCVTab_SIZE; //用于转换的通道数
- ADC_Init(ADC1, &ADC_InitStructure);
-
- /* ADC1 regular channels configuration [ADC1配置通道规则]*/
- ADC_RegularChannelConfig(ADC1, ADC_Channel_0 , 1, ADC_SampleTime_1Cycles5); //NICK
- ADC_RegularChannelConfig(ADC1, ADC_Channel_2 , 2, ADC_SampleTime_1Cycles5); //ROLL
- ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 3, ADC_SampleTime_1Cycles5); //GIER
- ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 4, ADC_SampleTime_1Cycles5); //X
- ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 5, ADC_SampleTime_1Cycles5); //Y
- ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 6, ADC_SampleTime_1Cycles5); //Z
- ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 7, ADC_SampleTime_1Cycles5); //气压
- ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 8, ADC_SampleTime_1Cycles5); //电压
-
- /* Enable ADC1 DMA [ADC1使能DMA]*/
- ADC_DMACmd(ADC1, ENABLE);
-
- /* Enable ADC1 [ADC1使能]*/
- ADC_Cmd(ADC1, ENABLE);
-
- /* Enable ADC1 reset calibaration register */
- ADC_ResetCalibration(ADC1);
- /* Check the end of ADC1 reset calibration register */
- while(ADC_GetResetCalibrationStatus(ADC1));
-
- /* Start ADC1 calibaration */
- ADC_StartCalibration(ADC1);
- /* Check the end of ADC1 calibration */
- while(ADC_GetCalibrationStatus(ADC1));
- }
- void ADC_RCVTabISRHandler (void)
- {
- CPU_SR cpu_sr;
- CPU_CRITICAL_ENTER(); /* Tell uC/OS-II that we are starting an ISR */
- OSIntNesting++;
- CPU_CRITICAL_EXIT();
- if (DMA_GetITStatus(DMA1_IT_TC1) != RESET) {
- ADC_CurConvCount++;
- ADC_ValueMux[ADC_NICK] += ADC_RCVTab[ADC_NICK] - ADC_Neutral[ADC_NICK];
- ADC_ValueMux[ADC_ROLL] += ADC_RCVTab[ADC_ROLL] - ADC_Neutral[ADC_ROLL];
- ADC_ValueMux[ADC_GIER] += ADC_Neutral[ADC_GIER] - ADC_RCVTab[ADC_GIER];
- ADC_ValueMux[ADC_ACCX] += ADC_Neutral[ADC_ACCX] - ADC_RCVTab[ADC_ACCX];
- ADC_ValueMux[ADC_ACCY] += ADC_RCVTab[ADC_ACCY] - ADC_Neutral[ADC_ACCY];
- ADC_ValueMux[ADC_ACCZ] += ADC_Neutral[ADC_ACCZ] - ADC_RCVTab[ADC_ACCZ];
- if(ADC_CurConvCount >= ADC_CONV_COUNT) {
- ADC_Mittelwert[ADC_NICK] = ADC_ValueMux[ADC_NICK] / ADC_CONV_COUNT;
- ADC_Mittelwert[ADC_ROLL] = ADC_ValueMux[ADC_ROLL] / ADC_CONV_COUNT;
- ADC_Mittelwert[ADC_GIER] = ADC_ValueMux[ADC_GIER] / ADC_CONV_COUNT;
- ADC_Mittelwert[ADC_ACCX] = ADC_ValueMux[ADC_ACCX] / ADC_CONV_COUNT;
- ADC_Mittelwert[ADC_ACCY] = ADC_ValueMux[ADC_ACCY] / ADC_CONV_COUNT;
- ADC_Mittelwert[ADC_ACCZ] = ADC_ValueMux[ADC_ACCZ] / ADC_CONV_COUNT;
-
- ADC_ValueMux[ADC_NICK] = 0;
- ADC_ValueMux[ADC_ROLL] = 0;
- ADC_ValueMux[ADC_GIER] = 0;
- ADC_ValueMux[ADC_ACCX] = 0;
- ADC_ValueMux[ADC_ACCZ] = 0;
- ADC_ValueMux[ADC_ACCY] = 0;
- ADC_ValueMux[6] = 0;
- ADC_ValueMux[7] = 0;
- ADC_CurConvCount = 0;
- OSSemPost(App_ADCSem);
- }else {
- ADC_SoftwareStartConvCmd(ADC1, ENABLE);
- }
- DMA_ClearITPendingBit(DMA1_IT_TC1);
- }
- OSIntExit(); /* Tell uC/OS-II that we are leaving the ISR */
- }
- /*
- *********************************************************************************************************
- * BSP_ADC_GetStatus()
- *
- * Description : This function initializes the board's ADC
- *
- * Argument(s) : adc ID of the ADC to probe. For this board, the only legitimate value is 1.
- *
- * Return(s) : The numerator of the binary fraction representing the result of the latest ADC conversion.
- * This value will be a 12-bit value between 0x0000 and 0x0FFF, inclusive.
- *
- * Caller(s) : Application.
- *
- * Note(s) : none.
- *********************************************************************************************************
- */
- CPU_INT16U BSP_ADC_GetStatus (CPU_INT08U adc)
- {
- CPU_INT16U result;
- result = 0;
- if (adc == 1) {
- result = ADC_GetConversionValue(ADC1);
- }
- return (result);
- }
- /*
- *********************************************************************************************************
- *********************************************************************************************************
- * LED FUNCTIONS
- *********************************************************************************************************
- *********************************************************************************************************
- */
- /*
- *********************************************************************************************************
- * BSP_LED_Init()
- *
- * Description : Initialize the I/O for the LEDs
- *
- * Argument(s) : none.
- *
- * Return(s) : none.
- *
- * Caller(s) : BSP_Init().
- *
- * Note(s) : none.
- *********************************************************************************************************
- */
- static void BSP_LED_Init (void)
- {
- GPIO_InitTypeDef gpio_init;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
- gpio_init.GPIO_Pin = BSP_GPIOC_LED_RED | BSP_GPIOC_LED_GRN;
- gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
- gpio_init.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOC, &gpio_init);
- }
- /*
- *********************************************************************************************************
- * BSP_LED_On()
- *
- * Description : Turn ON any or all the LEDs on the board.
- *
- * Argument(s) : led The ID of the LED to control:
- *
- * 0 turn ON all LEDs on the board
- * 1 turn ON LED RED
- * 2 turn ON LED GRN
- *
- * Return(s) : none.
- *
- * Caller(s) : Application.
- *
- * Note(s) : none.
- *********************************************************************************************************
- */
- void BSP_LED_On (CPU_INT08U led)
- {
- switch (led) {
- case 0:
- GPIO_SetBits(GPIOC, BSP_GPIOC_LED_RED | BSP_GPIOC_LED_GRN);
- break;
- case 1:
- GPIO_SetBits(GPIOC, BSP_GPIOC_LED_RED);
- break;
- case 2:
- GPIO_SetBits(GPIOC, BSP_GPIOC_LED_GRN);
- break;
- default:
- break;
- }
- }
- /*
- *********************************************************************************************************
- * BSP_LED_Off()
- *
- * Description : Turn OFF any or all the LEDs on the board.
- *
- * Argument(s) : led The ID of the LED to control:
- *
- * 0 turn OFF all LEDs on the board
- * 1 turn OFF LED RED
- * 2 turn OFF LED GRN
- *
- * Return(s) : none.
- *
- * Caller(s) : Application.
- *
- * Note(s) : none.
- *********************************************************************************************************
- */
- void BSP_LED_Off (CPU_INT08U led)
- {
- switch (led) {
- case 0:
- GPIO_ResetBits(GPIOC, BSP_GPIOC_LED_RED | BSP_GPIOC_LED_GRN);
- break;
- case 1:
- GPIO_ResetBits(GPIOC, BSP_GPIOC_LED_RED);
- break;
- case 2:
- GPIO_ResetBits(GPIOC, BSP_GPIOC_LED_GRN);
- break;
- default:
- break;
- }
- }
- /*
- *********************************************************************************************************
- * BSP_LED_Toggle()
- *
- * Description : TOGGLE any or all the LEDs on the board.
- *
- * Argument(s) : led The ID of the LED to control:
- *
- * 0 TOGGLE all LEDs on the board
- * 1 TOGGLE LED RED
- * 2 TOGGLE LED GRN
- *
- * Return(s) : none.
- *
- * Caller(s) : Application.
- *
- * Note(s) : none.
- *********************************************************************************************************
- */
- void BSP_LED_Toggle (CPU_INT08U led)
- {
- CPU_INT32U pins;
- pins = GPIO_ReadOutputData(GPIOC);
- switch (led) {
- case 0:
- BSP_LED_Toggle(1);
- BSP_LED_Toggle(2);
- break;
- case 1:
- if ((pins & BSP_GPIOC_LED_RED) == 0) {
- GPIO_SetBits( GPIOC, BSP_GPIOC_LED_RED);
- } else {
- GPIO_ResetBits(GPIOC, BSP_GPIOC_LED_RED);
- }
- break;
- case 2:
- if ((pins & BSP_GPIOC_LED_GRN) == 0) {
- GPIO_SetBits( GPIOC, BSP_GPIOC_LED_GRN);
- } else {
- GPIO_ResetBits(GPIOC, BSP_GPIOC_LED_GRN);
- }
- break;
- default:
- break;
- }
- }
- /*
- *********************************************************************************************************
- *********************************************************************************************************
- ** uC/OS-View FUNCTIONS
- *********************************************************************************************************
- *********************************************************************************************************
- */
- /*
- *********************************************************************************************************
- * OSView_TmrInit()
- *
- * Description : Select & initialize a timer for use with uC/OS-View.
- *
- * Argument(s) : none.
- *
- * Return(s) : none.
- *********************************************************************************************************
- */
- #if (OS_VIEW_MODULE == DEF_ENABLED)
- void OSView_TmrInit (void)
- {
- TIM_TimeBaseInitTypeDef tim_init;
- tim_init.TIM_Period = 0xFFFF;
- tim_init.TIM_Prescaler = 0x00;
- tim_init.TIM_ClockDivision = 0x0;
- tim_init.TIM_CounterMode = TIM_CounterMode_Up;
- #if (OS_VIEW_TIMER_SEL == 2)
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
- TIM_TimeBaseInit(TIM2, &tim_init);
- TIM_SetCounter(TIM2, 0);
- TIM_PrescalerConfig(TIM2, 256, TIM_PSCReloadMode_Immediate);
- TIM_Cmd(TIM2, ENABLE);
- #elif (OS_VIEW_TIMER_SEL == 3)
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
- TIM_TimeBaseInit(TIM3, &tim_init);
- TIM_SetCounter(TIM3, 0);
- TIM_PrescalerConfig(TIM3, 256, TIM_PSCReloadMode_Immediate);
- TIM_Cmd(TIM3, ENABLE);
- #elif (OS_VIEW_TIMER_SEL == 4)
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
- TIM_TimeBaseInit(TIM4, &tim_init);
- TIM_SetCounter(TIM4, 0);
- TIM_PrescalerConfig(TIM4, 256, TIM_PSCReloadMode_Immediate);
- TIM_Cmd(TIM4, ENABLE);
- #endif
- }
- #endif
- /*
- *********************************************************************************************************
- * OSView_TmrRd()
- *
- * Description : Read the current counts of a 32-bit free running timer.
- *
- * Argument(s) : none.
- *
- * Return(s) : The 32 bit counts of the timer.
- *********************************************************************************************************
- */
- #if (OS_VIEW_MODULE == DEF_ENABLED)
- CPU_INT32U OSView_TmrRd (void)
- {
- #if (OS_VIEW_TIMER_SEL == 2)
- return ((CPU_INT32U)TIM_GetCounter(TIM2));
- #elif (OS_VIEW_TIMER_SEL == 3)
- return ((CPU_INT32U)TIM_GetCounter(TIM3));
- #elif (OS_VIEW_TIMER_SEL == 4)
- return ((CPU_INT32U)TIM_GetCounter(TIM4));
- #endif
- }
- #endif
- /*
- *********************************************************************************************************
- * INITIALISE DEBUG COM PORT
- *********************************************************************************************************
- */
- #if (DEBUG_MODULE == DEF_ENABLED)
- static void Debug_InitTarget ()
- {
- GPIO_InitTypeDef gpio_init;
- USART_InitTypeDef usart_init;
- USART_ClockInitTypeDef usart_clk_init;
- /* ----------------- INIT USART STRUCT ---------------- */
- usart_init.USART_BaudRate = 115200;
- usart_init.USART_WordLength = USART_WordLength_8b;
- usart_init.USART_StopBits = USART_StopBits_1;
- usart_init.USART_Parity = USART_Parity_No ;
- usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- usart_init.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- usart_clk_init.USART_Clock = USART_Clock_Disable;
- usart_clk_init.USART_CPOL = USART_CPOL_Low;
- usart_clk_init.USART_CPHA = USART_CPHA_2Edge;
- usart_clk_init.USART_LastBit = USART_LastBit_Disable;
- #if (DEBUG_COMM_SEL == DEBUG_UART_1)
- BSP_PeriphEn(BSP_PERIPH_ID_USART1);
- /* ----------------- SETUP USART1 GPIO ---------------- */
- BSP_PeriphEn(BSP_PERIPH_ID_IOPA);
- /* Configure GPIOA.9 as push-pull */
- gpio_init.GPIO_Pin = GPIO_Pin_9;
- gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
- gpio_init.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOA, &gpio_init);
- /* Configure GPIOA.10 as input floating */
- gpio_init.GPIO_Pin = GPIO_Pin_10;
- gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOA, &gpio_init);
- /* ------------------ SETUP USART1 -------------------- */
- USART_Init(USART1, &usart_init);
- USART_ClockInit(USART1, &usart_clk_init);
- USART_Cmd(USART1, ENABLE);
- #endif
- #if (DEBUG_COMM_SEL == DEBUG_UART_2)
- BSP_PeriphEn(BSP_PERIPH_ID_USART2);
- /* ----------------- SETUP USART2 GPIO ---------------- */
- BSP_PeriphEn(BSP_PERIPH_ID_IOPA);
- /* Configure GPIOA.2 as push-pull */
- gpio_init.GPIO_Pin = GPIO_Pin_2;
- gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
- gpio_init.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOA, &gpio_init);
- /* Configure GPIOA.3 as input floating */
- gpio_init.GPIO_Pin = GPIO_Pin_3;
- gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOA, &gpio_init);
- /* ------------------ SETUP USART2 -------------------- */
- USART_Init(USART2, &usart_init);
- USART_ClockInit(USART2, &usart_clk_init);
- USART_Cmd(USART2, ENABLE);
- #endif
- #if (DEBUG_COMM_SEL == DEBUG_UART_3)
- BSP_PeriphEn(BSP_PERIPH_ID_USART3);
- /* ----------------- SETUP USART3 GPIO ---------------- */
- BSP_PeriphEn(BSP_PERIPH_ID_IOPB);
- /* Configure GPIOB.10 as push-pull */
- gpio_init.GPIO_Pin = GPIO_Pin_10;
- gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
- gpio_init.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOB, &gpio_init);
- /* Configure GPIOB.11 as input floating */
- gpio_init.GPIO_Pin = GPIO_Pin_11;
- gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOB, &gpio_init);
- /* ------------------ SETUP USART3 -------------------- */
- USART_Init(USART3, &usart_init);
- USART_ClockInit(USART3, &usart_clk_init);
- USART_Cmd(USART3, ENABLE);
- #endif
- }
- /* Implementation of putchar (also used by printf function to output data) */
- PUTCHAR_PROTOTYPE { /* Write character to Serial Port */
- USART_TypeDef *usart;
- #if (DEBUG_COMM_SEL == DEBUG_UART_1)
- usart = USART1;
- #elif (DEBUG_COMM_SEL == DEBUG_UART_2)
- usart = USART2;
- #elif (DEBUG_COMM_SEL == DEBUG_UART_3)
- usart = USART3;
- #else
- return;
- #endif
- while (USART_GetFlagStatus(usart, USART_FLAG_TXE) == RESET);
- USART_SendData(usart, (unsigned char) ch);
- return (ch);
- }
- int GetKey (void) { /* Read character from Serial Port */
- USART_TypeDef *usart;
- #if (DEBUG_COMM_SEL == DEBUG_UART_1)
- usart = USART1;
- #elif (DEBUG_COMM_SEL == DEBUG_UART_2)
- usart = USART2;
- #elif (DEBUG_COMM_SEL == DEBUG_UART_3)
- usart = USART3;
- #else
- return;
- #endif
- while (USART_GetITStatus(usart, USART_IT_RXNE) != RESET);
- return (USART_ReceiveData(usart));
- }
- #endif