gpio.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. GPIO & RTC GPIO
  2. ===============
  3. Overview
  4. --------
  5. .. only:: esp32
  6. The {IDF_TARGET_NAME} chip features 34 physical GPIO pads. Some GPIO pads cannot be used or do not have the corresponding pin on the chip package. For more details, see *{IDF_TARGET_NAME} Technical Reference Manual* > *IO MUX and GPIO Matrix (GPIO, IO_MUX)* [`PDF <{IDF_TARGET_TRM_EN_URL}#iomuxgpio>`__].
  7. Each pad can be used as a general purpose I/O or can be connected to an internal peripheral signal. The table below provides more information on pin usage, and please note the comments in the table for GPIOs with restrictions.
  8. .. list-table::
  9. :header-rows: 1
  10. :widths: 8 12 12 20
  11. * - GPIO
  12. - Analog Function
  13. - RTC GPIO
  14. - Comments
  15. * - GPIO0
  16. - ADC2_CH1
  17. - RTC_GPIO11
  18. - Strapping pin
  19. * - GPIO1
  20. -
  21. -
  22. - TXD
  23. * - GPIO2
  24. - ADC2_CH2
  25. - RTC_GPIO12
  26. - Strapping pin
  27. * - GPIO3
  28. -
  29. -
  30. - RXD
  31. * - GPIO4
  32. - ADC2_CH0
  33. - RTC_GPIO10
  34. -
  35. * - GPIO5
  36. -
  37. -
  38. - Strapping pin
  39. * - GPIO6
  40. -
  41. -
  42. - SPI0/1
  43. * - GPIO7
  44. -
  45. -
  46. - SPI0/1
  47. * - GPIO8
  48. -
  49. -
  50. - SPI0/1
  51. * - GPIO9
  52. -
  53. -
  54. - SPI0/1
  55. * - GPIO10
  56. -
  57. -
  58. - SPI0/1
  59. * - GPIO11
  60. -
  61. -
  62. - SPI0/1
  63. * - GPIO12
  64. - ADC2_CH5
  65. - RTC_GPIO15
  66. - Strapping pin; JTAG
  67. * - GPIO13
  68. - ADC2_CH4
  69. - RTC_GPIO14
  70. - JTAG
  71. * - GPIO14
  72. - ADC2_CH6
  73. - RTC_GPIO16
  74. - JTAG
  75. * - GPIO15
  76. - ADC2_CH3
  77. - RTC_GPIO13
  78. - Strapping pin; JTAG
  79. * - GPIO16
  80. -
  81. -
  82. - SPI0/1
  83. * - GPIO17
  84. -
  85. -
  86. - SPI0/1
  87. * - GPIO18
  88. -
  89. -
  90. -
  91. * - GPIO19
  92. -
  93. -
  94. -
  95. * - GPIO21
  96. -
  97. -
  98. -
  99. * - GPIO22
  100. -
  101. -
  102. -
  103. * - GPIO23
  104. -
  105. -
  106. -
  107. * - GPIO25
  108. - ADC2_CH8
  109. - RTC_GPIO6
  110. -
  111. * - GPIO26
  112. - ADC2_CH9
  113. - RTC_GPIO7
  114. -
  115. * - GPIO27
  116. - ADC2_CH7
  117. - RTC_GPIO17
  118. -
  119. * - GPIO32
  120. - ADC1_CH4
  121. - RTC_GPIO9
  122. -
  123. * - GPIO33
  124. - ADC1_CH5
  125. - RTC_GPIO8
  126. -
  127. * - GPIO34
  128. - ADC1_CH6
  129. - RTC_GPIO4
  130. - GPI
  131. * - GPIO35
  132. - ADC1_CH7
  133. - RTC_GPIO5
  134. - GPI
  135. * - GPIO36
  136. - ADC1_CH0
  137. - RTC_GPIO0
  138. - GPI
  139. * - GPIO37
  140. - ADC1_CH1
  141. - RTC_GPIO1
  142. - GPI
  143. * - GPIO38
  144. - ADC1_CH2
  145. - RTC_GPIO2
  146. - GPI
  147. * - GPIO39
  148. - ADC1_CH3
  149. - RTC_GPIO3
  150. - GPI
  151. .. note::
  152. - Strapping pin: GPIO0, GPIO2, GPIO5, GPIO12 (MTDI), and GPIO15 (MTDO) are strapping pins. For more infomation, please refer to `ESP32 datasheet <https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf>`_.
  153. - SPI0/1: GPIO6-11 and GPIO16-17 are usually connected to the SPI flash and PSRAM integrated on the module and therefore should not be used for other purposes.
  154. - JTAG: GPIO12-15 are usually used for inline debug.
  155. - GPI: GPIO34-39 can only be set as input mode and do not have software-enabled pullup or pulldown functions.
  156. - TXD & RXD are usually used for flashing and debugging.
  157. - ADC2: ADC2 pins cannot be used when Wi-Fi is used. So, if you’re using Wi-Fi and you’re having trouble getting the value from an ADC2 GPIO, you may consider using an ADC1 GPIO instead, that should solve your problem. For more details, please refer to `ADC limitations <https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/adc.html#adc-limitations>`_.
  158. .. only:: esp32s2
  159. The {IDF_TARGET_NAME} chip features 43 physical GPIO pads. Some GPIO pads cannot be used or do not have the corresponding pin on the chip package. For more details, see *{IDF_TARGET_NAME} Technical Reference Manual* > *IO MUX and GPIO Matrix (GPIO, IO_MUX)* [`PDF <{IDF_TARGET_TRM_EN_URL}#iomuxgpio>`__]. Each pad can be used as a general purpose I/O or can be connected to an internal peripheral signal.
  160. The table below provides more information on pin usage, and please note the comments in the table for GPIOs with restrictions.
  161. .. list-table::
  162. :header-rows: 1
  163. :widths: 8 12 12 20
  164. * - GPIO
  165. - Analog Function
  166. - RTC GPIO
  167. - Comment
  168. * - GPIO0
  169. -
  170. - RTC_GPIO0
  171. - Strapping pin
  172. * - GPIO1
  173. - ADC1_CH0
  174. - RTC_GPIO1
  175. -
  176. * - GPIO2
  177. - ADC1_CH1
  178. - RTC_GPIO2
  179. -
  180. * - GPIO3
  181. - ADC1_CH2
  182. - RTC_GPIO3
  183. -
  184. * - GPIO4
  185. - ADC1_CH3
  186. - RTC_GPIO4
  187. -
  188. * - GPIO5
  189. - ADC1_CH4
  190. - RTC_GPIO5
  191. -
  192. * - GPIO6
  193. - ADC1_CH5
  194. - RTC_GPIO6
  195. -
  196. * - GPIO7
  197. - ADC1_CH6
  198. - RTC_GPIO7
  199. -
  200. * - GPIO8
  201. - ADC1_CH7
  202. - RTC_GPIO8
  203. -
  204. * - GPIO9
  205. - ADC1_CH8
  206. - RTC_GPIO9
  207. -
  208. * - GPIO10
  209. - ADC1_CH9
  210. - RTC_GPIO10
  211. -
  212. * - GPIO11
  213. - ADC2_CH0
  214. - RTC_GPIO11
  215. -
  216. * - GPIO12
  217. - ADC2_CH1
  218. - RTC_GPIO12
  219. -
  220. * - GPIO13
  221. - ADC2_CH2
  222. - RTC_GPIO13
  223. -
  224. * - GPIO14
  225. - ADC2_CH3
  226. - RTC_GPIO14
  227. -
  228. * - GPIO15
  229. - ADC2_CH4
  230. - RTC_GPIO15
  231. -
  232. * - GPIO16
  233. - ADC2_CH5
  234. - RTC_GPIO16
  235. -
  236. * - GPIO17
  237. - ADC2_CH6
  238. - RTC_GPIO17
  239. -
  240. * - GPIO18
  241. - ADC2_CH7
  242. - RTC_GPIO18
  243. -
  244. * - GPIO19
  245. - ADC2_CH8
  246. - RTC_GPIO19
  247. -
  248. * - GPIO20
  249. - ADC2_CH9
  250. - RTC_GPIO20
  251. -
  252. * - GPIO21
  253. -
  254. - RTC_GPIO21
  255. -
  256. * - GPIO26
  257. -
  258. -
  259. - SPI0/1
  260. * - GPIO27
  261. -
  262. -
  263. - SPI0/1
  264. * - GPIO28
  265. -
  266. -
  267. - SPI0/1
  268. * - GPIO29
  269. -
  270. -
  271. - SPI0/1
  272. * - GPIO30
  273. -
  274. -
  275. - SPI0/1
  276. * - GPIO31
  277. -
  278. -
  279. - SPI0/1
  280. * - GPIO32
  281. -
  282. -
  283. - SPI0/1
  284. * - GPIO33
  285. -
  286. -
  287. -
  288. * - GPIO34
  289. -
  290. -
  291. -
  292. * - GPIO35
  293. -
  294. -
  295. -
  296. * - GPIO36
  297. -
  298. -
  299. -
  300. * - GPIO37
  301. -
  302. -
  303. -
  304. * - GPIO38
  305. -
  306. -
  307. -
  308. * - GPIO39
  309. -
  310. -
  311. - JTAG
  312. * - GPIO40
  313. -
  314. -
  315. - JTAG
  316. * - GPIO41
  317. -
  318. -
  319. - JTAG
  320. * - GPIO42
  321. -
  322. -
  323. - JTAG
  324. * - GPIO43
  325. -
  326. -
  327. -
  328. * - GPIO44
  329. -
  330. -
  331. -
  332. * - GPIO45
  333. -
  334. -
  335. - Strapping pin
  336. * - GPIO46
  337. -
  338. -
  339. - GPI;Strapping pin
  340. .. note::
  341. - Strapping pin: GPIO0, GPIO45 and GPIO46 are strapping pins. For more infomation, please refer to `ESP32-S2 datasheet <https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf>`_
  342. - SPI0/1: GPIO26-32 are usually used for SPI flash and PSRAM and not recommended for other uses.
  343. - JTAG: GPIO39-42 are usually used for inline debug.
  344. - GPI: GPIO46 is fixed to pull-down and is input only.
  345. .. only:: esp32c3
  346. The {IDF_TARGET_NAME} chip features 22 physical GPIO pads. Some GPIO pads cannot be used or do not have the corresponding pin on the chip package. For more details, see *{IDF_TARGET_NAME} Technical Reference Manual* > *IO MUX and GPIO Matrix (GPIO, IO_MUX)* [`PDF <{IDF_TARGET_TRM_EN_URL}#iomuxgpio>`__]. Each pad can be used as a general purpose I/O or can be connected to an internal peripheral signal.
  347. The table below provides more information on pin usage, and please note the comments in the table for GPIOs with restrictions.
  348. .. list-table::
  349. :header-rows: 1
  350. :widths: 12 12 22
  351. * - GPIO
  352. - Analog Function
  353. - Comment
  354. * - GPIO0
  355. - ADC1_CH0
  356. - RTC
  357. * - GPIO1
  358. - ADC1_CH1
  359. - RTC
  360. * - GPIO2
  361. - ADC1_CH2
  362. - Strapping pin;RTC
  363. * - GPIO3
  364. - ADC1_CH3
  365. - RTC
  366. * - GPIO4
  367. - ADC1_CH4
  368. - RTC
  369. * - GPIO5
  370. - ADC2_CH0
  371. - RTC
  372. * - GPIO6
  373. -
  374. -
  375. * - GPIO7
  376. -
  377. -
  378. * - GPIO8
  379. -
  380. - Strapping pin
  381. * - GPIO9
  382. -
  383. - Strapping pin
  384. * - GPIO10
  385. -
  386. -
  387. * - GPIO11
  388. -
  389. -
  390. * - GPIO12
  391. -
  392. - SPI0/1
  393. * - GPIO13
  394. -
  395. - SPI0/1
  396. * - GPIO14
  397. -
  398. - SPI0/1
  399. * - GPIO15
  400. -
  401. - SPI0/1
  402. * - GPIO16
  403. -
  404. - SPI0/1
  405. * - GPIO17
  406. -
  407. - SPI0/1
  408. * - GPIO18
  409. -
  410. - USB-JTAG
  411. * - GPIO19
  412. -
  413. - USB-JTAG
  414. * - GPIO20
  415. -
  416. -
  417. * - GPIO21
  418. -
  419. -
  420. .. note::
  421. - Strapping pin: GPIO2, GPIO8 and GPIO9 are strapping pins. For more infomation, please refer to `ESP32-C3 datasheet <https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf>`_.
  422. - SPI0/1: GPIO12-17 are usually used for SPI flash and PSRAM and not recommended for other uses.
  423. - USB-JTAG: GPIO 18 and 19 are used by USB-JTAG by default. In order to use them as GPIOs, USB-JTAG will be disabled by the drivers.
  424. - RTC: GPIO0-5 can be used when in deep sleep.
  425. .. only:: esp32s3
  426. The {IDF_TARGET_NAME} chip features 45 physical GPIO pads. Some GPIO pads cannot be used or do not have the corresponding pin on the chip package. For more details, see *{IDF_TARGET_NAME} Technical Reference Manual* > *IO MUX and GPIO Matrix (GPIO, IO_MUX)* [`PDF <{IDF_TARGET_TRM_EN_URL}#iomuxgpio>`__]. Each pad can be used as a general purpose I/O or can be connected to an internal peripheral signal.
  427. The table below provides more information on pin usage, and please note the comments in the table for GPIOs with restrictions.
  428. .. list-table::
  429. :header-rows: 1
  430. :widths: 8 12 12 20
  431. * - GPIO
  432. - Analog Function
  433. - RTC GPIO
  434. - Comment
  435. * - GPIO0
  436. -
  437. - RTC_GPIO0
  438. - Strapping pin
  439. * - GPIO1
  440. - ADC1_CH0
  441. - RTC_GPIO1
  442. -
  443. * - GPIO2
  444. - ADC1_CH1
  445. - RTC_GPIO2
  446. -
  447. * - GPIO3
  448. - ADC1_CH2
  449. - RTC_GPIO3
  450. - Strapping pin
  451. * - GPIO4
  452. - ADC1_CH3
  453. - RTC_GPIO4
  454. -
  455. * - GPIO5
  456. - ADC1_CH4
  457. - RTC_GPIO5
  458. -
  459. * - GPIO6
  460. - ADC1_CH5
  461. - RTC_GPIO6
  462. -
  463. * - GPIO7
  464. - ADC1_CH6
  465. - RTC_GPIO7
  466. -
  467. * - GPIO8
  468. - ADC1_CH7
  469. - RTC_GPIO8
  470. -
  471. * - GPIO9
  472. - ADC1_CH8
  473. - RTC_GPIO9
  474. -
  475. * - GPIO10
  476. - ADC1_CH9
  477. - RTC_GPIO10
  478. -
  479. * - GPIO11
  480. - ADC2_CH0
  481. - RTC_GPIO11
  482. -
  483. * - GPIO12
  484. - ADC2_CH1
  485. - RTC_GPIO12
  486. -
  487. * - GPIO13
  488. - ADC2_CH2
  489. - RTC_GPIO13
  490. -
  491. * - GPIO14
  492. - ADC2_CH3
  493. - RTC_GPIO14
  494. -
  495. * - GPIO15
  496. - ADC2_CH4
  497. - RTC_GPIO15
  498. -
  499. * - GPIO16
  500. - ADC2_CH5
  501. - RTC_GPIO16
  502. -
  503. * - GPIO17
  504. - ADC2_CH6
  505. - RTC_GPIO17
  506. -
  507. * - GPIO18
  508. - ADC2_CH7
  509. - RTC_GPIO18
  510. -
  511. * - GPIO19
  512. - ADC2_CH8
  513. - RTC_GPIO19
  514. - USB-JTAG
  515. * - GPIO20
  516. - ADC2_CH9
  517. - RTC_GPIO20
  518. - USB-JTAG
  519. * - GPIO21
  520. -
  521. - RTC_GPIO21
  522. -
  523. * - GPIO26
  524. -
  525. -
  526. - SPI0/1
  527. * - GPIO27
  528. -
  529. -
  530. - SPI0/1
  531. * - GPIO28
  532. -
  533. -
  534. - SPI0/1
  535. * - GPIO29
  536. -
  537. -
  538. - SPI0/1
  539. * - GPIO30
  540. -
  541. -
  542. - SPI0/1
  543. * - GPIO31
  544. -
  545. -
  546. - SPI0/1
  547. * - GPIO32
  548. -
  549. -
  550. - SPI0/1
  551. * - GPIO33
  552. -
  553. -
  554. - SPI0/1
  555. * - GPIO34
  556. -
  557. -
  558. - SPI0/1
  559. * - GPIO35
  560. -
  561. -
  562. - SPI0/1
  563. * - GPIO36
  564. -
  565. -
  566. - SPI0/1
  567. * - GPIO37
  568. -
  569. -
  570. - SPI0/1
  571. * - GPIO38
  572. -
  573. -
  574. -
  575. * - GPIO39
  576. -
  577. -
  578. -
  579. * - GPIO40
  580. -
  581. -
  582. -
  583. * - GPIO41
  584. -
  585. -
  586. -
  587. * - GPIO42
  588. -
  589. -
  590. -
  591. * - GPIO43
  592. -
  593. -
  594. -
  595. * - GPIO44
  596. -
  597. -
  598. -
  599. * - GPIO45
  600. -
  601. -
  602. - Strapping pin
  603. * - GPIO46
  604. -
  605. -
  606. - Strapping pin
  607. * - GPIO47
  608. -
  609. -
  610. -
  611. * - GPIO48
  612. -
  613. -
  614. -
  615. .. Note::
  616. - Strapping pin: GPIO0, GPIO3, GPIO45 and GPIO46 are strapping pins.
  617. - SPI0/1: GPIO26-32 are usually used for SPI flash and PSRAM and not recommended for other uses. When using Octal Flash or Octal PSRAM or both, GPIO33~37 are connected to SPIIO4 ~ SPIIO7 and SPIDQS. Therefore on ESP32-S3R8 / ESP32-S3R8V board GPIO33~37 are also not recommended for other uses.
  618. - USB-JTAG: GPIO 19 and 20 are used by USB-JTAG by default. In order to use them as GPIOs, USB-JTAG will be disabled by the drivers.
  619. .. only:: SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
  620. There is also separate "RTC GPIO" support, which functions when GPIOs are routed to the "RTC" low-power and analog subsystem. These pin functions can be used when:
  621. .. list::
  622. - In deep sleep
  623. :SOC_ULP_SUPPORTED: - The :doc:`Ultra Low Power co-processor <../../api-guides/ulp>` is running
  624. - Analog functions such as ADC/DAC/etc are in use.
  625. Application Example
  626. -------------------
  627. GPIO output and input interrupt example: :example:`peripherals/gpio/generic_gpio`.
  628. API Reference - Normal GPIO
  629. ---------------------------
  630. .. include-build-file:: inc/gpio.inc
  631. .. include-build-file:: inc/gpio_types.inc
  632. .. only:: SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
  633. API Reference - RTC GPIO
  634. ------------------------
  635. .. include-build-file:: inc/rtc_io.inc
  636. .. include-build-file:: inc/rtc_io_types.inc