Exemple #1
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;
}
Exemple #2
0
/********************************************************************************************************
* 函 数 名 : GPIO_config()
* 描    述 : GPIO管脚初始化
* 输入参数 : None.
* 输出参数 : None.
* 返   回  : None.
********************************************************************************************************/
void GPIO_config()
{
    GPIO_InitTypeDef GPIO_InitStructure;
    
    GPIO_AFIODeInit();
    GPIO_InitStructure.GPIO_Pin = LED1;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(LED_1_GRP, &GPIO_InitStructure); 
    
    GPIO_PinRemapConfig(GPIO_Remap_TIM4,ENABLE);
    
    GPIO_InitStructure.GPIO_Pin = LED2;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(LED_2_GRP, &GPIO_InitStructure); 
    
    GPIO_InitStructure.GPIO_Pin = LED3 | LED4 | LED5 | LED6;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(LED_3_6_GRP, &GPIO_InitStructure); 
    
    GPIO_InitStructure.GPIO_Pin = LED7 | LED8 ;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(LED_7_8_GRP, &GPIO_InitStructure); 

    GPIO_InitStructure.GPIO_Pin = KEY1 | KEY2 | KEY3 | KEY4 | KEY5; 
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;  
    GPIO_Init(GPIOF, &GPIO_InitStructure);
    
    GPIO_InitStructure.GPIO_Pin = KEY6 | KEY7 | KEY8 | SW1 | SW2 | SW3 | SW4;  
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;  
    GPIO_Init(GPIOE, &GPIO_InitStructure);
    
    GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource4);
    GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource5);
    GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource6);
    
    GPIO_InitStructure.GPIO_Pin = HEX_D0 | HEX_D1 | HEX_D2 | HEX_D3 | HEX_SCC;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOF, &GPIO_InitStructure); 
    
    GPIO_InitStructure.GPIO_Pin = HEX_SCA | HEX_SCB ;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOG, &GPIO_InitStructure); 
    
    GPIO_InitStructure.GPIO_Pin = HEX_D4 | HEX_D5 ;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    
    GPIO_InitStructure.GPIO_Pin = HEX_D6 | HEX_D7 ;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
    
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure); 
    
     /*USART1 GPIO Config*/
    GPIO_InitStructure.GPIO_Pin = UART1_TX ;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(UART1_GRP, &GPIO_InitStructure); 
    
    GPIO_InitStructure.GPIO_Pin = UART1_RX ;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(UART1_GRP, &GPIO_InitStructure);
    
    /*USART2 GPIO Config**********/
    GPIO_InitStructure.GPIO_Pin = UART2_TX ;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_Init(UART2_GRP, &GPIO_InitStructure); 
    
    GPIO_InitStructure.GPIO_Pin = UART2_RX;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(UART2_GRP, &GPIO_InitStructure);  
    
    /***************USART3 GPIO Config********************/
    GPIO_InitStructure.GPIO_Pin = UART3_485_TX ;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_Init(UART3_GRP, &GPIO_InitStructure); 
    
    GPIO_InitStructure.GPIO_Pin = UART3_485_RX ;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(UART3_GRP, &GPIO_InitStructure); 
    
    GPIO_InitStructure.GPIO_Pin = UART3_485_DIR ;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(UART3_GRP, &GPIO_InitStructure); 
    
    GPIO_InitStructure.GPIO_Pin = I2C1_SCL | I2C1_SDA;    //Configure I2C1 SCL and SDA(PB6 as alternate function push-pull 
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;  
    GPIO_Init(I2C1_GRP, &GPIO_InitStructure);
    
    /*所有Lcd引脚配置为推挽输出*/
    /*16位数据*/
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7| GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOE, &GPIO_InitStructure);
    
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOD, &GPIO_InitStructure);
    /*控制脚*/
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOD, &GPIO_InitStructure);
    
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOG, &GPIO_InitStructure);
    /*背光控制*/
    GPIO_InitStructure.GPIO_Pin =GPIO_Pin_6;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOG, &GPIO_InitStructure);
    
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;                 // Configure ADC channel10/11
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
    
    /***************外部中断********************/
    GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource4);
    GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource5);
    GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource6);
}
Exemple #3
0
//Initialization. Will set all motors ratio to 0%
void motorsInit()
{
  if (isInit)
    return;

  //Init structures
  GPIO_InitTypeDef GPIO_InitStructure;
  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  TIM_OCInitTypeDef  TIM_OCInitStructure;

  //Enable gpio and the timer
  RCC_APB2PeriphClockCmd( RCC_APB2Periph_AFIO 
	                    | MOTOR1_GPIO_PERIF
						| MOTOR2_GPIO_PERIF 
						| MOTOR3_GPIO_PERIF 
						| MOTOR4_GPIO_PERIF, ENABLE);

  RCC_APB1PeriphClockCmd( MOTOR1_TIM_PERIF 
	                    | MOTOR2_TIM_PERIF 
	                    | MOTOR3_TIM_PERIF
	                    | MOTOR4_TIM_PERIF, ENABLE);

  GPIO_AFIODeInit();  
  //Remap MOTO3 TIM
  GPIO_PinRemapConfig(MOTOR3_TIM_REMAP, ENABLE);

  //Remap MOTO4 TIM
  GPIO_PinRemapConfig(MOTOR4_TIM_REMAP, ENABLE);

  // Configure the GPIO for the MOTO1 output
  GPIO_InitStructure.GPIO_Pin = MOTOR1_GPIO_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(MOTOR1_GPIO_PORT, &GPIO_InitStructure);

  // Configure the GPIO for the MOTO2 output
  GPIO_InitStructure.GPIO_Pin = MOTOR2_GPIO_PIN;
  GPIO_Init(MOTOR2_GPIO_PORT, &GPIO_InitStructure);

  // Configure the GPIO for the MOTO3 output
  GPIO_InitStructure.GPIO_Pin = MOTOR3_GPIO_PIN;
  GPIO_Init(MOTOR3_GPIO_PORT, &GPIO_InitStructure);

  // Configure the GPIO for the MOTO2 output
  GPIO_InitStructure.GPIO_Pin = MOTOR4_GPIO_PIN;
  GPIO_Init(MOTOR4_GPIO_PORT, &GPIO_InitStructure);

  //Timer configuration
  TIM_TimeBaseStructure.TIM_Period = MOTORS_PWM_PERIOD;
  TIM_TimeBaseStructure.TIM_Prescaler = MOTORS_PWM_PRESCALE;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(MOTOR1_TIM, &TIM_TimeBaseStructure);

  TIM_TimeBaseStructure.TIM_Period = MOTORS_PWM_PERIOD;
  TIM_TimeBaseStructure.TIM_Prescaler = MOTORS_PWM_PRESCALE;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(MOTOR2_TIM, &TIM_TimeBaseStructure);

  TIM_TimeBaseStructure.TIM_Period = MOTORS_PWM_PERIOD;
  TIM_TimeBaseStructure.TIM_Prescaler = MOTORS_PWM_PRESCALE;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(MOTOR3_TIM, &TIM_TimeBaseStructure);

  TIM_TimeBaseStructure.TIM_Period = MOTORS_PWM_PERIOD;
  TIM_TimeBaseStructure.TIM_Prescaler = MOTORS_PWM_PRESCALE;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(MOTOR4_TIM, &TIM_TimeBaseStructure);

  //PWM channels configuration (All identical!)
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = 0;
  TIM_OCInitStructure.TIM_OCPolarity = MOTORS_POLARITY;

  TIM_OC4Init(MOTOR1_TIM, &TIM_OCInitStructure);
  TIM_OC4PreloadConfig(MOTOR1_TIM, TIM_OCPreload_Enable);

  TIM_OC4Init(MOTOR2_TIM, &TIM_OCInitStructure);
  TIM_OC4PreloadConfig(MOTOR2_TIM, TIM_OCPreload_Enable);

  TIM_OC4Init(MOTOR3_TIM, &TIM_OCInitStructure);
  TIM_OC4PreloadConfig(MOTOR3_TIM, TIM_OCPreload_Enable);

  TIM_OC3Init(MOTOR4_TIM, &TIM_OCInitStructure);
  TIM_OC3PreloadConfig(MOTOR4_TIM, TIM_OCPreload_Enable);

  //Enable the timer
  TIM_Cmd(MOTOR1_TIM, ENABLE);
  TIM_Cmd(MOTOR2_TIM, ENABLE);
  TIM_Cmd(MOTOR3_TIM, ENABLE);
  TIM_Cmd(MOTOR4_TIM, ENABLE);
  //Enable the timer PWM outputs
  //TIM_CtrlPWMOutputs(MOTOR1_TIM, ENABLE);
  //TIM_CtrlPWMOutputs(MOTOR2_TIM, ENABLE);
  //TIM_CtrlPWMOutputs(MOTOR3_TIM, ENABLE);
  //TIM_CtrlPWMOutputs(MOTOR4_TIM, ENABLE);
  TIM_ARRPreloadConfig(MOTOR1_TIM, ENABLE);
  TIM_ARRPreloadConfig(MOTOR2_TIM, ENABLE);
  TIM_ARRPreloadConfig(MOTOR3_TIM, ENABLE);
  TIM_ARRPreloadConfig(MOTOR4_TIM, ENABLE);
  // Halt timer during debug halt.
  DBGMCU_Config(MOTOR1_TIM_DBG, ENABLE);
  DBGMCU_Config(MOTOR2_TIM_DBG, ENABLE);
  DBGMCU_Config(MOTOR3_TIM_DBG, ENABLE);
  DBGMCU_Config(MOTOR4_TIM_DBG, ENABLE);
  
  isInit = RT_TRUE;
}