1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES
index dbb5843..8802fb5 100644
--- a/apps/plugins/SOURCES
+++ b/apps/plugins/SOURCES
@@ -244,3 +244,4 @@ test_touchscreen.c
 #endif
 test_viewports.c
 #endif
+test_disk.c
diff --git a/apps/plugins/test_disk.c b/apps/plugins/test_disk.c
index c83fb7e..c72f5d3 100644
--- a/apps/plugins/test_disk.c
+++ b/apps/plugins/test_disk.c
@@ -142,9 +142,10 @@ static bool test_fs(void)
         log_text(text_buf, false);

         mem_fill_frnd(audiobuf + align, current);
-        if (current != rb->write(fd, audiobuf + align, current))
+        int ret = rb->write(fd, audiobuf + align, current);
+        if (current != ret)
         {
-            rb->splash(0, "write() failed.");
+            rb->splashf(0, "write() failed %d/%d", ret, current);
             rb->close(fd);
             goto error;
         }
diff --git a/firmware/target/arm/as3525/sd-as3525.c b/firmware/target/arm/as3525/sd-as3525.c
index 19914ab..a0a5c20 100644
--- a/firmware/target/arm/as3525/sd-as3525.c
+++ b/firmware/target/arm/as3525/sd-as3525.c
@@ -866,6 +866,30 @@ long sd_last_disk_activity(void)

 void sd_enable(bool on)
 {
+    if(on == sd_enabled)
+        return;
+
+    if(on)
+    {
+        MCI_CLOCK(INTERNAL_AS3525) |= MCI_CLOCK_ENABLE;
+#ifdef HAVE_HOTSWAP
+        if(card_detect_target())
+            MCI_CLOCK(SD_SLOT_AS3525) |= MCI_CLOCK_ENABLE;
+#endif
+    }
+    else
+    {
+        MCI_CLOCK(INTERNAL_AS3525) &= ~MCI_CLOCK_ENABLE;
+#ifdef HAVE_MULTIDRIVE
+        MCI_CLOCK(SD_SLOT_AS3525) &= ~MCI_CLOCK_ENABLE;
+#endif
+    }
+
+    sd_enabled = on;
+    return;
+
+#if 0   /* causes freezes */
+
 #if defined(HAVE_BUTTON_LIGHT) && defined(HAVE_MULTIDRIVE)
     extern int buttonlight_is_on;
 #endif
@@ -930,6 +954,7 @@ void sd_enable(bool on)
         CGU_PERI &= ~CGU_NAF_CLOCK_ENABLE;
         CGU_IDE &= ~(1<<6);       /* disable non AHB interface*/
     }
+#endif
 }

 tCardInfo *card_get_info_target(int card_no)