spi_master.rst 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. SPI Master driver
  2. =================
  3. Overview
  4. --------
  5. The ESP32 has four SPI peripheral devices, called SPI0, SPI1, HSPI and VSPI. SPI0 is entirely dedicated to
  6. the flash cache the ESP32 uses to map the SPI flash device it is connected to into memory. SPI1 is
  7. connected to the same hardware lines as SPI0 and is used to write to the flash chip. HSPI and VSPI
  8. are free to use. SPI1, HSPI and VSPI all have three chip select lines, allowing them to drive up to
  9. three SPI devices each as a master.
  10. The spi_master driver
  11. ^^^^^^^^^^^^^^^^^^^^^
  12. The spi_master driver allows easy communicating with SPI slave devices, even in a multithreaded environment.
  13. It fully transparently handles DMA transfers to read and write data and automatically takes care of
  14. multiplexing between different SPI slaves on the same master.
  15. .. note::
  16. **Notes about thread safety**
  17. The SPI driver API is thread safe when multiple SPI devices on the same bus are accessed from different tasks. However, the driver is not thread safe if the same SPI device is accessed from multiple tasks.
  18. In this case, it is recommended to either refactor your application so only a single task accesses each SPI device, or to add mutex locking around access of the shared device.
  19. Terminology
  20. ^^^^^^^^^^^
  21. The spi_master driver uses the following terms:
  22. * Host: The SPI peripheral inside the ESP32 initiating the SPI transmissions. One of SPI, HSPI or VSPI. (For
  23. now, only HSPI or VSPI are actually supported in the driver; it will support all 3 peripherals
  24. somewhere in the future.)
  25. * Bus: The SPI bus, common to all SPI devices connected to one host. In general the bus consists of the
  26. miso, mosi, sclk and optionally quadwp and quadhd signals. The SPI slaves are connected to these
  27. signals in parallel.
  28. - miso - Also known as q, this is the input of the serial stream into the ESP32
  29. - mosi - Also known as d, this is the output of the serial stream from the ESP32
  30. - sclk - Clock signal. Each data bit is clocked out or in on the positive or negative edge of this signal
  31. - quadwp - Write Protect signal. Only used for 4-bit (qio/qout) transactions.
  32. - quadhd - Hold signal. Only used for 4-bit (qio/qout) transactions.
  33. * Device: A SPI slave. Each SPI slave has its own chip select (CS) line, which is made active when
  34. a transmission to/from the SPI slave occurs.
  35. * Transaction: One instance of CS going active, data transfer from and/or to a device happening, and
  36. CS going inactive again. Transactions are atomic, as in they will never be interrupted by another
  37. transaction.
  38. SPI transactions
  39. ^^^^^^^^^^^^^^^^
  40. A transaction on the SPI bus consists of five phases, any of which may be skipped:
  41. * The command phase. In this phase, a command (0-16 bit) is clocked out.
  42. * The address phase. In this phase, an address (0-64 bit) is clocked out.
  43. * The write phase. The master sends data to the slave.
  44. * The dummy phase. The phase is configurable, used to meet the timing requirements.
  45. * The read phase. The slave sends data to the master.
  46. In full duplex mode, the read and write phases are combined, and the SPI host reads and
  47. writes data simultaneously. The total transaction length is decided by
  48. ``command_bits + address_bits + trans_conf.length``, while the ``trans_conf.rx_length``
  49. only determins length of data received into the buffer.
  50. While in half duplex mode, the host have independent write and read phases. The length of write phase and read phase are
  51. decided by ``trans_conf.length`` and ``trans_conf.rx_length`` respectively.
  52. The command and address phase are optional in that not every SPI device will need to be sent a command
  53. and/or address. This is reflected in the device configuration: when the ``command_bits`` or ``address_bits``
  54. fields are set to zero, no command or address phase is done.
  55. Something similar is true for the read and write phase: not every transaction needs both data to be written
  56. as well as data to be read. When ``rx_buffer`` is NULL (and SPI_USE_RXDATA) is not set) the read phase
  57. is skipped. When ``tx_buffer`` is NULL (and SPI_USE_TXDATA) is not set) the write phase is skipped.
  58. The driver offers two different kinds of transactions: the interrupt
  59. transactions and the polling transactions. Each device can choose one kind of
  60. transaction to send. See :ref:`mixed_transactions` if your device do require
  61. both kinds of transactions.
  62. .. _interrupt_transactions:
  63. Interrupt transactions
  64. """"""""""""""""""""""""
  65. The interrupt transactions use an interrupt-driven logic when the
  66. transactions are in-flight. The routine will get blocked, allowing the CPU to
  67. run other tasks, while it is waiting for a transaction to be finished.
  68. Interrupt transactions can be queued into a device, the driver automatically
  69. send them one-by-one in the ISR. A task can queue several transactions, and
  70. then do something else before the transactions are finished.
  71. .. _polling_transactions:
  72. Polling transactions
  73. """"""""""""""""""""
  74. The polling transactions don't rely on the interrupt, the routine keeps polling
  75. the status bit of the SPI peripheral until the transaction is done.
  76. All the tasks that do interrupt transactions may get blocked by the queue, at
  77. which point they need to wait for the ISR to run twice before the transaction
  78. is done. Polling transactions save the time spent on queue handling and
  79. context switching, resulting in a smaller transaction interval smaller. The
  80. disadvantage is that the the CPU is busy while these transactions are in
  81. flight.
  82. The ``spi_device_polling_end`` routine spends at least 1us overhead to
  83. unblock other tasks when the transaction is done. It is strongly recommended
  84. to wrap a series of polling transactions inside of ``spi_device_acquire_bus``
  85. and ``spi_device_release_bus`` to avoid the overhead. (See
  86. :ref:`bus_acquiring`)
  87. Command and address phases
  88. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  89. During the command and address phases, ``cmd`` and ``addr`` field in the
  90. ``spi_transaction_t`` struct are sent to the bus, while nothing is read at the
  91. same time. The default length of command and address phase are set in the
  92. ``spi_device_interface_config_t`` and by ``spi_bus_add_device``. When the the
  93. flag ``SPI_TRANS_VARIABLE_CMD`` and ``SPI_TRANS_VARIABLE_ADDR`` are not set in
  94. the ``spi_transaction_t``,the driver automatically set the length of these
  95. phases to the default value as set when the device is initialized respectively.
  96. If the length of command and address phases needs to be variable, declare a
  97. ``spi_transaction_ext_t`` descriptor, set the flag ``SPI_TRANS_VARIABLE_CMD``
  98. or/and ``SPI_TRANS_VARIABLE_ADDR`` in the ``flags`` of ``base`` member and
  99. configure the rest part of ``base`` as usual. Then the length of each phases
  100. will be ``command_bits`` and ``address_bits`` set in the ``spi_transaction_ext_t``.
  101. Write and read phases
  102. ^^^^^^^^^^^^^^^^^^^^^
  103. Normally, data to be transferred to or from a device will be read from or written to a chunk of memory
  104. indicated by the ``rx_buffer`` and ``tx_buffer`` members of the transaction structure.
  105. When DMA is enabled for transfers, these buffers are highly recommended to meet the requirements as below:
  106. 1. allocated in DMA-capable memory using ``pvPortMallocCaps(size, MALLOC_CAP_DMA)``;
  107. 2. 32-bit aligned (start from the boundary and have length of multiples of 4 bytes).
  108. If these requirements are not satisfied, efficiency of the transaction will suffer due to the allocation and
  109. memcpy of temporary buffers.
  110. .. note:: Half duplex transactions with both read and write phases are not supported when using DMA. See
  111. :ref:`spi_known_issues` for details and workarounds.
  112. .. _bus_acquiring:
  113. Bus acquiring
  114. ^^^^^^^^^^^^^
  115. Sometimes you may want to send spi transactions exclusively, continuously, to
  116. make it as fast as possible. You may use ``spi_device_acquire_bus`` and
  117. ``spi_device_release_bus`` to realize this. When the bus is acquired,
  118. transactions to other devices (no matter polling or interrupt) are pending
  119. until the bus is released.
  120. Using the spi_master driver
  121. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  122. - Initialize a SPI bus by calling ``spi_bus_initialize``. Make sure to set the correct IO pins in
  123. the ``bus_config`` struct. Take care to set signals that are not needed to -1.
  124. - Tell the driver about a SPI slave device connected to the bus by calling spi_bus_add_device.
  125. Make sure to configure any timing requirements the device has in the ``dev_config`` structure.
  126. You should now have a handle for the device, to be used when sending it a transaction.
  127. - To interact with the device, fill one or more spi_transaction_t structure with any transaction
  128. parameters you need. Then send them either in a polling way or the interrupt way:
  129. - :ref:`Interrupt <interrupt_transactions>`
  130. Either queue all transactions by calling ``spi_device_queue_trans``,
  131. and at a later time query the result using
  132. ``spi_device_get_trans_result``, or handle all requests
  133. synchroneously by feeding them into ``spi_device_transmit``.
  134. - :ref:`Polling <polling_transactions>`
  135. Call the ``spi_device_polling_transmit`` to send polling
  136. transactions. Alternatively, you can send a polling transaction by
  137. ``spi_device_polling_start`` and ``spi_device_polling_end`` if you
  138. want to insert something between them.
  139. - Optional: to do back-to-back transactions to a device, call
  140. ``spi_device_acquire_bus`` before and ``spi_device_release_bus`` after the
  141. transactions.
  142. - Optional: to unload the driver for a device, call ``spi_bus_remove_device`` with the device
  143. handle as an argument
  144. - Optional: to remove the driver for a bus, make sure no more drivers are attached and call
  145. ``spi_bus_free``.
  146. Tips
  147. """"
  148. 1. Transactions with small amount of data:
  149. Sometimes, the amount of data is very small making it less than optimal allocating a separate buffer
  150. for it. If the data to be transferred is 32 bits or less, it can be stored in the transaction struct
  151. itself. For transmitted data, use the ``tx_data`` member for this and set the ``SPI_USE_TXDATA`` flag
  152. on the transmission. For received data, use ``rx_data`` and set ``SPI_USE_RXDATA``. In both cases, do
  153. not touch the ``tx_buffer`` or ``rx_buffer`` members, because they use the same memory locations
  154. as ``tx_data`` and ``rx_data``.
  155. 2. Transactions with integers other than uint8_t
  156. The SPI peripheral reads and writes the memory byte-by-byte. By default,
  157. the SPI works at MSB first mode, each bytes are sent or received from the
  158. MSB to the LSB. However, if you want to send data with length which is
  159. not multiples of 8 bits, unused bits are sent.
  160. E.g. you write ``uint8_t data = 0x15`` (00010101B), and set length to
  161. only 5 bits, the sent data is ``00010B`` rather than expected ``10101B``.
  162. Moreover, ESP32 is a little-endian chip whose lowest byte is stored at
  163. the very beginning address for uint16_t and uint32_t variables. Hence if
  164. a uint16_t is stored in the memory, it's bit 7 is first sent, then bit 6
  165. to 0, then comes its bit 15 to bit 8.
  166. To send data other than uint8_t arrays, macros ``SPI_SWAP_DATA_TX`` is
  167. provided to shift your data to the MSB and swap the MSB to the lowest
  168. address; while ``SPI_SWAP_DATA_RX`` can be used to swap received data
  169. from the MSB to it's correct place.
  170. GPIO matrix and IOMUX
  171. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  172. Most peripheral signals in ESP32 can connect directly to a specific GPIO, which is called its IOMUX pin. When a
  173. peripheral signal is routed to a pin other than its IOMUX pin, ESP32 uses the less direct GPIO matrix to make this
  174. connection.
  175. If the driver is configured with all SPI signals set to their specific IOMUX pins (or left unconnected), it will bypass
  176. the GPIO matrix. If any SPI signal is configured to a pin other than its IOMUx pin, the driver will automatically route
  177. all the signals via the GPIO Matrix. The GPIO matrix samples all signals at 80MHz and sends them between the GPIO and
  178. the peripheral.
  179. When the GPIO matrix is used, signals faster than 40MHz cannot propagate and the setup time of MISO is more easily
  180. violated, since the input delay of MISO signal is increased. The maximum clock frequency with GPIO Matrix is 40MHz
  181. or less, whereas using all IOMUX pins allows 80MHz.
  182. .. note:: More details about influence of input delay on the maximum clock frequency, see :ref:`timing_considerations` below.
  183. IOMUX pins for SPI controllers are as below:
  184. +----------+------+------+
  185. | Pin Name | HSPI | VSPI |
  186. + +------+------+
  187. | | GPIO Number |
  188. +==========+======+======+
  189. | CS0* | 15 | 5 |
  190. +----------+------+------+
  191. | SCLK | 14 | 18 |
  192. +----------+------+------+
  193. | MISO | 12 | 19 |
  194. +----------+------+------+
  195. | MOSI | 13 | 23 |
  196. +----------+------+------+
  197. | QUADWP | 2 | 22 |
  198. +----------+------+------+
  199. | QUADHD | 4 | 21 |
  200. +----------+------+------+
  201. note * Only the first device attaching to the bus can use CS0 pin.
  202. .. _mixed_transactions:
  203. Notes to send mixed transactions to the same device
  204. """""""""""""""""""""""""""""""""""""""""""""""""""
  205. Though we suggest to send only one type (interrupt or polling) of
  206. transactions to one device to reduce coding complexity, it is supported to
  207. send both interrupt and polling transactions alternately. Notes below is to
  208. help you do this.
  209. The polling transactions should be started when all the other transactions
  210. are finished, no matter they are polling or interrupt.
  211. An unfinished polling transaction forbid other transactions from being sent.
  212. Always call ``spi_device_polling_end`` after ``spi_device_polling_start`` to
  213. allow other device using the bus, or allow other transactions to be started
  214. to the same device. You can use ``spi_device_polling_transmit`` to simplify
  215. this if you don't need to do something during your polling transaction.
  216. An in-flight polling transaction would get disturbed by the ISR operation
  217. caused by interrupt transactions. Always make sure all the interrupt
  218. transactions sent to the ISR are finished before you call
  219. ``spi_device_polling_start``. To do that, you can call
  220. ``spi_device_get_trans_result`` until all the transactions are returned.
  221. It is strongly recommended to send mixed transactions to the same device in
  222. only one task to control the calling sequence of functions.
  223. Speed and Timing Considerations
  224. -------------------------------
  225. .. _speed_considerations:
  226. Transferring speed
  227. ^^^^^^^^^^^^^^^^^^
  228. There're three factors limiting the transferring speed: (1) The transaction interval, (2) The SPI clock frequency used.
  229. (3) The cache miss of SPI functions including callbacks.
  230. When large transactions are used, the clock frequency determines the transferring speed; while the interval effects the
  231. speed a lot if small transactions are used.
  232. 1. Transaction interval: It takes time for the software to setup spi
  233. peripheral registers as well as copy data to FIFOs, or setup DMA links.
  234. When the interrupt transactions are used, an extra overhead is appended,
  235. from the cost of FreeRTOS queues and the time switching between tasks and
  236. the ISR.
  237. 1. For **interrupt transactions**, the CPU can switched to other
  238. tasks when the transaction is in flight. This save the cpu time
  239. but increase the interval (See :ref:`interrupt_transactions`).
  240. For
  241. **polling transactions**, it does not block the task but do
  242. polling when the transaction is in flight. (See
  243. :ref:`polling_transactions`).
  244. 2. When the DMA is enabled, it needs about 2us per transaction to setup the linked list. When the master is
  245. transferring, it automatically read data from the linked list. If the DMA is not enabled,
  246. CPU has to write/read each byte to/from the FIFO by itself. Usually this is faster than 2us, but the
  247. transaction length is limited to 64 bytes for both write and read.
  248. Typical transaction interval with one byte data is as below:
  249. +--------+----------------+--------------+
  250. | | Typical Transaction Time (us) |
  251. +========+================+==============+
  252. | | Interrupt | Polling |
  253. +--------+----------------+--------------+
  254. | DMA | 24 | 8 |
  255. +--------+----------------+--------------+
  256. | No DMA | 22 | 7 |
  257. +--------+----------------+--------------+
  258. 2. SPI clock frequency: Each byte transferred takes 8 times of the clock period *8/fspi*. If the clock frequency is
  259. too high, some functions may be limited to use. See :ref:`timing_considerations`.
  260. 3. The cache miss: the default config puts only the ISR into the IRAM.
  261. Other SPI related functions including the driver itself and the callback
  262. may suffer from the cache miss and wait for some time while reading code
  263. from the flash. Select :ref:`CONFIG_SPI_MASTER_IN_IRAM` to put the whole
  264. SPI driver into IRAM, and put the entire callback(s) and its callee
  265. functions into IRAM to prevent this.
  266. For an interrupt transaction, the overall cost is *20+8n/Fspi[MHz]* [us] for n bytes tranferred
  267. in one transaction. Hence the transferring speed is : *n/(20+8n/Fspi)*. Example of transferring speed under 8MHz
  268. clock speed:
  269. +-----------+----------------------+--------------------+------------+-------------+
  270. | Frequency | Transaction Interval | Transaction Length | Total Time | Total Speed |
  271. | | | | | |
  272. | (MHz) | (us) | (bytes) | (us) | (kBps) |
  273. +===========+======================+====================+============+=============+
  274. | 8 | 25 | 1 | 26 | 38.5 |
  275. +-----------+----------------------+--------------------+------------+-------------+
  276. | 8 | 25 | 8 | 33 | 242.4 |
  277. +-----------+----------------------+--------------------+------------+-------------+
  278. | 8 | 25 | 16 | 41 | 490.2 |
  279. +-----------+----------------------+--------------------+------------+-------------+
  280. | 8 | 25 | 64 | 89 | 719.1 |
  281. +-----------+----------------------+--------------------+------------+-------------+
  282. | 8 | 25 | 128 | 153 | 836.6 |
  283. +-----------+----------------------+--------------------+------------+-------------+
  284. When the length of transaction is short, the cost of transaction interval is really high. Please try to squash data
  285. into one transaction if possible to get higher transfer speed.
  286. BTW, the ISR is disabled during flash operation by default. To keep sending
  287. transactions during flash operations, enable
  288. :ref:`CONFIG_SPI_MASTER_ISR_IN_IRAM` and set :cpp:class:`ESP_INTR_FLAG_IRAM`
  289. in the ``intr_flags`` member of :cpp:class:`spi_bus_config_t`. Then all the
  290. transactions queued before the flash operations will be handled by the ISR
  291. continuously during flash operation. Note that the callback of each devices,
  292. and their callee functions, should be in the IRAM in this case, or your
  293. callback will crash due to cache miss.
  294. .. _timing_considerations:
  295. Timing considerations
  296. ^^^^^^^^^^^^^^^^^^^^^
  297. As shown in the figure below, there is a delay on the MISO signal after SCLK
  298. launch edge and before it's latched by the internal register. As a result,
  299. the MISO pin setup time is the limiting factor for SPI clock speed. When the
  300. delay is too large, setup slack is < 0 and the setup timing requirement is
  301. violated, leads to the failure of reading correctly.
  302. .. image:: /../_static/spi_miso.png
  303. .. wavedrom don't support rendering pdflatex till now(1.3.1), so we use the png here
  304. .. image:: /../_static/miso_timing_waveform.png
  305. The maximum frequency allowed is related to the *input delay* (maximum valid
  306. time after SCLK on the MISO bus), as well as the usage of GPIO matrix. The
  307. maximum frequency allowed is reduced to about 33~77% (related to existing
  308. *input delay*) when the GPIO matrix is used. To work at higher frequency, you
  309. have to use the IOMUX pins or the *dummy bit workaround*. You can get the
  310. maximum reading frequency of the master by ``spi_get_freq_limit``.
  311. .. _dummy_bit_workaround:
  312. **Dummy bit workaround:** We can insert dummy clocks (during which the host does not read data) before the read phase
  313. actually begins. The slave still sees the dummy clocks and gives out data, but the host does not read until the read
  314. phase. This compensates the lack of setup time of MISO required by the host, allowing the host reading at higher
  315. frequency.
  316. In the ideal case (the slave is so fast that the input delay is shorter than an apb clock, 12.5ns), the maximum
  317. frequency host can read (or read and write) under different conditions is as below:
  318. +-------------+-------------+------------+-----------------------------+
  319. | Frequency Limit (MHz) | Dummy Bits | Comments |
  320. +-------------+-------------+ Used + +
  321. | GPIO matrix | IOMUX pins | By Driver | |
  322. +=============+=============+============+=============================+
  323. | 26.6 | 80 | No | |
  324. +-------------+-------------+------------+-----------------------------+
  325. | 40 | -- | Yes | Half Duplex, no DMA allowed |
  326. +-------------+-------------+------------+-----------------------------+
  327. And if the host only writes, the *dummy bit workaround* is not used and the frequency limit is as below:
  328. +-------------------+------------------+
  329. | GPIO matrix (MHz) | IOMUX pins (MHz) |
  330. +===================+==================+
  331. | 40 | 80 |
  332. +-------------------+------------------+
  333. The spi master driver can work even if the *input delay* in the ``spi_device_interface_config_t`` is set to 0.
  334. However, setting a accurate value helps to: (1) calculate the frequency limit in full duplex mode, and (2) compensate
  335. the timing correctly by dummy bits in half duplex mode. You may find the maximum data valid time after the launch edge
  336. of SPI clocks in the AC characteristics chapter of the device specifications, or measure the time on a oscilloscope or
  337. logic analyzer.
  338. .. wavedrom don't support rendering pdflatex till now(1.3.1), so we use the png here
  339. .. image:: /../_static/miso_timing_waveform_async.png
  340. As shown in the figure above, the input delay is usually:
  341. *[input delay] = [sample delay] + [slave output delay]*
  342. 1. The sample delay is the maximum random delay due to the
  343. asynchronization of SCLK and peripheral clock of the slave. It's usually
  344. 1 slave peripheral clock if the clock is asynchronize with SCLK, or 0 if
  345. the slave just use the SCLK to latch the SCLK and launch MISO data. e.g.
  346. for ESP32 slaves, the delay is 12.5ns (1 apb clock), while it is reduced
  347. to 0 if the slave is in the same chip as the master.
  348. 2. The slave output delay is the time for the MOSI to be stable after the
  349. launch edge. e.g. for ESP32 slaves, the output delay is 37.5ns (3 apb
  350. clocks) when IOMUX pins in the slave is used, or 62.5ns (5 apb clocks) if
  351. through the GPIO matrix.
  352. Some typical delays are shown in the following table:
  353. +--------------------+------------------+
  354. | Device | Input delay (ns) |
  355. +====================+==================+
  356. | Ideal device | 0 |
  357. +--------------------+------------------+
  358. | ESP32 slave IOMUX* | 50 |
  359. +--------------------+------------------+
  360. | ESP32 slave GPIO* | 75 |
  361. +--------------------+------------------+
  362. | ESP32 slave is on an independent |
  363. | chip, 12.5ns sample delay included. |
  364. +---------------------------------------+
  365. The MISO path delay(tv), consists of slave *input delay* and master *GPIO matrix delay*, finally determines the
  366. frequency limit, above which the full duplex mode will not work, or dummy bits are used in the half duplex mode. The
  367. frequency limit is:
  368. *Freq limit[MHz] = 80 / (floor(MISO delay[ns]/12.5) + 1)*
  369. The figure below shows the relations of frequency limit against the input delay. 2 extra apb clocks should be counted
  370. into the MISO delay if the GPIO matrix in the master is used.
  371. .. image:: /../_static/spi_master_freq_tv.png
  372. Corresponding frequency limit for different devices with different *input delay* are shown in the following
  373. table:
  374. +--------+------------------+----------------------+-------------------+
  375. | Master | Input delay (ns) | MISO path delay (ns) | Freq. limit (MHz) |
  376. +========+==================+======================+===================+
  377. | IOMUX | 0 | 0 | 80 |
  378. + (0ns) +------------------+----------------------+-------------------+
  379. | | 50 | 50 | 16 |
  380. + +------------------+----------------------+-------------------+
  381. | | 75 | 75 | 11.43 |
  382. +--------+------------------+----------------------+-------------------+
  383. | GPIO | 0 | 25 | 26.67 |
  384. + (25ns) +------------------+----------------------+-------------------+
  385. | | 50 | 75 | 11.43 |
  386. + +------------------+----------------------+-------------------+
  387. | | 75 | 100 | 8.89 |
  388. +--------+------------------+----------------------+-------------------+
  389. .. _spi_known_issues:
  390. Known Issues
  391. ------------
  392. 1. Half duplex mode is not compatible with DMA when both writing and reading phases exist.
  393. If such transactions are required, you have to use one of the alternative solutions:
  394. 1. use full-duplex mode instead.
  395. 2. disable the DMA by setting the last parameter to 0 in bus initialization function just as below:
  396. ``ret=spi_bus_initialize(VSPI_HOST, &buscfg, 0);``
  397. this may prohibit you from transmitting and receiving data longer than 64 bytes.
  398. 3. try to use command and address field to replace the write phase.
  399. 2. Full duplex mode is not compatible with the *dummy bit workaround*, hence the frequency is limited. See :ref:`dummy
  400. bit speed-up workaround <dummy_bit_workaround>`.
  401. 3. ``cs_ena_pretrans`` is not compatible with command, address phases in full duplex mode.
  402. Application Example
  403. -------------------
  404. Display graphics on the 320x240 LCD of WROVER-Kits: :example:`peripherals/spi_master`.
  405. API Reference - SPI Common
  406. --------------------------
  407. .. include:: /_build/inc/spi_common.inc
  408. API Reference - SPI Master
  409. --------------------------
  410. .. include:: /_build/inc/spi_master.inc