gpio.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  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. * - GPIO20
  96. -
  97. -
  98. - This pin is only available on ESP32-PICO-V3 chip package
  99. * - GPIO21
  100. -
  101. -
  102. -
  103. * - GPIO22
  104. -
  105. -
  106. -
  107. * - GPIO23
  108. -
  109. -
  110. -
  111. * - GPIO25
  112. - ADC2_CH8
  113. - RTC_GPIO6
  114. -
  115. * - GPIO26
  116. - ADC2_CH9
  117. - RTC_GPIO7
  118. -
  119. * - GPIO27
  120. - ADC2_CH7
  121. - RTC_GPIO17
  122. -
  123. * - GPIO32
  124. - ADC1_CH4
  125. - RTC_GPIO9
  126. -
  127. * - GPIO33
  128. - ADC1_CH5
  129. - RTC_GPIO8
  130. -
  131. * - GPIO34
  132. - ADC1_CH6
  133. - RTC_GPIO4
  134. - GPI
  135. * - GPIO35
  136. - ADC1_CH7
  137. - RTC_GPIO5
  138. - GPI
  139. * - GPIO36
  140. - ADC1_CH0
  141. - RTC_GPIO0
  142. - GPI
  143. * - GPIO37
  144. - ADC1_CH1
  145. - RTC_GPIO1
  146. - GPI
  147. * - GPIO38
  148. - ADC1_CH2
  149. - RTC_GPIO2
  150. - GPI
  151. * - GPIO39
  152. - ADC1_CH3
  153. - RTC_GPIO3
  154. - GPI
  155. .. note::
  156. - 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>`_.
  157. - 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.
  158. - JTAG: GPIO12-15 are usually used for inline debug.
  159. - GPI: GPIO34-39 can only be set as input mode and do not have software-enabled pullup or pulldown functions.
  160. - TXD & RXD are usually used for flashing and debugging.
  161. - 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>`_.
  162. .. only:: esp32s2
  163. 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.
  164. The table below provides more information on pin usage, and please note the comments in the table for GPIOs with restrictions.
  165. .. list-table::
  166. :header-rows: 1
  167. :widths: 8 12 12 20
  168. * - GPIO
  169. - Analog Function
  170. - RTC GPIO
  171. - Comment
  172. * - GPIO0
  173. -
  174. - RTC_GPIO0
  175. - Strapping pin
  176. * - GPIO1
  177. - ADC1_CH0
  178. - RTC_GPIO1
  179. -
  180. * - GPIO2
  181. - ADC1_CH1
  182. - RTC_GPIO2
  183. -
  184. * - GPIO3
  185. - ADC1_CH2
  186. - RTC_GPIO3
  187. -
  188. * - GPIO4
  189. - ADC1_CH3
  190. - RTC_GPIO4
  191. -
  192. * - GPIO5
  193. - ADC1_CH4
  194. - RTC_GPIO5
  195. -
  196. * - GPIO6
  197. - ADC1_CH5
  198. - RTC_GPIO6
  199. -
  200. * - GPIO7
  201. - ADC1_CH6
  202. - RTC_GPIO7
  203. -
  204. * - GPIO8
  205. - ADC1_CH7
  206. - RTC_GPIO8
  207. -
  208. * - GPIO9
  209. - ADC1_CH8
  210. - RTC_GPIO9
  211. -
  212. * - GPIO10
  213. - ADC1_CH9
  214. - RTC_GPIO10
  215. -
  216. * - GPIO11
  217. - ADC2_CH0
  218. - RTC_GPIO11
  219. -
  220. * - GPIO12
  221. - ADC2_CH1
  222. - RTC_GPIO12
  223. -
  224. * - GPIO13
  225. - ADC2_CH2
  226. - RTC_GPIO13
  227. -
  228. * - GPIO14
  229. - ADC2_CH3
  230. - RTC_GPIO14
  231. -
  232. * - GPIO15
  233. - ADC2_CH4
  234. - RTC_GPIO15
  235. -
  236. * - GPIO16
  237. - ADC2_CH5
  238. - RTC_GPIO16
  239. -
  240. * - GPIO17
  241. - ADC2_CH6
  242. - RTC_GPIO17
  243. -
  244. * - GPIO18
  245. - ADC2_CH7
  246. - RTC_GPIO18
  247. -
  248. * - GPIO19
  249. - ADC2_CH8
  250. - RTC_GPIO19
  251. -
  252. * - GPIO20
  253. - ADC2_CH9
  254. - RTC_GPIO20
  255. -
  256. * - GPIO21
  257. -
  258. - RTC_GPIO21
  259. -
  260. * - GPIO26
  261. -
  262. -
  263. - SPI0/1
  264. * - GPIO27
  265. -
  266. -
  267. - SPI0/1
  268. * - GPIO28
  269. -
  270. -
  271. - SPI0/1
  272. * - GPIO29
  273. -
  274. -
  275. - SPI0/1
  276. * - GPIO30
  277. -
  278. -
  279. - SPI0/1
  280. * - GPIO31
  281. -
  282. -
  283. - SPI0/1
  284. * - GPIO32
  285. -
  286. -
  287. - SPI0/1
  288. * - GPIO33
  289. -
  290. -
  291. -
  292. * - GPIO34
  293. -
  294. -
  295. -
  296. * - GPIO35
  297. -
  298. -
  299. -
  300. * - GPIO36
  301. -
  302. -
  303. -
  304. * - GPIO37
  305. -
  306. -
  307. -
  308. * - GPIO38
  309. -
  310. -
  311. -
  312. * - GPIO39
  313. -
  314. -
  315. - JTAG
  316. * - GPIO40
  317. -
  318. -
  319. - JTAG
  320. * - GPIO41
  321. -
  322. -
  323. - JTAG
  324. * - GPIO42
  325. -
  326. -
  327. - JTAG
  328. * - GPIO43
  329. -
  330. -
  331. -
  332. * - GPIO44
  333. -
  334. -
  335. -
  336. * - GPIO45
  337. -
  338. -
  339. - Strapping pin
  340. * - GPIO46
  341. -
  342. -
  343. - GPI;Strapping pin
  344. .. note::
  345. - 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>`_
  346. - SPI0/1: GPIO26-32 are usually used for SPI flash and PSRAM and not recommended for other uses.
  347. - JTAG: GPIO39-42 are usually used for inline debug.
  348. - GPI: GPIO46 is fixed to pull-down and is input only.
  349. .. only:: esp32c3
  350. 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.
  351. The table below provides more information on pin usage, and please note the comments in the table for GPIOs with restrictions.
  352. .. list-table::
  353. :header-rows: 1
  354. :widths: 12 12 22
  355. * - GPIO
  356. - Analog Function
  357. - Comment
  358. * - GPIO0
  359. - ADC1_CH0
  360. - RTC
  361. * - GPIO1
  362. - ADC1_CH1
  363. - RTC
  364. * - GPIO2
  365. - ADC1_CH2
  366. - Strapping pin;RTC
  367. * - GPIO3
  368. - ADC1_CH3
  369. - RTC
  370. * - GPIO4
  371. - ADC1_CH4
  372. - RTC
  373. * - GPIO5
  374. - ADC2_CH0
  375. - RTC
  376. * - GPIO6
  377. -
  378. -
  379. * - GPIO7
  380. -
  381. -
  382. * - GPIO8
  383. -
  384. - Strapping pin
  385. * - GPIO9
  386. -
  387. - Strapping pin
  388. * - GPIO10
  389. -
  390. -
  391. * - GPIO11
  392. -
  393. -
  394. * - GPIO12
  395. -
  396. - SPI0/1
  397. * - GPIO13
  398. -
  399. - SPI0/1
  400. * - GPIO14
  401. -
  402. - SPI0/1
  403. * - GPIO15
  404. -
  405. - SPI0/1
  406. * - GPIO16
  407. -
  408. - SPI0/1
  409. * - GPIO17
  410. -
  411. - SPI0/1
  412. * - GPIO18
  413. -
  414. - USB-JTAG
  415. * - GPIO19
  416. -
  417. - USB-JTAG
  418. * - GPIO20
  419. -
  420. -
  421. * - GPIO21
  422. -
  423. -
  424. .. note::
  425. - 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>`_.
  426. - SPI0/1: GPIO12-17 are usually used for SPI flash and PSRAM and not recommended for other uses.
  427. - 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.
  428. - RTC: GPIO0-5 can be used when in deep sleep.
  429. .. only:: esp32s3
  430. 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.
  431. The table below provides more information on pin usage, and please note the comments in the table for GPIOs with restrictions.
  432. .. list-table::
  433. :header-rows: 1
  434. :widths: 8 12 12 20
  435. * - GPIO
  436. - Analog Function
  437. - RTC GPIO
  438. - Comment
  439. * - GPIO0
  440. -
  441. - RTC_GPIO0
  442. - Strapping pin
  443. * - GPIO1
  444. - ADC1_CH0
  445. - RTC_GPIO1
  446. -
  447. * - GPIO2
  448. - ADC1_CH1
  449. - RTC_GPIO2
  450. -
  451. * - GPIO3
  452. - ADC1_CH2
  453. - RTC_GPIO3
  454. - Strapping pin
  455. * - GPIO4
  456. - ADC1_CH3
  457. - RTC_GPIO4
  458. -
  459. * - GPIO5
  460. - ADC1_CH4
  461. - RTC_GPIO5
  462. -
  463. * - GPIO6
  464. - ADC1_CH5
  465. - RTC_GPIO6
  466. -
  467. * - GPIO7
  468. - ADC1_CH6
  469. - RTC_GPIO7
  470. -
  471. * - GPIO8
  472. - ADC1_CH7
  473. - RTC_GPIO8
  474. -
  475. * - GPIO9
  476. - ADC1_CH8
  477. - RTC_GPIO9
  478. -
  479. * - GPIO10
  480. - ADC1_CH9
  481. - RTC_GPIO10
  482. -
  483. * - GPIO11
  484. - ADC2_CH0
  485. - RTC_GPIO11
  486. -
  487. * - GPIO12
  488. - ADC2_CH1
  489. - RTC_GPIO12
  490. -
  491. * - GPIO13
  492. - ADC2_CH2
  493. - RTC_GPIO13
  494. -
  495. * - GPIO14
  496. - ADC2_CH3
  497. - RTC_GPIO14
  498. -
  499. * - GPIO15
  500. - ADC2_CH4
  501. - RTC_GPIO15
  502. -
  503. * - GPIO16
  504. - ADC2_CH5
  505. - RTC_GPIO16
  506. -
  507. * - GPIO17
  508. - ADC2_CH6
  509. - RTC_GPIO17
  510. -
  511. * - GPIO18
  512. - ADC2_CH7
  513. - RTC_GPIO18
  514. -
  515. * - GPIO19
  516. - ADC2_CH8
  517. - RTC_GPIO19
  518. - USB-JTAG
  519. * - GPIO20
  520. - ADC2_CH9
  521. - RTC_GPIO20
  522. - USB-JTAG
  523. * - GPIO21
  524. -
  525. - RTC_GPIO21
  526. -
  527. * - GPIO26
  528. -
  529. -
  530. - SPI0/1
  531. * - GPIO27
  532. -
  533. -
  534. - SPI0/1
  535. * - GPIO28
  536. -
  537. -
  538. - SPI0/1
  539. * - GPIO29
  540. -
  541. -
  542. - SPI0/1
  543. * - GPIO30
  544. -
  545. -
  546. - SPI0/1
  547. * - GPIO31
  548. -
  549. -
  550. - SPI0/1
  551. * - GPIO32
  552. -
  553. -
  554. - SPI0/1
  555. * - GPIO33
  556. -
  557. -
  558. - SPI0/1
  559. * - GPIO34
  560. -
  561. -
  562. - SPI0/1
  563. * - GPIO35
  564. -
  565. -
  566. - SPI0/1
  567. * - GPIO36
  568. -
  569. -
  570. - SPI0/1
  571. * - GPIO37
  572. -
  573. -
  574. - SPI0/1
  575. * - GPIO38
  576. -
  577. -
  578. -
  579. * - GPIO39
  580. -
  581. -
  582. -
  583. * - GPIO40
  584. -
  585. -
  586. -
  587. * - GPIO41
  588. -
  589. -
  590. -
  591. * - GPIO42
  592. -
  593. -
  594. -
  595. * - GPIO43
  596. -
  597. -
  598. -
  599. * - GPIO44
  600. -
  601. -
  602. -
  603. * - GPIO45
  604. -
  605. -
  606. - Strapping pin
  607. * - GPIO46
  608. -
  609. -
  610. - Strapping pin
  611. * - GPIO47
  612. -
  613. -
  614. -
  615. * - GPIO48
  616. -
  617. -
  618. -
  619. .. Note::
  620. - Strapping pin: GPIO0, GPIO3, GPIO45 and GPIO46 are strapping pins.
  621. - 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.
  622. - 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.
  623. .. only:: SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
  624. 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:
  625. .. list::
  626. - In deep sleep
  627. :SOC_ULP_SUPPORTED: - The :doc:`Ultra Low Power co-processor <../../api-guides/ulp>` is running
  628. - Analog functions such as ADC/DAC/etc are in use.
  629. Application Example
  630. -------------------
  631. GPIO output and input interrupt example: :example:`peripherals/gpio/generic_gpio`.
  632. API Reference - Normal GPIO
  633. ---------------------------
  634. .. include-build-file:: inc/gpio.inc
  635. .. include-build-file:: inc/gpio_types.inc
  636. .. only:: SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
  637. API Reference - RTC GPIO
  638. ------------------------
  639. .. include-build-file:: inc/rtc_io.inc
  640. .. include-build-file:: inc/rtc_io_types.inc