|
@@ -0,0 +1,112 @@
|
|
1
|
+/**
|
|
2
|
+ * Marlin 3D Printer Firmware
|
|
3
|
+ *
|
|
4
|
+ * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
5
|
+ * Copyright (c) 2019 BigTreeTech [https://github.com/bigtreetech]
|
|
6
|
+ *
|
|
7
|
+ * This program is free software: you can redistribute it and/or modify
|
|
8
|
+ * it under the terms of the GNU General Public License as published by
|
|
9
|
+ * the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+ * (at your option) any later version.
|
|
11
|
+ *
|
|
12
|
+ * You should have received a copy of the GNU General Public License
|
|
13
|
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
14
|
+ *
|
|
15
|
+ */
|
|
16
|
+#include "../../inc/MarlinConfigPre.h"
|
|
17
|
+
|
|
18
|
+#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && HAS_SD_HOST_DRIVE
|
|
19
|
+
|
|
20
|
+#include "msc_sd.h"
|
|
21
|
+#include "../shared/Marduino.h"
|
|
22
|
+#include "usbd_core.h"
|
|
23
|
+#include <USB.h>
|
|
24
|
+#include <USBMscHandler.h>
|
|
25
|
+
|
|
26
|
+#define BLOCK_SIZE 512
|
|
27
|
+#define PRODUCT_ID 0x29
|
|
28
|
+
|
|
29
|
+#include "../../sd/cardreader.h"
|
|
30
|
+
|
|
31
|
+class Sd2CardUSBMscHandler : public USBMscHandler {
|
|
32
|
+public:
|
|
33
|
+ bool GetCapacity(uint32_t *pBlockNum, uint16_t *pBlockSize) {
|
|
34
|
+ *pBlockNum = card.getSd2Card().cardSize();
|
|
35
|
+ *pBlockSize = BLOCK_SIZE;
|
|
36
|
+ return true;
|
|
37
|
+ }
|
|
38
|
+
|
|
39
|
+ bool Write(uint8_t *pBuf, uint32_t blkAddr, uint16_t blkLen) {
|
|
40
|
+ auto sd2card = card.getSd2Card();
|
|
41
|
+ // single block
|
|
42
|
+ if (blkLen == 1) {
|
|
43
|
+ watchdog_refresh();
|
|
44
|
+ sd2card.writeBlock(blkAddr, pBuf);
|
|
45
|
+ return true;
|
|
46
|
+ }
|
|
47
|
+
|
|
48
|
+ // multi block optmization
|
|
49
|
+ sd2card.writeStart(blkAddr, blkLen);
|
|
50
|
+ while (blkLen--) {
|
|
51
|
+ watchdog_refresh();
|
|
52
|
+ sd2card.writeData(pBuf);
|
|
53
|
+ pBuf += BLOCK_SIZE;
|
|
54
|
+ }
|
|
55
|
+ sd2card.writeStop();
|
|
56
|
+ return true;
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ bool Read(uint8_t *pBuf, uint32_t blkAddr, uint16_t blkLen) {
|
|
60
|
+ auto sd2card = card.getSd2Card();
|
|
61
|
+ // single block
|
|
62
|
+ if (blkLen == 1) {
|
|
63
|
+ watchdog_refresh();
|
|
64
|
+ sd2card.readBlock(blkAddr, pBuf);
|
|
65
|
+ return true;
|
|
66
|
+ }
|
|
67
|
+
|
|
68
|
+ // multi block optmization
|
|
69
|
+ sd2card.readStart(blkAddr);
|
|
70
|
+ while (blkLen--) {
|
|
71
|
+ watchdog_refresh();
|
|
72
|
+ sd2card.readData(pBuf);
|
|
73
|
+ pBuf += BLOCK_SIZE;
|
|
74
|
+ }
|
|
75
|
+ sd2card.readStop();
|
|
76
|
+ return true;
|
|
77
|
+ }
|
|
78
|
+
|
|
79
|
+ bool IsReady() {
|
|
80
|
+ return card.isMounted();
|
|
81
|
+ }
|
|
82
|
+};
|
|
83
|
+
|
|
84
|
+Sd2CardUSBMscHandler usbMscHandler;
|
|
85
|
+
|
|
86
|
+/* USB Mass storage Standard Inquiry Data */
|
|
87
|
+uint8_t Marlin_STORAGE_Inquirydata[] = { /* 36 */
|
|
88
|
+ /* LUN 0 */
|
|
89
|
+ 0x00,
|
|
90
|
+ 0x80,
|
|
91
|
+ 0x02,
|
|
92
|
+ 0x02,
|
|
93
|
+ (STANDARD_INQUIRY_DATA_LEN - 5),
|
|
94
|
+ 0x00,
|
|
95
|
+ 0x00,
|
|
96
|
+ 0x00,
|
|
97
|
+ 'M', 'A', 'R', 'L', 'I', 'N', ' ', ' ', /* Manufacturer : 8 bytes */
|
|
98
|
+ 'P', 'r', 'o', 'd', 'u', 'c', 't', ' ', /* Product : 16 Bytes */
|
|
99
|
+ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
|
100
|
+ '0', '.', '0', '1', /* Version : 4 Bytes */
|
|
101
|
+};
|
|
102
|
+
|
|
103
|
+USBMscHandler *pSingleMscHandler = &usbMscHandler;
|
|
104
|
+
|
|
105
|
+void MSC_SD_init() {
|
|
106
|
+ USBDevice.end();
|
|
107
|
+ delay(200);
|
|
108
|
+ USBDevice.begin();
|
|
109
|
+ USBDevice.registerMscHandlers(1, &pSingleMscHandler, Marlin_STORAGE_Inquirydata);
|
|
110
|
+}
|
|
111
|
+
|
|
112
|
+#endif // __STM32F1__ && HAS_SD_HOST_DRIVE
|