document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /**
  2.  *    USB VCP for STM32F4xx example.
  3.  *    
  4.  *    @author     Tilen Majerle
  5.  *    @email        tilen@majerle.eu
  6.  *    @website    http://stm32f4-discovery.com
  7.  *    @ide        Keil uVision
  8.  *
  9.  * Add line below to use this example with F429 Discovery board (in defines.h file)
  10.  *
  11.  * #define USE_USB_OTG_HS
  12.  */
  13. #include <stm32f4xx.h>
  14. #include <stm32f4xx_rcc.h>
  15. #include <stm32f4xx_gpio.h>
  16. #include "stm32f4xx_conf.h"
  17. #include "tm_stm32f4_usb_vcp.h"
  18. #include "tm_stm32f4_disco.h"
  19. #include ".\\defines.h"
  20. /* Activate USB HS in FS mode */
  21. #define USE_USB_OTG_HS
  22.  
  23.  // Init system clock
  24. void SystemInit(void)
  25. {
  26.     // ...
  27. }
  28.  
  29.  
  30.  
  31. int main(void) {
  32.     uint8_t c;
  33.     /* System Init */
  34.     SystemInit();
  35.    
  36.     /* Initialize LED\'s. Make sure to check settings for your board in tm_stm32f4_disco.h file */
  37.     TM_DISCO_LedInit();
  38.     TM_DISCO_LedOn(LED_GREEN); // The IO system was loaded OK
  39.    
  40.     /* Initialize USB VCP */    
  41.     TM_USB_VCP_Init();
  42.    
  43.    
  44.     while (1) {
  45.          if (TM_USB_VCP_GetStatus() == TM_USB_VCP_NOT_CONNECTED) {
  46.               TM_DISCO_LedOn(LED_BLUE);
  47.          } else {
  48.               TM_DISCO_LedOff(LED_BLUE);
  49.              }
  50.  
  51.             /* USB configured OK, drivers OK */
  52.         if (TM_USB_VCP_GetStatus() == TM_USB_VCP_CONNECTED) {
  53.             /* Turn on GREEN led */
  54.             TM_DISCO_LedOn(LED_GREEN);
  55.             TM_DISCO_LedOff(LED_RED);
  56.             /* If something arrived at VCP */
  57.             if (TM_USB_VCP_Getc(&c) == TM_USB_VCP_DATA_OK) {
  58.                 /* Return data back */
  59.                 TM_USB_VCP_Putc(c);
  60.             }
  61.         } else {
  62.             /* USB not OK */
  63.             TM_DISCO_LedOff(LED_GREEN);
  64.             TM_DISCO_LedOn(LED_RED);
  65.         }
  66.     }
  67. }
');