Пример #1
0
static void prvSetupHardware( void )
{
	/* Configuration taken from the ST code.

	Set Flash banks size & address */
	FMI_BankRemapConfig( 4, 2, 0, 0x80000 );

	/* FMI Waite States */
	FMI_Config( FMI_READ_WAIT_STATE_2, FMI_WRITE_WAIT_STATE_0, FMI_PWD_ENABLE, FMI_LVD_ENABLE, FMI_FREQ_HIGH );

	/* Configure the FPLL = 96MHz, and APB to 48MHz. */
	SCU_PCLKDivisorConfig( SCU_PCLK_Div2 );
	SCU_PLLFactorsConfig( 192, 25, 2 );
	SCU_PLLCmd( ENABLE );
	SCU_MCLKSourceConfig( SCU_MCLK_PLL );

	WDG_Cmd( DISABLE );
	VIC_DeInit();

	/* GPIO8 clock source enable, used by the LCD. */
	SCU_APBPeriphClockConfig(__GPIO8, ENABLE);
	GPIO_DeInit(GPIO8);

	/* GPIO 9 clock source enable, used by the LCD. */
	SCU_APBPeriphClockConfig(__GPIO9, ENABLE);
	GPIO_DeInit(GPIO9);

	/* Enable VIC clock */
	SCU_AHBPeriphClockConfig(__VIC, ENABLE);
	SCU_AHBPeriphReset(__VIC, DISABLE);

	/* Peripheral initialisation. */
	vParTestInitialise();
}
Пример #2
0
int main(void)
{
  time_t then, now;

  cpu_init(DEFAULT_CPU_FREQ);

#ifdef CONSOLE_SERIAL
  serial_stdio(CONSOLE_PORT);
#endif

#ifdef CONSOLE_SEMIHOSTING
  semihosting_stdio(CONSOLE_PORT)
#endif

#ifdef CONSOLE_USB
  usb_serial_stdio(NULL);
  getch();
#endif

  puts("\033[H\033[2JSTR91x A/D Converter Test (" __DATE__ " " __TIME__ ")\n");
  puts(revision);
  printf("\nCPU Freq:%u Hz  Compiler:%s %s %s\n\n", (unsigned int) SystemCoreClock,
    __COMPILER__, __VERSION__, __ABI__);

// Turn on peripheral clocks

  SCU_APBPeriphClockConfig(__RTC, ENABLE);
  SCU_APBPeriphClockConfig(__ADC, ENABLE);
  SCU_APBPeriphClockConfig(__GPIO4, ENABLE);

// Configure RTC

  RTC_DeInit();			// Reset RTC

// Configure P4.6 as analog input 6

  GPIO_DeInit(GPIO4);		// Reset GPIO4
  GPIO_ANAPinConfig(GPIO_ANAChannel6, ENABLE);

// Configure A/D converter

  ADC_DeInit();			// Reset A/D converter
  ADC_Cmd(ENABLE);		// Power on A/D converter
  ADC_PrescalerConfig(0x2);	// Conversion clock is 24 MHz

// Sample analog input 6 once a second

  then = 0;

  for (;;)
  {
    now = time(NULL);
    if (now == then) continue;
    then = now;

    printf("The value of A/D input 6 is %04X\n", SampleADC(ADC_Channel_6));
  }
}
Пример #3
0
/*******************************************************************************
* Function Name  : SCU_Configuration
* Description    : Configure the different system clocks
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void SCU_Configuration(void)
{
  /*clock enable for used peripherals*/

  SCU_APBPeriphClockConfig(__I2C0,ENABLE);
  SCU_APBPeriphClockConfig(__I2C1,ENABLE);
  SCU_APBPeriphClockConfig(__GPIO2, ENABLE);
  SCU_AHBPeriphClockConfig(__VIC, ENABLE);
}
Пример #4
0
static void platform_config_scu()
{     
  volatile u16 i = 0xFFFF;
  while (i-- > 0);  
  
   // SCU initialization
  SCU_MCLKSourceConfig(SCU_MCLK_OSC);
  SCU_PLLFactorsConfig(192,25,2);            /* PLL = 96 MHz */
  SCU_PLLCmd(ENABLE);                        /* PLL Enabled  */
  SCU_MCLKSourceConfig(SCU_MCLK_PLL);        /* MCLK = PLL   */  
  
  SCU_PFQBCCmd( ENABLE );

  /* Set the RCLK Clock divider to max speed*/
  SCU_RCLKDivisorConfig(SCU_RCLK_Div1);
  /* Set the PCLK Clock to MCLK/2 */
  SCU_PCLKDivisorConfig(SCU_PCLK_Div2);
  /* Set the HCLK Clock to MCLK */
  SCU_HCLKDivisorConfig(SCU_HCLK_Div1);
  /* Set the BRCLK Clock to MCLK */
  SCU_BRCLKDivisorConfig(SCU_BRCLK_Div1);
  
  // Enable VIC clock
  SCU_AHBPeriphClockConfig(__VIC, ENABLE);
  SCU_AHBPeriphReset(__VIC, DISABLE);
                 
  // Enable the UART clocks
  SCU_APBPeriphClockConfig(__UART_ALL, ENABLE);

  // Enable the timer clocks
  SCU_APBPeriphClockConfig(__TIM01, ENABLE);
  SCU_APBPeriphReset(__TIM01, DISABLE);
  SCU_APBPeriphClockConfig(__TIM23, ENABLE);
  SCU_APBPeriphReset(__TIM23, DISABLE);

  // Enable the GPIO clocks  
  SCU_APBPeriphClockConfig(__GPIO_ALL, ENABLE);  

  // Enable the WIU clock
  SCU_APBPeriphClockConfig(__WIU, ENABLE);
  SCU_APBPeriphReset(__WIU, DISABLE);

  // Enable the I2C clocks
  SCU_APBPeriphClockConfig(__I2C0, ENABLE);
  SCU_APBPeriphReset(__I2C0, DISABLE);
  SCU_APBPeriphClockConfig(__I2C1, ENABLE);
  SCU_APBPeriphReset(__I2C1, DISABLE);
  
  // Enable the ADC clocks
  SCU_APBPeriphClockConfig(__ADC, ENABLE);

  // Enable the SSP clocks
  SCU_APBPeriphClockConfig(__SSP0,ENABLE);
  SCU_APBPeriphReset(__SSP0,DISABLE);
  SCU_APBPeriphClockConfig(__SSP1,ENABLE);
  SCU_APBPeriphReset(__SSP1,DISABLE);
}
Пример #5
0
/*******************************************************************************
* Function Name  : SCU_Configuration
* Description    : Configures the system clocks.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void SCU_Configuration(void)
{

  /* Enable the UART0 Clock */
  SCU_APBPeriphClockConfig(__UART0, ENABLE);

  /* Enable the GPIO3 Clock */
  SCU_APBPeriphClockConfig(__GPIO3, ENABLE);

  /* Enable the GPIO5 Clock */
  SCU_APBPeriphClockConfig(__GPIO5, ENABLE);

}
Пример #6
0
/*******************************************************************************
* Function Name  : SCU_Configuration
* Description    : Configure the different system clocks
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void SCU_Configuration(void)
{
  /* Enable the __SSP0 Clock */
  SCU_APBPeriphClockConfig(__SSP0 ,ENABLE);

  /* Enable the __SSP1 Clock */
  SCU_APBPeriphClockConfig(__SSP1 ,ENABLE);

  /* Enable the __GPIO5 for SSP0 Clock */
  SCU_APBPeriphClockConfig(__GPIO5 ,ENABLE);

  /* Enable the __GPIO3 for SSP1 Clock */
  SCU_APBPeriphClockConfig(__GPIO3 ,ENABLE);

}
Пример #7
0
	static void prvSetupTimerInterrupt( void )
	{
	WDG_InitTypeDef xWdg;
	unsigned short a;
	unsigned long n = configCPU_PERIPH_HZ / configTICK_RATE_HZ, b;
	
		/* Configure the watchdog as a free running timer that generates a
		periodic interrupt. */
	
		SCU_APBPeriphClockConfig( __WDG, ENABLE );
		WDG_DeInit();
		WDG_StructInit(&xWdg);
		prvFindFactors( n, &a, &b );
		xWdg.WDG_Prescaler = a - 1;
		xWdg.WDG_Preload = b - 1;
		WDG_Init( &xWdg );
		WDG_ITConfig(ENABLE);
		
		/* Configure the VIC for the WDG interrupt. */
		VIC_Config( WDG_ITLine, VIC_IRQ, 10 );
		VIC_ITCmd( WDG_ITLine, ENABLE );
		
		/* Install the default handlers for both VIC's. */
		VIC0->DVAR = ( unsigned long ) prvDefaultHandler;
		VIC1->DVAR = ( unsigned long ) prvDefaultHandler;
		
		WDG_Cmd(ENABLE);
	}
Пример #8
0
	static void prvSetupTimerInterrupt( void )
	{
		unsigned char a;
		unsigned short b;
		unsigned long n = configCPU_PERIPH_HZ / configTICK_RATE_HZ;
		
		TIM_InitTypeDef timer;
		
		SCU_APBPeriphClockConfig( __TIM23, ENABLE );
		TIM_DeInit(TIM2);
		TIM_StructInit(&timer);
		prvFindFactors( n, &a, &b );
		
		timer.TIM_Mode           = TIM_OCM_CHANNEL_1;
		timer.TIM_OC1_Modes      = TIM_TIMING;
		timer.TIM_Clock_Source   = TIM_CLK_APB;
		timer.TIM_Clock_Edge     = TIM_CLK_EDGE_RISING;
		timer.TIM_Prescaler      = a-1;
		timer.TIM_Pulse_Level_1  = TIM_HIGH;
		timer.TIM_Pulse_Length_1 = s_nPulseLength  = b-1;
		
		TIM_Init (TIM2, &timer);
		TIM_ITConfig(TIM2, TIM_IT_OC1, ENABLE);
		/* Configure the VIC for the WDG interrupt. */
		VIC_Config( TIM2_ITLine, VIC_IRQ, 10 );
		VIC_ITCmd( TIM2_ITLine, ENABLE );
		
		/* Install the default handlers for both VIC's. */
		VIC0->DVAR = ( unsigned long ) prvDefaultHandler;
		VIC1->DVAR = ( unsigned long ) prvDefaultHandler;
		
		TIM_CounterCmd(TIM2, TIM_CLEAR);
		TIM_CounterCmd(TIM2, TIM_START);
	}
Пример #9
0
/*******************************************************************************
* Function Name  : main
* Description    : Main program
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
int main()
{

#ifdef DEBUG
    debug();
#endif

    SCU_MCLKSourceConfig(SCU_MCLK_OSC);      /*Use OSC as the default clock source*/
    SCU_PCLKDivisorConfig(SCU_PCLK_Div1);   /* ARM Peripheral bus clokdivisor = 1*/

    WDG_InitTypeDef WDG_InitStructure;
    GPIO_InitTypeDef  GPIO3_InitStruct;

    SCU_APBPeriphClockConfig(__GPIO3, ENABLE);/* Enable the clock for GPIO3*/
    GPIO_DeInit(GPIO3);/* GPIO3 default configuration : Reset configuration*/

    /* Configure the GPIO3  */
    GPIO3_InitStruct.GPIO_Pin= GPIO_Pin_2;  /* Choose the pin  "P3.2 port"*/
    GPIO3_InitStruct.GPIO_Direction=GPIO_PinOutput; /* Choose the  P3.2 port Direction "output".*/
    GPIO3_InitStruct.GPIO_Type = GPIO_Type_PushPull ;
    GPIO3_InitStruct.GPIO_Alternate=GPIO_OutputAlt1;
    GPIO_Init(GPIO3,&GPIO3_InitStruct); /*GPIO3 initialization with the previous chosen parameters.*/

    GPIO_WriteBit(GPIO3, GPIO_Pin_2, Bit_RESET);  /*  Reset the P3.2 port " on STR912-SK-IAR Board, LED3 is on "*/

    SCU_APBPeriphClockConfig(__WDG, ENABLE); /* Enable the clock for the WDG peripheral*/
    WDG_DeInit();/* WDG default configuration : Reset configuration*/

    /* Configure the WDG to generate a system reset signal each 1s */
    WDG_InitStructure.WDG_Mode = WDG_Mode_Wdg;
    WDG_InitStructure.WDG_Preload = 0x7d;
    WDG_InitStructure.WDG_Prescaler = 0xFF;
    WDG_InitStructure.WDG_ClockSource=WDG_ClockSource_Rtc; /* using the 32khz RTC clock as clock source*/

    WDG_Init(&WDG_InitStructure);  /* WDG initialization with the previous chosen parameters.*/



    while(1)

    {
        GPIO_WriteBit(GPIO3, GPIO_Pin_2, Bit_SET);
    }


}
Пример #10
0
void debugInit(uint32_t baudrate)
{
   GPIO_InitTypeDef GPIO_InitStructure;
   UART_InitTypeDef UART_InitStructure;

   //Enable GPIO5 clock
   SCU_APBPeriphClockConfig(__GPIO5, ENABLE);
   //Enable UART0 clock
   SCU_APBPeriphClockConfig(__UART0, ENABLE);

   //Configure UART0_TX (P5.0)
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
   GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
   GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
   GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3;
   GPIO_Init(GPIO5, &GPIO_InitStructure);

   //Configure UART0_RX (P5.1)
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
   GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
   GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
   GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
   GPIO_Init(GPIO5, &GPIO_InitStructure);

   //Reset UART0 peripheral
   UART_DeInit(UART0);

   //Configure UART0
   UART_InitStructure.UART_BaudRate = baudrate;
   UART_InitStructure.UART_WordLength = UART_WordLength_8D;
   UART_InitStructure.UART_StopBits = UART_StopBits_1;
   UART_InitStructure.UART_Parity = UART_Parity_No;
   UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None;
   UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx;
   UART_InitStructure.UART_FIFO = UART_FIFO_Disable;
   UART_Init(UART0, &UART_InitStructure);

   //Enable UART0
   UART_Cmd(UART0, ENABLE);
}
Пример #11
0
/* Private functions ---------------------------------------------------------*/
void System_Setup(void)
{
  SCU_MCLKSourceConfig(SCU_MCLK_OSC);
  SCU_PCLKDivisorConfig(SCU_PCLK_Div2);
  SCU_PLLFactorsConfig(128,25,4);
  SCU_PLLCmd(ENABLE);
  SCU_MCLKSourceConfig(SCU_MCLK_PLL);

  SCU_APBPeriphClockConfig(__CAN, ENABLE);
  SCU_APBPeriphClockConfig(__GPIO0, ENABLE);
  SCU_APBPeriphClockConfig(__GPIO1, ENABLE);
  SCU_APBPeriphClockConfig(__GPIO3, ENABLE);
  SCU_APBPeriphClockConfig(__GPIO5, ENABLE);
   SCU_AHBPeriphClockConfig(__VIC, ENABLE);

  SCU_APBPeriphReset(__CAN, DISABLE);
  SCU_APBPeriphReset(__GPIO0, DISABLE);
  SCU_APBPeriphReset(__GPIO1, DISABLE);
  SCU_APBPeriphReset(__GPIO3, DISABLE);
  SCU_APBPeriphReset(__GPIO5, DISABLE);
  SCU_AHBPeriphReset(__VIC, DISABLE);
}
Пример #12
0
//------------------------------------------------------------------------------
static void ExternalButtonInit(void)
{
  SCU_APBPeriphClockConfig(__GPIO3 ,ENABLE);

  GPIO_InitTypeDef gpio_init;

  // Configure P3.1 -> external button as an input pin.
  gpio_init.GPIO_Direction = GPIO_PinInput;
  gpio_init.GPIO_Pin = GPIO_Pin_1;
  gpio_init.GPIO_Type = GPIO_Type_PushPull;
  gpio_init.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable;
  gpio_init.GPIO_Alternate = GPIO_InputAlt1;
  GPIO_Init(GPIO3, &gpio_init);
}
Пример #13
0
void ioInit(void)
{
   GPIO_InitTypeDef GPIO_InitStructure;

   //Enable GPIO clocks
   SCU_APBPeriphClockConfig(__GPIO0, ENABLE);
   SCU_APBPeriphClockConfig(__GPIO1, ENABLE);
   SCU_APBPeriphClockConfig(__GPIO3, ENABLE);
   SCU_APBPeriphClockConfig(__GPIO5, ENABLE);

   //Reset GPIO peripherals
   GPIO_DeInit(GPIO0);
   GPIO_DeInit(GPIO1);
   GPIO_DeInit(GPIO3);
   GPIO_DeInit(GPIO5);

   //Configure CENTER button (P5.4)
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
   GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
   GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable ;
   GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
   GPIO_Init(GPIO5, &GPIO_InitStructure);
}
Пример #14
0
void UART0_Connect_to_MK3MAG(void)
{
	u16 Baudrate;

	GPIO_InitTypeDef GPIO_InitStructure;

	UART0_Muxer = UART0_UNDEF;

	SCU_APBPeriphClockConfig(__GPIO5, ENABLE);
   	// unmap UART0 from GPS
	// set port pin 6.6 (serial data from gps) to input and disconnect from IP
	GPIO_StructInit(&GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Direction = 	GPIO_PinInput;
    GPIO_InitStructure.GPIO_Pin = 			GPIO_Pin_6;
    GPIO_InitStructure.GPIO_Type = 			GPIO_Type_PushPull;
    GPIO_InitStructure.GPIO_IPInputConnected = 	GPIO_IPInputConnected_Disable;
    GPIO_InitStructure.GPIO_Alternate = 	GPIO_InputAlt1;
    GPIO_Init(GPIO6, &GPIO_InitStructure);
	// set port pin 6.7 (serial data to gps) to input
	GPIO_StructInit(&GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Direction = 	GPIO_PinInput;
    GPIO_InitStructure.GPIO_Pin = 			GPIO_Pin_7;
    GPIO_InitStructure.GPIO_Type = 			GPIO_Type_PushPull;
	GPIO_InitStructure.GPIO_IPInputConnected = 	GPIO_IPInputConnected_Disable;
    GPIO_InitStructure.GPIO_Alternate = 	GPIO_InputAlt1;
    GPIO_Init(GPIO6, &GPIO_InitStructure);

	// map UART0 to Compass
	// set port pin 5.1 (serial data from compass) to input and connect to IP
	GPIO_StructInit(&GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Direction = 	GPIO_PinInput;
    GPIO_InitStructure.GPIO_Pin = 			GPIO_Pin_1;
    GPIO_InitStructure.GPIO_Type = 			GPIO_Type_PushPull ;
    GPIO_InitStructure.GPIO_IPInputConnected = 	GPIO_IPInputConnected_Enable;
    GPIO_InitStructure.GPIO_Alternate = 	GPIO_InputAlt1; //UART0_RxD
    GPIO_Init(GPIO5, &GPIO_InitStructure);
	// set port pin 5.0 (serial data to compass) to output
	GPIO_StructInit(&GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Direction = 	GPIO_PinOutput;
    GPIO_InitStructure.GPIO_Pin = 			GPIO_Pin_0;
    GPIO_InitStructure.GPIO_Type = 			GPIO_Type_PushPull;
	GPIO_InitStructure.GPIO_IPInputConnected = 	GPIO_IPInputConnected_Enable;
    GPIO_InitStructure.GPIO_Alternate = 	GPIO_OutputAlt3; //UART0_TX
    GPIO_Init(GPIO5, &GPIO_InitStructure);
   	Baudrate = UART0_BAUD_RATE + ((UART0_BAUD_RATE * 2)/100);   // MK3Mag baudrate is a little bit higher...
	UART0_Configure(Baudrate);
	UART0_Muxer = UART0_MK3MAG;
}
Пример #15
0
//-----------------------------------------------------------------
void USB_ConfigInit(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;

	UART1_PutString("\r\n USB init...");
  	#ifdef MCLK96MHZ
	//USB clock = MCLK/2 = 48MHz
	SCU_USBCLKConfig(SCU_USBCLK_MCLK2);
	#else
	//USB clock = MCLK = 48MHz
	SCU_USBCLKConfig(SCU_USBCLK_MCLK);
	#endif
	//Enable USB clock
	SCU_AHBPeriphClockConfig(__USB,ENABLE);
	SCU_AHBPeriphReset(__USB,DISABLE);
	SCU_AHBPeriphClockConfig(__USB48M,ENABLE);

	//Configure GPIO0 (D+ Pull-Up on P0.1)
	SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE);
	SCU_APBPeriphReset(__GPIO0,DISABLE);

	// GPIO_DeInit(P0.1);
	GPIO_StructInit(&GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
	GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
	GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
	GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1;
	GPIO_Init (GPIO0, &GPIO_InitStructure);

	// initialize the rx fifo, block UART IRQ geting a byte from fifo
	fifo_init(&USB_rx_fifo, USB_rxfifobuffer, USB_RX_FIFO_LEN, NO_ITLine, USBLP_ITLine);

	// initialize txd buffer
	Buffer_Init(&USB_tx_buffer, USB_tbuffer, USB_TX_BUFFER_LEN);

	// initialize rxd buffer
	Buffer_Init(&USB_rx_buffer, USB_rbuffer, USB_RX_BUFFER_LEN);

	VIC_Config(USBLP_ITLine, VIC_IRQ, PRIORITY_USB);
	VIC_ITCmd(USBLP_ITLine, ENABLE);

	USB_Init();

	UART1_PutString("ok");
}
Пример #16
0
void UART0_Connect_to_MKGPS(u16 Baudrate)
{
	GPIO_InitTypeDef GPIO_InitStructure;

	UART0_Muxer = UART0_UNDEF;

  	SCU_APBPeriphClockConfig(__GPIO6, ENABLE); // Enable the GPIO6 Clock
	// unmap UART0 from Compass
	// set port pin 5.1 (serial data from compass) to input and disconnect from IP
	GPIO_StructInit(&GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Direction = 	GPIO_PinInput;
    GPIO_InitStructure.GPIO_Pin = 			GPIO_Pin_1;
    GPIO_InitStructure.GPIO_Type = 			GPIO_Type_PushPull ;
    GPIO_InitStructure.GPIO_IPInputConnected = 	GPIO_IPInputConnected_Disable;
    GPIO_InitStructure.GPIO_Alternate = 	GPIO_InputAlt1;
    GPIO_Init(GPIO5, &GPIO_InitStructure);
	// set port pin 5.0 (serial data to compass) to input
	GPIO_StructInit(&GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Direction = 	GPIO_PinInput;
    GPIO_InitStructure.GPIO_Pin = 			GPIO_Pin_0;
    GPIO_InitStructure.GPIO_Type = 			GPIO_Type_PushPull;
	GPIO_InitStructure.GPIO_IPInputConnected = 	GPIO_IPInputConnected_Disable;
    GPIO_InitStructure.GPIO_Alternate = 	GPIO_InputAlt1;
    GPIO_Init(GPIO5, &GPIO_InitStructure);
	// map UART0 to GPS
	// set port pin 6.6 (serial data from gps) to input and connect to IP
	GPIO_StructInit(&GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Direction = 	GPIO_PinInput;
    GPIO_InitStructure.GPIO_Pin = 			GPIO_Pin_6;
    GPIO_InitStructure.GPIO_Type = 			GPIO_Type_PushPull ;
    GPIO_InitStructure.GPIO_IPInputConnected = 	GPIO_IPInputConnected_Enable;
    GPIO_InitStructure.GPIO_Alternate = 	GPIO_InputAlt1; //UART0_RxD
    GPIO_Init(GPIO6, &GPIO_InitStructure);
	// set port pin 6.7 (serial data to gps) to output
	GPIO_StructInit(&GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Direction = 	GPIO_PinOutput;
    GPIO_InitStructure.GPIO_Pin = 			GPIO_Pin_7;
    GPIO_InitStructure.GPIO_Type = 			GPIO_Type_PushPull;
	GPIO_InitStructure.GPIO_IPInputConnected = 	GPIO_IPInputConnected_Enable;
    GPIO_InitStructure.GPIO_Alternate = 	GPIO_OutputAlt3; //UART0_TX
    GPIO_Init(GPIO6, &GPIO_InitStructure);
	// configure the UART0
	UART0_Configure(Baudrate);
	
	UART0_Muxer = UART0_MKGPS;
}
Пример #17
0
//----------------------------------------------------------------------------------------------------
// 1ms Timer
//----------------------------------------------------------------------------------------------------
void TIMER1_Init(void)
{
	TIM_InitTypeDef   TIM_InitStructure;

	UART1_PutString("\r\n Timer1 init...");

	#define TIM1_FREQ 200000 // 200kHz
	// TimerOCR set in IntHandler

	SCU_APBPeriphClockConfig(__TIM01, ENABLE);

	TIM_DeInit(TIM1); 
	TIM_StructInit(&TIM_InitStructure);
	TIM_InitStructure.TIM_Mode = TIM_OCM_CHANNEL_1;
	TIM_InitStructure.TIM_OC1_Modes = TIM_TIMING;
	TIM_InitStructure.TIM_Clock_Source = TIM_CLK_APB;
	TIM_InitStructure.TIM_Prescaler = (SCU_GetPCLKFreqValue() * 1000) / TIM1_FREQ;	// is only valid up to 48 MHz !
	TIM_Init (TIM1, &TIM_InitStructure);

	TIM_ITConfig(TIM1, TIM_IT_OC1, ENABLE);
	TIM_CounterCmd(TIM1, TIM_START);

	VIC_Config(TIM1_ITLine, VIC_IRQ, PRIORITY_TIMER1);
	VIC_ITCmd(TIM1_ITLine, ENABLE);

	SystemTime.Year = 0;
	SystemTime.Month = 0;
	SystemTime.Day = 0;
	SystemTime.Hour = 0;
	SystemTime.Min = 0;
	SystemTime.Sec = 0;
	SystemTime.mSec = 0;
	SystemTime.Valid = 0;

	CountMilliseconds = 0;

	UART1_PutString("ok");

}
Пример #18
0
void UART0_Configure(u16 Baudrate)
{
	UART_InitTypeDef UART_InitStructure;

	SCU_APBPeriphClockConfig(__UART0, ENABLE);  // Enable the UART0 Clock

  	/* UART0 configured as follow:
          - Word Length = 8 Bits
          - One Stop Bit
          - No parity
          - BaudRate taken from function argument
          - Hardware flow control Disabled
          - Receive and transmit enabled
          - Receive and transmit FIFOs are Disabled
    */
	UART_StructInit(&UART_InitStructure);
    UART_InitStructure.UART_WordLength = 			UART_WordLength_8D;
    UART_InitStructure.UART_StopBits = 				UART_StopBits_1;
    UART_InitStructure.UART_Parity = 				UART_Parity_No ;
    UART_InitStructure.UART_BaudRate = 				Baudrate;
    UART_InitStructure.UART_HardwareFlowControl = 	UART_HardwareFlowControl_None;
    UART_InitStructure.UART_Mode = 					UART_Mode_Tx_Rx;
    UART_InitStructure.UART_FIFO = 					UART_FIFO_Enable;
    UART_InitStructure.UART_TxFIFOLevel = 			UART_FIFOLevel_1_2;
    UART_InitStructure.UART_RxFIFOLevel = 			UART_FIFOLevel_1_2;

	UART_DeInit(UART0);	// reset uart 0	to default
    UART_Init(UART0, &UART_InitStructure);  // initialize uart 0

	// enable uart 0 interrupts selective
    UART_ITConfig(UART0, UART_IT_Receive | UART_IT_ReceiveTimeOut  /*| UART_IT_FrameError*/, ENABLE);
	UART_Cmd(UART0, ENABLE); // enable uart 0
	// configure the uart 0 interupt line
 	VIC_Config(UART0_ITLine, VIC_IRQ, PRIORITY_UART0);
	// enable the uart 0 IRQ
	VIC_ITCmd(UART0_ITLine, ENABLE);
}
Пример #19
0
/*
 * See the serial2.h header file.
 */
xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
{
xComPortHandle xReturn;
UART_InitTypeDef xUART1_Init;
GPIO_InitTypeDef GPIO_InitStructure;
	
	/* Create the queues used to hold Rx characters. */
	xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
	
	/* Create the semaphore used to wake a task waiting for space to become
	available in the FIFO. */
	vSemaphoreCreateBinary( xTxFIFOSemaphore );

	/* If the queue/semaphore was created correctly then setup the serial port
	hardware. */
	if( ( xRxedChars != serINVALID_QUEUE ) && ( xTxFIFOSemaphore != serINVALID_QUEUE ) )
	{
		/* Pre take the semaphore so a task will block if it tries to access
		it. */
		xSemaphoreTake( xTxFIFOSemaphore, 0 );
		
		/* Configure the UART. */
		xUART1_Init.UART_WordLength = UART_WordLength_8D;
		xUART1_Init.UART_StopBits = UART_StopBits_1;
		xUART1_Init.UART_Parity = UART_Parity_No;
		xUART1_Init.UART_BaudRate = ulWantedBaud;
		xUART1_Init.UART_HardwareFlowControl = UART_HardwareFlowControl_None;
		xUART1_Init.UART_Mode = UART_Mode_Tx_Rx;
		xUART1_Init.UART_FIFO = UART_FIFO_Enable;

		/* Enable the UART1 Clock */
		SCU_APBPeriphClockConfig( __UART1, ENABLE );
		
		/* Enable the GPIO3 Clock */
		SCU_APBPeriphClockConfig( __GPIO3, ENABLE );
		
		/* Configure UART1_Rx pin GPIO3.2 */
		GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
		GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
		GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
		GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
		GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ;
		GPIO_Init( GPIO3, &GPIO_InitStructure );
		
		/* Configure UART1_Tx pin GPIO3.3 */
		GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
		GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
		GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
		GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
		GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2 ;
		GPIO_Init( GPIO3, &GPIO_InitStructure );
		
		
		portENTER_CRITICAL();
		{		
			/* Configure the UART itself. */
			UART_DeInit( UART1 );		
			UART_Init( UART1, &xUART1_Init );
			UART_ITConfig( UART1, UART_IT_Receive | UART_IT_Transmit, ENABLE );
			UART1->ICR = serCLEAR_ALL_INTERRUPTS;
			UART_LoopBackConfig( UART1, DISABLE );
			UART_IrDACmd( IrDA1, DISABLE );

			/* Configure the VIC for the UART interrupts. */			
			VIC_Config( UART1_ITLine, VIC_IRQ, 9 );
			VIC_ITCmd( UART1_ITLine, ENABLE );

			UART_Cmd( UART1, ENABLE );			
			lTaskWaiting = pdFALSE;
		}
		portEXIT_CRITICAL();
	}
	else
	{
		xReturn = ( xComPortHandle ) 0;
	}

	/* This demo file only supports a single port but we have to return
	something to comply with the standard demo header file. */
	return xReturn;
}
Пример #20
0
int main(void)
{
  u16 Conversion_Value = 0;

  #ifdef DEBUG
    debug();
  #endif
  
  SCU_MCLKSourceConfig(SCU_MCLK_OSC);         /*Use OSC as the default clock source*/
  SCU_PCLKDivisorConfig(SCU_PCLK_Div1);      /* ARM Peripheral bus clokdivisor = 1*/
  
  SCU_APBPeriphClockConfig(__ADC, ENABLE);    /* Enable the clock for the ADC */
  ADC_DeInit();                               /* ADC Deinitialization */

  SCU_APBPeriphClockConfig(__TIM01, ENABLE);  /* Enable the clock for TIM0 and TIM1 */
  TIM_DeInit(TIM0);                           /* TIM0 Deinitialization */

  SCU_APBPeriphClockConfig(__GPIO4, ENABLE);  /* Enable the clock for the GPIO4 */
  GPIO_DeInit(GPIO4);                         /* GPIO4 Deinitialization */

  SCU_APBPeriphClockConfig(__GPIO3, ENABLE);  /* Enable the clock for the GPIO3 */
  GPIO_DeInit(GPIO3);                         /* GPIO3 Deinitialization */

  /* Configure the GPIO4 pin 5 as analog input */
  GPIO_ANAPinConfig(GPIO_ANAChannel5, ENABLE);

  /* GPIO6 configuration (PWM on P3.0, pin 55) */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
  GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
  GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
  GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3;
  GPIO_Init(GPIO3,&GPIO_InitStructure);

  /* TIM0 Structure Initialization */
  TIM_StructInit(&TIM_InitStructure);

  /* TIM0 Configuration in PWM Mode */
  TIM_InitStructure.TIM_Mode = TIM_PWM;
  TIM_InitStructure.TIM_Clock_Source = TIM_CLK_APB;
  TIM_InitStructure.TIM_Prescaler = 0x0;
  TIM_InitStructure.TIM_Pulse_Level_1 = TIM_HIGH;
  TIM_InitStructure.TIM_Period_Level = TIM_LOW;
  TIM_InitStructure.TIM_Pulse_Length_1 = 0x200;
  TIM_InitStructure.TIM_Full_Period = 0x404;
  TIM_Init (TIM0, &TIM_InitStructure);

  /* Start the counter of TIM0 */
  TIM_CounterCmd(TIM0, TIM_START);

  /* ADC Structure Initialization */
  ADC_StructInit(&ADC_InitStructure);

  /* Configure the ADC in continuous mode conversion */
  ADC_InitStructure.ADC_Channel_5_Mode = ADC_NoThreshold_Conversion;
  ADC_InitStructure.ADC_Select_Channel = ADC_Channel_5;
  ADC_InitStructure.ADC_Scan_Mode = DISABLE;
  ADC_InitStructure.ADC_Conversion_Mode = ADC_Continuous_Mode;

  /* Enable the ADC */
  ADC_Cmd(ENABLE);

  /* Prescaler config */
  ADC_PrescalerConfig(0x0);

  /* Configure the ADC */
  ADC_Init(&ADC_InitStructure);

  /* Start the conversion */
  ADC_ConversionCmd(ADC_Conversion_Start);

  while(1)
  {
        /* Wait until conversion completion */
    while(ADC_GetFlagStatus(ADC_FLAG_ECV) == RESET);

    /* Get the conversion value */
    Conversion_Value = ADC_GetConversionValue(ADC_Channel_5);

    /* Clear the end of conversion flag */
    ADC_ClearFlag(ADC_FLAG_ECV);

    /* Set the new pulse of the TIM0 */
    TIM_SetPulse(TIM0, TIM_PWM_OC1_Channel, Conversion_Value);
  }
}
Пример #21
0
void UBloxInit(void)
{
  SCU_APBPeriphClockConfig(__GPIO6, ENABLE);  // Enable the GPIO6 Clock
  SCU_APBPeriphClockConfig(__UART0, ENABLE);  // Enable the UART0 Clock

  GPIO_InitTypeDef gpio_init;

  // Configure pin GPIO6.6 to be UART0 Rx
  gpio_init.GPIO_Direction = GPIO_PinInput;
  gpio_init.GPIO_Pin = GPIO_Pin_6;
  gpio_init.GPIO_Type = GPIO_Type_PushPull;
  gpio_init.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
  gpio_init.GPIO_Alternate = GPIO_InputAlt1;  // UART0 Rx
  GPIO_Init(GPIO6, &gpio_init);

  // Configure pin GPIO6.6 to be UART0 Tx
  gpio_init.GPIO_Direction = GPIO_PinOutput;
  gpio_init.GPIO_Pin = GPIO_Pin_7;
  gpio_init.GPIO_Type = GPIO_Type_PushPull;
  gpio_init.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable;
  gpio_init.GPIO_Alternate = GPIO_OutputAlt3;  // UART0 Tx
  GPIO_Init(GPIO6, &gpio_init);

  UART1Init(UBLOX_INITIAL_BAUD);

  {
    // Set the port to UART UBX @ 57600.
    const uint8_t tx_buffer[28] = { 0xb5, 0x62, 0x06, 0x00, 0x14, 0x00, 0x01,
      0x00, 0x00, 0x00, 0xd0, 0x08, 0x00, 0x00, 0x00, 0xe1, 0x00, 0x00, 0x01,
      0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd6, 0x8d };
    UBloxTxBuffer(tx_buffer, 28);
  }

  Wait(150);
  UART1Init(UBLOX_OPERATING_BAUD);

  // Enable UART Rx interrupt.
  UART_ITConfig(UART0, UART_IT_Receive, ENABLE);
  VIC_Config(UART0_ITLine, VIC_IRQ, IRQ_PRIORITY_UART0);
  VIC_ITCmd(UART0_ITLine, ENABLE);

  {  // Configure USB for UBX input with no output.
    const uint8_t tx_buffer[28] = { 0xb5, 0x62, 0x06, 0x00, 0x14, 0x00, 0x03,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x8c };
    UBloxTxBuffer(tx_buffer, 28);
  }
  {  // Set antenna flags to 0x0b and pins to 0x380f.
    const uint8_t tx_buffer[12] = { 0xb5, 0x62, 0x06, 0x13, 0x04, 0x00, 0x0b,
      0x00, 0x0f, 0x38, 0x6f, 0x4f };
    UBloxTxBuffer(tx_buffer, 12);
  }
  {  // Set measurement period to 200ms (5Hz) with UTC reference.
    const uint8_t tx_buffer[14] = { 0xb5, 0x62, 0x06, 0x08, 0x06, 0x00, 0xc8,
      0x00, 0x01, 0x00, 0x00, 0x00, 0xdd, 0x68 };
    UBloxTxBuffer(tx_buffer, 14);
  }
  {  // Configure TimPulse.
    const uint8_t tx_buffer[28] = { 0xb5, 0x62, 0x06, 0x07, 0x14, 0x00, 0x40,
      0x42, 0x0f, 0x00, 0x90, 0x86, 0x03, 0x00, 0xff, 0x01, 0x00, 0x00, 0x32,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfd, 0x70 };
    UBloxTxBuffer(tx_buffer, 28);
  }
  {  // Configure SBAS.
    const uint8_t tx_buffer[16] = { 0xb5, 0x62, 0x06, 0x16, 0x08, 0x00, 0x03,
      0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 0xbd };
    UBloxTxBuffer(tx_buffer, 16);
  }
  {  // Configure navigation engine.
    const uint8_t tx_buffer[44] = { 0xb5, 0x62, 0x06, 0x24, 0x24, 0x00, 0xff,
      0xff, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00, 0x08,
      0x3c, 0x50, 0x00, 0x32, 0x00, 0x23, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x97,
      0xfa };
    UBloxTxBuffer(tx_buffer, 44);
  }
  {  // Configure navigation engine expert settings.
    const uint8_t tx_buffer[48] = { 0xb5, 0x62, 0x06, 0x23, 0x28, 0x00, 0x00,
      0x00, 0x4c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x10, 0x14,
      0x00, 0x01, 0x00, 0x00, 0x00, 0xf8, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0xc9, 0xea };
    UBloxTxBuffer(tx_buffer, 48);
  }
  {  // Request NAV-POSLLH message to be output every measurement cycle.
    const uint8_t tx_buffer[11] = { 0xb5, 0x62, 0x06, 0x01, 0x03, 0x00, 0x01,
      0x02, 0x01, 0x0e, 0x47 };
    UBloxTxBuffer(tx_buffer, 11);
  }
  {  // Request NAV-VELNED message to be output every measurement cycle.
    const uint8_t tx_buffer[11] = { 0xb5, 0x62, 0x06, 0x01, 0x03, 0x00, 0x01,
      0x12, 0x01, 0x1e, 0x67 };
    UBloxTxBuffer(tx_buffer, 11);
  }
  {  // Request NAV-SOL message to be output every measurement cycle.
    const uint8_t tx_buffer[11] = { 0xb5, 0x62, 0x06, 0x01, 0x03, 0x00, 0x01,
      0x06, 0x01, 0x12, 0x4f };
    UBloxTxBuffer(tx_buffer, 11);
  }
  {  // Request Time-UTC message to be output every 5 measurement cycles.
    const uint8_t tx_buffer[11] = { 0xb5, 0x62, 0x06, 0x01, 0x03, 0x00, 0x01,
      0x21, 0x05, 0x31, 0x89 };
    UBloxTxBuffer(tx_buffer, 11);
  }
}
Пример #22
0
int serial_open(char *name, unsigned int *subdevice)
{
  unsigned int port;
  unsigned int baudrate;
  GPIO_InitTypeDef config_pin;
  UART_InitTypeDef config_uart;

  errno_r = 0;

// Look up serial port number

  port = serial_name_to_port(name);
  if (port < 0) return port;

// Pass up port number, if requested

  if (subdevice != NULL)
    *subdevice = port;

// Extract baud rate from device name

  baudrate = atoi(name+5);

/* We assume the UART pin configuration of the STR910-EVAL board: */

/*   UART0 RxD is P51 alt in  1 */
/*   UART0 TxD is P34 alt out 3 */
/*   UART1 RxD is P32 alt in  1 */
/*   UART1 TxD is P33 alt out 2 */
/*   UART2 RxD is P31 alt in  1 */
/*   UART2 TxD is P35 alt out 3 */

  switch (port)
  {
    case 0:

// Turn on UART clock

      SCU_APBPeriphClockConfig(__UART0, ENABLE);

// Let UART out of reset

      SCU_APBPeriphReset(__UART0, DISABLE);

// Disable IRDA mode

      SCU_UARTIrDASelect(SCU_UART0, SCU_UARTMode_UART);

// Turn on GPIO clock

      SCU_APBPeriphClockConfig(__GPIO3, ENABLE);
      SCU_APBPeriphClockConfig(__GPIO5, ENABLE);

// Let GPIO out of reset

      SCU_APBPeriphReset(__GPIO3, DISABLE);
      SCU_APBPeriphReset(__GPIO5, DISABLE);

// Configure RxD on P51 alt in 1

      GPIO_StructInit(&config_pin);
      config_pin.GPIO_Pin = GPIO_Pin_1;
      config_pin.GPIO_Direction = GPIO_PinInput;
      config_pin.GPIO_Type = GPIO_Type_PushPull;
      config_pin.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
      config_pin.GPIO_Alternate = GPIO_InputAlt1;
      GPIO_Init(GPIO5, &config_pin);

// Configure TxD on P34 alt out 3

      GPIO_StructInit(&config_pin);
      config_pin.GPIO_Pin = GPIO_Pin_4;
      config_pin.GPIO_Direction = GPIO_PinOutput;
      config_pin.GPIO_Type = GPIO_Type_PushPull;
      config_pin.GPIO_Alternate = GPIO_OutputAlt3;
      GPIO_Init(GPIO3, &config_pin);
      break;

    case 1:

// Turn on UART clock

      SCU_APBPeriphClockConfig(__UART1, ENABLE);

// Let UART out of reset

      SCU_APBPeriphReset(__UART1, DISABLE);

// Disable IRDA mode

      SCU_UARTIrDASelect(SCU_UART1, SCU_UARTMode_UART);

// Turn on GPIO clock

      SCU_APBPeriphClockConfig(__GPIO3, ENABLE);

// Let GPIO out of reset

      SCU_APBPeriphReset(__GPIO3, DISABLE);

// Configure RxD on P32 alt in 1

      GPIO_StructInit(&config_pin);
      config_pin.GPIO_Pin = GPIO_Pin_2;
      config_pin.GPIO_Direction = GPIO_PinInput;
      config_pin.GPIO_Type = GPIO_Type_PushPull;
      config_pin.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
      config_pin.GPIO_Alternate = GPIO_InputAlt1;
      GPIO_Init(GPIO3, &config_pin);

// Configure TxD on P33 alt out 2

      GPIO_StructInit(&config_pin);
      config_pin.GPIO_Pin = GPIO_Pin_3;
      config_pin.GPIO_Direction = GPIO_PinOutput;
      config_pin.GPIO_Type = GPIO_Type_PushPull;
      config_pin.GPIO_Alternate = GPIO_OutputAlt2;
      GPIO_Init(GPIO3, &config_pin);
      break;

    case 2:

// Turn on UART clock

      SCU_APBPeriphClockConfig(__UART2, ENABLE);

// Let UART out of reset

      SCU_APBPeriphReset(__UART2, DISABLE);

// Disable IRDA mode

      SCU_UARTIrDASelect(SCU_UART2, SCU_UARTMode_UART);

// Turn on GPIO clock

      SCU_APBPeriphClockConfig(__GPIO3, ENABLE);

// Let GPIO out of reset

      SCU_APBPeriphReset(__GPIO3, DISABLE);

// Configure RxD on P31 alt in 1

      GPIO_StructInit(&config_pin);
      config_pin.GPIO_Pin = GPIO_Pin_1;
      config_pin.GPIO_Direction = GPIO_PinInput;
      config_pin.GPIO_Type = GPIO_Type_PushPull;
      config_pin.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
      config_pin.GPIO_Alternate = GPIO_InputAlt1;
      GPIO_Init(GPIO3, &config_pin);

// Configure TxD on P35 alt out 3

      GPIO_StructInit(&config_pin);
      config_pin.GPIO_Pin = GPIO_Pin_5;
      config_pin.GPIO_Direction = GPIO_PinOutput;
      config_pin.GPIO_Type = GPIO_Type_PushPull;
      config_pin.GPIO_Alternate = GPIO_OutputAlt3;
      GPIO_Init(GPIO3, &config_pin);
      break;

    default :
      errno_r = ENODEV;
      return -1;
  }

// Reset UART

  UART_DeInit(UARTS[port]);

// Configure UART

  UART_StructInit(&config_uart);
  config_uart.UART_WordLength = UART_WordLength_8D;
  config_uart.UART_StopBits = UART_StopBits_1;
  config_uart.UART_Parity = UART_Parity_No;
  config_uart.UART_BaudRate = baudrate;
  config_uart.UART_HardwareFlowControl = UART_HardwareFlowControl_None;
  config_uart.UART_Mode = UART_Mode_Tx_Rx;
  config_uart.UART_FIFO = UART_FIFO_Enable;
  config_uart.UART_TxFIFOLevel = UART_FIFOLevel_1_2;
  config_uart.UART_RxFIFOLevel = UART_FIFOLevel_1_2;
  UART_Init(UARTS[port], &config_uart);

// Enable UART

  UART_Cmd(UARTS[port], ENABLE);
  return 0;
}