1 /*---------------------------------------------------------------------------*\ 2 3 FILE........: stm32f4_usb_vcp.c 4 AUTHOR......: xenovacivus 5 DATE CREATED: 3 Sep 2014 6 7 USB Virtual COM Port (VCP) module adapted from code I found here: 8 9 https://github.com/xenovacivus/STM32DiscoveryVCP 10 11 \*---------------------------------------------------------------------------*/ 12 13 #include "stm32f4xx_conf.h" 14 #include "stm32f4xx.h" 15 #include "stm32f4xx_gpio.h" 16 #include "stm32f4xx_rcc.h" 17 #include "stm32f4xx_exti.h" 18 #include "usbd_cdc_core.h" 19 #include "usbd_usr.h" 20 #include "usbd_desc.h" 21 #include "usbd_cdc_vcp.h" 22 #include "usb_dcd_int.h" 23 #include "sm1000_leds_switches.h" 24 #include "stm32f4_usb_vcp.h" 25 26 /* 27 * The USB data must be 4 byte aligned if DMA is enabled. This macro handles 28 * the alignment, if necessary (it's actually magic, but don't tell anyone). 29 */ 30 __ALIGN_BEGIN USB_OTG_CORE_HANDLE USB_OTG_dev __ALIGN_END; 31 32 33 /* 34 * Define prototypes for interrupt handlers here. The conditional "extern" 35 * ensures the weak declarations from startup_stm32f4xx.c are overridden. 36 */ 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 void NMI_Handler(void); 42 void HardFault_Handler(void); 43 void MemManage_Handler(void); 44 void BusFault_Handler(void); 45 void UsageFault_Handler(void); 46 void SVC_Handler(void); 47 void DebugMon_Handler(void); 48 void PendSV_Handler(void); 49 void OTG_FS_IRQHandler(void); 50 void OTG_FS_WKUP_IRQHandler(void); 51 52 #ifdef __cplusplus 53 } 54 #endif 55 56 usb_vcp_init()57void usb_vcp_init() { 58 /* Setup USB */ 59 USBD_Init(&USB_OTG_dev, 60 USB_OTG_FS_CORE_ID, 61 &USR_desc, 62 &USBD_CDC_cb, 63 &USR_cb); 64 } 65 66 67 /* 68 * Interrupt Handlers 69 */ 70 NMI_Handler(void)71void NMI_Handler(void) {} SVC_Handler(void)72void SVC_Handler(void) {} DebugMon_Handler(void)73void DebugMon_Handler(void) {} PendSV_Handler(void)74void PendSV_Handler(void) {} 75 OTG_FS_IRQHandler(void)76void OTG_FS_IRQHandler(void) 77 { 78 USBD_OTG_ISR_Handler (&USB_OTG_dev); 79 } 80 OTG_FS_WKUP_IRQHandler(void)81void OTG_FS_WKUP_IRQHandler(void) 82 { 83 if(USB_OTG_dev.cfg.low_power) 84 { 85 *(uint32_t *)(0xE000ED10) &= 0xFFFFFFF9 ; 86 SystemInit(); 87 USB_OTG_UngateClock(&USB_OTG_dev); 88 } 89 EXTI_ClearITPendingBit(EXTI_Line18); 90 } 91