cubemx.patch 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. diff --git b/STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_sd.c a/STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_sd.c
  2. index 4df41a0..7312d0e 100755
  3. --- b/STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_sd.c
  4. +++ a/STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_sd.c
  5. @@ -178,7 +178,6 @@
  6. /* Includes ------------------------------------------------------------------*/
  7. #include "stm32f2xx_hal.h"
  8. -
  9. #ifdef HAL_SD_MODULE_ENABLED
  10. /** @addtogroup STM32F2xx_HAL_Driver
  11. @@ -893,7 +892,7 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pRead
  12. SDIO_IT_STBITERR));
  13. /* Enable SDIO DMA transfer */
  14. - __HAL_SD_SDIO_DMA_ENABLE();
  15. + // MM disabled, as this fails on fast cards. __HAL_SD_SDIO_DMA_ENABLE();
  16. /* Configure DMA user callbacks */
  17. hsd->hdmarx->XferCpltCallback = SD_DMA_RxCplt;
  18. @@ -902,26 +901,29 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pRead
  19. /* Enable the DMA Stream */
  20. HAL_DMA_Start_IT(hsd->hdmarx, (uint32_t)&hsd->Instance->FIFO, (uint32_t)pReadBuffer, (uint32_t)(BlockSize * NumberOfBlocks)/4);
  21. + sdio_cmdinitstructure.Response = SDIO_RESPONSE_SHORT;
  22. + sdio_cmdinitstructure.WaitForInterrupt = SDIO_WAIT_NO;
  23. + sdio_cmdinitstructure.CPSM = SDIO_CPSM_ENABLE;
  24. +
  25. if (hsd->CardType == HIGH_CAPACITY_SD_CARD)
  26. {
  27. BlockSize = 512;
  28. ReadAddr /= 512;
  29. - }
  30. + } else {
  31. - /* Set Block Size for Card */
  32. - sdio_cmdinitstructure.Argument = (uint32_t)BlockSize;
  33. - sdio_cmdinitstructure.CmdIndex = SD_CMD_SET_BLOCKLEN;
  34. - sdio_cmdinitstructure.Response = SDIO_RESPONSE_SHORT;
  35. - sdio_cmdinitstructure.WaitForInterrupt = SDIO_WAIT_NO;
  36. - sdio_cmdinitstructure.CPSM = SDIO_CPSM_ENABLE;
  37. - SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
  38. + /* Set Block Size for Card */
  39. + sdio_cmdinitstructure.Argument = (uint32_t)BlockSize;
  40. + sdio_cmdinitstructure.CmdIndex = SD_CMD_SET_BLOCKLEN;
  41. +
  42. + SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
  43. - /* Check for error conditions */
  44. - errorstate = SD_CmdResp1Error(hsd, SD_CMD_SET_BLOCKLEN);
  45. + /* Check for error conditions */
  46. + errorstate = SD_CmdResp1Error(hsd, SD_CMD_SET_BLOCKLEN);
  47. - if (errorstate != SD_OK)
  48. - {
  49. - return errorstate;
  50. + if (errorstate != SD_OK)
  51. + {
  52. + return errorstate;
  53. + }
  54. }
  55. /* Configure the SD DPSM (Data Path State Machine) */
  56. @@ -931,6 +933,11 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pRead
  57. sdio_datainitstructure.TransferDir = SDIO_TRANSFER_DIR_TO_SDIO;
  58. sdio_datainitstructure.TransferMode = SDIO_TRANSFER_MODE_BLOCK;
  59. sdio_datainitstructure.DPSM = SDIO_DPSM_ENABLE;
  60. +
  61. + // We cannot enable DMA too early on UHS-I class 3 SD cards, or else the
  62. + // data is just discarded before the dpsm is started.
  63. + __HAL_SD_SDIO_DMA_ENABLE();
  64. +
  65. SDIO_DataConfig(hsd->Instance, &sdio_datainitstructure);
  66. /* Check number of blocks command */
  67. @@ -1017,28 +1024,30 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pWri
  68. HAL_DMA_Start_IT(hsd->hdmatx, (uint32_t)pWriteBuffer, (uint32_t)&hsd->Instance->FIFO, (uint32_t)(BlockSize * NumberOfBlocks)/4);
  69. /* Enable SDIO DMA transfer */
  70. - __HAL_SD_SDIO_DMA_ENABLE();
  71. + // MM disabled, as this fails on fast cards. __HAL_SD_SDIO_DMA_ENABLE();
  72. +
  73. + sdio_cmdinitstructure.Response = SDIO_RESPONSE_SHORT;
  74. + sdio_cmdinitstructure.WaitForInterrupt = SDIO_WAIT_NO;
  75. + sdio_cmdinitstructure.CPSM = SDIO_CPSM_ENABLE;
  76. if (hsd->CardType == HIGH_CAPACITY_SD_CARD)
  77. {
  78. BlockSize = 512;
  79. WriteAddr /= 512;
  80. - }
  81. + } else {
  82. + /* Set Block Size for Card */
  83. + sdio_cmdinitstructure.Argument = (uint32_t)BlockSize;
  84. + sdio_cmdinitstructure.CmdIndex = SD_CMD_SET_BLOCKLEN;
  85. - /* Set Block Size for Card */
  86. - sdio_cmdinitstructure.Argument = (uint32_t)BlockSize;
  87. - sdio_cmdinitstructure.CmdIndex = SD_CMD_SET_BLOCKLEN;
  88. - sdio_cmdinitstructure.Response = SDIO_RESPONSE_SHORT;
  89. - sdio_cmdinitstructure.WaitForInterrupt = SDIO_WAIT_NO;
  90. - sdio_cmdinitstructure.CPSM = SDIO_CPSM_ENABLE;
  91. - SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
  92. + SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
  93. - /* Check for error conditions */
  94. - errorstate = SD_CmdResp1Error(hsd, SD_CMD_SET_BLOCKLEN);
  95. + /* Check for error conditions */
  96. + errorstate = SD_CmdResp1Error(hsd, SD_CMD_SET_BLOCKLEN);
  97. - if (errorstate != SD_OK)
  98. - {
  99. - return errorstate;
  100. + if (errorstate != SD_OK)
  101. + {
  102. + return errorstate;
  103. + }
  104. }
  105. /* Check number of blocks command */
  106. @@ -1049,13 +1058,34 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pWri
  107. }
  108. else
  109. {
  110. + /* MM: Prepare for write */
  111. + sdio_cmdinitstructure.Argument = (uint32_t)(hsd->RCA << 16);
  112. + sdio_cmdinitstructure.CmdIndex = SD_CMD_APP_CMD;
  113. + SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
  114. + errorstate = SD_CmdResp1Error(hsd, SD_CMD_APP_CMD);
  115. + if (errorstate != SD_OK)
  116. + {
  117. + return errorstate;
  118. + }
  119. + sdio_cmdinitstructure.Argument = (uint32_t)NumberOfBlocks;
  120. + sdio_cmdinitstructure.CmdIndex = SD_CMD_SET_BLOCK_COUNT;
  121. + SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
  122. + errorstate = SD_CmdResp1Error(hsd, SD_CMD_SET_BLOCK_COUNT);
  123. + if (errorstate != SD_OK)
  124. + {
  125. + return errorstate;
  126. + }
  127. +
  128. + /* /MM */
  129. +
  130. /* Send CMD25 WRITE_MULT_BLOCK with argument data address */
  131. sdio_cmdinitstructure.CmdIndex = SD_CMD_WRITE_MULT_BLOCK;
  132. }
  133. -
  134. +
  135. sdio_cmdinitstructure.Argument = (uint32_t)WriteAddr;
  136. SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
  137. +
  138. /* Check for error conditions */
  139. if(NumberOfBlocks > 1)
  140. {
  141. @@ -1078,6 +1108,11 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pWri
  142. sdio_datainitstructure.TransferDir = SDIO_TRANSFER_DIR_TO_CARD;
  143. sdio_datainitstructure.TransferMode = SDIO_TRANSFER_MODE_BLOCK;
  144. sdio_datainitstructure.DPSM = SDIO_DPSM_ENABLE;
  145. +
  146. + // We cannot enable DMA too early on UHS-I class 3 SD cards, or else the
  147. + // data is just discarded before the dpsm is started.
  148. + __HAL_SD_SDIO_DMA_ENABLE();
  149. +
  150. SDIO_DataConfig(hsd->Instance, &sdio_datainitstructure);
  151. hsd->SdTransferErr = errorstate;
  152. @@ -1116,7 +1151,9 @@ HAL_SD_ErrorTypedef HAL_SD_CheckReadOperation(SD_HandleTypeDef *hsd, uint32_t Ti
  153. timeout = Timeout;
  154. - /* Wait until the Rx transfer is no longer active */
  155. + /* Wait until the Rx transfer is no longer active. IE. fifo is empty.
  156. +Once FIFO is empty, the DMA will have finished and DmaTransferCplt should
  157. +be true */
  158. while((__HAL_SD_SDIO_GET_FLAG(hsd, SDIO_FLAG_RXACT)) && (timeout > 0))
  159. {
  160. timeout--;
  161. @@ -1916,10 +1953,12 @@ HAL_SD_ErrorTypedef HAL_SD_HighSpeed (SD_HandleTypeDef *hsd)
  162. __HAL_SD_SDIO_CLEAR_FLAG(hsd, SDIO_STATIC_FLAGS);
  163. /* Test if the switch mode HS is ok */
  164. - if ((SD_hs[13]& 2) != 2)
  165. - {
  166. - errorstate = SD_UNSUPPORTED_FEATURE;
  167. - }
  168. + // MM: These bits (0 to 271) are reserved in the spec I'm looking at ???
  169. + // Should be safe to ignore the result.
  170. + //if ((SD_hs[13]& 2) != 2)
  171. + //{
  172. + //errorstate = SD_UNSUPPORTED_FEATURE;
  173. + //}
  174. }
  175. return errorstate;
  176. diff --git b/STM32CubeMX/SCSI2SD-V6/Inc/stm32f2xx_hal_conf.h a/STM32CubeMX/SCSI2SD-V6/Inc/stm32f2xx_hal_conf.h
  177. index ef23c94..c899300 100755
  178. --- b/STM32CubeMX/SCSI2SD-V6/Inc/stm32f2xx_hal_conf.h
  179. +++ a/STM32CubeMX/SCSI2SD-V6/Inc/stm32f2xx_hal_conf.h
  180. @@ -76,7 +76,7 @@
  181. //#define HAL_SMARTCARD_MODULE_ENABLED
  182. //#define HAL_WWDG_MODULE_ENABLED
  183. #define HAL_PCD_MODULE_ENABLED
  184. -//#define HAL_HCD_MODULE_ENABLED
  185. +#define HAL_HCD_MODULE_ENABLED
  186. #define HAL_GPIO_MODULE_ENABLED
  187. #define HAL_DMA_MODULE_ENABLED
  188. #define HAL_RCC_MODULE_ENABLED
  189. diff --git b/STM32CubeMX/SCSI2SD-V6/Src/fsmc.c a/STM32CubeMX/SCSI2SD-V6/Src/fsmc.c
  190. index c257924..5261aa9 100755
  191. --- b/STM32CubeMX/SCSI2SD-V6/Src/fsmc.c
  192. +++ a/STM32CubeMX/SCSI2SD-V6/Src/fsmc.c
  193. @@ -66,12 +66,28 @@ void MX_FSMC_Init(void)
  194. hsram1.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE;
  195. hsram1.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;
  196. /* Timing */
  197. +
  198. + // 1 clock to read the address, + 1 for synchroniser skew
  199. Timing.AddressSetupTime = 2;
  200. Timing.AddressHoldTime = 1;
  201. +
  202. + // Writes to device:
  203. + // 1 for synchroniser skew (dbx also delayed)
  204. + // 1 to skip hold time
  205. + // 1 to write data.
  206. +
  207. + // Reads from device:
  208. + // 3 for syncroniser
  209. + // 1 to write back to fsmc bus.
  210. Timing.DataSetupTime = 4;
  211. +
  212. + // Allow a clock for us to release signals
  213. + // Need to avoid both devices acting as outputs
  214. + // on the multiplexed lines at the same time.
  215. Timing.BusTurnAroundDuration = 1;
  216. - Timing.CLKDivision = 16;
  217. - Timing.DataLatency = 17;
  218. +
  219. + Timing.CLKDivision = 16; // Ignored for async
  220. + Timing.DataLatency = 17; // Ignored for async
  221. Timing.AccessMode = FSMC_ACCESS_MODE_A;
  222. /* ExtTiming */
  223. @@ -91,7 +107,7 @@ static void HAL_FSMC_MspInit(void){
  224. }
  225. FSMC_Initialized = 1;
  226. /* Peripheral clock enable */
  227. - #__FSMC_CLK_ENABLE();
  228. + __FSMC_CLK_ENABLE();
  229. /** FSMC GPIO Configuration
  230. PE7 ------> FSMC_DA4
  231. @@ -103,9 +119,6 @@ static void HAL_FSMC_MspInit(void){
  232. PE13 ------> FSMC_DA10
  233. PE14 ------> FSMC_DA11
  234. PE15 ------> FSMC_DA12
  235. - PD8 ------> FSMC_DA13
  236. - PD9 ------> FSMC_DA14
  237. - PD10 ------> FSMC_DA15
  238. PD14 ------> FSMC_DA0
  239. PD15 ------> FSMC_DA1
  240. PD0 ------> FSMC_DA2
  241. @@ -113,28 +126,31 @@ static void HAL_FSMC_MspInit(void){
  242. PD4 ------> FSMC_NOE
  243. PD5 ------> FSMC_NWE
  244. PD7 ------> FSMC_NE1
  245. + PD8 ------> FSMC_DA13
  246. + PD9 ------> FSMC_DA14
  247. + PD10 ------> FSMC_DA15
  248. PB7 ------> FSMC_NL
  249. PE0 ------> FSMC_NBL0
  250. PE1 ------> FSMC_NBL1
  251. */
  252. + // MM: GPIO_SPEED_FREQ_MEDIUM is rated up to 50MHz, which is fine as all the
  253. + // fsmc timings are > 1 (ie. so clock speed / 2 is around 50MHz).
  254. +
  255. /* GPIO_InitStruct */
  256. - GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
  257. - |GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
  258. - |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1;
  259. + GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
  260. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  261. GPIO_InitStruct.Pull = GPIO_NOPULL;
  262. - GPIO_InitStruct.Speed = GPIO_SPEED_MEDIUM;
  263. + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; //HIGH;
  264. GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
  265. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  266. /* GPIO_InitStruct */
  267. - GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_14
  268. - |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4
  269. - |GPIO_PIN_5|GPIO_PIN_7;
  270. + GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1
  271. + |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;
  272. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  273. GPIO_InitStruct.Pull = GPIO_NOPULL;
  274. - GPIO_InitStruct.Speed = GPIO_SPEED_MEDIUM;
  275. + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; //HIGH;
  276. GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
  277. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  278. @@ -143,7 +159,7 @@ static void HAL_FSMC_MspInit(void){
  279. GPIO_InitStruct.Pin = GPIO_PIN_7;
  280. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  281. GPIO_InitStruct.Pull = GPIO_NOPULL;
  282. - GPIO_InitStruct.Speed = GPIO_SPEED_MEDIUM;
  283. + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;//HIGH;
  284. GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
  285. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  286. @@ -186,9 +202,6 @@ static void HAL_FSMC_MspDeInit(void){
  287. PE13 ------> FSMC_DA10
  288. PE14 ------> FSMC_DA11
  289. PE15 ------> FSMC_DA12
  290. - PD8 ------> FSMC_DA13
  291. - PD9 ------> FSMC_DA14
  292. - PD10 ------> FSMC_DA15
  293. PD14 ------> FSMC_DA0
  294. PD15 ------> FSMC_DA1
  295. PD0 ------> FSMC_DA2
  296. @@ -196,18 +209,18 @@ static void HAL_FSMC_MspDeInit(void){
  297. PD4 ------> FSMC_NOE
  298. PD5 ------> FSMC_NWE
  299. PD7 ------> FSMC_NE1
  300. + PD8 ------> FSMC_DA13
  301. + PD9 ------> FSMC_DA14
  302. + PD10 ------> FSMC_DA15
  303. PB7 ------> FSMC_NL
  304. PE0 ------> FSMC_NBL0
  305. PE1 ------> FSMC_NBL1
  306. */
  307. - HAL_GPIO_DeInit(GPIOE, GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
  308. - |GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
  309. - |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1);
  310. + HAL_GPIO_DeInit(GPIOE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15);
  311. - HAL_GPIO_DeInit(GPIOD, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_14
  312. - |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4
  313. - |GPIO_PIN_5|GPIO_PIN_7);
  314. + HAL_GPIO_DeInit(GPIOD, GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1
  315. + |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10);
  316. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7);
  317. diff --git b/STM32CubeMX/SCSI2SD-V6/Src/main.c a/STM32CubeMX/SCSI2SD-V6/Src/main.c
  318. index 48e1f9a..a80e078 100755
  319. --- b/STM32CubeMX/SCSI2SD-V6/Src/main.c
  320. +++ a/STM32CubeMX/SCSI2SD-V6/Src/main.c
  321. @@ -32,12 +32,10 @@
  322. */
  323. /* Includes ------------------------------------------------------------------*/
  324. #include "stm32f2xx_hal.h"
  325. -#include "dma.h"
  326. #include "sdio.h"
  327. #include "spi.h"
  328. -#include "tim.h"
  329. #include "usart.h"
  330. #include "usb_device.h"
  331. #include "gpio.h"
  332. #include "fsmc.h"
  333. @@ -87,14 +87,10 @@ int main(void)
  334. /* Initialize all configured peripherals */
  335. MX_GPIO_Init();
  336. - MX_DMA_Init();
  337. - SystemClock_Config();
  338. MX_FSMC_Init();
  339. MX_SDIO_SD_Init();
  340. MX_SPI1_Init();
  341. - MX_TIM4_Init();
  342. - MX_USART3_UART_Init();
  343. - MX_USB_DEVICE_Init();
  344. + MX_USART3_UART_Init(); // Not used, but we don't want the pins floating.
  345. /* USER CODE BEGIN 2 */
  346. mainInit();
  347. diff --git b/STM32CubeMX/SCSI2SD-V6/Src/sdio.c a/STM32CubeMX/SCSI2SD-V6/Src/sdio.c
  348. index e8b2ad8..0f9a34b 100755
  349. --- b/STM32CubeMX/SCSI2SD-V6/Src/sdio.c
  350. +++ a/STM32CubeMX/SCSI2SD-V6/Src/sdio.c
  351. @@ -36,7 +36,6 @@
  352. #include "sdio.h"
  353. #include "gpio.h"
  354. -#include "dma.h"
  355. /* USER CODE BEGIN 0 */
  356. @@ -59,9 +58,6 @@ void MX_SDIO_SD_Init(void)
  357. hsd.Init.BusWide = SDIO_BUS_WIDE_1B;
  358. hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
  359. hsd.Init.ClockDiv = 0;
  360. - HAL_SD_Init(&hsd, &SDCardInfo);
  361. -
  362. - HAL_SD_WideBusOperation_Config(&hsd, SDIO_BUS_WIDE_4B);
  363. }
  364. @@ -143,6 +140,7 @@ void HAL_SD_MspInit(SD_HandleTypeDef* hsd)
  365. __HAL_LINKDMA(hsd,hdmarx,hdma_sdio_rx);
  366. /* Peripheral interrupt init*/
  367. + HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
  368. HAL_NVIC_SetPriority(SDIO_IRQn, 0, 0);
  369. HAL_NVIC_EnableIRQ(SDIO_IRQn);
  370. /* USER CODE BEGIN SDIO_MspInit 1 */
  371. diff --git b/STM32CubeMX/SCSI2SD-V6/Src/spi.c a/STM32CubeMX/SCSI2SD-V6/Src/spi.c
  372. index cfb19ce..25e0745 100755
  373. --- b/STM32CubeMX/SCSI2SD-V6/Src/spi.c
  374. +++ a/STM32CubeMX/SCSI2SD-V6/Src/spi.c
  375. @@ -54,6 +54,7 @@ void MX_SPI1_Init(void)
  376. hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
  377. hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
  378. hspi1.Init.NSS = SPI_NSS_SOFT;
  379. + // (96MHz / 2) / 4 = 12MHz. FPGA device allows up to 25MHz write
  380. hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
  381. hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  382. hspi1.Init.TIMode = SPI_TIMODE_DISABLED;
  383. diff --git b/STM32CubeMX/SCSI2SD-V6/Src/stm32f2xx_hal_msp.c a/STM32CubeMX/SCSI2SD-V6/Src/stm32f2xx_hal_msp.c
  384. index e6b7783..b7ab0a3 100755
  385. --- b/STM32CubeMX/SCSI2SD-V6/Src/stm32f2xx_hal_msp.c
  386. +++ a/STM32CubeMX/SCSI2SD-V6/Src/stm32f2xx_hal_msp.c
  387. @@ -50,14 +50,6 @@ void HAL_MspInit(void)
  388. HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
  389. /* System interrupt init*/
  390. - /* MemoryManagement_IRQn interrupt configuration */
  391. - HAL_NVIC_SetPriority(MemoryManagement_IRQn, 0, 0);
  392. - /* BusFault_IRQn interrupt configuration */
  393. - HAL_NVIC_SetPriority(BusFault_IRQn, 0, 0);
  394. - /* UsageFault_IRQn interrupt configuration */
  395. - HAL_NVIC_SetPriority(UsageFault_IRQn, 0, 0);
  396. - /* DebugMonitor_IRQn interrupt configuration */
  397. - HAL_NVIC_SetPriority(DebugMonitor_IRQn, 0, 0);
  398. /* SysTick_IRQn interrupt configuration */
  399. HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  400. diff --git b/STM32CubeMX/SCSI2SD-V6/Src/usbd_conf.c a/STM32CubeMX/SCSI2SD-V6/Src/usbd_conf.c
  401. index 272d388..07387ca 100755
  402. --- b/STM32CubeMX/SCSI2SD-V6/Src/usbd_conf.c
  403. +++ a/STM32CubeMX/SCSI2SD-V6/Src/usbd_conf.c
  404. @@ -108,7 +108,18 @@ void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
  405. PA11 ------> USB_OTG_FS_DM
  406. PA12 ------> USB_OTG_FS_DP
  407. */
  408. - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_11|GPIO_PIN_12);
  409. + // HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_11|GPIO_PIN_12);
  410. + // MM: Don't let pins float.
  411. + GPIO_InitTypeDef GPIO_InitStruct;
  412. + GPIO_InitStruct.Pin = GPIO_PIN_9;
  413. + GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  414. + GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  415. + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  416. +
  417. + GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
  418. + GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  419. + GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  420. + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  421. /* Peripheral interrupt Deinit*/
  422. HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
  423. @@ -294,9 +305,11 @@ USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev)
  424. hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
  425. HAL_PCD_Init(&hpcd_USB_OTG_FS);
  426. + // Sum of all FIFOs must be <= 320.
  427. HAL_PCD_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80);
  428. HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x40);
  429. - HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x80);
  430. + HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x40);
  431. + HAL_PCD_SetTxFiFo(&hpcd_USB_OTG_FS, 2, 0x40);
  432. }
  433. return USBD_OK;
  434. }