drv_spi.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-11-5 SummerGift first version
  9. * 2018-12-11 greedyhao Porting for stm32f7xx
  10. * 2019-01-03 zylx modify DMA initialization and spixfer function
  11. * 2020-01-15 whj4674672 Porting for stm32h7xx
  12. * 2020-06-18 thread-liu Porting for stm32mp1xx
  13. * 2020-10-14 Dozingfiretruck Porting for stm32wbxx
  14. */
  15. #include <rtthread.h>
  16. #include <rtdevice.h>
  17. #include "board.h"
  18. #ifdef BSP_USING_SPI
  19. #if defined(BSP_USING_SPI1) || defined(BSP_USING_SPI2) || defined(BSP_USING_SPI3) || defined(BSP_USING_SPI4) || defined(BSP_USING_SPI5) || defined(BSP_USING_SPI6)
  20. #include "drv_spi.h"
  21. #include "drv_config.h"
  22. #include <string.h>
  23. //#define DRV_DEBUG
  24. #define LOG_TAG "drv.spi"
  25. #include <drv_log.h>
  26. enum
  27. {
  28. #ifdef BSP_USING_SPI1
  29. SPI1_INDEX,
  30. #endif
  31. #ifdef BSP_USING_SPI2
  32. SPI2_INDEX,
  33. #endif
  34. #ifdef BSP_USING_SPI3
  35. SPI3_INDEX,
  36. #endif
  37. #ifdef BSP_USING_SPI4
  38. SPI4_INDEX,
  39. #endif
  40. #ifdef BSP_USING_SPI5
  41. SPI5_INDEX,
  42. #endif
  43. #ifdef BSP_USING_SPI6
  44. SPI6_INDEX,
  45. #endif
  46. };
  47. static struct stm32_spi_config spi_config[] =
  48. {
  49. #ifdef BSP_USING_SPI1
  50. SPI1_BUS_CONFIG,
  51. #endif
  52. #ifdef BSP_USING_SPI2
  53. SPI2_BUS_CONFIG,
  54. #endif
  55. #ifdef BSP_USING_SPI3
  56. SPI3_BUS_CONFIG,
  57. #endif
  58. #ifdef BSP_USING_SPI4
  59. SPI4_BUS_CONFIG,
  60. #endif
  61. #ifdef BSP_USING_SPI5
  62. SPI5_BUS_CONFIG,
  63. #endif
  64. #ifdef BSP_USING_SPI6
  65. SPI6_BUS_CONFIG,
  66. #endif
  67. };
  68. static struct stm32_spi spi_bus_obj[sizeof(spi_config) / sizeof(spi_config[0])] = {0};
  69. static rt_err_t stm32_spi_init(struct stm32_spi *spi_drv, struct rt_spi_configuration *cfg)
  70. {
  71. RT_ASSERT(spi_drv != RT_NULL);
  72. RT_ASSERT(cfg != RT_NULL);
  73. SPI_HandleTypeDef *spi_handle = &spi_drv->handle;
  74. if (cfg->mode & RT_SPI_SLAVE)
  75. {
  76. spi_handle->Init.Mode = SPI_MODE_SLAVE;
  77. }
  78. else
  79. {
  80. spi_handle->Init.Mode = SPI_MODE_MASTER;
  81. }
  82. if (cfg->mode & RT_SPI_3WIRE)
  83. {
  84. spi_handle->Init.Direction = SPI_DIRECTION_1LINE;
  85. }
  86. else
  87. {
  88. spi_handle->Init.Direction = SPI_DIRECTION_2LINES;
  89. }
  90. if (cfg->data_width == 8)
  91. {
  92. spi_handle->Init.DataSize = SPI_DATASIZE_8BIT;
  93. spi_handle->TxXferSize = 8;
  94. spi_handle->RxXferSize = 8;
  95. }
  96. else if (cfg->data_width == 16)
  97. {
  98. spi_handle->Init.DataSize = SPI_DATASIZE_16BIT;
  99. }
  100. else
  101. {
  102. return -RT_EIO;
  103. }
  104. if (cfg->mode & RT_SPI_CPHA)
  105. {
  106. spi_handle->Init.CLKPhase = SPI_PHASE_2EDGE;
  107. }
  108. else
  109. {
  110. spi_handle->Init.CLKPhase = SPI_PHASE_1EDGE;
  111. }
  112. if (cfg->mode & RT_SPI_CPOL)
  113. {
  114. spi_handle->Init.CLKPolarity = SPI_POLARITY_HIGH;
  115. }
  116. else
  117. {
  118. spi_handle->Init.CLKPolarity = SPI_POLARITY_LOW;
  119. }
  120. spi_handle->Init.NSS = SPI_NSS_SOFT;
  121. uint32_t SPI_CLOCK;
  122. /* Some series may only have APBPERIPH_BASE, but don't have HAL_RCC_GetPCLK2Freq */
  123. #if defined(APBPERIPH_BASE)
  124. SPI_CLOCK = HAL_RCC_GetPCLK1Freq();
  125. #elif defined(APB1PERIPH_BASE) || defined(APB2PERIPH_BASE)
  126. /* The SPI clock for H7 cannot be configured with a peripheral bus clock, so it needs to be written separately */
  127. #if defined(SOC_SERIES_STM32H7)
  128. /* When the configuration is generated using CUBEMX, the configuration for the SPI clock is placed in the HAL_SPI_Init function.
  129. Therefore, it is necessary to initialize and configure the SPI clock to automatically configure the frequency division */
  130. HAL_SPI_Init(spi_handle);
  131. SPI_CLOCK = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SPI123);
  132. #else
  133. if ((rt_uint32_t)spi_drv->config->Instance >= APB2PERIPH_BASE)
  134. {
  135. SPI_CLOCK = HAL_RCC_GetPCLK2Freq();
  136. }
  137. else
  138. {
  139. SPI_CLOCK = HAL_RCC_GetPCLK1Freq();
  140. }
  141. #endif /* SOC_SERIES_STM32H7) */
  142. #endif /* APBPERIPH_BASE */
  143. if (cfg->max_hz >= SPI_CLOCK / 2)
  144. {
  145. spi_handle->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
  146. }
  147. else if (cfg->max_hz >= SPI_CLOCK / 4)
  148. {
  149. spi_handle->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
  150. }
  151. else if (cfg->max_hz >= SPI_CLOCK / 8)
  152. {
  153. spi_handle->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
  154. }
  155. else if (cfg->max_hz >= SPI_CLOCK / 16)
  156. {
  157. spi_handle->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
  158. }
  159. else if (cfg->max_hz >= SPI_CLOCK / 32)
  160. {
  161. spi_handle->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
  162. }
  163. else if (cfg->max_hz >= SPI_CLOCK / 64)
  164. {
  165. spi_handle->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
  166. }
  167. else if (cfg->max_hz >= SPI_CLOCK / 128)
  168. {
  169. spi_handle->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
  170. }
  171. else
  172. {
  173. /* min prescaler 256 */
  174. spi_handle->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
  175. }
  176. LOG_D("sys freq: %d, pclk freq: %d, SPI limiting freq: %d, SPI usage freq: %d",
  177. #if defined(SOC_SERIES_STM32MP1)
  178. HAL_RCC_GetSystemCoreClockFreq(),
  179. #else
  180. HAL_RCC_GetSysClockFreq(),
  181. #endif
  182. SPI_CLOCK,
  183. cfg->max_hz,
  184. SPI_CLOCK / (rt_size_t)pow(2,(spi_handle->Init.BaudRatePrescaler >> 28) + 1));
  185. if (cfg->mode & RT_SPI_MSB)
  186. {
  187. spi_handle->Init.FirstBit = SPI_FIRSTBIT_MSB;
  188. }
  189. else
  190. {
  191. spi_handle->Init.FirstBit = SPI_FIRSTBIT_LSB;
  192. }
  193. spi_handle->Init.TIMode = SPI_TIMODE_DISABLE;
  194. spi_handle->Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  195. spi_handle->State = HAL_SPI_STATE_RESET;
  196. #if defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32WB)
  197. spi_handle->Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
  198. #elif defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32MP1)
  199. spi_handle->Init.Mode = SPI_MODE_MASTER;
  200. spi_handle->Init.NSS = SPI_NSS_SOFT;
  201. spi_handle->Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
  202. spi_handle->Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
  203. spi_handle->Init.CRCPolynomial = 7;
  204. spi_handle->Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
  205. spi_handle->Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
  206. spi_handle->Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
  207. spi_handle->Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
  208. spi_handle->Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
  209. spi_handle->Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_ENABLE;
  210. spi_handle->Init.IOSwap = SPI_IO_SWAP_DISABLE;
  211. spi_handle->Init.FifoThreshold = SPI_FIFO_THRESHOLD_08DATA;
  212. #endif
  213. if (HAL_SPI_Init(spi_handle) != HAL_OK)
  214. {
  215. return -RT_EIO;
  216. }
  217. #if defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F0) \
  218. || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32WB)
  219. SET_BIT(spi_handle->Instance->CR2, SPI_RXFIFO_THRESHOLD_HF);
  220. #endif
  221. /* DMA configuration */
  222. if (spi_drv->spi_dma_flag & SPI_USING_RX_DMA_FLAG)
  223. {
  224. HAL_DMA_Init(&spi_drv->dma.handle_rx);
  225. __HAL_LINKDMA(&spi_drv->handle, hdmarx, spi_drv->dma.handle_rx);
  226. /* NVIC configuration for DMA transfer complete interrupt */
  227. HAL_NVIC_SetPriority(spi_drv->config->dma_rx->dma_irq, 0, 0);
  228. HAL_NVIC_EnableIRQ(spi_drv->config->dma_rx->dma_irq);
  229. }
  230. if (spi_drv->spi_dma_flag & SPI_USING_TX_DMA_FLAG)
  231. {
  232. HAL_DMA_Init(&spi_drv->dma.handle_tx);
  233. __HAL_LINKDMA(&spi_drv->handle, hdmatx, spi_drv->dma.handle_tx);
  234. /* NVIC configuration for DMA transfer complete interrupt */
  235. HAL_NVIC_SetPriority(spi_drv->config->dma_tx->dma_irq, 1, 0);
  236. HAL_NVIC_EnableIRQ(spi_drv->config->dma_tx->dma_irq);
  237. }
  238. if(spi_drv->spi_dma_flag & SPI_USING_TX_DMA_FLAG || spi_drv->spi_dma_flag & SPI_USING_RX_DMA_FLAG)
  239. {
  240. HAL_NVIC_SetPriority(spi_drv->config->irq_type, 2, 0);
  241. HAL_NVIC_EnableIRQ(spi_drv->config->irq_type);
  242. }
  243. LOG_D("%s init done", spi_drv->config->bus_name);
  244. return RT_EOK;
  245. }
  246. static rt_ssize_t spixfer(struct rt_spi_device *device, struct rt_spi_message *message)
  247. {
  248. HAL_StatusTypeDef state = HAL_OK;
  249. rt_size_t message_length, already_send_length;
  250. rt_uint16_t send_length;
  251. rt_uint8_t *recv_buf;
  252. const rt_uint8_t *send_buf;
  253. RT_ASSERT(device != RT_NULL);
  254. RT_ASSERT(device->bus != RT_NULL);
  255. RT_ASSERT(message != RT_NULL);
  256. struct stm32_spi *spi_drv = rt_container_of(device->bus, struct stm32_spi, spi_bus);
  257. SPI_HandleTypeDef *spi_handle = &spi_drv->handle;
  258. if (message->cs_take && !(device->config.mode & RT_SPI_NO_CS) && (device->cs_pin != PIN_NONE))
  259. {
  260. if (device->config.mode & RT_SPI_CS_HIGH)
  261. rt_pin_write(device->cs_pin, PIN_HIGH);
  262. else
  263. rt_pin_write(device->cs_pin, PIN_LOW);
  264. }
  265. LOG_D("%s transfer prepare and start", spi_drv->config->bus_name);
  266. LOG_D("%s sendbuf: %X, recvbuf: %X, length: %d",
  267. spi_drv->config->bus_name,
  268. (uint32_t)message->send_buf,
  269. (uint32_t)message->recv_buf, message->length);
  270. message_length = message->length;
  271. recv_buf = message->recv_buf;
  272. send_buf = message->send_buf;
  273. while (message_length)
  274. {
  275. /* the HAL library use uint16 to save the data length */
  276. if (message_length > 65535)
  277. {
  278. send_length = 65535;
  279. message_length = message_length - 65535;
  280. }
  281. else
  282. {
  283. send_length = message_length;
  284. message_length = 0;
  285. }
  286. /* calculate the start address */
  287. already_send_length = message->length - send_length - message_length;
  288. send_buf = (rt_uint8_t *)message->send_buf + already_send_length;
  289. recv_buf = (rt_uint8_t *)message->recv_buf + already_send_length;
  290. #if defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32F7)
  291. rt_uint32_t* dma_buf = RT_NULL;
  292. if ((spi_drv->spi_dma_flag & SPI_USING_TX_DMA_FLAG) && (spi_drv->spi_dma_flag & SPI_USING_RX_DMA_FLAG))
  293. {
  294. dma_buf = (rt_uint32_t *)rt_malloc_align(send_length,32);
  295. if(send_buf)
  296. {
  297. rt_memcpy(dma_buf, send_buf, send_length);
  298. }
  299. else
  300. {
  301. rt_memset(dma_buf, 0xFF, send_length);
  302. }
  303. rt_hw_cpu_dcache_ops(RT_HW_CACHE_FLUSH, dma_buf, send_length);
  304. state = HAL_SPI_TransmitReceive_DMA(spi_handle, (uint8_t *)dma_buf, (uint8_t *)dma_buf, send_length);
  305. }
  306. else
  307. #endif /* SOC_SERIES_STM32H7 || SOC_SERIES_STM32F7 */
  308. /* start once data exchange in DMA mode */
  309. if (message->send_buf && message->recv_buf)
  310. {
  311. if ((spi_drv->spi_dma_flag & SPI_USING_TX_DMA_FLAG) && (spi_drv->spi_dma_flag & SPI_USING_RX_DMA_FLAG))
  312. {
  313. state = HAL_SPI_TransmitReceive_DMA(spi_handle, (uint8_t *)send_buf, (uint8_t *)recv_buf, send_length);
  314. }
  315. else
  316. {
  317. state = HAL_SPI_TransmitReceive(spi_handle, (uint8_t *)send_buf, (uint8_t *)recv_buf, send_length, 1000);
  318. }
  319. }
  320. else if (message->send_buf)
  321. {
  322. if (spi_drv->spi_dma_flag & SPI_USING_TX_DMA_FLAG)
  323. {
  324. state = HAL_SPI_Transmit_DMA(spi_handle, (uint8_t *)send_buf, send_length);
  325. }
  326. else
  327. {
  328. state = HAL_SPI_Transmit(spi_handle, (uint8_t *)send_buf, send_length, 1000);
  329. }
  330. if (message->cs_release && (device->config.mode & RT_SPI_3WIRE))
  331. {
  332. /* release the CS by disable SPI when using 3 wires SPI */
  333. __HAL_SPI_DISABLE(spi_handle);
  334. }
  335. }
  336. else
  337. {
  338. memset((uint8_t *)recv_buf, 0xff, send_length);
  339. if (spi_drv->spi_dma_flag & SPI_USING_RX_DMA_FLAG)
  340. {
  341. state = HAL_SPI_Receive_DMA(spi_handle, (uint8_t *)recv_buf, send_length);
  342. }
  343. else
  344. {
  345. /* clear the old error flag */
  346. __HAL_SPI_CLEAR_OVRFLAG(spi_handle);
  347. state = HAL_SPI_Receive(spi_handle, (uint8_t *)recv_buf, send_length, 1000);
  348. }
  349. }
  350. if (state != HAL_OK)
  351. {
  352. LOG_I("spi transfer error : %d", state);
  353. message->length = 0;
  354. spi_handle->State = HAL_SPI_STATE_READY;
  355. }
  356. else
  357. {
  358. LOG_D("%s transfer done", spi_drv->config->bus_name);
  359. }
  360. /* For simplicity reasons, this example is just waiting till the end of the
  361. transfer, but application may perform other tasks while transfer operation
  362. is ongoing. */
  363. if (spi_drv->spi_dma_flag & (SPI_USING_TX_DMA_FLAG | SPI_USING_RX_DMA_FLAG))
  364. {
  365. /* blocking the thread,and the other tasks can run */
  366. rt_completion_wait(&spi_drv->cpt, RT_WAITING_FOREVER);
  367. }
  368. else
  369. {
  370. while (HAL_SPI_GetState(spi_handle) != HAL_SPI_STATE_READY);
  371. }
  372. #if defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32F7)
  373. if(dma_buf)
  374. {
  375. if(recv_buf)
  376. {
  377. rt_hw_cpu_dcache_ops(RT_HW_CACHE_INVALIDATE, dma_buf, send_length);
  378. rt_memcpy(recv_buf, dma_buf,send_length);
  379. }
  380. rt_free_align(dma_buf);
  381. }
  382. #endif /* SOC_SERIES_STM32H7 || SOC_SERIES_STM32F7 */
  383. }
  384. if (message->cs_release && !(device->config.mode & RT_SPI_NO_CS) && (device->cs_pin != PIN_NONE))
  385. {
  386. if (device->config.mode & RT_SPI_CS_HIGH)
  387. rt_pin_write(device->cs_pin, PIN_LOW);
  388. else
  389. rt_pin_write(device->cs_pin, PIN_HIGH);
  390. }
  391. if(state != HAL_OK)
  392. {
  393. return -RT_ERROR;
  394. }
  395. return message->length;
  396. }
  397. static rt_err_t spi_configure(struct rt_spi_device *device,
  398. struct rt_spi_configuration *configuration)
  399. {
  400. RT_ASSERT(device != RT_NULL);
  401. RT_ASSERT(configuration != RT_NULL);
  402. struct stm32_spi *spi_drv = rt_container_of(device->bus, struct stm32_spi, spi_bus);
  403. spi_drv->cfg = configuration;
  404. return stm32_spi_init(spi_drv, configuration);
  405. }
  406. static const struct rt_spi_ops stm_spi_ops =
  407. {
  408. .configure = spi_configure,
  409. .xfer = spixfer,
  410. };
  411. static int rt_hw_spi_bus_init(void)
  412. {
  413. rt_err_t result;
  414. for (rt_size_t i = 0; i < sizeof(spi_config) / sizeof(spi_config[0]); i++)
  415. {
  416. spi_bus_obj[i].config = &spi_config[i];
  417. spi_bus_obj[i].spi_bus.parent.user_data = &spi_config[i];
  418. spi_bus_obj[i].handle.Instance = spi_config[i].Instance;
  419. if (spi_bus_obj[i].spi_dma_flag & SPI_USING_RX_DMA_FLAG)
  420. {
  421. /* Configure the DMA handler for Transmission process */
  422. spi_bus_obj[i].dma.handle_rx.Instance = spi_config[i].dma_rx->Instance;
  423. #if defined(SOC_SERIES_STM32F2) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7)
  424. spi_bus_obj[i].dma.handle_rx.Init.Channel = spi_config[i].dma_rx->channel;
  425. #elif defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32WB) || defined(SOC_SERIES_STM32H7)
  426. spi_bus_obj[i].dma.handle_rx.Init.Request = spi_config[i].dma_rx->request;
  427. #endif
  428. spi_bus_obj[i].dma.handle_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
  429. spi_bus_obj[i].dma.handle_rx.Init.PeriphInc = DMA_PINC_DISABLE;
  430. spi_bus_obj[i].dma.handle_rx.Init.MemInc = DMA_MINC_ENABLE;
  431. spi_bus_obj[i].dma.handle_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  432. spi_bus_obj[i].dma.handle_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  433. spi_bus_obj[i].dma.handle_rx.Init.Mode = DMA_NORMAL;
  434. spi_bus_obj[i].dma.handle_rx.Init.Priority = DMA_PRIORITY_HIGH;
  435. #if defined(SOC_SERIES_STM32F2) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32H7)
  436. spi_bus_obj[i].dma.handle_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
  437. spi_bus_obj[i].dma.handle_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
  438. spi_bus_obj[i].dma.handle_rx.Init.MemBurst = DMA_MBURST_INC4;
  439. spi_bus_obj[i].dma.handle_rx.Init.PeriphBurst = DMA_PBURST_INC4;
  440. #endif
  441. {
  442. rt_uint32_t tmpreg = 0x00U;
  443. #if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32F0)
  444. /* enable DMA clock && Delay after an RCC peripheral clock enabling*/
  445. SET_BIT(RCC->AHBENR, spi_config[i].dma_rx->dma_rcc);
  446. tmpreg = READ_BIT(RCC->AHBENR, spi_config[i].dma_rx->dma_rcc);
  447. #elif defined(SOC_SERIES_STM32F2) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32WB) || defined(SOC_SERIES_STM32H7)
  448. SET_BIT(RCC->AHB1ENR, spi_config[i].dma_rx->dma_rcc);
  449. /* Delay after an RCC peripheral clock enabling */
  450. tmpreg = READ_BIT(RCC->AHB1ENR, spi_config[i].dma_rx->dma_rcc);
  451. #elif defined(SOC_SERIES_STM32MP1)
  452. __HAL_RCC_DMAMUX_CLK_ENABLE();
  453. SET_BIT(RCC->MP_AHB2ENSETR, spi_config[i].dma_rx->dma_rcc);
  454. tmpreg = READ_BIT(RCC->MP_AHB2ENSETR, spi_config[i].dma_rx->dma_rcc);
  455. #endif
  456. UNUSED(tmpreg); /* To avoid compiler warnings */
  457. }
  458. }
  459. if (spi_bus_obj[i].spi_dma_flag & SPI_USING_TX_DMA_FLAG)
  460. {
  461. /* Configure the DMA handler for Transmission process */
  462. spi_bus_obj[i].dma.handle_tx.Instance = spi_config[i].dma_tx->Instance;
  463. #if defined(SOC_SERIES_STM32F2) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7)
  464. spi_bus_obj[i].dma.handle_tx.Init.Channel = spi_config[i].dma_tx->channel;
  465. #elif defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32WB) || defined(SOC_SERIES_STM32H7)
  466. spi_bus_obj[i].dma.handle_tx.Init.Request = spi_config[i].dma_tx->request;
  467. #endif
  468. spi_bus_obj[i].dma.handle_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
  469. spi_bus_obj[i].dma.handle_tx.Init.PeriphInc = DMA_PINC_DISABLE;
  470. spi_bus_obj[i].dma.handle_tx.Init.MemInc = DMA_MINC_ENABLE;
  471. spi_bus_obj[i].dma.handle_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  472. spi_bus_obj[i].dma.handle_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  473. spi_bus_obj[i].dma.handle_tx.Init.Mode = DMA_NORMAL;
  474. spi_bus_obj[i].dma.handle_tx.Init.Priority = DMA_PRIORITY_LOW;
  475. #if defined(SOC_SERIES_STM32F2) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32H7)
  476. spi_bus_obj[i].dma.handle_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
  477. spi_bus_obj[i].dma.handle_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
  478. spi_bus_obj[i].dma.handle_tx.Init.MemBurst = DMA_MBURST_INC4;
  479. spi_bus_obj[i].dma.handle_tx.Init.PeriphBurst = DMA_PBURST_INC4;
  480. #endif
  481. {
  482. rt_uint32_t tmpreg = 0x00U;
  483. #if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32F0)
  484. /* enable DMA clock && Delay after an RCC peripheral clock enabling*/
  485. SET_BIT(RCC->AHBENR, spi_config[i].dma_tx->dma_rcc);
  486. tmpreg = READ_BIT(RCC->AHBENR, spi_config[i].dma_tx->dma_rcc);
  487. #elif defined(SOC_SERIES_STM32F2) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32WB) || defined(SOC_SERIES_STM32H7)
  488. SET_BIT(RCC->AHB1ENR, spi_config[i].dma_tx->dma_rcc);
  489. /* Delay after an RCC peripheral clock enabling */
  490. tmpreg = READ_BIT(RCC->AHB1ENR, spi_config[i].dma_tx->dma_rcc);
  491. #elif defined(SOC_SERIES_STM32MP1)
  492. __HAL_RCC_DMAMUX_CLK_ENABLE();
  493. SET_BIT(RCC->MP_AHB2ENSETR, spi_config[i].dma_tx->dma_rcc);
  494. tmpreg = READ_BIT(RCC->MP_AHB2ENSETR, spi_config[i].dma_tx->dma_rcc);
  495. #endif
  496. UNUSED(tmpreg); /* To avoid compiler warnings */
  497. }
  498. }
  499. /* initialize completion object */
  500. rt_completion_init(&spi_bus_obj[i].cpt);
  501. result = rt_spi_bus_register(&spi_bus_obj[i].spi_bus, spi_config[i].bus_name, &stm_spi_ops);
  502. RT_ASSERT(result == RT_EOK);
  503. LOG_D("%s bus init done", spi_config[i].bus_name);
  504. }
  505. return result;
  506. }
  507. /**
  508. * Attach the spi device to SPI bus, this function must be used after initialization.
  509. */
  510. rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin)
  511. {
  512. RT_ASSERT(bus_name != RT_NULL);
  513. RT_ASSERT(device_name != RT_NULL);
  514. rt_err_t result;
  515. struct rt_spi_device *spi_device;
  516. /* attach the device to spi bus*/
  517. spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device));
  518. RT_ASSERT(spi_device != RT_NULL);
  519. result = rt_spi_bus_attach_device_cspin(spi_device, device_name, bus_name, cs_pin, RT_NULL);
  520. if (result != RT_EOK)
  521. {
  522. LOG_E("%s attach to %s faild, %d\n", device_name, bus_name, result);
  523. }
  524. RT_ASSERT(result == RT_EOK);
  525. LOG_D("%s attach to %s done", device_name, bus_name);
  526. return result;
  527. }
  528. #if defined(BSP_SPI1_TX_USING_DMA) || defined(BSP_SPI1_RX_USING_DMA)
  529. void SPI1_IRQHandler(void)
  530. {
  531. /* enter interrupt */
  532. rt_interrupt_enter();
  533. HAL_SPI_IRQHandler(&spi_bus_obj[SPI1_INDEX].handle);
  534. /* leave interrupt */
  535. rt_interrupt_leave();
  536. }
  537. #endif
  538. #if defined(BSP_USING_SPI1) && defined(BSP_SPI1_RX_USING_DMA)
  539. /**
  540. * @brief This function handles DMA Rx interrupt request.
  541. * @param None
  542. * @retval None
  543. */
  544. void SPI1_DMA_RX_IRQHandler(void)
  545. {
  546. /* enter interrupt */
  547. rt_interrupt_enter();
  548. HAL_DMA_IRQHandler(&spi_bus_obj[SPI1_INDEX].dma.handle_rx);
  549. /* leave interrupt */
  550. rt_interrupt_leave();
  551. }
  552. #endif
  553. #if defined(BSP_USING_SPI1) && defined(BSP_SPI1_TX_USING_DMA)
  554. /**
  555. * @brief This function handles DMA Tx interrupt request.
  556. * @param None
  557. * @retval None
  558. */
  559. void SPI1_DMA_TX_IRQHandler(void)
  560. {
  561. /* enter interrupt */
  562. rt_interrupt_enter();
  563. HAL_DMA_IRQHandler(&spi_bus_obj[SPI1_INDEX].dma.handle_tx);
  564. /* leave interrupt */
  565. rt_interrupt_leave();
  566. }
  567. #endif /* defined(BSP_USING_SPI1) && defined(BSP_SPI_USING_DMA) */
  568. #if defined(BSP_SPI2_TX_USING_DMA) || defined(BSP_SPI2_RX_USING_DMA)
  569. void SPI2_IRQHandler(void)
  570. {
  571. /* enter interrupt */
  572. rt_interrupt_enter();
  573. HAL_SPI_IRQHandler(&spi_bus_obj[SPI2_INDEX].handle);
  574. /* leave interrupt */
  575. rt_interrupt_leave();
  576. }
  577. #endif
  578. #if defined(BSP_USING_SPI2) && defined(BSP_SPI2_RX_USING_DMA)
  579. /**
  580. * @brief This function handles DMA Rx interrupt request.
  581. * @param None
  582. * @retval None
  583. */
  584. void SPI2_DMA_RX_IRQHandler(void)
  585. {
  586. /* enter interrupt */
  587. rt_interrupt_enter();
  588. HAL_DMA_IRQHandler(&spi_bus_obj[SPI2_INDEX].dma.handle_rx);
  589. /* leave interrupt */
  590. rt_interrupt_leave();
  591. }
  592. #endif
  593. #if defined(BSP_USING_SPI2) && defined(BSP_SPI2_TX_USING_DMA)
  594. /**
  595. * @brief This function handles DMA Tx interrupt request.
  596. * @param None
  597. * @retval None
  598. */
  599. void SPI2_DMA_TX_IRQHandler(void)
  600. {
  601. /* enter interrupt */
  602. rt_interrupt_enter();
  603. HAL_DMA_IRQHandler(&spi_bus_obj[SPI2_INDEX].dma.handle_tx);
  604. /* leave interrupt */
  605. rt_interrupt_leave();
  606. }
  607. #endif /* defined(BSP_USING_SPI2) && defined(BSP_SPI_USING_DMA) */
  608. #if defined(BSP_SPI3_TX_USING_DMA) || defined(BSP_SPI3_RX_USING_DMA)
  609. void SPI3_IRQHandler(void)
  610. {
  611. /* enter interrupt */
  612. rt_interrupt_enter();
  613. HAL_SPI_IRQHandler(&spi_bus_obj[SPI3_INDEX].handle);
  614. /* leave interrupt */
  615. rt_interrupt_leave();
  616. }
  617. #endif
  618. #if defined(BSP_USING_SPI3) && defined(BSP_SPI3_RX_USING_DMA)
  619. /**
  620. * @brief This function handles DMA Rx interrupt request.
  621. * @param None
  622. * @retval None
  623. */
  624. void SPI3_DMA_RX_IRQHandler(void)
  625. {
  626. /* enter interrupt */
  627. rt_interrupt_enter();
  628. HAL_DMA_IRQHandler(&spi_bus_obj[SPI3_INDEX].dma.handle_rx);
  629. /* leave interrupt */
  630. rt_interrupt_leave();
  631. }
  632. #endif
  633. #if defined(BSP_USING_SPI3) && defined(BSP_SPI3_TX_USING_DMA)
  634. /**
  635. * @brief This function handles DMA Tx interrupt request.
  636. * @param None
  637. * @retval None
  638. */
  639. void SPI3_DMA_TX_IRQHandler(void)
  640. {
  641. /* enter interrupt */
  642. rt_interrupt_enter();
  643. HAL_DMA_IRQHandler(&spi_bus_obj[SPI3_INDEX].dma.handle_tx);
  644. /* leave interrupt */
  645. rt_interrupt_leave();
  646. }
  647. #endif /* defined(BSP_USING_SPI3) && defined(BSP_SPI_USING_DMA) */
  648. #if defined(BSP_SPI4_TX_USING_DMA) || defined(BSP_SPI4_RX_USING_DMA)
  649. void SPI4_IRQHandler(void)
  650. {
  651. /* enter interrupt */
  652. rt_interrupt_enter();
  653. HAL_SPI_IRQHandler(&spi_bus_obj[SPI4_INDEX].handle);
  654. /* leave interrupt */
  655. rt_interrupt_leave();
  656. }
  657. #endif
  658. #if defined(BSP_USING_SPI4) && defined(BSP_SPI4_RX_USING_DMA)
  659. /**
  660. * @brief This function handles DMA Rx interrupt request.
  661. * @param None
  662. * @retval None
  663. */
  664. void SPI4_DMA_RX_IRQHandler(void)
  665. {
  666. /* enter interrupt */
  667. rt_interrupt_enter();
  668. HAL_DMA_IRQHandler(&spi_bus_obj[SPI4_INDEX].dma.handle_rx);
  669. /* leave interrupt */
  670. rt_interrupt_leave();
  671. }
  672. #endif
  673. #if defined(BSP_USING_SPI4) && defined(BSP_SPI4_TX_USING_DMA)
  674. /**
  675. * @brief This function handles DMA Tx interrupt request.
  676. * @param None
  677. * @retval None
  678. */
  679. void SPI4_DMA_TX_IRQHandler(void)
  680. {
  681. /* enter interrupt */
  682. rt_interrupt_enter();
  683. HAL_DMA_IRQHandler(&spi_bus_obj[SPI4_INDEX].dma.handle_tx);
  684. /* leave interrupt */
  685. rt_interrupt_leave();
  686. }
  687. #endif /* defined(BSP_USING_SPI4) && defined(BSP_SPI_USING_DMA) */
  688. #if defined(BSP_SPI5_TX_USING_DMA) || defined(BSP_SPI5_RX_USING_DMA)
  689. void SPI5_IRQHandler(void)
  690. {
  691. /* enter interrupt */
  692. rt_interrupt_enter();
  693. HAL_SPI_IRQHandler(&spi_bus_obj[SPI5_INDEX].handle);
  694. /* leave interrupt */
  695. rt_interrupt_leave();
  696. }
  697. #endif
  698. #if defined(BSP_USING_SPI5) && defined(BSP_SPI5_RX_USING_DMA)
  699. /**
  700. * @brief This function handles DMA Rx interrupt request.
  701. * @param None
  702. * @retval None
  703. */
  704. void SPI5_DMA_RX_IRQHandler(void)
  705. {
  706. /* enter interrupt */
  707. rt_interrupt_enter();
  708. HAL_DMA_IRQHandler(&spi_bus_obj[SPI5_INDEX].dma.handle_rx);
  709. /* leave interrupt */
  710. rt_interrupt_leave();
  711. }
  712. #endif
  713. #if defined(BSP_USING_SPI5) && defined(BSP_SPI5_TX_USING_DMA)
  714. /**
  715. * @brief This function handles DMA Tx interrupt request.
  716. * @param None
  717. * @retval None
  718. */
  719. void SPI5_DMA_TX_IRQHandler(void)
  720. {
  721. /* enter interrupt */
  722. rt_interrupt_enter();
  723. HAL_DMA_IRQHandler(&spi_bus_obj[SPI5_INDEX].dma.handle_tx);
  724. /* leave interrupt */
  725. rt_interrupt_leave();
  726. }
  727. #endif /* defined(BSP_USING_SPI5) && defined(BSP_SPI_USING_DMA) */
  728. #if defined(BSP_USING_SPI6) && defined(BSP_SPI6_RX_USING_DMA)
  729. /**
  730. * @brief This function handles DMA Rx interrupt request.
  731. * @param None
  732. * @retval None
  733. */
  734. void SPI6_DMA_RX_IRQHandler(void)
  735. {
  736. /* enter interrupt */
  737. rt_interrupt_enter();
  738. HAL_DMA_IRQHandler(&spi_bus_obj[SPI6_INDEX].dma.handle_rx);
  739. /* leave interrupt */
  740. rt_interrupt_leave();
  741. }
  742. #endif
  743. #if defined(BSP_USING_SPI6) && defined(BSP_SPI6_TX_USING_DMA)
  744. /**
  745. * @brief This function handles DMA Tx interrupt request.
  746. * @param None
  747. * @retval None
  748. */
  749. void SPI6_DMA_TX_IRQHandler(void)
  750. {
  751. /* enter interrupt */
  752. rt_interrupt_enter();
  753. HAL_DMA_IRQHandler(&spi_bus_obj[SPI6_INDEX].dma.handle_tx);
  754. /* leave interrupt */
  755. rt_interrupt_leave();
  756. }
  757. #endif /* defined(BSP_USING_SPI6) && defined(BSP_SPI_USING_DMA) */
  758. static void stm32_get_dma_info(void)
  759. {
  760. #ifdef BSP_SPI1_RX_USING_DMA
  761. spi_bus_obj[SPI1_INDEX].spi_dma_flag |= SPI_USING_RX_DMA_FLAG;
  762. static struct dma_config spi1_dma_rx = SPI1_RX_DMA_CONFIG;
  763. spi_config[SPI1_INDEX].dma_rx = &spi1_dma_rx;
  764. #endif
  765. #ifdef BSP_SPI1_TX_USING_DMA
  766. spi_bus_obj[SPI1_INDEX].spi_dma_flag |= SPI_USING_TX_DMA_FLAG;
  767. static struct dma_config spi1_dma_tx = SPI1_TX_DMA_CONFIG;
  768. spi_config[SPI1_INDEX].dma_tx = &spi1_dma_tx;
  769. #endif
  770. #ifdef BSP_SPI2_RX_USING_DMA
  771. spi_bus_obj[SPI2_INDEX].spi_dma_flag |= SPI_USING_RX_DMA_FLAG;
  772. static struct dma_config spi2_dma_rx = SPI2_RX_DMA_CONFIG;
  773. spi_config[SPI2_INDEX].dma_rx = &spi2_dma_rx;
  774. #endif
  775. #ifdef BSP_SPI2_TX_USING_DMA
  776. spi_bus_obj[SPI2_INDEX].spi_dma_flag |= SPI_USING_TX_DMA_FLAG;
  777. static struct dma_config spi2_dma_tx = SPI2_TX_DMA_CONFIG;
  778. spi_config[SPI2_INDEX].dma_tx = &spi2_dma_tx;
  779. #endif
  780. #ifdef BSP_SPI3_RX_USING_DMA
  781. spi_bus_obj[SPI3_INDEX].spi_dma_flag |= SPI_USING_RX_DMA_FLAG;
  782. static struct dma_config spi3_dma_rx = SPI3_RX_DMA_CONFIG;
  783. spi_config[SPI3_INDEX].dma_rx = &spi3_dma_rx;
  784. #endif
  785. #ifdef BSP_SPI3_TX_USING_DMA
  786. spi_bus_obj[SPI3_INDEX].spi_dma_flag |= SPI_USING_TX_DMA_FLAG;
  787. static struct dma_config spi3_dma_tx = SPI3_TX_DMA_CONFIG;
  788. spi_config[SPI3_INDEX].dma_tx = &spi3_dma_tx;
  789. #endif
  790. #ifdef BSP_SPI4_RX_USING_DMA
  791. spi_bus_obj[SPI4_INDEX].spi_dma_flag |= SPI_USING_RX_DMA_FLAG;
  792. static struct dma_config spi4_dma_rx = SPI4_RX_DMA_CONFIG;
  793. spi_config[SPI4_INDEX].dma_rx = &spi4_dma_rx;
  794. #endif
  795. #ifdef BSP_SPI4_TX_USING_DMA
  796. spi_bus_obj[SPI4_INDEX].spi_dma_flag |= SPI_USING_TX_DMA_FLAG;
  797. static struct dma_config spi4_dma_tx = SPI4_TX_DMA_CONFIG;
  798. spi_config[SPI4_INDEX].dma_tx = &spi4_dma_tx;
  799. #endif
  800. #ifdef BSP_SPI5_RX_USING_DMA
  801. spi_bus_obj[SPI5_INDEX].spi_dma_flag |= SPI_USING_RX_DMA_FLAG;
  802. static struct dma_config spi5_dma_rx = SPI5_RX_DMA_CONFIG;
  803. spi_config[SPI5_INDEX].dma_rx = &spi5_dma_rx;
  804. #endif
  805. #ifdef BSP_SPI5_TX_USING_DMA
  806. spi_bus_obj[SPI5_INDEX].spi_dma_flag |= SPI_USING_TX_DMA_FLAG;
  807. static struct dma_config spi5_dma_tx = SPI5_TX_DMA_CONFIG;
  808. spi_config[SPI5_INDEX].dma_tx = &spi5_dma_tx;
  809. #endif
  810. #ifdef BSP_SPI6_RX_USING_DMA
  811. spi_bus_obj[SPI6_INDEX].spi_dma_flag |= SPI_USING_RX_DMA_FLAG;
  812. static struct dma_config spi6_dma_rx = SPI6_RX_DMA_CONFIG;
  813. spi_config[SPI6_INDEX].dma_rx = &spi6_dma_rx;
  814. #endif
  815. #ifdef BSP_SPI6_TX_USING_DMA
  816. spi_bus_obj[SPI6_INDEX].spi_dma_flag |= SPI_USING_TX_DMA_FLAG;
  817. static struct dma_config spi6_dma_tx = SPI6_TX_DMA_CONFIG;
  818. spi_config[SPI6_INDEX].dma_tx = &spi6_dma_tx;
  819. #endif
  820. }
  821. void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
  822. {
  823. struct stm32_spi *spi_drv = rt_container_of(hspi, struct stm32_spi, handle);
  824. rt_completion_done(&spi_drv->cpt);
  825. }
  826. void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
  827. {
  828. struct stm32_spi *spi_drv = rt_container_of(hspi, struct stm32_spi, handle);
  829. rt_completion_done(&spi_drv->cpt);
  830. }
  831. void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
  832. {
  833. struct stm32_spi *spi_drv = rt_container_of(hspi, struct stm32_spi, handle);
  834. rt_completion_done(&spi_drv->cpt);
  835. }
  836. #if defined(SOC_SERIES_STM32F0)
  837. void SPI1_DMA_RX_TX_IRQHandler(void)
  838. {
  839. #if defined(BSP_USING_SPI1) && defined(BSP_SPI1_TX_USING_DMA)
  840. SPI1_DMA_TX_IRQHandler();
  841. #endif
  842. #if defined(BSP_USING_SPI1) && defined(BSP_SPI1_RX_USING_DMA)
  843. SPI1_DMA_RX_IRQHandler();
  844. #endif
  845. }
  846. void SPI2_DMA_RX_TX_IRQHandler(void)
  847. {
  848. #if defined(BSP_USING_SPI2) && defined(BSP_SPI2_TX_USING_DMA)
  849. SPI2_DMA_TX_IRQHandler();
  850. #endif
  851. #if defined(BSP_USING_SPI2) && defined(BSP_SPI2_RX_USING_DMA)
  852. SPI2_DMA_RX_IRQHandler();
  853. #endif
  854. }
  855. #endif /* SOC_SERIES_STM32F0 */
  856. int rt_hw_spi_init(void)
  857. {
  858. stm32_get_dma_info();
  859. return rt_hw_spi_bus_init();
  860. }
  861. INIT_BOARD_EXPORT(rt_hw_spi_init);
  862. #endif /* BSP_USING_SPI1 || BSP_USING_SPI2 || BSP_USING_SPI3 || BSP_USING_SPI4 || BSP_USING_SPI5 */
  863. #endif /* BSP_USING_SPI */