spi_slave.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #include <string.h>
  14. #include "driver/spi_common.h"
  15. #include "driver/spi_slave.h"
  16. #include "soc/gpio_sig_map.h"
  17. #include "soc/spi_reg.h"
  18. #include "soc/dport_reg.h"
  19. #include "soc/spi_struct.h"
  20. #include "rom/ets_sys.h"
  21. #include "esp_types.h"
  22. #include "esp_attr.h"
  23. #include "esp_intr.h"
  24. #include "esp_intr_alloc.h"
  25. #include "esp_log.h"
  26. #include "esp_err.h"
  27. #include "esp_pm.h"
  28. #include "freertos/FreeRTOS.h"
  29. #include "freertos/semphr.h"
  30. #include "freertos/xtensa_api.h"
  31. #include "freertos/task.h"
  32. #include "freertos/ringbuf.h"
  33. #include "soc/soc.h"
  34. #include "soc/soc_memory_layout.h"
  35. #include "soc/dport_reg.h"
  36. #include "rom/lldesc.h"
  37. #include "driver/gpio.h"
  38. #include "driver/periph_ctrl.h"
  39. #include "esp_heap_caps.h"
  40. static const char *SPI_TAG = "spi_slave";
  41. #define SPI_CHECK(a, str, ret_val) \
  42. if (!(a)) { \
  43. ESP_LOGE(SPI_TAG,"%s(%d): %s", __FUNCTION__, __LINE__, str); \
  44. return (ret_val); \
  45. }
  46. #define VALID_HOST(x) (x>SPI_HOST && x<=VSPI_HOST)
  47. typedef struct {
  48. spi_slave_interface_config_t cfg;
  49. intr_handle_t intr;
  50. spi_dev_t *hw;
  51. spi_slave_transaction_t *cur_trans;
  52. lldesc_t *dmadesc_tx;
  53. lldesc_t *dmadesc_rx;
  54. bool no_gpio_matrix;
  55. int max_transfer_sz;
  56. QueueHandle_t trans_queue;
  57. QueueHandle_t ret_queue;
  58. int dma_chan;
  59. #ifdef CONFIG_PM_ENABLE
  60. esp_pm_lock_handle_t pm_lock;
  61. #endif
  62. } spi_slave_t;
  63. static spi_slave_t *spihost[3];
  64. static void IRAM_ATTR spi_intr(void *arg);
  65. esp_err_t spi_slave_initialize(spi_host_device_t host, const spi_bus_config_t *bus_config, const spi_slave_interface_config_t *slave_config, int dma_chan)
  66. {
  67. bool native, spi_chan_claimed, dma_chan_claimed;
  68. //We only support HSPI/VSPI, period.
  69. SPI_CHECK(VALID_HOST(host), "invalid host", ESP_ERR_INVALID_ARG);
  70. SPI_CHECK( dma_chan >= 0 && dma_chan <= 2, "invalid dma channel", ESP_ERR_INVALID_ARG );
  71. spi_chan_claimed=spicommon_periph_claim(host);
  72. SPI_CHECK(spi_chan_claimed, "host already in use", ESP_ERR_INVALID_STATE);
  73. if ( dma_chan != 0 ) {
  74. dma_chan_claimed=spicommon_dma_chan_claim(dma_chan);
  75. if ( !dma_chan_claimed ) {
  76. spicommon_periph_free( host );
  77. SPI_CHECK(dma_chan_claimed, "dma channel already in use", ESP_ERR_INVALID_STATE);
  78. }
  79. }
  80. spihost[host] = malloc(sizeof(spi_slave_t));
  81. if (spihost[host] == NULL) goto nomem;
  82. memset(spihost[host], 0, sizeof(spi_slave_t));
  83. memcpy(&spihost[host]->cfg, slave_config, sizeof(spi_slave_interface_config_t));
  84. spicommon_bus_initialize_io(host, bus_config, dma_chan, SPICOMMON_BUSFLAG_SLAVE, &native);
  85. gpio_set_direction(slave_config->spics_io_num, GPIO_MODE_INPUT);
  86. spicommon_cs_initialize(host, slave_config->spics_io_num, 0, native == false);
  87. spihost[host]->no_gpio_matrix = native;
  88. spihost[host]->dma_chan = dma_chan;
  89. if (dma_chan != 0) {
  90. //See how many dma descriptors we need and allocate them
  91. int dma_desc_ct = (bus_config->max_transfer_sz + SPI_MAX_DMA_LEN - 1) / SPI_MAX_DMA_LEN;
  92. if (dma_desc_ct == 0) dma_desc_ct = 1; //default to 4k when max is not given
  93. spihost[host]->max_transfer_sz = dma_desc_ct * SPI_MAX_DMA_LEN;
  94. spihost[host]->dmadesc_tx = heap_caps_malloc(sizeof(lldesc_t) * dma_desc_ct, MALLOC_CAP_DMA);
  95. spihost[host]->dmadesc_rx = heap_caps_malloc(sizeof(lldesc_t) * dma_desc_ct, MALLOC_CAP_DMA);
  96. if (!spihost[host]->dmadesc_tx || !spihost[host]->dmadesc_rx) goto nomem;
  97. } else {
  98. //We're limited to non-DMA transfers: the SPI work registers can hold 64 bytes at most.
  99. spihost[host]->max_transfer_sz = 16 * 4;
  100. }
  101. #ifdef CONFIG_PM_ENABLE
  102. esp_err_t err = esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "spi_slave",
  103. &spihost[host]->pm_lock);
  104. if (err != ESP_OK) {
  105. goto nomem;
  106. }
  107. // Lock APB frequency while SPI slave driver is in use
  108. esp_pm_lock_acquire(spihost[host]->pm_lock);
  109. #endif //CONFIG_PM_ENABLE
  110. //Create queues
  111. spihost[host]->trans_queue = xQueueCreate(slave_config->queue_size, sizeof(spi_slave_transaction_t *));
  112. spihost[host]->ret_queue = xQueueCreate(slave_config->queue_size, sizeof(spi_slave_transaction_t *));
  113. if (!spihost[host]->trans_queue || !spihost[host]->ret_queue) goto nomem;
  114. esp_intr_alloc(spicommon_irqsource_for_host(host), ESP_INTR_FLAG_INTRDISABLED, spi_intr, (void *)spihost[host], &spihost[host]->intr);
  115. spihost[host]->hw = spicommon_hw_for_host(host);
  116. //Configure slave
  117. spihost[host]->hw->clock.val = 0;
  118. spihost[host]->hw->user.val = 0;
  119. spihost[host]->hw->ctrl.val = 0;
  120. spihost[host]->hw->slave.wr_rd_buf_en = 1; //no sure if needed
  121. spihost[host]->hw->user.doutdin = 1; //we only support full duplex
  122. spihost[host]->hw->user.sio = 0;
  123. spihost[host]->hw->slave.slave_mode = 1;
  124. spihost[host]->hw->dma_conf.val |= SPI_OUT_RST | SPI_IN_RST | SPI_AHBM_RST | SPI_AHBM_FIFO_RST;
  125. spihost[host]->hw->dma_out_link.start = 0;
  126. spihost[host]->hw->dma_in_link.start = 0;
  127. spihost[host]->hw->dma_conf.val &= ~(SPI_OUT_RST | SPI_IN_RST | SPI_AHBM_RST | SPI_AHBM_FIFO_RST);
  128. spihost[host]->hw->dma_conf.out_data_burst_en = 1;
  129. spihost[host]->hw->slave.sync_reset = 1;
  130. spihost[host]->hw->slave.sync_reset = 0;
  131. bool nodelay = true;
  132. spihost[host]->hw->ctrl.rd_bit_order = (slave_config->flags & SPI_SLAVE_RXBIT_LSBFIRST) ? 1 : 0;
  133. spihost[host]->hw->ctrl.wr_bit_order = (slave_config->flags & SPI_SLAVE_TXBIT_LSBFIRST) ? 1 : 0;
  134. if (slave_config->mode == 0) {
  135. spihost[host]->hw->pin.ck_idle_edge = 0;
  136. spihost[host]->hw->user.ck_i_edge = 1;
  137. spihost[host]->hw->ctrl2.miso_delay_mode = nodelay ? 0 : 2;
  138. } else if (slave_config->mode == 1) {
  139. spihost[host]->hw->pin.ck_idle_edge = 0;
  140. spihost[host]->hw->user.ck_i_edge = 0;
  141. spihost[host]->hw->ctrl2.miso_delay_mode = nodelay ? 0 : 1;
  142. } else if (slave_config->mode == 2) {
  143. spihost[host]->hw->pin.ck_idle_edge = 1;
  144. spihost[host]->hw->user.ck_i_edge = 0;
  145. spihost[host]->hw->ctrl2.miso_delay_mode = nodelay ? 0 : 1;
  146. } else if (slave_config->mode == 3) {
  147. spihost[host]->hw->pin.ck_idle_edge = 1;
  148. spihost[host]->hw->user.ck_i_edge = 1;
  149. spihost[host]->hw->ctrl2.miso_delay_mode = nodelay ? 0 : 2;
  150. }
  151. //Reset DMA
  152. spihost[host]->hw->dma_conf.val |= SPI_OUT_RST | SPI_IN_RST | SPI_AHBM_RST | SPI_AHBM_FIFO_RST;
  153. spihost[host]->hw->dma_out_link.start = 0;
  154. spihost[host]->hw->dma_in_link.start = 0;
  155. spihost[host]->hw->dma_conf.val &= ~(SPI_OUT_RST | SPI_IN_RST | SPI_AHBM_RST | SPI_AHBM_FIFO_RST);
  156. //Disable unneeded ints
  157. spihost[host]->hw->slave.rd_buf_done = 0;
  158. spihost[host]->hw->slave.wr_buf_done = 0;
  159. spihost[host]->hw->slave.rd_sta_done = 0;
  160. spihost[host]->hw->slave.wr_sta_done = 0;
  161. spihost[host]->hw->slave.rd_buf_inten = 0;
  162. spihost[host]->hw->slave.wr_buf_inten = 0;
  163. spihost[host]->hw->slave.rd_sta_inten = 0;
  164. spihost[host]->hw->slave.wr_sta_inten = 0;
  165. //Force a transaction done interrupt. This interrupt won't fire yet because we initialized the SPI interrupt as
  166. //disabled. This way, we can just enable the SPI interrupt and the interrupt handler will kick in, handling
  167. //any transactions that are queued.
  168. spihost[host]->hw->slave.trans_inten = 1;
  169. spihost[host]->hw->slave.trans_done = 1;
  170. return ESP_OK;
  171. nomem:
  172. if (spihost[host]) {
  173. if (spihost[host]->trans_queue) vQueueDelete(spihost[host]->trans_queue);
  174. if (spihost[host]->ret_queue) vQueueDelete(spihost[host]->ret_queue);
  175. free(spihost[host]->dmadesc_tx);
  176. free(spihost[host]->dmadesc_rx);
  177. #ifdef CONFIG_PM_ENABLE
  178. if (spihost[host]->pm_lock) {
  179. esp_pm_lock_release(spihost[host]->pm_lock);
  180. esp_pm_lock_delete(spihost[host]->pm_lock);
  181. }
  182. #endif
  183. }
  184. free(spihost[host]);
  185. spihost[host] = NULL;
  186. spicommon_periph_free(host);
  187. spicommon_dma_chan_free(dma_chan);
  188. return ESP_ERR_NO_MEM;
  189. }
  190. esp_err_t spi_slave_free(spi_host_device_t host)
  191. {
  192. SPI_CHECK(VALID_HOST(host), "invalid host", ESP_ERR_INVALID_ARG);
  193. SPI_CHECK(spihost[host], "host not slave", ESP_ERR_INVALID_ARG);
  194. if (spihost[host]->trans_queue) vQueueDelete(spihost[host]->trans_queue);
  195. if (spihost[host]->ret_queue) vQueueDelete(spihost[host]->ret_queue);
  196. if ( spihost[host]->dma_chan > 0 ) {
  197. spicommon_dma_chan_free ( spihost[host]->dma_chan );
  198. }
  199. free(spihost[host]->dmadesc_tx);
  200. free(spihost[host]->dmadesc_rx);
  201. esp_intr_free(spihost[host]->intr);
  202. #ifdef CONFIG_PM_ENABLE
  203. esp_pm_lock_release(spihost[host]->pm_lock);
  204. esp_pm_lock_delete(spihost[host]->pm_lock);
  205. #endif //CONFIG_PM_ENABLE
  206. free(spihost[host]);
  207. spihost[host] = NULL;
  208. spicommon_periph_free(host);
  209. return ESP_OK;
  210. }
  211. esp_err_t spi_slave_queue_trans(spi_host_device_t host, const spi_slave_transaction_t *trans_desc, TickType_t ticks_to_wait)
  212. {
  213. BaseType_t r;
  214. SPI_CHECK(VALID_HOST(host), "invalid host", ESP_ERR_INVALID_ARG);
  215. SPI_CHECK(spihost[host], "host not slave", ESP_ERR_INVALID_ARG);
  216. SPI_CHECK(spihost[host]->dma_chan == 0 || trans_desc->tx_buffer==NULL || esp_ptr_dma_capable(trans_desc->tx_buffer),
  217. "txdata not in DMA-capable memory", ESP_ERR_INVALID_ARG);
  218. SPI_CHECK(spihost[host]->dma_chan == 0 || trans_desc->rx_buffer==NULL || esp_ptr_dma_capable(trans_desc->rx_buffer),
  219. "rxdata not in DMA-capable memory", ESP_ERR_INVALID_ARG);
  220. SPI_CHECK(trans_desc->length <= spihost[host]->max_transfer_sz * 8, "data transfer > host maximum", ESP_ERR_INVALID_ARG);
  221. r = xQueueSend(spihost[host]->trans_queue, (void *)&trans_desc, ticks_to_wait);
  222. if (!r) return ESP_ERR_TIMEOUT;
  223. esp_intr_enable(spihost[host]->intr);
  224. return ESP_OK;
  225. }
  226. esp_err_t spi_slave_get_trans_result(spi_host_device_t host, spi_slave_transaction_t **trans_desc, TickType_t ticks_to_wait)
  227. {
  228. BaseType_t r;
  229. SPI_CHECK(VALID_HOST(host), "invalid host", ESP_ERR_INVALID_ARG);
  230. SPI_CHECK(spihost[host], "host not slave", ESP_ERR_INVALID_ARG);
  231. r = xQueueReceive(spihost[host]->ret_queue, (void *)trans_desc, ticks_to_wait);
  232. if (!r) return ESP_ERR_TIMEOUT;
  233. return ESP_OK;
  234. }
  235. esp_err_t spi_slave_transmit(spi_host_device_t host, spi_slave_transaction_t *trans_desc, TickType_t ticks_to_wait)
  236. {
  237. esp_err_t ret;
  238. spi_slave_transaction_t *ret_trans;
  239. //ToDo: check if any spi transfers in flight
  240. ret = spi_slave_queue_trans(host, trans_desc, ticks_to_wait);
  241. if (ret != ESP_OK) return ret;
  242. ret = spi_slave_get_trans_result(host, &ret_trans, ticks_to_wait);
  243. if (ret != ESP_OK) return ret;
  244. assert(ret_trans == trans_desc);
  245. return ESP_OK;
  246. }
  247. #ifdef DEBUG_SLAVE
  248. static void dumpregs(spi_dev_t *hw)
  249. {
  250. ets_printf("***REG DUMP ***\n");
  251. ets_printf("mosi_dlen : %08X\n", hw->mosi_dlen.val);
  252. ets_printf("miso_dlen : %08X\n", hw->miso_dlen.val);
  253. ets_printf("slv_wrbuf_dlen : %08X\n", hw->slv_wrbuf_dlen.val);
  254. ets_printf("slv_rdbuf_dlen : %08X\n", hw->slv_rdbuf_dlen.val);
  255. ets_printf("slave : %08X\n", hw->slave.val);
  256. ets_printf("slv_rdata_bit : %x\n", hw->slv_rd_bit.slv_rdata_bit);
  257. ets_printf("dma_rx_status : %08X\n", hw->dma_rx_status);
  258. ets_printf("dma_tx_status : %08X\n", hw->dma_tx_status);
  259. }
  260. static void dumpll(lldesc_t *ll)
  261. {
  262. ets_printf("****LL DUMP****\n");
  263. ets_printf("Size %d\n", ll->size);
  264. ets_printf("Len: %d\n", ll->length);
  265. ets_printf("Owner: %s\n", ll->owner ? "dma" : "cpu");
  266. }
  267. #endif
  268. static void IRAM_ATTR spi_slave_restart_after_dmareset(void *arg)
  269. {
  270. spi_slave_t *host = (spi_slave_t *)arg;
  271. esp_intr_enable(host->intr);
  272. }
  273. //This is run in interrupt context and apart from initialization and destruction, this is the only code
  274. //touching the host (=spihost[x]) variable. The rest of the data arrives in queues. That is why there are
  275. //no muxes in this code.
  276. static void IRAM_ATTR spi_intr(void *arg)
  277. {
  278. BaseType_t r;
  279. BaseType_t do_yield = pdFALSE;
  280. spi_slave_transaction_t *trans = NULL;
  281. spi_slave_t *host = (spi_slave_t *)arg;
  282. #ifdef DEBUG_SLAVE
  283. dumpregs(host->hw);
  284. if (host->dmadesc_rx) dumpll(&host->dmadesc_rx[0]);
  285. #endif
  286. //Ignore all but the trans_done int.
  287. if (!host->hw->slave.trans_done) return;
  288. if (host->cur_trans) {
  289. //when data of cur_trans->length are all sent, the slv_rdata_bit
  290. //will be the length sent-1 (i.e. cur_trans->length-1 ), otherwise
  291. //the length sent.
  292. host->cur_trans->trans_len = host->hw->slv_rd_bit.slv_rdata_bit;
  293. if ( host->cur_trans->trans_len == host->cur_trans->length - 1 ) {
  294. host->cur_trans->trans_len++;
  295. }
  296. if (host->dma_chan == 0 && host->cur_trans->rx_buffer) {
  297. //Copy result out
  298. uint32_t *data = host->cur_trans->rx_buffer;
  299. for (int x = 0; x < host->cur_trans->trans_len; x += 32) {
  300. uint32_t word;
  301. int len = host->cur_trans->trans_len - x;
  302. if (len > 32) len = 32;
  303. word = host->hw->data_buf[(x / 32)];
  304. memcpy(&data[x / 32], &word, (len + 7) / 8);
  305. }
  306. } else if (host->dma_chan != 0 && host->cur_trans->rx_buffer) {
  307. int i;
  308. //In case CS goes high too soon, the transfer is aborted while the DMA channel still thinks it's going. This
  309. //leads to issues later on, so in that case we need to reset the channel. The state can be detected because
  310. //the DMA system doesn't give back the offending descriptor; the owner is still set to DMA.
  311. for (i = 0; host->dmadesc_rx[i].eof == 0 && host->dmadesc_rx[i].owner == 0; i++) ;
  312. if (host->dmadesc_rx[i].owner) {
  313. spicommon_dmaworkaround_req_reset(host->dma_chan, spi_slave_restart_after_dmareset, host);
  314. }
  315. }
  316. if (host->cfg.post_trans_cb) host->cfg.post_trans_cb(host->cur_trans);
  317. //Okay, transaction is done.
  318. //Return transaction descriptor.
  319. xQueueSendFromISR(host->ret_queue, &host->cur_trans, &do_yield);
  320. host->cur_trans = NULL;
  321. }
  322. if (host->dma_chan != 0) {
  323. spicommon_dmaworkaround_idle(host->dma_chan);
  324. if (spicommon_dmaworkaround_reset_in_progress()) {
  325. //We need to wait for the reset to complete. Disable int (will be re-enabled on reset callback) and exit isr.
  326. esp_intr_disable(host->intr);
  327. if (do_yield) portYIELD_FROM_ISR();
  328. return;
  329. }
  330. }
  331. //Grab next transaction
  332. r = xQueueReceiveFromISR(host->trans_queue, &trans, &do_yield);
  333. if (!r) {
  334. //No packet waiting. Disable interrupt.
  335. esp_intr_disable(host->intr);
  336. } else {
  337. //We have a transaction. Send it.
  338. host->hw->slave.trans_done = 0; //clear int bit
  339. host->cur_trans = trans;
  340. if (host->dma_chan != 0) {
  341. spicommon_dmaworkaround_transfer_active(host->dma_chan);
  342. host->hw->dma_conf.val |= SPI_OUT_RST | SPI_IN_RST | SPI_AHBM_RST | SPI_AHBM_FIFO_RST;
  343. host->hw->dma_out_link.start = 0;
  344. host->hw->dma_in_link.start = 0;
  345. host->hw->dma_conf.val &= ~(SPI_OUT_RST | SPI_IN_RST | SPI_AHBM_RST | SPI_AHBM_FIFO_RST);
  346. host->hw->dma_conf.out_data_burst_en = 0;
  347. host->hw->dma_conf.indscr_burst_en = 0;
  348. host->hw->dma_conf.outdscr_burst_en = 0;
  349. //Fill DMA descriptors
  350. if (trans->rx_buffer) {
  351. host->hw->user.usr_miso_highpart = 0;
  352. spicommon_setup_dma_desc_links(host->dmadesc_rx, ((trans->length + 7) / 8), trans->rx_buffer, true);
  353. host->hw->dma_in_link.addr = (int)(&host->dmadesc_rx[0]) & 0xFFFFF;
  354. host->hw->dma_in_link.start = 1;
  355. }
  356. if (trans->tx_buffer) {
  357. spicommon_setup_dma_desc_links(host->dmadesc_tx, (trans->length + 7) / 8, trans->tx_buffer, false);
  358. host->hw->user.usr_mosi_highpart = 0;
  359. host->hw->dma_out_link.addr = (int)(&host->dmadesc_tx[0]) & 0xFFFFF;
  360. host->hw->dma_out_link.start = 1;
  361. }
  362. host->hw->slave.sync_reset = 1;
  363. host->hw->slave.sync_reset = 0;
  364. } else {
  365. //No DMA. Turn off SPI and copy data to transmit buffers.
  366. host->hw->cmd.usr = 0;
  367. host->hw->slave.sync_reset = 1;
  368. host->hw->slave.sync_reset = 0;
  369. host->hw->user.usr_miso_highpart = 0;
  370. host->hw->user.usr_mosi_highpart = 0;
  371. if (trans->tx_buffer) {
  372. const uint32_t *data = host->cur_trans->tx_buffer;
  373. for (int x = 0; x < trans->length; x += 32) {
  374. uint32_t word;
  375. memcpy(&word, &data[x / 32], 4);
  376. host->hw->data_buf[(x / 32)] = word;
  377. }
  378. }
  379. }
  380. host->hw->slv_rd_bit.slv_rdata_bit = 0;
  381. host->hw->slv_wrbuf_dlen.bit_len = trans->length - 1;
  382. host->hw->slv_rdbuf_dlen.bit_len = trans->length - 1;
  383. host->hw->mosi_dlen.usr_mosi_dbitlen = trans->length - 1;
  384. host->hw->miso_dlen.usr_miso_dbitlen = trans->length - 1;
  385. host->hw->user.usr_mosi = (trans->tx_buffer == NULL) ? 0 : 1;
  386. host->hw->user.usr_miso = (trans->rx_buffer == NULL) ? 0 : 1;
  387. //Kick off transfer
  388. host->hw->cmd.usr = 1;
  389. if (host->cfg.post_setup_cb) host->cfg.post_setup_cb(trans);
  390. }
  391. if (do_yield) portYIELD_FROM_ISR();
  392. }