My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

SdInfo.h 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. #include "Marlin.h"
  29. #if ENABLED(SDSUPPORT)
  30. #ifndef SdInfo_h
  31. #define SdInfo_h
  32. #include <stdint.h>
  33. // Based on the document:
  34. //
  35. // SD Specifications
  36. // Part 1
  37. // Physical Layer
  38. // Simplified Specification
  39. // Version 3.01
  40. // May 18, 2010
  41. //
  42. // http://www.sdcard.org/developers/tech/sdcard/pls/simplified_specs
  43. //------------------------------------------------------------------------------
  44. // SD card commands
  45. /** GO_IDLE_STATE - init card in spi mode if CS low */
  46. uint8_t const CMD0 = 0X00;
  47. /** SEND_IF_COND - verify SD Memory Card interface operating condition.*/
  48. uint8_t const CMD8 = 0X08;
  49. /** SEND_CSD - read the Card Specific Data (CSD register) */
  50. uint8_t const CMD9 = 0X09;
  51. /** SEND_CID - read the card identification information (CID register) */
  52. uint8_t const CMD10 = 0X0A;
  53. /** STOP_TRANSMISSION - end multiple block read sequence */
  54. uint8_t const CMD12 = 0X0C;
  55. /** SEND_STATUS - read the card status register */
  56. uint8_t const CMD13 = 0X0D;
  57. /** READ_SINGLE_BLOCK - read a single data block from the card */
  58. uint8_t const CMD17 = 0X11;
  59. /** READ_MULTIPLE_BLOCK - read a multiple data blocks from the card */
  60. uint8_t const CMD18 = 0X12;
  61. /** WRITE_BLOCK - write a single data block to the card */
  62. uint8_t const CMD24 = 0X18;
  63. /** WRITE_MULTIPLE_BLOCK - write blocks of data until a STOP_TRANSMISSION */
  64. uint8_t const CMD25 = 0X19;
  65. /** ERASE_WR_BLK_START - sets the address of the first block to be erased */
  66. uint8_t const CMD32 = 0X20;
  67. /** ERASE_WR_BLK_END - sets the address of the last block of the continuous
  68. range to be erased*/
  69. uint8_t const CMD33 = 0X21;
  70. /** ERASE - erase all previously selected blocks */
  71. uint8_t const CMD38 = 0X26;
  72. /** APP_CMD - escape for application specific command */
  73. uint8_t const CMD55 = 0X37;
  74. /** READ_OCR - read the OCR register of a card */
  75. uint8_t const CMD58 = 0X3A;
  76. /** SET_WR_BLK_ERASE_COUNT - Set the number of write blocks to be
  77. pre-erased before writing */
  78. uint8_t const ACMD23 = 0X17;
  79. /** SD_SEND_OP_COMD - Sends host capacity support information and
  80. activates the card's initialization process */
  81. uint8_t const ACMD41 = 0X29;
  82. //------------------------------------------------------------------------------
  83. /** status for card in the ready state */
  84. uint8_t const R1_READY_STATE = 0X00;
  85. /** status for card in the idle state */
  86. uint8_t const R1_IDLE_STATE = 0X01;
  87. /** status bit for illegal command */
  88. uint8_t const R1_ILLEGAL_COMMAND = 0X04;
  89. /** start data token for read or write single block*/
  90. uint8_t const DATA_START_BLOCK = 0XFE;
  91. /** stop token for write multiple blocks*/
  92. uint8_t const STOP_TRAN_TOKEN = 0XFD;
  93. /** start data token for write multiple blocks*/
  94. uint8_t const WRITE_MULTIPLE_TOKEN = 0XFC;
  95. /** mask for data response tokens after a write block operation */
  96. uint8_t const DATA_RES_MASK = 0X1F;
  97. /** write data accepted token */
  98. uint8_t const DATA_RES_ACCEPTED = 0X05;
  99. //------------------------------------------------------------------------------
  100. /** Card IDentification (CID) register */
  101. typedef struct CID {
  102. // byte 0
  103. /** Manufacturer ID */
  104. unsigned char mid;
  105. // byte 1-2
  106. /** OEM/Application ID */
  107. char oid[2];
  108. // byte 3-7
  109. /** Product name */
  110. char pnm[5];
  111. // byte 8
  112. /** Product revision least significant digit */
  113. unsigned char prv_m : 4;
  114. /** Product revision most significant digit */
  115. unsigned char prv_n : 4;
  116. // byte 9-12
  117. /** Product serial number */
  118. uint32_t psn;
  119. // byte 13
  120. /** Manufacturing date year low digit */
  121. unsigned char mdt_year_high : 4;
  122. /** not used */
  123. unsigned char reserved : 4;
  124. // byte 14
  125. /** Manufacturing date month */
  126. unsigned char mdt_month : 4;
  127. /** Manufacturing date year low digit */
  128. unsigned char mdt_year_low : 4;
  129. // byte 15
  130. /** not used always 1 */
  131. unsigned char always1 : 1;
  132. /** CRC7 checksum */
  133. unsigned char crc : 7;
  134. } cid_t;
  135. //------------------------------------------------------------------------------
  136. /** CSD for version 1.00 cards */
  137. typedef struct CSDV1 {
  138. // byte 0
  139. unsigned char reserved1 : 6;
  140. unsigned char csd_ver : 2;
  141. // byte 1
  142. unsigned char taac;
  143. // byte 2
  144. unsigned char nsac;
  145. // byte 3
  146. unsigned char tran_speed;
  147. // byte 4
  148. unsigned char ccc_high;
  149. // byte 5
  150. unsigned char read_bl_len : 4;
  151. unsigned char ccc_low : 4;
  152. // byte 6
  153. unsigned char c_size_high : 2;
  154. unsigned char reserved2 : 2;
  155. unsigned char dsr_imp : 1;
  156. unsigned char read_blk_misalign : 1;
  157. unsigned char write_blk_misalign : 1;
  158. unsigned char read_bl_partial : 1;
  159. // byte 7
  160. unsigned char c_size_mid;
  161. // byte 8
  162. unsigned char vdd_r_curr_max : 3;
  163. unsigned char vdd_r_curr_min : 3;
  164. unsigned char c_size_low : 2;
  165. // byte 9
  166. unsigned char c_size_mult_high : 2;
  167. unsigned char vdd_w_cur_max : 3;
  168. unsigned char vdd_w_curr_min : 3;
  169. // byte 10
  170. unsigned char sector_size_high : 6;
  171. unsigned char erase_blk_en : 1;
  172. unsigned char c_size_mult_low : 1;
  173. // byte 11
  174. unsigned char wp_grp_size : 7;
  175. unsigned char sector_size_low : 1;
  176. // byte 12
  177. unsigned char write_bl_len_high : 2;
  178. unsigned char r2w_factor : 3;
  179. unsigned char reserved3 : 2;
  180. unsigned char wp_grp_enable : 1;
  181. // byte 13
  182. unsigned char reserved4 : 5;
  183. unsigned char write_partial : 1;
  184. unsigned char write_bl_len_low : 2;
  185. // byte 14
  186. unsigned char reserved5: 2;
  187. unsigned char file_format : 2;
  188. unsigned char tmp_write_protect : 1;
  189. unsigned char perm_write_protect : 1;
  190. unsigned char copy : 1;
  191. /** Indicates the file format on the card */
  192. unsigned char file_format_grp : 1;
  193. // byte 15
  194. unsigned char always1 : 1;
  195. unsigned char crc : 7;
  196. } csd1_t;
  197. //------------------------------------------------------------------------------
  198. /** CSD for version 2.00 cards */
  199. typedef struct CSDV2 {
  200. // byte 0
  201. unsigned char reserved1 : 6;
  202. unsigned char csd_ver : 2;
  203. // byte 1
  204. /** fixed to 0X0E */
  205. unsigned char taac;
  206. // byte 2
  207. /** fixed to 0 */
  208. unsigned char nsac;
  209. // byte 3
  210. unsigned char tran_speed;
  211. // byte 4
  212. unsigned char ccc_high;
  213. // byte 5
  214. /** This field is fixed to 9h, which indicates READ_BL_LEN=512 Byte */
  215. unsigned char read_bl_len : 4;
  216. unsigned char ccc_low : 4;
  217. // byte 6
  218. /** not used */
  219. unsigned char reserved2 : 4;
  220. unsigned char dsr_imp : 1;
  221. /** fixed to 0 */
  222. unsigned char read_blk_misalign : 1;
  223. /** fixed to 0 */
  224. unsigned char write_blk_misalign : 1;
  225. /** fixed to 0 - no partial read */
  226. unsigned char read_bl_partial : 1;
  227. // byte 7
  228. /** not used */
  229. unsigned char reserved3 : 2;
  230. /** high part of card size */
  231. unsigned char c_size_high : 6;
  232. // byte 8
  233. /** middle part of card size */
  234. unsigned char c_size_mid;
  235. // byte 9
  236. /** low part of card size */
  237. unsigned char c_size_low;
  238. // byte 10
  239. /** sector size is fixed at 64 KB */
  240. unsigned char sector_size_high : 6;
  241. /** fixed to 1 - erase single is supported */
  242. unsigned char erase_blk_en : 1;
  243. /** not used */
  244. unsigned char reserved4 : 1;
  245. // byte 11
  246. unsigned char wp_grp_size : 7;
  247. /** sector size is fixed at 64 KB */
  248. unsigned char sector_size_low : 1;
  249. // byte 12
  250. /** write_bl_len fixed for 512 byte blocks */
  251. unsigned char write_bl_len_high : 2;
  252. /** fixed value of 2 */
  253. unsigned char r2w_factor : 3;
  254. /** not used */
  255. unsigned char reserved5 : 2;
  256. /** fixed value of 0 - no write protect groups */
  257. unsigned char wp_grp_enable : 1;
  258. // byte 13
  259. unsigned char reserved6 : 5;
  260. /** always zero - no partial block read*/
  261. unsigned char write_partial : 1;
  262. /** write_bl_len fixed for 512 byte blocks */
  263. unsigned char write_bl_len_low : 2;
  264. // byte 14
  265. unsigned char reserved7: 2;
  266. /** Do not use always 0 */
  267. unsigned char file_format : 2;
  268. unsigned char tmp_write_protect : 1;
  269. unsigned char perm_write_protect : 1;
  270. unsigned char copy : 1;
  271. /** Do not use always 0 */
  272. unsigned char file_format_grp : 1;
  273. // byte 15
  274. /** not used always 1 */
  275. unsigned char always1 : 1;
  276. /** checksum */
  277. unsigned char crc : 7;
  278. } csd2_t;
  279. //------------------------------------------------------------------------------
  280. /** union of old and new style CSD register */
  281. union csd_t {
  282. csd1_t v1;
  283. csd2_t v2;
  284. };
  285. #endif // SdInfo_h
  286. #endif