summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2012-12-14 23:52:52 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2012-12-14 23:52:52 +0100
commitf4405ea56a5d9439dcb564711d46449451f2d326 (patch)
treedcf42bb5294dc946b54cf28c7011e1d56091d394
parent12d993a5d26a98fce5ab445be76e42de139e1294 (diff)
Temp: HS.usb_msc_hs
m---------laks0
-rw-r--r--main.cpp56
2 files changed, 37 insertions, 19 deletions
diff --git a/laks b/laks
-Subproject 8df0bd6997b6c32e93cae81438d0fe97066d909
+Subproject 4222cc7f75a4a97e34544741e18bb8c7cd0e605
diff --git a/main.cpp b/main.cpp
index e21dd84..c1fb251 100644
--- a/main.cpp
+++ b/main.cpp
@@ -12,6 +12,13 @@ static Pin sdio_pins[] = {
PC12, PD2
};
+static Pin ulpi_pins[] = {
+ // D0-7:
+ PA3, PB0, PB1, PB10, PB11, PB12, PB13, PB5,
+ // CK, STP, DIR, NXT:
+ PA5, PC0, PC2, PC3
+};
+
RBLog<64, 2> sd_rblog;
uint32_t sd_buf[512 / 4];
@@ -113,7 +120,7 @@ class SD_driver {
void enable() {
sdio.reg.POWER = 3;
sdio.reg.CLKCR = (1 << 11) | (1 << 9) | (1 << 8) | (48000000 / 400000 - 1); // 4-bit, PWRSAV, CLKEN, 400 kHz
- sdio.reg.DTIMER = 0xffffffff; // TODO: Find a sane value for this?
+ sdio.reg.DTIMER = 12000000; // TODO: Find a sane value for this?
initialize_card();
}
@@ -157,8 +164,8 @@ auto dev_desc = device_desc(0x200, 0, 0, 0, 64, 0x1234, 0x5678, 0, 0, 0, 0, 1);
auto conf_desc = configuration_desc(1, 1, 0, 0xc0, 0,
// MSC BBB
interface_desc(0, 0, 2, 0x08, 0x06, 0x50, 0,
- endpoint_desc(0x81, 0x02, 64, 0), // IN
- endpoint_desc(0x01, 0x02, 64, 0) // OUT
+ endpoint_desc(0x81, 0x02, 512, 0), // IN
+ endpoint_desc(0x01, 0x02, 512, 0) // OUT
)
);
@@ -169,7 +176,7 @@ Pin& usb_vbus = PA9;
Pin& usb_dm = PA11;
Pin& usb_dp = PA12;
-USB_otg usb(OTG_FS, dev_desc_p, conf_desc_p);
+USB_otg usb(OTG_HS, dev_desc_p, conf_desc_p);
struct CBW {
uint32_t dCBWSignature;
@@ -255,8 +262,8 @@ class USB_MSC_BBB : public USB_class_driver {
virtual void handle_set_configuration(uint8_t configuration) {
if(configuration) {
usb.register_out_handler(this, 1);
- usb.hw_conf_ep(0x01, EPType::Bulk, 64);
- usb.hw_conf_ep(0x81, EPType::Bulk, 64);
+ usb.hw_conf_ep(0x01, EPType::Bulk, 512);
+ usb.hw_conf_ep(0x81, EPType::Bulk, 512);
pending_data_in = 0;
pending_write = false;
@@ -327,10 +334,10 @@ class USB_MSC_BBB : public USB_class_driver {
void write_zero() {
uint32_t len = cbw.dCBWDataTransferLength;
- while(len > 64) {
- usb.write(1, nullbuf, 64);
+ while(len > 512) {
+ usb.write(1, nullbuf, 512);
while(!usb.ep_ready(1));
- len -= 64;
+ len -= 512;
}
usb.write(1, nullbuf, len);
@@ -344,8 +351,8 @@ class USB_MSC_BBB : public USB_class_driver {
while(num_blocks--) {
sd_driver.read_block(block++);
- for(uint32_t i = 0; i < 512; i += 64) {
- usb.write(1, sd_buf + i / 4, 64);
+ for(uint32_t i = 0; i < 512; i += 512) {
+ usb.write(1, sd_buf + i / 4, 512);
while(!usb.ep_ready(1));
}
}
@@ -362,8 +369,8 @@ class USB_MSC_BBB : public USB_class_driver {
void handle_write_block_packet() {
usb_rblog.log("Received write packet. offset=%d, block=%d", pending_write_recv, pending_write_addr);
- usb.read(1, sd_buf + pending_write_recv / 4, 64);
- pending_write_recv += 64;
+ usb.read(1, sd_buf + pending_write_recv / 4, 512);
+ pending_write_recv += 512;
if(pending_write_recv < 512) {
return;
@@ -456,6 +463,7 @@ int main() {
STK.CTRL = 0x03;
RCC.enable(RCC.GPIOA);
+ RCC.enable(RCC.GPIOB);
RCC.enable(RCC.GPIOC);
RCC.enable(RCC.GPIOD);
@@ -469,14 +477,24 @@ int main() {
sd_driver.enable();
- usb_vbus.set_mode(Pin::Input);
- usb_dm.set_mode(Pin::AF);
- usb_dm.set_af(10);
- usb_dp.set_mode(Pin::AF);
- usb_dp.set_af(10);
+ //usb_vbus.set_mode(Pin::Input);
+ //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);
+
+ for(Pin& p : ulpi_pins) {
+ p.set_mode(Pin::AF);
+ p.set_af(10);
+ p.set_speed(Pin::High);
+ }
- RCC.enable(RCC.OTGFS);
+ RCC.enable(RCC.OTGHS);
+ RCC.enable(RCC.OTGHSULPI);
+ usb.set_rxfifo_size(768);
usb.init();
while(1) {