summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2012-03-25 01:44:07 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2012-03-25 03:42:29 +0200
commit0d9b1a8d77ef83080d56959c9369a75859bc7289 (patch)
tree316b30f5d9d6cea21386a0c67eeb70edd6b538c5
parent521e8dfbb0fdf9d65c0732c03a9d367c1e248fff (diff)
Ported to suzumebachi r3 board.
-rw-r--r--hal/interrupt.cpp12
-rw-r--r--hal/usb.h1
-rw-r--r--main.cpp111
3 files changed, 66 insertions, 58 deletions
diff --git a/hal/interrupt.cpp b/hal/interrupt.cpp
index ab9c89a..cebfed7 100644
--- a/hal/interrupt.cpp
+++ b/hal/interrupt.cpp
@@ -173,5 +173,15 @@ vector_t vectors[] __attribute__((section(".vectors"))) = {
0, // 64
0, // 65
0, // 66
- interrupt<(Interrupt::IRQ)67>, // 67
+ 0, // 67
+ 0, // 68
+ 0, // 69
+ 0, // 70
+ 0, // 71
+ 0, // 72
+ 0, // 73
+ 0, // 74
+ 0, // 75
+ 0, // 76
+ interrupt<(Interrupt::IRQ)77>, // 77
};
diff --git a/hal/usb.h b/hal/usb.h
index 5acb721..8376727 100644
--- a/hal/usb.h
+++ b/hal/usb.h
@@ -82,6 +82,7 @@ class USB_t {
#elif defined(STM32F4)
static USB_t OTG_FS(0x50000000);
+static USB_t OTG_HS(0x40040000);
#endif
#endif
diff --git a/main.cpp b/main.cpp
index 47c14e2..59fa5bf 100644
--- a/main.cpp
+++ b/main.cpp
@@ -8,14 +8,12 @@
#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& led_status = PA4;
+static Pin& led_error = PC4;
-static Pin& usb_dm = PA11;
-static Pin& usb_dp = PA12;
-static Pin& usb_vbus = PA9;
+static Pin& usb_vbus = PB13;
+static Pin& usb_dm = PB14;
+static Pin& usb_dp = PB15;
static Pin& jtag_tdo = PC3;
static Pin& jtag_tms = PC13;
@@ -38,15 +36,15 @@ bool jtag_tick(bool tdi, bool tms) {
}
void usb_write(uint32_t* bufp, uint32_t len) {
- OTG_FS.dev_iep_reg[0].DIEPTSIZ = (1 << 19) | len;
+ OTG_HS.dev_iep_reg[0].DIEPTSIZ = (1 << 19) | len;
// PKTCNT
- OTG_FS.dev_iep_reg[0].DIEPCTL |= (1 << 31) | (1 << 26);
+ OTG_HS.dev_iep_reg[0].DIEPCTL |= (1 << 31) | (1 << 26);
// EPENA CNAK
len = (len + 3) >> 2;
while(len--) {
- OTG_FS.fifo = *bufp++;
+ OTG_HS.fifo = *bufp++;
}
}
@@ -67,7 +65,7 @@ bool get_descriptor(uint16_t wValue, uint16_t wIndex, uint16_t wLength) {
}
bool set_address(uint16_t wValue, uint16_t wIndex, uint16_t wLength) {
- OTG_FS.dev_reg.DCFG |= wValue << 4;
+ OTG_HS.dev_reg.DCFG |= wValue << 4;
usb_write(0, 0);
return true;
}
@@ -90,7 +88,7 @@ bool jtag_shift(uint16_t wValue, uint16_t wIndex, uint16_t wLength) {
}
void handle_setup(const uint32_t* bufp) {
- led_red.toggle();
+ led_error.toggle();
uint8_t bmRequestType = bufp[0] & 0xff;
uint8_t bRequest = (bufp[0] >> 8) & 0xff;
@@ -119,57 +117,57 @@ void handle_setup(const uint32_t* bufp) {
}
}
- OTG_FS.dev_iep_reg[0].DIEPCTL |= (1 << 21);
+ OTG_HS.dev_iep_reg[0].DIEPCTL |= (1 << 21);
}
static uint32_t buf[16];
void handle_rxfifo() {
- uint32_t status = OTG_FS.reg.GRXSTSP;
+ uint32_t status = OTG_HS.reg.GRXSTSP;
uint32_t len = (status & 0x7ff0) >> 6;
for(uint32_t i = 0; i < len; i++) {
- buf[i] = OTG_FS.fifo;
+ buf[i] = OTG_HS.fifo;
}
//if(status == 0x000c0080) {
if((status & (0xf << 17)) == (0x4 << 17)) {
handle_setup(buf);
- OTG_FS.dev_oep_reg[0].DOEPCTL |= (1 << 26);
+ OTG_HS.dev_oep_reg[0].DOEPCTL |= (1 << 26);
}
}
template<>
-void interrupt<(Interrupt::IRQ)67>() {
- //led_red.toggle();
+void interrupt<(Interrupt::IRQ)77>() {
+ led_status.toggle();
// USB reset.
- if(OTG_FS.reg.GINTSTS & (1 << 12)) {
- led_yellow.toggle();
- OTG_FS.dev_oep_reg[0].DOEPCTL = (1 << 27);
- OTG_FS.dev_reg.DAINTMSK = (1 << 16) | 1;
- OTG_FS.dev_reg.DOEPMSK = (1 << 3) | 1;
- OTG_FS.dev_reg.DIEPEMPMSK = (1 << 3) | 1;
- OTG_FS.reg.GRXFSIZ = 256;
- OTG_FS.reg.DIEPTXF0 = (64 << 16) | 256;
- OTG_FS.dev_oep_reg[0].DOEPTSIZ = (3 << 29);
+ if(OTG_HS.reg.GINTSTS & (1 << 12)) {
+ //led_yellow.toggle();
+ OTG_HS.dev_oep_reg[0].DOEPCTL = (1 << 27);
+ OTG_HS.dev_reg.DAINTMSK = (1 << 16) | 1;
+ OTG_HS.dev_reg.DOEPMSK = (1 << 3) | 1;
+ OTG_HS.dev_reg.DIEPEMPMSK = (1 << 3) | 1;
+ OTG_HS.reg.GRXFSIZ = 256;
+ OTG_HS.reg.DIEPTXF0 = (64 << 16) | 256;
+ OTG_HS.dev_oep_reg[0].DOEPTSIZ = (3 << 29);
}
// OTG interrupt.
- if(OTG_FS.reg.GINTSTS & (1 << 2)) {
- led_blue.toggle();
+ if(OTG_HS.reg.GINTSTS & (1 << 2)) {
+ led_status.toggle();
- OTG_FS.reg.GOTGINT = (1 << 2); // SEDET
+ OTG_HS.reg.GOTGINT = (1 << 2); // SEDET
}
// RxFIFO non-empty.
- if(OTG_FS.reg.GINTSTS & (1 << 4)) {
+ if(OTG_HS.reg.GINTSTS & (1 << 4)) {
handle_rxfifo();
}
- OTG_FS.reg.GINTSTS = 0xffffffff;
+ OTG_HS.reg.GINTSTS = 0xffffffff;
}
int main() {
@@ -182,57 +180,56 @@ int main() {
RCC.enable(RCC.GPIOC);
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.off();
- led_blue.off();
- led_yellow.off();
+ 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::AF);
- usb_vbus.set_pull(Pin::PullNone);
- usb_vbus.set_af(10);
+ usb_vbus.set_mode(Pin::Input);
usb_dm.set_mode(Pin::AF);
usb_dm.set_pull(Pin::PullNone);
- usb_dm.set_af(10);
+ usb_dm.set_af(12);
usb_dp.set_mode(Pin::AF);
usb_dp.set_pull(Pin::PullNone);
- usb_dp.set_af(10);
+ usb_dp.set_af(12);
+
+ RCC.enable(RCC.OTGHS);
+ Interrupt::enable((Interrupt::IRQ)77);
+
+ // Set PHYSEL.
+ OTG_HS.reg.GUSBCFG |= (1 << 6);
- RCC.enable(RCC.OTGFS);
- Interrupt::enable((Interrupt::IRQ)67);
+ Time::sleep(10);
- OTG_FS.reg.GAHBCFG = 1;
+ while(!(OTG_HS.reg.GRSTCTL & (1 << 31)));
+ OTG_HS.reg.GRSTCTL |= 1;
+ while(OTG_HS.reg.GRSTCTL & 1);
- //OTG_FS.reg.GRSTCTL |= 1;
- //while(OTG_FS.reg.GRSTCTL & 1);
- //Time::sleep(10);
+ OTG_HS.reg.GAHBCFG = 1;
// USB configuration
- OTG_FS.reg.GUSBCFG = (1 << 30) | (0xf << 10) | (0 << 9) | (0 << 8);
- // FDMOD TRDT HNPCAP SRPCAP
+ OTG_HS.reg.GUSBCFG = (1 << 30) | (0xf << 10) | (0 << 9) | (0 << 8) | (1 << 6);
+ // FDMOD TRDT HNPCAP SRPCAP PHYSEL
// interrupt mask
- OTG_FS.reg.GINTMSK = (1 << 13) | (1 << 12) | (1 << 11) | (1 << 10) | (1 << 3) | (1 << 2) | (1 << 1) | (1 << 4);
+ 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_FS.dev_reg.DCFG = (1 << 2) | 3;
+ OTG_HS.dev_reg.DCFG = (1 << 2) | 3;
// NZLSOHSK DSPD
// core configuration
- OTG_FS.reg.GCCFG = (1 << 19) | (1 << 16);
+ OTG_HS.reg.GCCFG = (1 << 19) | (1 << 16);
// VBUSBSEN PWRDWN
while(1) {
- led_green.toggle();
+ led_error.toggle();
Time::sleep(100);
}
}