#include "stm32.h" #include "rcc.h" #include "interrupt.h" #include "thread.h" #include "time.h" #include "pin.h" #include "usb.h" static Pin& led_green = PD12; static Pin& led_yellow = PD13; static Pin& led_red = PD14; static Pin& led_blue = PD15; static Pin& usb_dm = PA11; static Pin& usb_dp = PA12; static Pin& usb_vbus = PA9; template<> void interrupt<(Interrupt::IRQ)67>() { led_blue.toggle(); led_red.toggle(); OTG_FS.reg.GINTSTS = 0xffffffff; } int main() { // Initialize system timer. STK.LOAD = 168000000 / 8 / 1000; // 1000 Hz. STK.CTRL = 0x03; RCC.enable(RCC.GPIOA); RCC.enable(RCC.GPIOB); RCC.enable(RCC.GPIOD); led_green.set_mode(Pin::Output); led_yellow.set_mode(Pin::Output); led_red.set_mode(Pin::Output); led_blue.set_mode(Pin::Output); led_red.on(); led_blue.off(); usb_dm.set_mode(Pin::AF); usb_dm.set_af(10); usb_dp.set_mode(Pin::AF); usb_dp.set_af(10); RCC.enable(RCC.OTGFS); Interrupt::enable((Interrupt::IRQ)67); OTG_FS.reg.GAHBCFG = 1; // USB configuration OTG_FS.reg.GUSBCFG = (1 << 30) | (0xf << 10) | (1 << 9) | (1 << 8); // FDMOD TRDT HNPCAP SRPCAP // interrupt mask OTG_FS.reg.GINTMSK = (1 << 13) | (1 << 12) | (1 << 11) | (1 << 10) | (1 << 3) | (1 << 2) | (1 << 1); // ENUMDNEM USBRST USBSUSPM ESUSPM SOFM OTGINT MMISM // device configuration OTG_FS.dev_reg.DCFG = (1 << 2) | 3; // NZLSOHSK DSPD // core configuration OTG_FS.reg.GCCFG = (1 << 19); // VBUSBSEN while(1) { led_green.toggle(); Time::sleep(100); } }