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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. // SD card commands
  42. uint8_t const CMD0 = 0x00, // GO_IDLE_STATE - init card in spi mode if CS low
  43. CMD8 = 0x08, // SEND_IF_COND - verify SD Memory Card interface operating condition
  44. CMD9 = 0x09, // SEND_CSD - read the Card Specific Data (CSD register)
  45. CMD10 = 0x0A, // SEND_CID - read the card identification information (CID register)
  46. CMD12 = 0x0C, // STOP_TRANSMISSION - end multiple block read sequence
  47. CMD13 = 0x0D, // SEND_STATUS - read the card status register
  48. CMD17 = 0x11, // READ_SINGLE_BLOCK - read a single data block from the card
  49. CMD18 = 0x12, // READ_MULTIPLE_BLOCK - read a multiple data blocks from the card
  50. CMD24 = 0x18, // WRITE_BLOCK - write a single data block to the card
  51. CMD25 = 0x19, // WRITE_MULTIPLE_BLOCK - write blocks of data until a STOP_TRANSMISSION
  52. CMD32 = 0x20, // ERASE_WR_BLK_START - sets the address of the first block to be erased
  53. CMD33 = 0x21, // ERASE_WR_BLK_END - sets the address of the last block of the continuous range to be erased
  54. CMD38 = 0x26, // ERASE - erase all previously selected blocks
  55. CMD55 = 0x37, // APP_CMD - escape for application specific command
  56. CMD58 = 0x3A, // READ_OCR - read the OCR register of a card
  57. CMD59 = 0x3B, // CRC_ON_OFF - enable or disable CRC checking
  58. ACMD23 = 0x17, // SET_WR_BLK_ERASE_COUNT - Set the number of write blocks to be pre-erased before writing
  59. ACMD41 = 0x29; // SD_SEND_OP_COMD - Sends host capacity support information and activates the card's initialization process
  60. /** status for card in the ready state */
  61. uint8_t const R1_READY_STATE = 0x00;
  62. /** status for card in the idle state */
  63. uint8_t const R1_IDLE_STATE = 0x01;
  64. /** status bit for illegal command */
  65. uint8_t const R1_ILLEGAL_COMMAND = 0x04;
  66. /** start data token for read or write single block*/
  67. uint8_t const DATA_START_BLOCK = 0xFE;
  68. /** stop token for write multiple blocks*/
  69. uint8_t const STOP_TRAN_TOKEN = 0xFD;
  70. /** start data token for write multiple blocks*/
  71. uint8_t const WRITE_MULTIPLE_TOKEN = 0xFC;
  72. /** mask for data response tokens after a write block operation */
  73. uint8_t const DATA_RES_MASK = 0x1F;
  74. /** write data accepted token */
  75. uint8_t const DATA_RES_ACCEPTED = 0x05;
  76. /** Card IDentification (CID) register */
  77. typedef struct CID {
  78. // byte 0
  79. /** Manufacturer ID */
  80. unsigned char mid;
  81. // byte 1-2
  82. /** OEM/Application ID */
  83. char oid[2];
  84. // byte 3-7
  85. /** Product name */
  86. char pnm[5];
  87. // byte 8
  88. /** Product revision least significant digit */
  89. unsigned char prv_m : 4;
  90. /** Product revision most significant digit */
  91. unsigned char prv_n : 4;
  92. // byte 9-12
  93. /** Product serial number */
  94. uint32_t psn;
  95. // byte 13
  96. /** Manufacturing date year low digit */
  97. unsigned char mdt_year_high : 4;
  98. /** not used */
  99. unsigned char reserved : 4;
  100. // byte 14
  101. /** Manufacturing date month */
  102. unsigned char mdt_month : 4;
  103. /** Manufacturing date year low digit */
  104. unsigned char mdt_year_low : 4;
  105. // byte 15
  106. /** not used always 1 */
  107. unsigned char always1 : 1;
  108. /** CRC7 checksum */
  109. unsigned char crc : 7;
  110. } cid_t;
  111. /** CSD for version 1.00 cards */
  112. typedef struct CSDV1 {
  113. // byte 0
  114. unsigned char reserved1 : 6;
  115. unsigned char csd_ver : 2;
  116. // byte 1
  117. unsigned char taac;
  118. // byte 2
  119. unsigned char nsac;
  120. // byte 3
  121. unsigned char tran_speed;
  122. // byte 4
  123. unsigned char ccc_high;
  124. // byte 5
  125. unsigned char read_bl_len : 4;
  126. unsigned char ccc_low : 4;
  127. // byte 6
  128. unsigned char c_size_high : 2;
  129. unsigned char reserved2 : 2;
  130. unsigned char dsr_imp : 1;
  131. unsigned char read_blk_misalign : 1;
  132. unsigned char write_blk_misalign : 1;
  133. unsigned char read_bl_partial : 1;
  134. // byte 7
  135. unsigned char c_size_mid;
  136. // byte 8
  137. unsigned char vdd_r_curr_max : 3;
  138. unsigned char vdd_r_curr_min : 3;
  139. unsigned char c_size_low : 2;
  140. // byte 9
  141. unsigned char c_size_mult_high : 2;
  142. unsigned char vdd_w_cur_max : 3;
  143. unsigned char vdd_w_curr_min : 3;
  144. // byte 10
  145. unsigned char sector_size_high : 6;
  146. unsigned char erase_blk_en : 1;
  147. unsigned char c_size_mult_low : 1;
  148. // byte 11
  149. unsigned char wp_grp_size : 7;
  150. unsigned char sector_size_low : 1;
  151. // byte 12
  152. unsigned char write_bl_len_high : 2;
  153. unsigned char r2w_factor : 3;
  154. unsigned char reserved3 : 2;
  155. unsigned char wp_grp_enable : 1;
  156. // byte 13
  157. unsigned char reserved4 : 5;
  158. unsigned char write_partial : 1;
  159. unsigned char write_bl_len_low : 2;
  160. // byte 14
  161. unsigned char reserved5: 2;
  162. unsigned char file_format : 2;
  163. unsigned char tmp_write_protect : 1;
  164. unsigned char perm_write_protect : 1;
  165. unsigned char copy : 1;
  166. /** Indicates the file format on the card */
  167. unsigned char file_format_grp : 1;
  168. // byte 15
  169. unsigned char always1 : 1;
  170. unsigned char crc : 7;
  171. } csd1_t;
  172. /** CSD for version 2.00 cards */
  173. typedef struct CSDV2 {
  174. // byte 0
  175. unsigned char reserved1 : 6;
  176. unsigned char csd_ver : 2;
  177. // byte 1
  178. /** fixed to 0x0E */
  179. unsigned char taac;
  180. // byte 2
  181. /** fixed to 0 */
  182. unsigned char nsac;
  183. // byte 3
  184. unsigned char tran_speed;
  185. // byte 4
  186. unsigned char ccc_high;
  187. // byte 5
  188. /** This field is fixed to 9h, which indicates READ_BL_LEN=512 Byte */
  189. unsigned char read_bl_len : 4;
  190. unsigned char ccc_low : 4;
  191. // byte 6
  192. /** not used */
  193. unsigned char reserved2 : 4;
  194. unsigned char dsr_imp : 1;
  195. /** fixed to 0 */
  196. unsigned char read_blk_misalign : 1;
  197. /** fixed to 0 */
  198. unsigned char write_blk_misalign : 1;
  199. /** fixed to 0 - no partial read */
  200. unsigned char read_bl_partial : 1;
  201. // byte 7
  202. /** not used */
  203. unsigned char reserved3 : 2;
  204. /** high part of card size */
  205. unsigned char c_size_high : 6;
  206. // byte 8
  207. /** middle part of card size */
  208. unsigned char c_size_mid;
  209. // byte 9
  210. /** low part of card size */
  211. unsigned char c_size_low;
  212. // byte 10
  213. /** sector size is fixed at 64 KB */
  214. unsigned char sector_size_high : 6;
  215. /** fixed to 1 - erase single is supported */
  216. unsigned char erase_blk_en : 1;
  217. /** not used */
  218. unsigned char reserved4 : 1;
  219. // byte 11
  220. unsigned char wp_grp_size : 7;
  221. /** sector size is fixed at 64 KB */
  222. unsigned char sector_size_low : 1;
  223. // byte 12
  224. /** write_bl_len fixed for 512 byte blocks */
  225. unsigned char write_bl_len_high : 2;
  226. /** fixed value of 2 */
  227. unsigned char r2w_factor : 3;
  228. /** not used */
  229. unsigned char reserved5 : 2;
  230. /** fixed value of 0 - no write protect groups */
  231. unsigned char wp_grp_enable : 1;
  232. // byte 13
  233. unsigned char reserved6 : 5;
  234. /** always zero - no partial block read*/
  235. unsigned char write_partial : 1;
  236. /** write_bl_len fixed for 512 byte blocks */
  237. unsigned char write_bl_len_low : 2;
  238. // byte 14
  239. unsigned char reserved7: 2;
  240. /** Do not use always 0 */
  241. unsigned char file_format : 2;
  242. unsigned char tmp_write_protect : 1;
  243. unsigned char perm_write_protect : 1;
  244. unsigned char copy : 1;
  245. /** Do not use always 0 */
  246. unsigned char file_format_grp : 1;
  247. // byte 15
  248. /** not used always 1 */
  249. unsigned char always1 : 1;
  250. /** checksum */
  251. unsigned char crc : 7;
  252. } csd2_t;
  253. /** union of old and new style CSD register */
  254. union csd_t {
  255. csd1_t v1;
  256. csd2_t v2;
  257. };
  258. #endif // _SDINFO_H_