From b1b3b431ac499d850a9f44b5ed104ebbcefc3c58 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Mon, 2 Apr 2012 20:24:07 +0200 Subject: Moved usb initialization to usb thread. --- main.cpp | 67 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/main.cpp b/main.cpp index ce799d9..591d99b 100644 --- a/main.cpp +++ b/main.cpp @@ -193,36 +193,6 @@ void interrupt<(Interrupt::IRQ)77>() { } void usb_main() { - while(1) { - usb_process(); - Thread::yield(); - } -} - -uint32_t usb_stack[1024]; - -Thread usb_thread(usb_stack, sizeof(usb_stack), usb_main); - -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.GPIOC); - RCC.enable(RCC.GPIOD); - - led_status.set_mode(Pin::Output); - led_status.off(); - led_error.set_mode(Pin::Output); - led_error.off(); - - jtag_tdi.set_mode(Pin::Output); - jtag_tms.set_mode(Pin::Output); - jtag_tck.set_mode(Pin::Output); - jtag_tdo.set_mode(Pin::Input); - usb_vbus.set_mode(Pin::Input); usb_dm.set_mode(Pin::AF); usb_dm.set_pull(Pin::PullNone); @@ -248,19 +218,50 @@ int main() { // USB configuration OTG_HS.reg.GUSBCFG = (1 << 30) | (0xf << 10) | (0 << 9) | (0 << 8) | (1 << 6); // FDMOD TRDT HNPCAP SRPCAP PHYSEL - + // interrupt mask OTG_HS.reg.GINTMSK = (1 << 13) | (1 << 12) | (1 << 11) | (1 << 10) | (1 << 3) | (1 << 2) | (1 << 1) | (1 << 4); // ENUMDNEM USBRST USBSUSPM ESUSPM SOFM OTGINT MMISM - + // device configuration OTG_HS.dev_reg.DCFG = (1 << 2) | 3; // NZLSOHSK DSPD - + // core configuration OTG_HS.reg.GCCFG = (1 << 19) | (1 << 16); // VBUSBSEN PWRDWN + + while(1) { + usb_process(); + Thread::yield(); + } +} + +uint32_t usb_stack[1024]; + +Thread usb_thread(usb_stack, sizeof(usb_stack), usb_main); + +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.GPIOC); + RCC.enable(RCC.GPIOD); + + led_status.set_mode(Pin::Output); + led_status.off(); + led_error.set_mode(Pin::Output); + led_error.off(); + + jtag_tdi.set_mode(Pin::Output); + jtag_tms.set_mode(Pin::Output); + jtag_tck.set_mode(Pin::Output); + jtag_tdo.set_mode(Pin::Input); + RCC.enable(RCC.I2C2); I2C2.enable(i2c_scl, i2c_sda); -- cgit v1.2.3