My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SdInfo.h 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * Arduino Sd2Card Library
  24. * Copyright (C) 2009 by William Greiman
  25. *
  26. * This file is part of the Arduino Sd2Card Library
  27. */
  28. #ifndef SDINFO_H
  29. #define SDINFO_H
  30. #include <stdint.h>
  31. // Based on the document:
  32. //
  33. // SD Specifications
  34. // Part 1
  35. // Physical Layer
  36. // Simplified Specification
  37. // Version 3.01
  38. // May 18, 2010
  39. //
  40. // http://www.sdcard.org/developers/tech/sdcard/pls/simplified_specs
  41. //------------------------------------------------------------------------------
  42. // SD card commands
  43. /** GO_IDLE_STATE - init card in spi mode if CS low */
  44. uint8_t const CMD0 = 0x00;
  45. /** SEND_IF_COND - verify SD Memory Card interface operating condition.*/
  46. uint8_t const CMD8 = 0x08;
  47. /** SEND_CSD - read the Card Specific Data (CSD register) */
  48. uint8_t const CMD9 = 0x09;
  49. /** SEND_CID - read the card identification information (CID register) */
  50. uint8_t const CMD10 = 0x0A;
  51. /** STOP_TRANSMISSION - end multiple block read sequence */
  52. uint8_t const CMD12 = 0x0C;
  53. /** SEND_STATUS - read the card status register */
  54. uint8_t const CMD13 = 0x0D;
  55. /** READ_SINGLE_BLOCK - read a single data block from the card */
  56. uint8_t const CMD17 = 0x11;
  57. /** READ_MULTIPLE_BLOCK - read a multiple data blocks from the card */
  58. uint8_t const CMD18 = 0x12;
  59. /** WRITE_BLOCK - write a single data block to the card */
  60. uint8_t const CMD24 = 0x18;
  61. /** WRITE_MULTIPLE_BLOCK - write blocks of data until a STOP_TRANSMISSION */
  62. uint8_t const CMD25 = 0x19;
  63. /** ERASE_WR_BLK_START - sets the address of the first block to be erased */
  64. uint8_t const CMD32 = 0x20;
  65. /** ERASE_WR_BLK_END - sets the address of the last block of the continuous
  66. range to be erased*/
  67. uint8_t const CMD33 = 0x21;
  68. /** ERASE - erase all previously selected blocks */
  69. uint8_t const CMD38 = 0x26;
  70. /** APP_CMD - escape for application specific command */
  71. uint8_t const CMD55 = 0x37;
  72. /** READ_OCR - read the OCR register of a card */
  73. uint8_t const CMD58 = 0x3A;
  74. /** SET_WR_BLK_ERASE_COUNT - Set the number of write blocks to be
  75. pre-erased before writing */
  76. uint8_t const ACMD23 = 0x17;
  77. /** SD_SEND_OP_COMD - Sends host capacity support information and
  78. activates the card's initialization process */
  79. uint8_t const ACMD41 = 0x29;
  80. //------------------------------------------------------------------------------
  81. /** status for card in the ready state */
  82. uint8_t const R1_READY_STATE = 0x00;
  83. /** status for card in the idle state */
  84. uint8_t const R1_IDLE_STATE = 0x01;
  85. /** status bit for illegal command */
  86. uint8_t const R1_ILLEGAL_COMMAND = 0x04;
  87. /** start data token for read or write single block*/
  88. uint8_t const DATA_START_BLOCK = 0xFE;
  89. /** stop token for write multiple blocks*/
  90. uint8_t const STOP_TRAN_TOKEN = 0xFD;
  91. /** start data token for write multiple blocks*/
  92. uint8_t const WRITE_MULTIPLE_TOKEN = 0xFC;
  93. /** mask for data response tokens after a write block operation */
  94. uint8_t const DATA_RES_MASK = 0x1F;
  95. /** write data accepted token */
  96. uint8_t const DATA_RES_ACCEPTED = 0x05;
  97. //------------------------------------------------------------------------------
  98. /** Card IDentification (CID) register */
  99. typedef struct CID {
  100. // byte 0
  101. /** Manufacturer ID */
  102. unsigned char mid;
  103. // byte 1-2
  104. /** OEM/Application ID */
  105. char oid[2];
  106. // byte 3-7
  107. /** Product name */
  108. char pnm[5];
  109. // byte 8
  110. /** Product revision least significant digit */
  111. unsigned char prv_m : 4;
  112. /** Product revision most significant digit */
  113. unsigned char prv_n : 4;
  114. // byte 9-12
  115. /** Product serial number */
  116. uint32_t psn;
  117. // byte 13
  118. /** Manufacturing date year low digit */
  119. unsigned char mdt_year_high : 4;
  120. /** not used */
  121. unsigned char reserved : 4;
  122. // byte 14
  123. /** Manufacturing date month */
  124. unsigned char mdt_month : 4;
  125. /** Manufacturing date year low digit */
  126. unsigned char mdt_year_low : 4;
  127. // byte 15
  128. /** not used always 1 */
  129. unsigned char always1 : 1;
  130. /** CRC7 checksum */
  131. unsigned char crc : 7;
  132. } cid_t;
  133. //------------------------------------------------------------------------------
  134. /** CSD for version 1.00 cards */
  135. typedef struct CSDV1 {
  136. // byte 0
  137. unsigned char reserved1 : 6;
  138. unsigned char csd_ver : 2;
  139. // byte 1
  140. unsigned char taac;
  141. // byte 2
  142. unsigned char nsac;
  143. // byte 3
  144. unsigned char tran_speed;
  145. // byte 4
  146. unsigned char ccc_high;
  147. // byte 5
  148. unsigned char read_bl_len : 4;
  149. unsigned char ccc_low : 4;
  150. // byte 6
  151. unsigned char c_size_high : 2;
  152. unsigned char reserved2 : 2;
  153. unsigned char dsr_imp : 1;
  154. unsigned char read_blk_misalign : 1;
  155. unsigned char write_blk_misalign : 1;
  156. unsigned char read_bl_partial : 1;
  157. // byte 7
  158. unsigned char c_size_mid;
  159. // byte 8
  160. unsigned char vdd_r_curr_max : 3;
  161. unsigned char vdd_r_curr_min : 3;
  162. unsigned char c_size_low : 2;
  163. // byte 9
  164. unsigned char c_size_mult_high : 2;
  165. unsigned char vdd_w_cur_max : 3;
  166. unsigned char vdd_w_curr_min : 3;
  167. // byte 10
  168. unsigned char sector_size_high : 6;
  169. unsigned char erase_blk_en : 1;
  170. unsigned char c_size_mult_low : 1;
  171. // byte 11
  172. unsigned char wp_grp_size : 7;
  173. unsigned char sector_size_low : 1;
  174. // byte 12
  175. unsigned char write_bl_len_high : 2;
  176. unsigned char r2w_factor : 3;
  177. unsigned char reserved3 : 2;
  178. unsigned char wp_grp_enable : 1;
  179. // byte 13
  180. unsigned char reserved4 : 5;
  181. unsigned char write_partial : 1;
  182. unsigned char write_bl_len_low : 2;
  183. // byte 14
  184. unsigned char reserved5: 2;
  185. unsigned char file_format : 2;
  186. unsigned char tmp_write_protect : 1;
  187. unsigned char perm_write_protect : 1;
  188. unsigned char copy : 1;
  189. /** Indicates the file format on the card */
  190. unsigned char file_format_grp : 1;
  191. // byte 15
  192. unsigned char always1 : 1;
  193. unsigned char crc : 7;
  194. } csd1_t;
  195. //------------------------------------------------------------------------------
  196. /** CSD for version 2.00 cards */
  197. typedef struct CSDV2 {
  198. // byte 0
  199. unsigned char reserved1 : 6;
  200. unsigned char csd_ver : 2;
  201. // byte 1
  202. /** fixed to 0x0E */
  203. unsigned char taac;
  204. // byte 2
  205. /** fixed to 0 */
  206. unsigned char nsac;
  207. // byte 3
  208. unsigned char tran_speed;
  209. // byte 4
  210. unsigned char ccc_high;
  211. // byte 5
  212. /** This field is fixed to 9h, which indicates READ_BL_LEN=512 Byte */
  213. unsigned char read_bl_len : 4;
  214. unsigned char ccc_low : 4;
  215. // byte 6
  216. /** not used */
  217. unsigned char reserved2 : 4;
  218. unsigned char dsr_imp : 1;
  219. /** fixed to 0 */
  220. unsigned char read_blk_misalign : 1;
  221. /** fixed to 0 */
  222. unsigned char write_blk_misalign : 1;
  223. /** fixed to 0 - no partial read */
  224. unsigned char read_bl_partial : 1;
  225. // byte 7
  226. /** not used */
  227. unsigned char reserved3 : 2;
  228. /** high part of card size */
  229. unsigned char c_size_high : 6;
  230. // byte 8
  231. /** middle part of card size */
  232. unsigned char c_size_mid;
  233. // byte 9
  234. /** low part of card size */
  235. unsigned char c_size_low;
  236. // byte 10
  237. /** sector size is fixed at 64 KB */
  238. unsigned char sector_size_high : 6;
  239. /** fixed to 1 - erase single is supported */
  240. unsigned char erase_blk_en : 1;
  241. /** not used */
  242. unsigned char reserved4 : 1;
  243. // byte 11
  244. unsigned char wp_grp_size : 7;
  245. /** sector size is fixed at 64 KB */
  246. unsigned char sector_size_low : 1;
  247. // byte 12
  248. /** write_bl_len fixed for 512 byte blocks */
  249. unsigned char write_bl_len_high : 2;
  250. /** fixed value of 2 */
  251. unsigned char r2w_factor : 3;
  252. /** not used */
  253. unsigned char reserved5 : 2;
  254. /** fixed value of 0 - no write protect groups */
  255. unsigned char wp_grp_enable : 1;
  256. // byte 13
  257. unsigned char reserved6 : 5;
  258. /** always zero - no partial block read*/
  259. unsigned char write_partial : 1;
  260. /** write_bl_len fixed for 512 byte blocks */
  261. unsigned char write_bl_len_low : 2;
  262. // byte 14
  263. unsigned char reserved7: 2;
  264. /** Do not use always 0 */
  265. unsigned char file_format : 2;
  266. unsigned char tmp_write_protect : 1;
  267. unsigned char perm_write_protect : 1;
  268. unsigned char copy : 1;
  269. /** Do not use always 0 */
  270. unsigned char file_format_grp : 1;
  271. // byte 15
  272. /** not used always 1 */
  273. unsigned char always1 : 1;
  274. /** checksum */
  275. unsigned char crc : 7;
  276. } csd2_t;
  277. //------------------------------------------------------------------------------
  278. /** union of old and new style CSD register */
  279. union csd_t {
  280. csd1_t v1;
  281. csd2_t v2;
  282. };
  283. #endif // SDINFO_H