Esempio n. 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();
}
Esempio n. 2
0
/*******************************************************************************
 * 名    称: IAP_DevDeInit()
 * 功    能: 设备恢复默认值
 * 入口参数:
 * 出口参数: 无
 * 作   者: 无名沈
 * 创建日期: 2014-04-23
 * 修    改: 
 * 修改日期: 
 *******************************************************************************/
void IAP_DevDeInit(void)
{    
    /***********************************************
    * 描述: 端口恢复默认
    */
    GPIO_DeInit(GPIOA);
    GPIO_DeInit(GPIOB);
    GPIO_DeInit(GPIOC);
    GPIO_DeInit(GPIOD);
    GPIO_DeInit(GPIOE);
    
    /***********************************************
    * 描述: 串口恢复默认
    */
    USART_DeInit(USART1);
    USART_DeInit(USART2);
    USART_DeInit(USART3);
        
    /***********************************************
    * 描述: 定时器恢复默认
    */
    TIM_DeInit(TIM1);
    TIM_DeInit(TIM2);
    TIM_DeInit(TIM2);
    TIM_DeInit(TIM3);
    TIM_DeInit(TIM4);
    TIM_DeInit(TIM5);
    TIM_DeInit(TIM6);
    TIM_DeInit(TIM7);
    TIM_DeInit(TIM8);
}
Esempio n. 3
0
int main(void)
{
		TIME  time;
		
		 /*时钟初始化*/
		CLK_Config();
			
		/*初始化电源控制*/
		GPIO_DeInit(GPIOD); 
		GPIO_Init(GPIOD,GPIO_PIN_3,GPIO_MODE_OUT_PP_LOW_FAST);
		GPIO_DeInit(GPIOC); 
		GPIO_Init(GPIOC,GPIO_PIN_1,GPIO_MODE_OUT_PP_LOW_FAST);	
	
		/*上电,3.3V/12V*/
		VDD3V3_ON();
		VDD12_ON();
	
		RTC_Init();


		while (1)
		{
			RTC_ReadDate(&time);

		  
		}
			

	


	return 0;
}
void gpioconfig(void){

    /* GPIO configuration */
    GPIO_InitTypeDef GPIO_InitStructure;

    GPIO_DeInit(GPIOB);//função deinit faz reset as configs do porto
    GPIO_DeInit(GPIOA);
    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_8; //pino 8 
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //modo saida
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);//inicia o GPIOB8 como saida


    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_9; //pino 9
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //modo AF (alternated function) para o timer 4 poder controlar o led
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);//inicia o GPIOB9 como saida para PWM

    GPIO_InitStructure.GPIO_Pin =   GPIO_Pin_0 ; //pino 0
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //modo AF(alternated funcion) para o botão no GPIOA0 poder operar em modo gated
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);//inicia o GPIOA0 como Entrada ligada ao timer2 

GPIO_InitStructure.GPIO_Pin =   GPIO_Pin_0 ; //pino 0
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //modo AF(alternated funcion) para o botão no GPIOA0 poder operar em modo gated
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);//inicia o GPIOA0 como Entrada ligada ao timer2 

}
Esempio n. 5
0
//*********************************//
void  sysio_ini(void)
{
    GPIO_DeInit(GPIOD);
    GPIO_Init(GPIOD,GPIO_PIN_2 ,GPIO_MODE_IN_PU_NO_IT); //data165
    GPIO_Init(GPIOD,GPIO_PIN_3 ,GPIO_MODE_OUT_PP_HIGH_FAST); //clk165
    GPIO_Init(GPIOD,GPIO_PIN_4 ,GPIO_MODE_OUT_PP_HIGH_FAST); //sh165
    GPIO_WriteHigh(GPIOD,H165_SH);
    GPIO_WriteHigh(GPIOD,H165_CLK);

    GPIO_DeInit(GPIOC);
    GPIO_Init(GPIOC,GPIO_PIN_4,GPIO_MODE_OUT_PP_HIGH_FAST);//led
    GPIO_Init(GPIOC,GPIO_PIN_5,GPIO_MODE_OUT_PP_HIGH_FAST);//c138
    GPIO_Init(GPIOC,GPIO_PIN_6,GPIO_MODE_OUT_PP_HIGH_FAST);//b138
    GPIO_Init(GPIOC,GPIO_PIN_7,GPIO_MODE_OUT_PP_HIGH_FAST);//a138
    GPIO_WriteLow(GPIOC,GPIO_PIN_4);

    GPIO_DeInit(GPIOB);
    GPIO_Init(GPIOB,GPIO_PIN_4 ,GPIO_MODE_OUT_OD_HIZ_SLOW); //clk1637
    GPIO_Init(GPIOB,GPIO_PIN_5 ,GPIO_MODE_OUT_OD_HIZ_SLOW); //sh1637
    GPIO_WriteHigh(GPIOB,T1637_CLK);
    GPIO_WriteHigh(GPIOB,T1637_DATA);



}
Esempio n. 6
0
/*******************************************************************************
* Function Name  : ENET_InitClocksGPIO
* Description    : Reset, clocks & GPIO Ethernet Pin initializations
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void ENET_InitClocksGPIO(void)
{

  GPIO_InitTypeDef GPIO_Struct;

  SCU_AHBPeriphClockConfig(__ENET, ENABLE);
  SCU_AHBPeriphReset(__ENET,DISABLE);
  SCU_PHYCLKConfig(ENABLE);

  GPIO_DeInit(GPIO1);
  GPIO_Struct.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 |GPIO_Pin_3 |GPIO_Pin_4 |GPIO_Pin_7 ;
  GPIO_Struct.GPIO_Type = GPIO_Type_PushPull;
  GPIO_Struct.GPIO_Direction = GPIO_PinOutput;
  GPIO_Struct.GPIO_IPConnected = GPIO_IPConnected_Disable;
  GPIO_Struct.GPIO_Alternate=GPIO_OutputAlt2;
  GPIO_Init(GPIO1, &GPIO_Struct);


  GPIO_DeInit(GPIO5);
  GPIO_Struct.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
  GPIO_Struct.GPIO_Type = GPIO_Type_PushPull;
  GPIO_Struct.GPIO_Direction = GPIO_PinOutput;
  GPIO_Struct.GPIO_IPConnected = GPIO_IPConnected_Disable;
  GPIO_Struct.GPIO_Alternate=GPIO_OutputAlt2;
  GPIO_Init(GPIO5, &GPIO_Struct);

}
Esempio n. 7
0
File: main.c Progetto: eleqian/WiDSO
// 判断按键是否按下
BOOL key_is_pressed(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    BOOL is_press = FALSE;

    // 打开按键端口时钟
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

    GPIO_DeInit(GPIOC);
    
    // 初始化KEY端口(PC13)
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
    
    delay_ms(10);

    // KEY按下时为低电平
    is_press = !GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13);

    // 复位按键端口状态
    GPIO_DeInit(GPIOC);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, DISABLE);

    return is_press;
}
Esempio n. 8
0
/*******************************************************************************
* Function Name  : LCD_CtrlLinesConfig
* Description    : Configures LCD Control lines (FSMC Pins) in alternate function
                   Push-Pull mode.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_CtrlLinesConfig(void)
{
#ifndef NO_LCD  
  GPIO_InitTypeDef GPIO_InitStructure;

  GPIO_DeInit(GPIOD);

  /* Set PD.00(D2), PD.01(D3), PD.04(NOE), PD.05(NWE), PD.14(D0), PD.15(D1) as alternate 
     function push pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |
                                 GPIO_Pin_14 | GPIO_Pin_15;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  GPIO_DeInit(GPIOE);
  /* Set PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7) as alternate function push pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 ;
  GPIO_Init(GPIOE, &GPIO_InitStructure);

  GPIO_DeInit(GPIOF);
  /* Set PF.00(A0 (RS)) as alternate function push pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  GPIO_Init(GPIOF, &GPIO_InitStructure);

  GPIO_DeInit(GPIOG);
  /* Set PG.12(NE4 (LCD/CS)) as alternate function push pull - CE3(LCD /CS) */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
  GPIO_Init(GPIOG, &GPIO_InitStructure);
#endif
}
void bootpinDeinit(void)
{
  GPIO_DeInit(GPIOA);
  GPIO_DeInit(GPIOC);

  RCC_AHB1PeriphClockCmd(RCC_AHB1ENR_GPIOAEN, DISABLE);
  RCC_AHB1PeriphClockCmd(RCC_AHB1ENR_GPIOCEN, DISABLE);
}
static void deinit_esc_gpio(int8_t escIndex) {
  int i = 0;
  if (escIndex == -1) {
    for (i = 0; i < ESC_COUNT; i++) {
      GPIO_DeInit(escHardware[i].gpio);
    }
  }
  else {
    GPIO_DeInit(escHardware[escIndex].gpio);
  }
}
Esempio n. 11
0
/**
  * @}
  */ 
void STM_EVAL_GPIOReset(void)
{
  GPIO_DeInit(GPIOA);
  GPIO_DeInit(GPIOB);
  GPIO_DeInit(GPIOC);
  GPIO_DeInit(GPIOD);
  GPIO_DeInit(GPIOE);
  GPIO_DeInit(GPIOF);
  GPIO_DeInit(GPIOG);
  GPIO_DeInit(GPIOH);
  GPIO_DeInit(GPIOI);
}
Esempio n. 12
0
int platform_init()
{
  unsigned i;
  TIM_InitTypeDef tim;
  TIM_TypeDef* base;  
        
  // System configuration
  platform_config_scu();
  
  // PIO setup
  for( i = 0; i < 10; i ++ )
    GPIO_DeInit( ( GPIO_TypeDef* )port_data[ i ] );
    
  // Initialize VIC
  VIC_DeInit();
  
  // UART setup (only STR9_UART is used in this example)
  platform_uart_setup( CON_UART_ID, CON_UART_SPEED, 8, PLATFORM_UART_PARITY_NONE, PLATFORM_UART_STOPBITS_1 );

  // Initialize timers
  for( i = 0; i < 4; i ++ )
  {
    base = ( TIM_TypeDef* )timer_data[ i ];
    TIM_DeInit( base );
    TIM_StructInit( &tim );
    tim.TIM_Clock_Source = TIM_CLK_APB;
    tim.TIM_Prescaler = 255;      
    TIM_Init( base, &tim );    
    TIM_CounterCmd( base, TIM_START );
  }
  
  cmn_platform_init();

  return PLATFORM_OK;
} 
Esempio n. 13
0
bool CheckXCLK(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	uint32_t EdgeCount = 0, time;

	// Output HSE clock on MCO2 pin(PC9) ****************************************/
	// Enable the GPIOA peripheral
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

	// Configure pin(PC9) as input
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
	GPIO_Init(GPIOC, &GPIO_InitStructure);
	
	time = 50000000;
	while (time--)
	{
		if (((~(GPIOC->IDR)) & GPIO_Pin_9) != 0)
		{
			EdgeCount++;
		}
	}
	
	GPIO_DeInit(GPIOC);
	if (EdgeCount > 1000)
	{
		return true;
	}
	return false;
}
Esempio n. 14
0
int main( void ){

    uint16_t i;
    // Reset GPIO port D to a default state
    GPIO_DeInit(GPIOD);

    /* Clock configuration -----------------------------------------*/
    //CLK_Config();

    /*AWU configuration --------------------------------------------*/
    AWU_Config();

    GPIO_Init(GPIOD, GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_FAST);
    // The main loop
    while( 1 ){

        GPIO_WriteLow(GPIOD, GPIO_PIN_0);

        for(i=0;i<10000;i++) // A delay loop
        {
            nop();
        }
        GPIO_WriteHigh(GPIOD, GPIO_PIN_0);

        halt();/* Program halted */
    }

}
Esempio n. 15
0
int platform_init()
{
  unsigned i;
  TIM_InitTypeDef tim;
  TIM_TypeDef* base;  
        
  // System configuration
  platform_config_scu();
  
  // PIO setup
  for( i = 0; i < 10; i ++ )
    GPIO_DeInit( ( GPIO_TypeDef* )port_data[ i ] );
  
  // UART setup (only STR9_UART is used in this example)
  platform_uart_setup( 0, 115200, 8, PLATFORM_UART_PARITY_NONE, PLATFORM_UART_STOPBITS_1 );
  
  // Initialize timers
  for( i = 0; i < 4; i ++ )
  {
    base = ( TIM_TypeDef* )timer_data[ i ];
    TIM_DeInit( base );
    TIM_StructInit( &tim );
    tim.TIM_Clock_Source = TIM_CLK_APB;
    tim.TIM_Prescaler = 255;      
    TIM_Init( base, &tim );    
    TIM_CounterCmd( base, TIM_START );
  }
  
  // Set the send/recv functions                          
  std_set_send_func( uart_send );
  std_set_get_func( uart_recv );  
     
  return PLATFORM_OK;
} 
Esempio n. 16
0
int main(void) {

	// Initialise the clock to have a /1 prescaler and use the external crystal clock source for accuracy.
	CLK_DeInit();
	CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
	CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
	
	// Reset ("de-initialise") GPIO port D.
	GPIO_DeInit(GPIOD);
	// Initialise pin 0 of port D by setting it as:
	// - an output pin,
	// - using a push-pull driver,
	// - at a low logic level (0V), and
	// - 10MHz.
	GPIO_Init(GPIOD, GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_FAST);
	
	LCDInit(); // Init the LCD
	DecodeInit(); // Init the GPS decoding
	DrawScreen(); // Setup Screen and Buffer
	
	// Infinite loop.
	for(;;) {
		// Blink Debug LED
		GPIO_WriteReverse(GPIOD, GPIO_PIN_0);
		
		DrawDemo();	
	}
}
Esempio n. 17
0
void main(void) {

	GPIO_DeInit(GPIOD);
	GPIO_Init(GPIOD, GPIO_PIN_3, GPIO_MODE_OUT_PP_LOW_FAST);
	GPIO_Init(GPIOD, GPIO_PIN_2, GPIO_MODE_OUT_PP_LOW_FAST);
    
    KT_I2C_LCD_Init();
	
	KT_I2C_LCD_Puts("I2C LCD STM8S003");
	KT_I2C_LCD_NewLine();
	KT_I2C_LCD_Puts("Ngo Hung Cuong");
    //KT_I2C_LCD_BackLight(1);
    // Infinite loop.
    while(1) {
      /*
        // Delay for a short while.
        u16 d;
        for (d = 0; d < 20000; ++d) {
            // Without a nop() in here, the entire loop would be optimised away!
            nop();
        }
		GPIO_WriteReverse(GPIOD, GPIO_PIN_3);
		GPIO_WriteReverse(GPIOD, GPIO_PIN_2);
      */
    }
	
}
Esempio n. 18
0
void CH375_PortInit(void)
{
	int i;

	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | 
						   RCC_APB2Periph_GPIOB |
						   RCC_APB2Periph_GPIOC ,
						   ENABLE  );
	GPIO_DeInit(GPIOA);
	GPIO_DeInit(GPIOB);
	GPIO_DeInit(GPIOC);

	for(i = CH375_PIN_D0; i <= CH375_PIN_D7; i++)
	{
		GPIO_Pin_Config(CH375_Pin_Map[i].Gpio, 
						CH375_Pin_Map[i].Gpio_Pin, 
						GPIO_Mode_Out_OD, 
						GPIO_Speed_50MHz);				
	}

	GPIO_Pin_Config(CH375_Pin_Map[CH375_PIN_CS].Gpio, 
				 	CH375_Pin_Map[CH375_PIN_CS].Gpio_Pin, 
					GPIO_Mode_Out_OD, 
					GPIO_Speed_50MHz);
	GPIO_Pin_Config(CH375_Pin_Map[CH375_PIN_RD].Gpio, 
				 	CH375_Pin_Map[CH375_PIN_RD].Gpio_Pin, 
					GPIO_Mode_Out_OD, 
					GPIO_Speed_50MHz);
	GPIO_Pin_Config(CH375_Pin_Map[CH375_PIN_WR].Gpio, 
				 	CH375_Pin_Map[CH375_PIN_WR].Gpio_Pin, 
					GPIO_Mode_Out_OD, 
					GPIO_Speed_50MHz);
	GPIO_Pin_Config(CH375_Pin_Map[CH375_PIN_A0].Gpio, 
				 	CH375_Pin_Map[CH375_PIN_A0].Gpio_Pin, 
					GPIO_Mode_Out_OD, 
					GPIO_Speed_50MHz);

	GPIO_Pin_Config(CH375_Pin_Map[CH375_PIN_INT].Gpio, 
				 	CH375_Pin_Map[CH375_PIN_INT].Gpio_Pin, 
					GPIO_Mode_IPU, 
					GPIO_Speed_50MHz);

	CH375_Set_CS(1);
	CH375_Set_RD(1);
	CH375_Set_WR(1);
	CH375_Set_A0(1);	
}
Esempio n. 19
0
/********************************* Main���� *************************************/
int main(void)
{
#ifdef JKB_SW_H
	NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x10000);
#endif

	GPIO_DeInit(GPIOA);
	GPIO_DeInit(GPIOB);
	GPIO_DeInit(GPIOC);
	GPIO_AFIODeInit();

	/******************************** �ж�������ʼ�� ****************************/

	/****************************** GPIO�ָ���Ĭ������ **************************/

	/******************************** uCOS-II��ʼ�� *****************************/
  __set_PRIMASK(0);	//enable interrupts
	
	USB_IO_PullDown();
	stm32_delay_ms(200);
	USB_IO_PullUp();
	stm32_delay_ms(10);
	usbHIDInit();	
	stm32_delay_ms(500);
	

	OSInit();
  	/******************************** Create uCOS Task ******************************/
	OSTaskCreateExt(TaskStart,
					(void *)0,
					&Task_Start_Stk[Task_Start_Size - 1],
					Task_Start_Prio,
					Task_Start_Prio,
					Task_Start_Stk,
					Task_Start_Size,
					(void *)0,
					OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);


	/******************************** ʹ��ϵͳ���� ******************************/
	SysTick_Config(SystemCoreClock / 1000);

	/******************************** ��ʼ������ ******************************/
	OSStart();

	return 1;
}
static void ledInitDebug(void)
{
  uint32_t pinmask = LED_PRGMR_RX|LED_PRGMR_TX;
  GPIO_DeInit(GPIOE);
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE, ENABLE);
  gpio_set_mode(GPIOE, pinmask, Mode_Out_PP);
  GPIOE->BRR = pinmask;
}
Esempio n. 21
0
void GPIO_Configuration(void)
{
	/* GPIOD reset */
	GPIO_DeInit(GPIOD);
	
	/* Configure PD4 (BEEPER) as output push-pull low */
  GPIO_Init(GPIOD, GPIO_PIN_4 , GPIO_MODE_OUT_PP_LOW_FAST);	
}
Esempio n. 22
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));
  }
}
Esempio n. 23
0
AJ_Status AJS_TargetIO_PinClose(void* pinCtx)
{
    GPIO* gpio = (GPIO*)pinCtx;
    if (gpio->pwm.dutyCycle) {
        ReleasePWM(gpio);
    }
    GPIO_DeInit(gpio->GPIOx);
    return AJ_OK;
}
Esempio n. 24
0
void gpio_init(gpio_dev* dev) 
{
	/* Check the parameters */
	assert_param(IS_GPIO_ALL_PERIPH(dev->GPIOx));
	GPIO_DeInit(dev->GPIOx);
	/* Enable the GPIO Clock  */
	//LASER_PWM_PATCH
	dev->clkcmd(dev->clk | RCC_APB2Periph_AFIO, ENABLE);
}
Esempio n. 25
0
/**
  * @brief Configure the USART Device
  * @param  None
  * @retval None
  */
static void USART_Configuration(void)
{ 
  USART_InitTypeDef USART_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure; 
  NVIC_InitTypeDef NVIC_InitStructure;
  
  /* Enable GPIOA and DMA clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA , ENABLE);
  
  /* Enable USART1 APB clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
  
  /* Configure the HSI as USART clock */
  RCC_USARTCLKConfig(RCC_USART1CLK_HSI);
  
  /* USART1 Pins configuration **************************************************/
  GPIO_DeInit(GPIOA);
  
  /* Connect pin to Periph */
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);    
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1); 
  
  /* Configure pins as AF pushpull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOA, &GPIO_InitStructure); 
  
 
  /* USARTx configured as follow:
  - BaudRate = 115200 baud  
  - Word Length = 8 Bits
  - Stop Bit = 1 Stop Bit
  - Parity = No Parity
  - Hardware flow control disabled (RTS and CTS signals)
  - Receive and transmit enabled
  */
  
  USART_DeInit(USART1);
  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;
  USART_Init(USART1, &USART_InitStructure);
  
  /* USART1 IRQ Channel configuration */
  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPriority = 0x01;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}
static void ledInitDebug(void)
{
#if defined(STM32F3DISCOVERY)
  GPIO_DeInit(GPIOE);
  gpio_enable_clock(RCC_AHBPeriph_GPIOE);
  gpio_set_mode(GPIOE, GPIO_Pin_8|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_14|GPIO_Pin_15, Mode_Out_PP);
  // Inverted LEDs
  ledSetState(GPIOE, GPIO_Pin_8|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_14|GPIO_Pin_15, Bit_RESET);
#endif
  return;
}
Esempio n. 27
0
/*******************************************************************************
* Function Name  : GPIO_Configuration
* Description    : Configure the used I/O ports pins
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void GPIO_Configuration(void)
{
  GPIO_InitTypeDef  GPIO_Struct;

 /* GPIO2 Config */
  GPIO_DeInit(GPIO2);
  GPIO_Struct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3  ;
  GPIO_Struct.GPIO_Type = GPIO_Type_OpenCollector;
  GPIO_Struct.GPIO_IPConnected = GPIO_IPConnected_Enable;
  GPIO_Struct.GPIO_Alternate=GPIO_OutputAlt2;
  GPIO_Init(GPIO2, &GPIO_Struct);
}
Esempio n. 28
0
/*******************************************************************************
* Function Name  : GPIO_Configuration
* Description    : Configures the different GPIO ports.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
   
  GPIO_DeInit(GPIO3);
  /*Gonfigure UART0_Tx pin GPIO3.4*/
  GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
  GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
  GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3  ;
  GPIO_Init (GPIO3, &GPIO_InitStructure);
  
  GPIO_DeInit(GPIO5);
  /*Gonfigure UART0_Rx pin GPIO5.1*/
  GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
  GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
  GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1  ;
  GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
  GPIO_Init (GPIO5, &GPIO_InitStructure);
}
Esempio n. 29
0
/*******************************************************************************
* Function Name  : GPIO_Configuration
* Description    : Configure the used I/O ports pins
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void GPIO_Configuration(void)
{
  GPIO_InitTypeDef  GPIO_InitStructure;

  /* SSP0 and SSP1 pins Config */

  GPIO_DeInit(GPIO5);
  /*Gonfigure SSP0_CLK, SSP0_MOSI, SSP0_nSS pins */
  GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
  GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
  GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2  ;
  GPIO_Init (GPIO5, &GPIO_InitStructure);

   /*Gonfigure SSP0_MISO pin GPIO5.6*/
  GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
  GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
  GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1  ;
  GPIO_Init (GPIO5, &GPIO_InitStructure);

  GPIO_DeInit(GPIO3);
  /*Gonfigure SSP1_MISO pin */
  GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
  GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
  GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2  ;
  GPIO_Init (GPIO3, &GPIO_InitStructure);

   /*Gonfigure SSP1_CLK, SSP1_MOSI, SSP1_nSS pins */
  GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4| GPIO_Pin_6|GPIO_Pin_7;
  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);
}
Esempio n. 30
0
/***********************************Functions *********************************/
void GPIO_Config(void)
{

  GPIO_InitTypeDef   GPIO_InitStructure;
  NVIC_InitTypeDef   NVIC_InitStructure;
  EXTI_InitTypeDef   EXTI_InitStructure;

  GPIO_DeInit(GPIOA);
  GPIO_DeInit(GPIOC);
  
  /* Enable GPIOB clock */
  RCC_AHBPeriphClockCmd(INVEN_INT_GPIO_CLK, ENABLE);
  /* Enable SYSCFG clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  
  /* Configure invensense sensor interrupt pin as input floating */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
  GPIO_InitStructure.GPIO_Pin = INVEN_INT_PIN;
  GPIO_Init(INVEN_INT_GPIO_PORT, &GPIO_InitStructure);

  /* Connect EXTI Line1 to inv sensor interrupt pin */
  SYSCFG_EXTILineConfig(INVEN_INT_EXTI_PORT, INVEN_INT_EXTI_PIN);

  /* Configure EXTI Line1 */
  EXTI_InitStructure.EXTI_Line = INVEN_INT_EXTI_LINE;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;  
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);

  /* Enable and set EXTI Line1 Interrupt to the highest priority */
  NVIC_InitStructure.NVIC_IRQChannel = INVEN_INT_EXTI_IRQ;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}