Exemple #1
0
/**
* @brief  USBH_USR_Init 
*         Displays the message on LCD for host lib initialization
* @param  None
* @retval None
*/
void USBH_USR_Init(void)
{
  static uint8_t startup = 0;  
  
  if(startup == 0 )
  {
    startup = 1;
    /* Configure the LEDs */
    STM_EVAL_LEDInit(LED1);
    STM_EVAL_LEDInit(LED2);
    STM_EVAL_LEDInit(LED3); 
    STM_EVAL_LEDInit(LED4); 
    
    STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO);
    
#ifdef USE_STM3210C_EVAL
    STM3210C_LCD_Init();  
#else
    STM322xG_LCD_Init();
#endif
    LCD_LOG_Init();
#ifdef USE_USB_OTG_HS 
    LCD_LOG_SetHeader(" USB OTG HS HID Host");
#else
    LCD_LOG_SetHeader(" USB OTG FS HID Host");
#endif
    LCD_UsrLog("> USB Host library started.\n"); 
    LCD_LOG_SetFooter ("     USB Host Library v2.0.0" );
  }
}
Exemple #2
0
/**
* @brief  USBD_USR_Init 
*         Displays the message on LCD for host lib initialization
* @param  None
* @retval None
*/
void USBD_USR_Init(void)
{  
  /* Initialize LEDs */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);   
  
  /* Initialize the LCD */
#if defined (USE_STM322xG_EVAL)
  STM322xG_LCD_Init();
#elif defined(USE_STM324xG_EVAL)
  STM324xG_LCD_Init();
#elif defined (USE_STM3210C_EVAL)
  STM3210C_LCD_Init();
#else
 #error "Missing define: Evaluation board (ie. USE_STM322xG_EVAL)"
#endif
  
  LCD_LOG_Init();
  
#ifdef USE_USB_OTG_HS 
  LCD_LOG_SetHeader(" USB OTG HS DFU Device");
#else
  LCD_LOG_SetHeader(" USB OTG FS DFU Device");
#endif
  
  LCD_UsrLog("> USB device library started.\n"); 
  LCD_LOG_SetFooter ("     USB Device Library v1.1.0" ); 
  
  /* Information panel */
  LCD_SetTextColor(Green);
  LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 30, USER_INFORMATION1);
  LCD_SetTextColor(LCD_LOG_DEFAULT_COLOR);
}
Exemple #3
0
/*..........................................................................*/
void BSP_init(void) {

    SystemInit();         /* initialize STM32 system (clock, PLL and Flash) */

             /* initialize LEDs, Key Button, and LCD on STM3210X-EVAL board */
    STM_EVAL_LEDInit(LED1);
    STM_EVAL_LEDInit(LED2);
    STM_EVAL_LEDInit(LED3);
    STM_EVAL_LEDInit(LED4);

    STM3210C_LCD_Init();                              /* initialize the LCD */
    LCD_Clear(White);                                      /* clear the LCD */
    LCD_SetBackColor(Grey);
    LCD_SetTextColor(Black);
    LCD_DisplayString(Line0, 0, "   Quantum Leaps    ");
    LCD_DisplayString(Line1, 0, "     DPP example    ");
    LCD_DisplayString(Line2, 0, "QP/C(Vanilla)       ");
    LCD_DisplayString(Line2, 14*16, QF_getVersion());
    LCD_SetBackColor(White);
    LCD_DisplayString(Line5, 0, "DPP:");
    LCD_SetBackColor(Black);
    LCD_SetTextColor(Yellow);
    LCD_DisplayString(Line9, 0, "  state-machine.com ");
    LCD_SetBackColor(Blue);
    LCD_SetTextColor(White);
    LCD_DisplayString(Line5, 4*16, "0 ,1 ,2 ,3 ,4    ");

    if (QS_INIT((void *)0) == 0) {    /* initialize the QS software tracing */
        Q_ERROR();
    }
}
Exemple #4
0
/**
 * @brief  Initializes the LCD.
 * @param  None
 * @retval None
 */
void GL_LCD_Init(void)
{
	/* Setups the LCD */
#if defined(USE_STM3210C_EVAL)
	STM3210C_LCD_Init();
#elif defined (USE_STM3210B_EVAL)
	STM3210B_LCD_Init();
#elif  defined (USE_STM32100B_EVAL)
	STM32100B_LCD_Init();
#elif defined(USE_STM3210E_EVAL)
	STM3210E_LCD_Init();
#elif defined(USE_STM32100E_EVAL)
	STM32100E_LCD_Init();
#elif defined(USE_STM322xG_EVAL)
	STM322xG_LCD_Init();
#elif defined(USE_STM32L152_EVAL)  
	STM32L152_LCD_Init();
#endif
}
/*..........................................................................*/
void BSP_init(void) {
    EXTI_InitTypeDef exti_init;

    SystemInit();         /* initialize STM32 system (clock, PLL and Flash) */

             /* initialize LEDs, Key Button, and LCD on STM3210X-EVAL board */
    STM_EVAL_LEDInit(LED1);
    STM_EVAL_LEDInit(LED2);
    STM_EVAL_LEDInit(LED3);
    STM_EVAL_LEDInit(LED4);

                    /* initialize the EXTI Line0 interrupt used for testing */
    exti_init.EXTI_Mode    = EXTI_Mode_Interrupt;
    exti_init.EXTI_Trigger = EXTI_Trigger_Rising;
    exti_init.EXTI_Line    = EXTI_Line0;
    exti_init.EXTI_LineCmd = ENABLE;
    EXTI_Init(&exti_init);

    STM3210C_LCD_Init();                              /* initialize the LCD */
    LCD_Clear(White);                                      /* clear the LCD */
    LCD_SetBackColor(Grey);
    LCD_SetTextColor(Black);
    LCD_DisplayString(Line0, 0, "   Quantum Leaps    ");
    LCD_DisplayString(Line1, 0, "     DPP example    ");
    LCD_DisplayString(Line2, 0, " QP/C (QK)          ");
    LCD_DisplayString(Line2, 14*16, QF_getVersion());
    LCD_SetBackColor(White);
    LCD_DisplayString(Line5, 0, "DPP:");
    LCD_SetBackColor(Black);
    LCD_SetTextColor(Yellow);
    LCD_DisplayString(Line9, 0, "  state-machine.com ");
    LCD_SetBackColor(Blue);
    LCD_SetTextColor(White);
    LCD_DisplayString(Line5, 4*16, "0 ,1 ,2 ,3 ,4    ");

    if (QS_INIT((void *)0) == 0) {    /* initialize the QS software tracing */
        Q_ERROR();
    }

    QS_OBJ_DICTIONARY(&l_SysTick_Handler);
}
/**
* @brief  USBH_USR_Init 
*         Displays the message on LCD for host lib initialization
* @param  None
* @retval None
*/
void USBH_USR_Init(void)
{
  static uint8_t startup = 0;  
  
  if(startup == 0 )
  {
    startup = 1;
    /* Configure the LEDs */
    STM_EVAL_LEDInit(LED1);
//    STM_EVAL_LEDInit(LED2);
//    STM_EVAL_LEDInit(LED3); 
//    STM_EVAL_LEDInit(LED4); 
    
    STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO);
    
#if defined (USE_STM322xG_EVAL)
  STM322xG_LCD_Init();
#elif defined(USE_STM324xG_EVAL)
  STM324xG_LCD_Init();
#elif defined (USE_STM3210C_EVAL)
  STM3210C_LCD_Init();
#else
 #error "Missing define: Evaluation board (ie. USE_STM322xG_EVAL)"
#endif
    
    LCD_LOG_Init();
      
#ifdef USE_USB_OTG_HS 
    LCD_LOG_SetHeader(" USB OTG HS MSC Host");
#else
    LCD_LOG_SetHeader(" USB OTG FS MSC Host");
#endif
    LCD_UsrLog("> USB Host library started.\n"); 
    LCD_LOG_SetFooter ("     USB Host Library v2.1.0" );
  }
}
Exemple #7
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */     

  /* Initialize LEDs, Key Button, LCD and COM port(USART) available on
     STM3210X-EVAL board ******************************************************/
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

  /* USARTx configured as follow:
        - BaudRate = 115200 baud  
        - Word Length = 8 Bits
        - One Stop Bit
        - No parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Receive and transmit enabled
  */
  USART_InitStructure.USART_BaudRate = 115200;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

  STM_EVAL_COMInit(COM1, &USART_InitStructure);

  /* Initialize the LCD */
#ifdef USE_STM32100B_EVAL
  STM32100B_LCD_Init();
#elif defined (USE_STM3210B_EVAL)
  STM3210B_LCD_Init();
#elif defined (USE_STM3210E_EVAL)
  STM3210E_LCD_Init();
#elif defined (USE_STM3210C_EVAL)
  STM3210C_LCD_Init();
#elif defined (USE_STM32100E_EVAL)
  STM32100E_LCD_Init();  
#endif

  /* Display message on STM3210X-EVAL LCD *************************************/
  /* Clear the LCD */ 
  LCD_Clear(LCD_COLOR_WHITE);

  /* Set the LCD Back Color */
  LCD_SetBackColor(LCD_COLOR_BLUE);
  /* Set the LCD Text Color */
  LCD_SetTextColor(LCD_COLOR_WHITE);
  LCD_DisplayStringLine(LCD_LINE_0, (uint8_t *)MESSAGE1);
  LCD_DisplayStringLine(LCD_LINE_1, (uint8_t *)MESSAGE2);
  LCD_DisplayStringLine(LCD_LINE_2, (uint8_t *)MESSAGE3);

  /* Retarget the C library printf function to the USARTx, can be USART1 or USART2
     depending on the EVAL board you are using ********************************/
  printf("\n\r %s", MESSAGE1);
  printf(" %s", MESSAGE2);
  printf(" %s\n\r", MESSAGE3);

  /* Turn on leds available on STM3210X-EVAL **********************************/
  STM_EVAL_LEDOn(LED1);
  STM_EVAL_LEDOn(LED2);
  STM_EVAL_LEDOn(LED3);
  STM_EVAL_LEDOn(LED4);

  /* Add your application code here
     */

  /* Infinite loop */
  while (1)
  {
  }
}
Exemple #8
0
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* System Clocks Configuration */
  RCC_Configuration();

  /* Initialize the LCD */
  STM3210C_LCD_Init();
  /* Clear the LCD */ 
  LCD_Clear(White);
  /* Set the LCD Text Color */
  LCD_SetTextColor(Black);
  printf("   STM3210C-EVAL    \n");
  printf("Irda receive example\n");
  printf("Set JP16 to IRXD\n\n");

  /* Configure the GPIO ports */
  GPIO_Configuration();

  //////////////////////////////////////////////////////
  NVIC_Configuration();
  //////////////////////////////////////////////////////

  /* Initialize Leds mounted on STM3210X-EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);
  
/* USARTy configuration ------------------------------------------------------*/
  /* USARTy configured as follow:
        - BaudRate = 115200 baud  
        - Word Length = 8 Bits
        - One Stop Bit
        - No parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Receive and transmit enabled
  */
  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;
  
  /* Configure the USARTy */
  USART_Init(USARTy, &USART_InitStructure);
  /* Enable the USARTy */
  USART_Cmd(USARTy, ENABLE);

  /* Set the USARTy prescaler */
  USART_SetPrescaler(USARTy, 0x1);
  /* Configure the USARTy IrDA mode */
  USART_IrDAConfig(USARTy, USART_IrDAMode_Normal);

  /* Enable the USARTy IrDA mode */
  USART_IrDACmd(USARTy, ENABLE);

  //////////////////////////////////////////////////////////////////////////
  TIM_TimeBaseStructure.TIM_Period = 4095;
  TIM_TimeBaseStructure.TIM_Prescaler = 10;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

  /* Output Compare Toggle Mode configuration: Channel1 */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = speed;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
  TIM_OC1Init(TIM3, &TIM_OCInitStructure);

  TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Disable);

  /* Output Compare Toggle Mode configuration: Channel2 */
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = speed;

  TIM_OC2Init(TIM3, &TIM_OCInitStructure);

  TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Disable);

  /* Output Compare Toggle Mode configuration: Channel3 */
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = speed;

  TIM_OC3Init(TIM3, &TIM_OCInitStructure);

  TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Disable);

  /* Output Compare Toggle Mode configuration: Channel4 */
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = speed;

  TIM_OC4Init(TIM3, &TIM_OCInitStructure);

  TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Disable);

  /* TIM enable counter */
  TIM_Cmd(TIM3, ENABLE);

  /* TIM IT enable */
  
  TIM_ITConfig(TIM3,TIM_IT_Update | TIM_IT_CC1,ENABLE);
  //////////////////////////////////////////////////////////

  while (1)
  {
    /* Wait until a byte is received */
    while(USART_GetFlagStatus(USARTy, USART_FLAG_RXNE) == RESET)
    {
    }
    /* Read the received byte */
	data = USART_ReceiveData(USARTy);
	//printf("data = %d\n",data);
	if(data == 0xff)
	{
		while(USART_GetFlagStatus(USARTy, USART_FLAG_RXNE) == RESET)
    	{
			
    	}
	    ReceivedData = (JOY_State_TypeDef)USART_ReceiveData(USARTy);
	    switch(ReceivedData)
	    {
	      case JOY_UP:
			printf("---JOY_UP---\n");
			funcNum = 1;
	        break;
	      case JOY_DOWN:
			printf("---JOY_DOWN---\n"); 
			funcNum = 2;
	        break;
	      case JOY_LEFT:
			printf("---JOY_LEFT---\n");
			funcNum = 3;
	        break;
	      case JOY_RIGHT:
			printf("---JOY_RIGHT---\n");
			funcNum = 4;
	        break;
	      case JOY_CENTER:
			printf("---JOY_CENTER---\n");
	        break;
	      case JOY_NONE:
	//	  	LCD_ClearLine(Line5);
	        break;
	      default:
	        break;
	    }
	}
	else if(data == 0xee)
	{
		while(USART_GetFlagStatus(USARTy, USART_FLAG_RXNE) == RESET)
    	{
			
    	}
		value = USART_ReceiveData(USARTy);
		speed = value<<4;
		//printf("\n speed = %d\n",speed) ;
	}
  }
}
Exemple #9
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */
        
  /* NVIC configuration */
  NVIC_Config();

  /* Configures LED 1..4 */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

  /* LCD Initialization */
  STM3210C_LCD_Init();
  LCD_Clear(LCD_COLOR_WHITE);

  /* Set the LCD Back Color */
  LCD_SetBackColor(LCD_COLOR_RED);
  /* Set the LCD Text Color */
  LCD_SetTextColor(LCD_COLOR_GREEN);
  
  LCD_DisplayStringLine(LCD_LINE_0, "   STM3210C-EVAL    ");
  LCD_DisplayStringLine(LCD_LINE_1, " STM32F10x Dual CAN ");
  LCD_DisplayStringLine(LCD_LINE_2, "To start Press on:  ");
  LCD_DisplayStringLine(LCD_LINE_3, "Key or Tamper Button");

  /* Set the LCD Back Color */
  LCD_SetBackColor(LCD_COLOR_BLUE);

#if CAN_BAUDRATE == 1000 /* 1MBps */
  LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 1MBps   ");
#elif CAN_BAUDRATE == 500 /* 500KBps */
  LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 500kBps   ");
#elif CAN_BAUDRATE == 250 /* 250KBps */
  LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 250kBps   ");
#elif CAN_BAUDRATE == 125 /* 125KBps */
  LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 125kBps   ");
#elif  CAN_BAUDRATE == 100 /* 100KBps */
  LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 100kBps   ");
#elif  CAN_BAUDRATE == 50 /* 50KBps */
  LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 50kBps   ");
#elif  CAN_BAUDRATE == 20 /* 20KBps */
  LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 20kBps   ");
#elif  CAN_BAUDRATE == 10 /* 10KBps */
  LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 10kBps   ");
#endif
  /* Set the LCD Text Color */
  LCD_SetTextColor(LCD_COLOR_WHITE);   
    
  /* Configure BUTTON_KEY */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); 
  
  /* Configure BUTTON_TAMPER */
  STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_GPIO); 
   
  /* CANs configuration */
  CAN_Config();

  /* IT Configuration for CAN1 */  
  CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);

  /* IT Configuration for CAN2 */  
  CAN_ITConfig(CAN2, CAN_IT_FMP0, ENABLE);

  /* turn off all leds*/
  STM_EVAL_LEDOff(LED1);
  STM_EVAL_LEDOff(LED2);
  STM_EVAL_LEDOff(LED3);
  STM_EVAL_LEDOff(LED4);
 
  /* Infinite loop */
  while(1)
  {
    if(STM_EVAL_PBGetState(BUTTON_KEY)== RESET)
    {
      /* Turn On LED1 */
      LED_Display(0x01);
      TxMessage.Data[0] = 0x55;
      CAN_Transmit(CAN1, &TxMessage);

      /* Loop while KEY button is pressed */
      while(STM_EVAL_PBGetState(BUTTON_KEY)== RESET)
      {
      }
    }
    if(STM_EVAL_PBGetState(BUTTON_TAMPER)== RESET)
    {
      /* Turn On LED2 */
      LED_Display(0x2);
      TxMessage.Data[0] = 0xAA;
      CAN_Transmit(CAN2, &TxMessage);

      /* Loop while TAMPER button is pressed */
      while(STM_EVAL_PBGetState(BUTTON_TAMPER)== RESET)
      {
      }
    }
  }
}
Exemple #10
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* Initialize LEDs and push-buttons mounted on STM3210X-EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);
  
   /* Initialize the LCD */
#ifdef USE_STM3210C_EVAL
  STM3210C_LCD_Init();
#elif defined (USE_STM32100E_EVAL)
  STM32100E_LCD_Init();  
#endif /* USE_STM3210C_EVAL */
 
  /* Clear the LCD */ 
  LCD_Clear(White);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(White);    
 
  /* Display messages on the LCD */
  LCD_DisplayStringLine(Line0, MESSAGE1);
  LCD_DisplayStringLine(Line1, MESSAGE2);
  LCD_DisplayStringLine(Line2, MESSAGE3);
  
  /* Configure the IO Expander */
  if (IOE_Config() == IOE_OK)
  {
    /* Display "IO Expander OK" on the LCD */
    LCD_DisplayStringLine(Line4, "   IO Expander OK   ");
  }
  else
  { 
    LCD_DisplayStringLine(Line4, "IO Expander FAILED ");
    LCD_DisplayStringLine(Line5, " Please Reset the  ");
    LCD_DisplayStringLine(Line6, "   board and start ");
    LCD_DisplayStringLine(Line7, "    again          ");
    while(1);
  }

  /* Draw a rectangle with the specifies parameters and Blue Color */
  LCD_SetTextColor(Blue);
  LCD_DrawRect(180, 310, 40, 60);
  
  /* Draw a rectangle with the specifies parameters and Red Color */
  LCD_SetTextColor(Red);
  LCD_DrawRect(180, 230, 40, 60);
  
  /* Draw a rectangle with the specifies parameters and Yellow Color */
  LCD_SetTextColor(Yellow);
  LCD_DrawRect(180, 150, 40, 60);
  
  /* Draw a rectangle with the specifies parameters and Black Color */
  LCD_SetTextColor(Black);
  LCD_DrawRect(180, 70, 40, 60);
  

#ifdef IOE_INTERRUPT_MODE

 #ifdef  USE_STM32100E_EVAL
  /* Enable the Touch Screen interrupts */
  IOE_ITConfig(IOE_ITSRC_TSC);
  
 #else
  /* Enable the Touch Screen and Joystick interrupts */
  IOE_ITConfig(IOE_ITSRC_JOYSTICK | IOE_ITSRC_TSC);
 #endif /* USE_STM32100E_EVAL */
 
#endif /* IOE_INTERRUPT_MODE */
  
  /* Loop infinitely */
  while(1)
  {
#ifdef IOE_POLLING_MODE
 static TS_STATE* TS_State;
    
 #ifdef  USE_STM3210C_EVAL
 
    static JOY_State_TypeDef JoyState = JOY_NONE;
    
    /* Get the Joytick State */
    JoyState = IOE_JoyStickGetState();
    
    switch (JoyState)
    {
	/* None Joystick has been selected */
    case JOY_NONE:
      LCD_DisplayStringLine(Line5, "JOY:     ----       ");
      break; 
    case JOY_UP:
      LCD_DisplayStringLine(Line5, "JOY:     UP         ");
      break;     
    case JOY_DOWN:
      LCD_DisplayStringLine(Line5, "JOY:    DOWN        ");
      break;          
    case JOY_LEFT:
      LCD_DisplayStringLine(Line5, "JOY:    LEFT        ");
      break;         
    case JOY_RIGHT:
      LCD_DisplayStringLine(Line5, "JOY:    RIGHT       ");
      break;                 
    case JOY_CENTER:
      LCD_DisplayStringLine(Line5, "JOY:    CENTER      ");
      break; 
    default:
      LCD_DisplayStringLine(Line5, "JOY:    ERROR       ");
      break;         
    }
 #endif /* USE_STM3210C_EVAL */
    
   
    /* Update the structure with the current position of the Touch screen */
    TS_State = IOE_TS_GetState();  
    
    if ((TS_State->TouchDetected) && (TS_State->Y < 220) && (TS_State->Y > 180))
    {
      if ((TS_State->X > 10) && (TS_State->X < 70))
      { 
      /* Display LD4 on the LCD and turn on LED4 */
        LCD_DisplayStringLine(Line6, " LD4                ");
        STM_EVAL_LEDOn(LED4);
      }
      else if ((TS_State->X > 90) && (TS_State->X < 150))
      {
      /* Display LD3 on the LCD and turn on LED3 */
        LCD_DisplayStringLine(Line6, "      LD3           ");
        STM_EVAL_LEDOn(LED3);
      }
      else if ((TS_State->X > 170) && (TS_State->X < 230))
      {
      /* Display LD2 on the LCD and turn on LED2 */
        LCD_DisplayStringLine(Line6, "           LD2      ");
        STM_EVAL_LEDOn(LED2);
      } 
      else if ((TS_State->X > 250) && (TS_State->X < 310))
      {
      /* Display LD1 on the LCD and turn on LED1 */
        LCD_DisplayStringLine(Line6, "                LD1 ");
        STM_EVAL_LEDOn(LED1);
      }
      
    }
    else
    {
    /* Turn off LED1..4 */
      STM_EVAL_LEDOff(LED1);
      STM_EVAL_LEDOff(LED2);
      STM_EVAL_LEDOff(LED3);
      STM_EVAL_LEDOff(LED4);
    }

#endif /* IOE_POLLING_MODE */  
  }
}
Exemple #11
0
/**
  * @brief  Setup STM32 system (clocks, Ethernet, GPIO, NVIC) and STM3210C-EVAL resources.
  * @param  None
  * @retval None
  */
void System_Setup(void)
{
  /* Reset the RCC clock configuration to the default reset state(for debug purpose) */
  /* Set HSION bit */
  RCC->CR |= (uint32_t)0x00000001;

  /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */
  RCC->CFGR &= (uint32_t)0xF0FF0000;  
  
  /* Reset HSEON, CSSON and PLLON bits */
  RCC->CR &= (uint32_t)0xFEF6FFFF;

  /* Reset HSEBYP bit */
  RCC->CR &= (uint32_t)0xFFFBFFFF;

  /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */
  RCC->CFGR &= (uint32_t)0xFF80FFFF;

  /* Reset PLL2ON and PLL3ON bits */
  RCC->CR &= (uint32_t)0xEBFFFFFF;

  /* Disable all interrupts and clear pending bits  */
  RCC->CIR = 0x00FF0000;

  /* Reset CFGR2 register */
  RCC->CFGR2 = 0x00000000;  
  
  SetSysClockTo72(); 
  
  //SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */  
  
  
  RCC_ClocksTypeDef RCC_Clocks;

  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */ 

  /* Enable USART2 clock */
  //RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);


  /* Enable ETHERNET clock  */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ETH_MAC | RCC_AHBPeriph_ETH_MAC_Tx |
                        RCC_AHBPeriph_ETH_MAC_Rx, ENABLE);

  /* Enable GPIOs and ADC1 clocks */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC |
                         RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);

  /* Configure the GPIO ports */
  GPIO_Configuration();

#ifdef USE_LCD
  /* Initialize the STM3210C-EVAL's LCD */
  STM3210C_LCD_Init();
#endif
    
//  /* Initialize STM3210C-EVAL's LEDs */
//  STM_EVAL_LEDInit(LED1);
//  STM_EVAL_LEDInit(LED2);
//  STM_EVAL_LEDInit(LED3);
//  STM_EVAL_LEDInit(LED4);
//
//  /* Turn on leds available on STM3210X-EVAL */
//  STM_EVAL_LEDOn(LED1);
//  STM_EVAL_LEDOn(LED2);
//  STM_EVAL_LEDOn(LED3);
//  STM_EVAL_LEDOn(LED4);
  
#ifdef USE_LCD
  /* Clear the LCD */
  LCD_Clear(Black);

  /* Set the LCD Back Color */
  LCD_SetBackColor(Black);

  /* Set the LCD Text Color */
  LCD_SetTextColor(White);

  /* Display message on the LCD*/
  LCD_DisplayStringLine(Line0, MESSAGE1);
  LCD_DisplayStringLine(Line1, MESSAGE2);
  LCD_DisplayStringLine(Line2, MESSAGE3);
  LCD_DisplayStringLine(Line3, MESSAGE4);  
#endif

  /* SystTick configuration: an interrupt every 10ms */
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);
 
  /* Configure the Key button */ 
  //STM_EVAL_PBInit(Button_KEY, Mode_GPIO);
}
/**
  * @brief  Setup STM32 system (clocks, Ethernet, GPIO, NVIC) and STM3210C-EVAL resources.
  * @param  None
  * @retval None
  */
void System_Setup(void)
{
  RCC_ClocksTypeDef RCC_Clocks;

	
  /* Setup STM32 clock, PLL and Flash configuration) */
  SystemInit();

  /* Enable USART2 clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);


  /* Enable ETHERNET clock  */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ETH_MAC | RCC_AHBPeriph_ETH_MAC_Tx |
                        RCC_AHBPeriph_ETH_MAC_Rx, ENABLE);

  /* Enable GPIOs and ADC1 clocks */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC |
                         RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO |
						 RCC_APB2Periph_ADC1, ENABLE);
  
  /* NVIC configuration */
  NVIC_Configuration();  

  /* ADC configuration */
  ADC_Configuration();

  /* Configure the GPIO ports */
  GPIO_Configuration();

  /* Initialize the STM3210C-EVAL's LCD */
  STM3210C_LCD_Init();

  /* Initialize STM3210C-EVAL's LEDs */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

  /* Turn on leds available on STM3210X-EVAL */
  STM_EVAL_LEDOn(LED1);
  STM_EVAL_LEDOn(LED2);
  STM_EVAL_LEDOn(LED3);
  STM_EVAL_LEDOn(LED4);

  /* Clear the LCD */
  LCD_Clear(Blue);

  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);

  /* Set the LCD Text Color */
  LCD_SetTextColor(White);

  /* Display message on the LCD*/
  LCD_DisplayStringLine(Line0, MESSAGE1);
  LCD_DisplayStringLine(Line1, MESSAGE2);
  LCD_DisplayStringLine(Line2, MESSAGE3);
  LCD_DisplayStringLine(Line3, MESSAGE4);

  /* Configure the Ethernet peripheral */
  Ethernet_Configuration();

  /* SystTick configuration: an interrupt every 10ms */
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.SYSCLK_Frequency / 100);

  /* Update the SysTick IRQ priority should be higher than the Ethernet IRQ */
  /* The Localtime should be updated during the Ethernet packets processing */
  NVIC_SetPriority (SysTick_IRQn, 1);  
  
  /* Configure the Key button */ 
  STM_EVAL_PBInit(Button_KEY, Mode_GPIO);
	

}
Exemple #13
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32xxx_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32xxx.c file
  */
  
  /* Initialize LEDs, Key Button, LCD and COM port(USART) available on
  STM3210X-EVAL board ******************************************************/
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);
    
  /* Initialize TIM6 */
  TIM6_Config();
  
  /* Initialize the LCD */
#ifdef USE_STM322xG_EVAL   
  STM322xG_LCD_Init();
#elif defined USE_STM324xG_EVAL   
  STM324xG_LCD_Init();
#elif defined USE_STM3210C_EVAL   
  STM3210C_LCD_Init();
#elif defined USE_STM32100E_EVAL
  STM32100E_LCD_Init();  
#elif defined USE_STM32L152_EVAL
  STM32L152_LCD_Init();
#elif defined USE_STM32L152D_EVAL
  STM32L152D_LCD_Init();
#endif
  
  /* Display message on STM3210X-EVAL LCD *************************************/
  /* Clear the LCD */ 
  LCD_Clear(White);  
  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  /* Set the LCD Text Color */
  LCD_SetTextColor(Yellow);
  LCD_DisplayStringLine(Line0, MESSAGE1);
  LCD_DisplayStringLine(Line1, MESSAGE2);
  LCD_DisplayStringLine(Line5, MESSAGE3);
  
  /* Configure the Push buttons in interrupt mode *****************************/
#if defined (USE_STM32100E_EVAL) || defined(USE_STM3210C_EVAL)  || defined(USE_STM322xG_EVAL ) || defined (USE_STM324xG_EVAL)
  STM_EVAL_PBInit(BUTTON_KEY, Mode_EXTI);
  STM_EVAL_PBInit(BUTTON_TAMPER, Mode_EXTI);
#elif defined (USE_STM32L152_EVAL) || defined (USE_STM32L152D_EVAL)
  STM_EVAL_PBInit(BUTTON_LEFT, Mode_EXTI);
  STM_EVAL_PBInit(BUTTON_RIGHT, Mode_EXTI);
#endif /* USE_STM32100E_EVAL || USE_STM3210C_EVAL || USE_STM322xG_EVAL || USE_STM324xG_EVAL */
  
  /* Start CPAL communication configuration ***********************************/
  /* Initialize local Reception structures */
  sRxStructure.wNumData = BufferSize;       /* Maximum Number of data to be received */
  sRxStructure.pbBuffer = tRxBuffer;        /* Common Rx buffer for all received data */
  sRxStructure.wAddr1 = OWN_ADDRESS;        /* The own board address */
  sRxStructure.wAddr2 = 0;                  /* Not needed */
  
  /* Initialize local Transmission structures */
  sTxStructure.wNumData = BufferSize;       /* Maximum Number of data to be received */
  sTxStructure.pbBuffer = (uint8_t*)tStateSignal;     /* Common Rx buffer for all received data */
  sTxStructure.wAddr1 = OWN_ADDRESS;        /* The own board address */
  sTxStructure.wAddr2 = 0;                  /* Not needed */
  
  /* Configure the device structure */
  CPAL_I2C_StructInit(&I2C_DevStructure);      /* Set all fields to default values */
  I2C_DevStructure.CPAL_Mode = CPAL_MODE_SLAVE;
#ifdef CPAL_I2C_DMA_PROGMODEL
  I2C_DevStructure.wCPAL_Options =  CPAL_OPT_NO_MEM_ADDR | CPAL_OPT_I2C_NACK_ADD;
  I2C_DevStructure.CPAL_ProgModel = CPAL_PROGMODEL_DMA;
#elif defined (CPAL_I2C_IT_PROGMODEL)
  I2C_DevStructure.wCPAL_Options =  CPAL_OPT_NO_MEM_ADDR | CPAL_OPT_I2C_NACK_ADD;
  I2C_DevStructure.CPAL_ProgModel = CPAL_PROGMODEL_INTERRUPT;
#else
 #error "Please select one of the programming model (in main.h)"
#endif
  I2C_DevStructure.pCPAL_I2C_Struct->I2C_ClockSpeed = I2C_SPEED;
  I2C_DevStructure.pCPAL_I2C_Struct->I2C_OwnAddress1 = OWN_ADDRESS;
  I2C_DevStructure.pCPAL_TransferRx = &sRxStructure;
  I2C_DevStructure.pCPAL_TransferTx = &sTxStructure;
  
  /* Initialize CPAL device with the selected parameters */
  CPAL_I2C_Init(&I2C_DevStructure);    
  
  /* Infinite loop */
  while (1)
  {
    /* Write operations ------------------------------------------------------*/
    /* Check if any action has been triggered by push buttons */
    if ((ActionState != ACTION_PENDING) && (ActionState != ACTION_NONE))
    {
      /* Check if the current CPAL device state allows write operation */
      if (((DeviceMode == SLAVE) && (LastMode == SLAVE))||\
         (((I2C_DevStructure.CPAL_State == CPAL_STATE_READY) ||\
           (I2C_DevStructure.CPAL_State == CPAL_STATE_DISABLED)) && (DeviceMode == MASTER)))
      {  
        if (LastMode == SLAVE)
        {         
          /* Set the LCD Back Color */
          LCD_SetBackColor(Red);
          /* Set the LCD Text Color */
          LCD_SetTextColor(White);
          LCD_DisplayStringLine(Line3, (uint8_t*)" MASTER MODE ACTIVE ");
          /* Set the LCD Back Color */
          LCD_SetBackColor(White);
          /* Set the LCD Text Color */
          LCD_SetTextColor(Blue);
          
          /* Disable CPAL_OPT_I2C_NACK_ADD option when switch to Master mode */
          I2C_DevStructure.wCPAL_Options &= (~CPAL_OPT_I2C_NACK_ADD);
        }
        
        LastMode = MASTER;        
        
        /* Initialize local Reception structures */
        sRxStructure.wNumData = BufferSize;
        
        /* Initialize local Transmission structures */
        sTxStructure.wNumData = BufferSize;
        
        switch (ActionState)
        {
          
        case BUTTON_KEY: 
          TransmitMode = STATE_ON;
          sTxStructure.pbBuffer = (uint8_t*)tSignal; 
          Divider = 2;
          break;
          
        case BUTTON_TAMPER:
          TransmitMode = STATE_OFF;          
          sRxStructure.pbBuffer = tRxBuffer;        
          Divider = 4;
          break;
          
        case ACTION_PERIODIC:
          if(TransmitMode == STATE_ON)
          {
            sTxStructure.pbBuffer = (uint8_t*)tStateSignal; 
          }
          break;    
          
        default:
          break;            
        } 
        
        /* Configure the device mode to master */
        I2C_DevStructure.CPAL_Mode = CPAL_MODE_MASTER;
        /* Force the CPAL state to ready (in case a read operation has been initiated) */
        I2C_DevStructure.CPAL_State = CPAL_STATE_READY;
        
        /* Prevent other actions to be performed while the current is not finished */
        ActionState = ACTION_PENDING;
        DeviceMode = MASTER;
        
        /* Configure a Timer to generate periodic interrupt: used to send state signal */
        TIM7_Config(PeriodicValue/Divider);   
        
        if(TransmitMode == STATE_ON)
        {
          /* Start writing data in master mode */
          if (CPAL_I2C_Write(&I2C_DevStructure) == CPAL_PASS)
          {
          }
        }
        else
        {
          /* Start reading data in master mode */
          if (CPAL_I2C_Read(&I2C_DevStructure) == CPAL_PASS)
          {
          }
        }
        
      }      
    }
    
    
    /* Read Operations -------------------------------------------------------*/
    if (((I2C_DevStructure.CPAL_State == CPAL_STATE_READY) || \
         (I2C_DevStructure.CPAL_State == CPAL_STATE_DISABLED)) && \
         (DeviceMode == SLAVE))
    {                  
      /* Reconfigure device for slave receiver mode */
      I2C_DevStructure.CPAL_Mode = CPAL_MODE_SLAVE;
      I2C_DevStructure.CPAL_State = CPAL_STATE_READY;
      
      if (LastMode == SLAVE)
      {        
        /* Set the LCD Back Color */
        LCD_SetBackColor(Red);
        /* Set the LCD Text Color */
        LCD_SetTextColor(White);
        LCD_DisplayStringLine(Line3, (uint8_t*)"  SLAVE MODE ACTIVE ");
        /* Set the LCD Back Color */
        LCD_SetBackColor(White);
        /* Set the LCD Text Color */
        LCD_SetTextColor(Blue);
      }
      
      /* Start waiting for data to be received in slave mode */
      if (CPAL_I2C_Listen(&I2C_DevStructure) == CPAL_PASS)
      {
        LCD_DisplayStringLine(Line9, MEASSAGE_EMPTY); 
      }
    }   
  }
}