drv_spi.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  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_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *message)
  247. {
  248. HAL_StatusTypeDef state;
  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. return message->length;
  392. }
  393. static rt_err_t spi_configure(struct rt_spi_device *device,
  394. struct rt_spi_configuration *configuration)
  395. {
  396. RT_ASSERT(device != RT_NULL);
  397. RT_ASSERT(configuration != RT_NULL);
  398. struct stm32_spi *spi_drv = rt_container_of(device->bus, struct stm32_spi, spi_bus);
  399. spi_drv->cfg = configuration;
  400. return stm32_spi_init(spi_drv, configuration);
  401. }
  402. static const struct rt_spi_ops stm_spi_ops =
  403. {
  404. .configure = spi_configure,
  405. .xfer = spixfer,
  406. };
  407. static int rt_hw_spi_bus_init(void)
  408. {
  409. rt_err_t result;
  410. for (rt_size_t i = 0; i < sizeof(spi_config) / sizeof(spi_config[0]); i++)
  411. {
  412. spi_bus_obj[i].config = &spi_config[i];
  413. spi_bus_obj[i].spi_bus.parent.user_data = &spi_config[i];
  414. spi_bus_obj[i].handle.Instance = spi_config[i].Instance;
  415. if (spi_bus_obj[i].spi_dma_flag & SPI_USING_RX_DMA_FLAG)
  416. {
  417. /* Configure the DMA handler for Transmission process */
  418. spi_bus_obj[i].dma.handle_rx.Instance = spi_config[i].dma_rx->Instance;
  419. #if defined(SOC_SERIES_STM32F2) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7)
  420. spi_bus_obj[i].dma.handle_rx.Init.Channel = spi_config[i].dma_rx->channel;
  421. #elif defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32WB) || defined(SOC_SERIES_STM32H7)
  422. spi_bus_obj[i].dma.handle_rx.Init.Request = spi_config[i].dma_rx->request;
  423. #endif
  424. spi_bus_obj[i].dma.handle_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
  425. spi_bus_obj[i].dma.handle_rx.Init.PeriphInc = DMA_PINC_DISABLE;
  426. spi_bus_obj[i].dma.handle_rx.Init.MemInc = DMA_MINC_ENABLE;
  427. spi_bus_obj[i].dma.handle_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  428. spi_bus_obj[i].dma.handle_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  429. spi_bus_obj[i].dma.handle_rx.Init.Mode = DMA_NORMAL;
  430. spi_bus_obj[i].dma.handle_rx.Init.Priority = DMA_PRIORITY_HIGH;
  431. #if defined(SOC_SERIES_STM32F2) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32H7)
  432. spi_bus_obj[i].dma.handle_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
  433. spi_bus_obj[i].dma.handle_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
  434. spi_bus_obj[i].dma.handle_rx.Init.MemBurst = DMA_MBURST_INC4;
  435. spi_bus_obj[i].dma.handle_rx.Init.PeriphBurst = DMA_PBURST_INC4;
  436. #endif
  437. {
  438. rt_uint32_t tmpreg = 0x00U;
  439. #if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32F0)
  440. /* enable DMA clock && Delay after an RCC peripheral clock enabling*/
  441. SET_BIT(RCC->AHBENR, spi_config[i].dma_rx->dma_rcc);
  442. tmpreg = READ_BIT(RCC->AHBENR, spi_config[i].dma_rx->dma_rcc);
  443. #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)
  444. SET_BIT(RCC->AHB1ENR, spi_config[i].dma_rx->dma_rcc);
  445. /* Delay after an RCC peripheral clock enabling */
  446. tmpreg = READ_BIT(RCC->AHB1ENR, spi_config[i].dma_rx->dma_rcc);
  447. #elif defined(SOC_SERIES_STM32MP1)
  448. __HAL_RCC_DMAMUX_CLK_ENABLE();
  449. SET_BIT(RCC->MP_AHB2ENSETR, spi_config[i].dma_rx->dma_rcc);
  450. tmpreg = READ_BIT(RCC->MP_AHB2ENSETR, spi_config[i].dma_rx->dma_rcc);
  451. #endif
  452. UNUSED(tmpreg); /* To avoid compiler warnings */
  453. }
  454. }
  455. if (spi_bus_obj[i].spi_dma_flag & SPI_USING_TX_DMA_FLAG)
  456. {
  457. /* Configure the DMA handler for Transmission process */
  458. spi_bus_obj[i].dma.handle_tx.Instance = spi_config[i].dma_tx->Instance;
  459. #if defined(SOC_SERIES_STM32F2) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7)
  460. spi_bus_obj[i].dma.handle_tx.Init.Channel = spi_config[i].dma_tx->channel;
  461. #elif defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32WB) || defined(SOC_SERIES_STM32H7)
  462. spi_bus_obj[i].dma.handle_tx.Init.Request = spi_config[i].dma_tx->request;
  463. #endif
  464. spi_bus_obj[i].dma.handle_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
  465. spi_bus_obj[i].dma.handle_tx.Init.PeriphInc = DMA_PINC_DISABLE;
  466. spi_bus_obj[i].dma.handle_tx.Init.MemInc = DMA_MINC_ENABLE;
  467. spi_bus_obj[i].dma.handle_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  468. spi_bus_obj[i].dma.handle_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  469. spi_bus_obj[i].dma.handle_tx.Init.Mode = DMA_NORMAL;
  470. spi_bus_obj[i].dma.handle_tx.Init.Priority = DMA_PRIORITY_LOW;
  471. #if defined(SOC_SERIES_STM32F2) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32H7)
  472. spi_bus_obj[i].dma.handle_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
  473. spi_bus_obj[i].dma.handle_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
  474. spi_bus_obj[i].dma.handle_tx.Init.MemBurst = DMA_MBURST_INC4;
  475. spi_bus_obj[i].dma.handle_tx.Init.PeriphBurst = DMA_PBURST_INC4;
  476. #endif
  477. {
  478. rt_uint32_t tmpreg = 0x00U;
  479. #if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32F0)
  480. /* enable DMA clock && Delay after an RCC peripheral clock enabling*/
  481. SET_BIT(RCC->AHBENR, spi_config[i].dma_tx->dma_rcc);
  482. tmpreg = READ_BIT(RCC->AHBENR, spi_config[i].dma_tx->dma_rcc);
  483. #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)
  484. SET_BIT(RCC->AHB1ENR, spi_config[i].dma_tx->dma_rcc);
  485. /* Delay after an RCC peripheral clock enabling */
  486. tmpreg = READ_BIT(RCC->AHB1ENR, spi_config[i].dma_tx->dma_rcc);
  487. #elif defined(SOC_SERIES_STM32MP1)
  488. __HAL_RCC_DMAMUX_CLK_ENABLE();
  489. SET_BIT(RCC->MP_AHB2ENSETR, spi_config[i].dma_tx->dma_rcc);
  490. tmpreg = READ_BIT(RCC->MP_AHB2ENSETR, spi_config[i].dma_tx->dma_rcc);
  491. #endif
  492. UNUSED(tmpreg); /* To avoid compiler warnings */
  493. }
  494. }
  495. /* initialize completion object */
  496. rt_completion_init(&spi_bus_obj[i].cpt);
  497. result = rt_spi_bus_register(&spi_bus_obj[i].spi_bus, spi_config[i].bus_name, &stm_spi_ops);
  498. RT_ASSERT(result == RT_EOK);
  499. LOG_D("%s bus init done", spi_config[i].bus_name);
  500. }
  501. return result;
  502. }
  503. /**
  504. * Attach the spi device to SPI bus, this function must be used after initialization.
  505. */
  506. rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin)
  507. {
  508. RT_ASSERT(bus_name != RT_NULL);
  509. RT_ASSERT(device_name != RT_NULL);
  510. rt_err_t result;
  511. struct rt_spi_device *spi_device;
  512. /* attach the device to spi bus*/
  513. spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device));
  514. RT_ASSERT(spi_device != RT_NULL);
  515. spi_device->cs_pin = cs_pin;
  516. if(cs_pin != PIN_NONE)
  517. {
  518. rt_pin_mode(cs_pin, PIN_MODE_OUTPUT);
  519. rt_pin_write(cs_pin, PIN_HIGH);
  520. }
  521. result = rt_spi_bus_attach_device(spi_device, device_name, bus_name, RT_NULL);
  522. if (result != RT_EOK)
  523. {
  524. LOG_E("%s attach to %s faild, %d\n", device_name, bus_name, result);
  525. }
  526. RT_ASSERT(result == RT_EOK);
  527. LOG_D("%s attach to %s done", device_name, bus_name);
  528. return result;
  529. }
  530. #if defined(BSP_SPI1_TX_USING_DMA) || defined(BSP_SPI1_RX_USING_DMA)
  531. void SPI1_IRQHandler(void)
  532. {
  533. /* enter interrupt */
  534. rt_interrupt_enter();
  535. HAL_SPI_IRQHandler(&spi_bus_obj[SPI1_INDEX].handle);
  536. /* leave interrupt */
  537. rt_interrupt_leave();
  538. }
  539. #endif
  540. #if defined(BSP_USING_SPI1) && defined(BSP_SPI1_RX_USING_DMA)
  541. /**
  542. * @brief This function handles DMA Rx interrupt request.
  543. * @param None
  544. * @retval None
  545. */
  546. void SPI1_DMA_RX_IRQHandler(void)
  547. {
  548. /* enter interrupt */
  549. rt_interrupt_enter();
  550. HAL_DMA_IRQHandler(&spi_bus_obj[SPI1_INDEX].dma.handle_rx);
  551. /* leave interrupt */
  552. rt_interrupt_leave();
  553. }
  554. #endif
  555. #if defined(BSP_USING_SPI1) && defined(BSP_SPI1_TX_USING_DMA)
  556. /**
  557. * @brief This function handles DMA Tx interrupt request.
  558. * @param None
  559. * @retval None
  560. */
  561. void SPI1_DMA_TX_IRQHandler(void)
  562. {
  563. /* enter interrupt */
  564. rt_interrupt_enter();
  565. HAL_DMA_IRQHandler(&spi_bus_obj[SPI1_INDEX].dma.handle_tx);
  566. /* leave interrupt */
  567. rt_interrupt_leave();
  568. }
  569. #endif /* defined(BSP_USING_SPI1) && defined(BSP_SPI_USING_DMA) */
  570. #if defined(BSP_SPI2_TX_USING_DMA) || defined(BSP_SPI2_RX_USING_DMA)
  571. void SPI2_IRQHandler(void)
  572. {
  573. /* enter interrupt */
  574. rt_interrupt_enter();
  575. HAL_SPI_IRQHandler(&spi_bus_obj[SPI2_INDEX].handle);
  576. /* leave interrupt */
  577. rt_interrupt_leave();
  578. }
  579. #endif
  580. #if defined(BSP_USING_SPI2) && defined(BSP_SPI2_RX_USING_DMA)
  581. /**
  582. * @brief This function handles DMA Rx interrupt request.
  583. * @param None
  584. * @retval None
  585. */
  586. void SPI2_DMA_RX_IRQHandler(void)
  587. {
  588. /* enter interrupt */
  589. rt_interrupt_enter();
  590. HAL_DMA_IRQHandler(&spi_bus_obj[SPI2_INDEX].dma.handle_rx);
  591. /* leave interrupt */
  592. rt_interrupt_leave();
  593. }
  594. #endif
  595. #if defined(BSP_USING_SPI2) && defined(BSP_SPI2_TX_USING_DMA)
  596. /**
  597. * @brief This function handles DMA Tx interrupt request.
  598. * @param None
  599. * @retval None
  600. */
  601. void SPI2_DMA_TX_IRQHandler(void)
  602. {
  603. /* enter interrupt */
  604. rt_interrupt_enter();
  605. HAL_DMA_IRQHandler(&spi_bus_obj[SPI2_INDEX].dma.handle_tx);
  606. /* leave interrupt */
  607. rt_interrupt_leave();
  608. }
  609. #endif /* defined(BSP_USING_SPI2) && defined(BSP_SPI_USING_DMA) */
  610. #if defined(BSP_SPI3_TX_USING_DMA) || defined(BSP_SPI3_RX_USING_DMA)
  611. void SPI3_IRQHandler(void)
  612. {
  613. /* enter interrupt */
  614. rt_interrupt_enter();
  615. HAL_SPI_IRQHandler(&spi_bus_obj[SPI3_INDEX].handle);
  616. /* leave interrupt */
  617. rt_interrupt_leave();
  618. }
  619. #endif
  620. #if defined(BSP_USING_SPI3) && defined(BSP_SPI3_RX_USING_DMA)
  621. /**
  622. * @brief This function handles DMA Rx interrupt request.
  623. * @param None
  624. * @retval None
  625. */
  626. void SPI3_DMA_RX_IRQHandler(void)
  627. {
  628. /* enter interrupt */
  629. rt_interrupt_enter();
  630. HAL_DMA_IRQHandler(&spi_bus_obj[SPI3_INDEX].dma.handle_rx);
  631. /* leave interrupt */
  632. rt_interrupt_leave();
  633. }
  634. #endif
  635. #if defined(BSP_USING_SPI3) && defined(BSP_SPI3_TX_USING_DMA)
  636. /**
  637. * @brief This function handles DMA Tx interrupt request.
  638. * @param None
  639. * @retval None
  640. */
  641. void SPI3_DMA_TX_IRQHandler(void)
  642. {
  643. /* enter interrupt */
  644. rt_interrupt_enter();
  645. HAL_DMA_IRQHandler(&spi_bus_obj[SPI3_INDEX].dma.handle_tx);
  646. /* leave interrupt */
  647. rt_interrupt_leave();
  648. }
  649. #endif /* defined(BSP_USING_SPI3) && defined(BSP_SPI_USING_DMA) */
  650. #if defined(BSP_SPI4_TX_USING_DMA) || defined(BSP_SPI4_RX_USING_DMA)
  651. void SPI4_IRQHandler(void)
  652. {
  653. /* enter interrupt */
  654. rt_interrupt_enter();
  655. HAL_SPI_IRQHandler(&spi_bus_obj[SPI4_INDEX].handle);
  656. /* leave interrupt */
  657. rt_interrupt_leave();
  658. }
  659. #endif
  660. #if defined(BSP_USING_SPI4) && defined(BSP_SPI4_RX_USING_DMA)
  661. /**
  662. * @brief This function handles DMA Rx interrupt request.
  663. * @param None
  664. * @retval None
  665. */
  666. void SPI4_DMA_RX_IRQHandler(void)
  667. {
  668. /* enter interrupt */
  669. rt_interrupt_enter();
  670. HAL_DMA_IRQHandler(&spi_bus_obj[SPI4_INDEX].dma.handle_rx);
  671. /* leave interrupt */
  672. rt_interrupt_leave();
  673. }
  674. #endif
  675. #if defined(BSP_USING_SPI4) && defined(BSP_SPI4_TX_USING_DMA)
  676. /**
  677. * @brief This function handles DMA Tx interrupt request.
  678. * @param None
  679. * @retval None
  680. */
  681. void SPI4_DMA_TX_IRQHandler(void)
  682. {
  683. /* enter interrupt */
  684. rt_interrupt_enter();
  685. HAL_DMA_IRQHandler(&spi_bus_obj[SPI4_INDEX].dma.handle_tx);
  686. /* leave interrupt */
  687. rt_interrupt_leave();
  688. }
  689. #endif /* defined(BSP_USING_SPI4) && defined(BSP_SPI_USING_DMA) */
  690. #if defined(BSP_SPI5_TX_USING_DMA) || defined(BSP_SPI5_RX_USING_DMA)
  691. void SPI5_IRQHandler(void)
  692. {
  693. /* enter interrupt */
  694. rt_interrupt_enter();
  695. HAL_SPI_IRQHandler(&spi_bus_obj[SPI5_INDEX].handle);
  696. /* leave interrupt */
  697. rt_interrupt_leave();
  698. }
  699. #endif
  700. #if defined(BSP_USING_SPI5) && defined(BSP_SPI5_RX_USING_DMA)
  701. /**
  702. * @brief This function handles DMA Rx interrupt request.
  703. * @param None
  704. * @retval None
  705. */
  706. void SPI5_DMA_RX_IRQHandler(void)
  707. {
  708. /* enter interrupt */
  709. rt_interrupt_enter();
  710. HAL_DMA_IRQHandler(&spi_bus_obj[SPI5_INDEX].dma.handle_rx);
  711. /* leave interrupt */
  712. rt_interrupt_leave();
  713. }
  714. #endif
  715. #if defined(BSP_USING_SPI5) && defined(BSP_SPI5_TX_USING_DMA)
  716. /**
  717. * @brief This function handles DMA Tx interrupt request.
  718. * @param None
  719. * @retval None
  720. */
  721. void SPI5_DMA_TX_IRQHandler(void)
  722. {
  723. /* enter interrupt */
  724. rt_interrupt_enter();
  725. HAL_DMA_IRQHandler(&spi_bus_obj[SPI5_INDEX].dma.handle_tx);
  726. /* leave interrupt */
  727. rt_interrupt_leave();
  728. }
  729. #endif /* defined(BSP_USING_SPI5) && defined(BSP_SPI_USING_DMA) */
  730. #if defined(BSP_USING_SPI6) && defined(BSP_SPI6_RX_USING_DMA)
  731. /**
  732. * @brief This function handles DMA Rx interrupt request.
  733. * @param None
  734. * @retval None
  735. */
  736. void SPI6_DMA_RX_IRQHandler(void)
  737. {
  738. /* enter interrupt */
  739. rt_interrupt_enter();
  740. HAL_DMA_IRQHandler(&spi_bus_obj[SPI6_INDEX].dma.handle_rx);
  741. /* leave interrupt */
  742. rt_interrupt_leave();
  743. }
  744. #endif
  745. #if defined(BSP_USING_SPI6) && defined(BSP_SPI6_TX_USING_DMA)
  746. /**
  747. * @brief This function handles DMA Tx interrupt request.
  748. * @param None
  749. * @retval None
  750. */
  751. void SPI6_DMA_TX_IRQHandler(void)
  752. {
  753. /* enter interrupt */
  754. rt_interrupt_enter();
  755. HAL_DMA_IRQHandler(&spi_bus_obj[SPI6_INDEX].dma.handle_tx);
  756. /* leave interrupt */
  757. rt_interrupt_leave();
  758. }
  759. #endif /* defined(BSP_USING_SPI6) && defined(BSP_SPI_USING_DMA) */
  760. static void stm32_get_dma_info(void)
  761. {
  762. #ifdef BSP_SPI1_RX_USING_DMA
  763. spi_bus_obj[SPI1_INDEX].spi_dma_flag |= SPI_USING_RX_DMA_FLAG;
  764. static struct dma_config spi1_dma_rx = SPI1_RX_DMA_CONFIG;
  765. spi_config[SPI1_INDEX].dma_rx = &spi1_dma_rx;
  766. #endif
  767. #ifdef BSP_SPI1_TX_USING_DMA
  768. spi_bus_obj[SPI1_INDEX].spi_dma_flag |= SPI_USING_TX_DMA_FLAG;
  769. static struct dma_config spi1_dma_tx = SPI1_TX_DMA_CONFIG;
  770. spi_config[SPI1_INDEX].dma_tx = &spi1_dma_tx;
  771. #endif
  772. #ifdef BSP_SPI2_RX_USING_DMA
  773. spi_bus_obj[SPI2_INDEX].spi_dma_flag |= SPI_USING_RX_DMA_FLAG;
  774. static struct dma_config spi2_dma_rx = SPI2_RX_DMA_CONFIG;
  775. spi_config[SPI2_INDEX].dma_rx = &spi2_dma_rx;
  776. #endif
  777. #ifdef BSP_SPI2_TX_USING_DMA
  778. spi_bus_obj[SPI2_INDEX].spi_dma_flag |= SPI_USING_TX_DMA_FLAG;
  779. static struct dma_config spi2_dma_tx = SPI2_TX_DMA_CONFIG;
  780. spi_config[SPI2_INDEX].dma_tx = &spi2_dma_tx;
  781. #endif
  782. #ifdef BSP_SPI3_RX_USING_DMA
  783. spi_bus_obj[SPI3_INDEX].spi_dma_flag |= SPI_USING_RX_DMA_FLAG;
  784. static struct dma_config spi3_dma_rx = SPI3_RX_DMA_CONFIG;
  785. spi_config[SPI3_INDEX].dma_rx = &spi3_dma_rx;
  786. #endif
  787. #ifdef BSP_SPI3_TX_USING_DMA
  788. spi_bus_obj[SPI3_INDEX].spi_dma_flag |= SPI_USING_TX_DMA_FLAG;
  789. static struct dma_config spi3_dma_tx = SPI3_TX_DMA_CONFIG;
  790. spi_config[SPI3_INDEX].dma_tx = &spi3_dma_tx;
  791. #endif
  792. #ifdef BSP_SPI4_RX_USING_DMA
  793. spi_bus_obj[SPI4_INDEX].spi_dma_flag |= SPI_USING_RX_DMA_FLAG;
  794. static struct dma_config spi4_dma_rx = SPI4_RX_DMA_CONFIG;
  795. spi_config[SPI4_INDEX].dma_rx = &spi4_dma_rx;
  796. #endif
  797. #ifdef BSP_SPI4_TX_USING_DMA
  798. spi_bus_obj[SPI4_INDEX].spi_dma_flag |= SPI_USING_TX_DMA_FLAG;
  799. static struct dma_config spi4_dma_tx = SPI4_TX_DMA_CONFIG;
  800. spi_config[SPI4_INDEX].dma_tx = &spi4_dma_tx;
  801. #endif
  802. #ifdef BSP_SPI5_RX_USING_DMA
  803. spi_bus_obj[SPI5_INDEX].spi_dma_flag |= SPI_USING_RX_DMA_FLAG;
  804. static struct dma_config spi5_dma_rx = SPI5_RX_DMA_CONFIG;
  805. spi_config[SPI5_INDEX].dma_rx = &spi5_dma_rx;
  806. #endif
  807. #ifdef BSP_SPI5_TX_USING_DMA
  808. spi_bus_obj[SPI5_INDEX].spi_dma_flag |= SPI_USING_TX_DMA_FLAG;
  809. static struct dma_config spi5_dma_tx = SPI5_TX_DMA_CONFIG;
  810. spi_config[SPI5_INDEX].dma_tx = &spi5_dma_tx;
  811. #endif
  812. #ifdef BSP_SPI6_RX_USING_DMA
  813. spi_bus_obj[SPI6_INDEX].spi_dma_flag |= SPI_USING_RX_DMA_FLAG;
  814. static struct dma_config spi6_dma_rx = SPI6_RX_DMA_CONFIG;
  815. spi_config[SPI6_INDEX].dma_rx = &spi6_dma_rx;
  816. #endif
  817. #ifdef BSP_SPI6_TX_USING_DMA
  818. spi_bus_obj[SPI6_INDEX].spi_dma_flag |= SPI_USING_TX_DMA_FLAG;
  819. static struct dma_config spi6_dma_tx = SPI6_TX_DMA_CONFIG;
  820. spi_config[SPI6_INDEX].dma_tx = &spi6_dma_tx;
  821. #endif
  822. }
  823. void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
  824. {
  825. struct stm32_spi *spi_drv = rt_container_of(hspi, struct stm32_spi, handle);
  826. rt_completion_done(&spi_drv->cpt);
  827. }
  828. void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
  829. {
  830. struct stm32_spi *spi_drv = rt_container_of(hspi, struct stm32_spi, handle);
  831. rt_completion_done(&spi_drv->cpt);
  832. }
  833. void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
  834. {
  835. struct stm32_spi *spi_drv = rt_container_of(hspi, struct stm32_spi, handle);
  836. rt_completion_done(&spi_drv->cpt);
  837. }
  838. #if defined(SOC_SERIES_STM32F0)
  839. void SPI1_DMA_RX_TX_IRQHandler(void)
  840. {
  841. #if defined(BSP_USING_SPI1) && defined(BSP_SPI1_TX_USING_DMA)
  842. SPI1_DMA_TX_IRQHandler();
  843. #endif
  844. #if defined(BSP_USING_SPI1) && defined(BSP_SPI1_RX_USING_DMA)
  845. SPI1_DMA_RX_IRQHandler();
  846. #endif
  847. }
  848. void SPI2_DMA_RX_TX_IRQHandler(void)
  849. {
  850. #if defined(BSP_USING_SPI2) && defined(BSP_SPI2_TX_USING_DMA)
  851. SPI2_DMA_TX_IRQHandler();
  852. #endif
  853. #if defined(BSP_USING_SPI2) && defined(BSP_SPI2_RX_USING_DMA)
  854. SPI2_DMA_RX_IRQHandler();
  855. #endif
  856. }
  857. #endif /* SOC_SERIES_STM32F0 */
  858. int rt_hw_spi_init(void)
  859. {
  860. stm32_get_dma_info();
  861. return rt_hw_spi_bus_init();
  862. }
  863. INIT_BOARD_EXPORT(rt_hw_spi_init);
  864. #endif /* BSP_USING_SPI1 || BSP_USING_SPI2 || BSP_USING_SPI3 || BSP_USING_SPI4 || BSP_USING_SPI5 */
  865. #endif /* BSP_USING_SPI */