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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  5. * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
  6. * Copyright (c) 2017 Victor Perez
  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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include "../../inc/MarlinConfig.h" // Allow pins/pins.h to override SDIO clock / retries
  24. #include <libmaple/sdio.h>
  25. #include <libmaple/dma.h>
  26. // ------------------------
  27. // Defines
  28. // ------------------------
  29. #define SDMMC_CMD_GO_IDLE_STATE ((uint8_t)0) /* Resets the SD memory card. */
  30. #define SDMMC_CMD_ALL_SEND_CID ((uint8_t)2) /* Asks any card connected to the host to send the CID numbers on the CMD line. */
  31. #define SDMMC_CMD_SET_REL_ADDR ((uint8_t)3) /* Asks the card to publish a new relative address (RCA). */
  32. #define SDMMC_CMD_SEL_DESEL_CARD ((uint8_t)7) /* Selects the card by its own relative address and gets deselected by any other address */
  33. #define SDMMC_CMD_HS_SEND_EXT_CSD ((uint8_t)8) /* Sends SD Memory Card interface condition, which includes host supply voltage information and asks the card whether card supports voltage. */
  34. #define SDMMC_CMD_SEND_CSD ((uint8_t)9) /* Addressed card sends its card specific data (CSD) on the CMD line. */
  35. #define SDMMC_CMD_SEND_STATUS ((uint8_t)13) /*!< Addressed card sends its status register. */
  36. #define SDMMC_CMD_READ_SINGLE_BLOCK ((uint8_t)17) /* Reads single block of size selected by SET_BLOCKLEN in case of SDSC, and a block of fixed 512 bytes in case of SDHC and SDXC. */
  37. #define SDMMC_CMD_WRITE_SINGLE_BLOCK ((uint8_t)24) /* Writes single block of size selected by SET_BLOCKLEN in case of SDSC, and a block of fixed 512 bytes in case of SDHC and SDXC. */
  38. #define SDMMC_CMD_APP_CMD ((uint8_t)55) /* Indicates to the card that the next command is an application specific command rather than a standard command. */
  39. #define SDMMC_ACMD_APP_SD_SET_BUSWIDTH ((uint8_t)6) /* (ACMD6) Defines the data bus width to be used for data transfer. The allowed data bus widths are given in SCR register. */
  40. #define SDMMC_ACMD_SD_APP_OP_COND ((uint8_t)41) /* (ACMD41) Sends host capacity support information (HCS) and asks the accessed card to send its operating condition register (OCR) content in the response on the CMD line. */
  41. #define SDMMC_ACMD_SD_APP_SET_CLR_CARD_DETECT ((uint8_t)42) /* (ACMD42) Connect/Disconnect the 50 KOhm pull-up resistor on CD/DAT3 (pin 1) of the card */
  42. #define CMD0_GO_IDLE_STATE (uint16_t)(SDMMC_CMD_GO_IDLE_STATE | SDIO_CMD_WAIT_NO_RESP)
  43. #define CMD2_ALL_SEND_CID (uint16_t)(SDMMC_CMD_ALL_SEND_CID | SDIO_CMD_WAIT_LONG_RESP)
  44. #define CMD3_SET_REL_ADDR (uint16_t)(SDMMC_CMD_SET_REL_ADDR | SDIO_CMD_WAIT_SHORT_RESP)
  45. #define CMD7_SEL_DESEL_CARD (uint16_t)(SDMMC_CMD_SEL_DESEL_CARD | SDIO_CMD_WAIT_SHORT_RESP)
  46. #define CMD8_HS_SEND_EXT_CSD (uint16_t)(SDMMC_CMD_HS_SEND_EXT_CSD | SDIO_CMD_WAIT_SHORT_RESP)
  47. #define CMD9_SEND_CSD (uint16_t)(SDMMC_CMD_SEND_CSD | SDIO_CMD_WAIT_LONG_RESP)
  48. #define CMD13_SEND_STATUS (uint16_t)(SDMMC_CMD_SEND_STATUS | SDIO_CMD_WAIT_SHORT_RESP)
  49. #define CMD17_READ_SINGLE_BLOCK (uint16_t)(SDMMC_CMD_READ_SINGLE_BLOCK | SDIO_CMD_WAIT_SHORT_RESP)
  50. #define CMD24_WRITE_SINGLE_BLOCK (uint16_t)(SDMMC_CMD_WRITE_SINGLE_BLOCK | SDIO_CMD_WAIT_SHORT_RESP)
  51. #define CMD55_APP_CMD (uint16_t)(SDMMC_CMD_APP_CMD | SDIO_CMD_WAIT_SHORT_RESP)
  52. #define ACMD6_APP_SD_SET_BUSWIDTH (uint16_t)(SDMMC_ACMD_APP_SD_SET_BUSWIDTH | SDIO_CMD_WAIT_SHORT_RESP)
  53. #define ACMD41_SD_APP_OP_COND (uint16_t)(SDMMC_ACMD_SD_APP_OP_COND | SDIO_CMD_WAIT_SHORT_RESP)
  54. #define ACMD42_SD_APP_SET_CLR_CARD_DETECT (uint16_t)(SDMMC_ACMD_SD_APP_SET_CLR_CARD_DETECT | SDIO_CMD_WAIT_SHORT_RESP)
  55. #define SDMMC_ALLZERO 0x00000000U
  56. #define SDMMC_OCR_ERRORBITS 0xFDFFE008U
  57. #define SDMMC_R6_GENERAL_UNKNOWN_ERROR 0x00002000U
  58. #define SDMMC_R6_ILLEGAL_CMD 0x00004000U
  59. #define SDMMC_R6_COM_CRC_FAILED 0x00008000U
  60. #define SDMMC_VOLTAGE_WINDOW_SD 0x80100000U
  61. #define SDMMC_HIGH_CAPACITY 0x40000000U
  62. #define SDMMC_STD_CAPACITY 0x00000000U
  63. #define SDMMC_CHECK_PATTERN 0x000001AAU
  64. #define SDIO_TRANSFER_MODE_BLOCK 0x00000000U
  65. #define SDIO_DPSM_ENABLE 0x00000001U
  66. #define SDIO_TRANSFER_DIR_TO_CARD 0x00000000U
  67. #define SDIO_DATABLOCK_SIZE_512B 0x00000090U
  68. #define SDIO_TRANSFER_DIR_TO_SDIO 0x00000100U
  69. #define SDIO_DMA_ENABLE 0x00001000U
  70. #define CARD_V1_X 0x00000000U
  71. #define CARD_V2_X 0x00000001U
  72. #define CARD_SDSC 0x00000000U
  73. #define CARD_SDHC_SDXC 0x00000001U
  74. #define SDIO_RESP1 0
  75. #define SDIO_RESP2 1
  76. #define SDIO_RESP3 2
  77. #define SDIO_RESP4 3
  78. #define SDIO_GET_FLAG(__FLAG__) !!((SDIO->STA) & (__FLAG__))
  79. #define SDIO_CLEAR_FLAG(__FLAG__) (SDIO->ICR = (__FLAG__))
  80. #define SDMMC_MAX_VOLT_TRIAL 0x00000FFFU
  81. #define SDIO_CARD_TRANSFER 0x00000004U /* Card is in transfer state */
  82. #define SDIO_CARD_ERROR 0x000000FFU /* Card response Error */
  83. #define SDIO_CMDTIMEOUT 200U /* Command send and response timeout */
  84. #define SDIO_DATA_TIMEOUT 100U /* Read data transfer timeout */
  85. #define SDIO_WRITE_TIMEOUT 200U /* Write data transfer timeout */
  86. #ifndef SDIO_CLOCK
  87. #define SDIO_CLOCK 18000000 /* 18 MHz */
  88. #endif
  89. #ifndef SDIO_READ_RETRIES
  90. #define SDIO_READ_RETRIES 3
  91. #endif
  92. // ------------------------
  93. // Types
  94. // ------------------------
  95. typedef struct {
  96. uint32_t CardType; // Card Type
  97. uint32_t CardVersion; // Card version
  98. uint32_t Class; // Class of the card class
  99. uint32_t RelCardAdd; // Relative Card Address
  100. uint32_t BlockNbr; // Card Capacity in blocks
  101. uint32_t BlockSize; // One block size in bytes
  102. uint32_t LogBlockNbr; // Card logical Capacity in blocks
  103. uint32_t LogBlockSize; // Logical block size in bytes
  104. } SDIO_CardInfoTypeDef;
  105. // ------------------------
  106. // Public functions
  107. // ------------------------
  108. inline uint32_t SDIO_GetCardState();
  109. bool SDIO_CmdGoIdleState();
  110. bool SDIO_CmdSendCID();
  111. bool SDIO_CmdSetRelAdd(uint32_t *rca);
  112. bool SDIO_CmdSelDesel(uint32_t address);
  113. bool SDIO_CmdOperCond();
  114. bool SDIO_CmdSendCSD(uint32_t argument);
  115. bool SDIO_CmdSendStatus(uint32_t argument);
  116. bool SDIO_CmdReadSingleBlock(uint32_t address);
  117. bool SDIO_CmdWriteSingleBlock(uint32_t address);
  118. bool SDIO_CmdAppCommand(uint32_t rsa);
  119. bool SDIO_CmdAppSetBusWidth(uint32_t rsa, uint32_t argument);
  120. bool SDIO_CmdAppOperCommand(uint32_t sdType);
  121. bool SDIO_CmdAppSetClearCardDetect(uint32_t rsa);
  122. void SDIO_SendCommand(uint16_t command, uint32_t argument);
  123. uint8_t SDIO_GetCommandResponse();
  124. uint32_t SDIO_GetResponse(uint32_t response);
  125. bool SDIO_GetCmdError();
  126. bool SDIO_GetCmdResp1(uint8_t command);
  127. bool SDIO_GetCmdResp2();
  128. bool SDIO_GetCmdResp3();
  129. bool SDIO_GetCmdResp6(uint8_t command, uint32_t *rca);
  130. bool SDIO_GetCmdResp7();