Line 23: Line 23:
  
 
The components directory holds all the 'C'  code for the ESP32. It contains all the 'components' that make up the ESP32. It includes Drivers for numerous peripherals, the bootloader, bt(bluetooth), freeRTOS etc.  
 
The components directory holds all the 'C'  code for the ESP32. It contains all the 'components' that make up the ESP32. It includes Drivers for numerous peripherals, the bootloader, bt(bluetooth), freeRTOS etc.  
 +
If we expand the ''components'' the tree looks like so:
 +
<syntaxhighlight>
 +
+---components
 +
|  +---app_update
 +
|  |  |  component.mk
 +
|  |  |  esp_ota_ops.c
 +
|  |  | 
 +
|  |  \---include
 +
|  |          esp_ota_ops.h
 +
|  |         
 +
|  +---bootloader
 +
|  |  |  component.mk
 +
|  |  |  README.rst
 +
|  |  | 
 +
|  |  +---include
 +
|  |  |      esp_image_format.h
 +
|  |  |      esp_secure_boot.h
 +
|  |  |     
 +
|  |  +---include_priv
 +
|  |  |      bootloader_flash.h
 +
|  |  |     
 +
|  |  \---src
 +
|  |          bootloader_flash.c
 +
|  |          esp_image_format.c
 +
|  |          secure_boot.c
 +
|  |          secure_boot_signatures.c
 +
|  |         
 +
|  +---bt
 +
|  |  |  bt.c
 +
|  |  |  component.mk
 +
|  |  |  Kconfig
 +
|  |  | 
 +
|  |  +---bluedroid
 +
.  .
 +
.  .
 +
.  .
 +
|  |         
 +
|  +---driver
 +
|  |  |  component.mk
 +
|  |  |  gpio.c
 +
|  |  |  ledc.c
 +
|  |  |  pcnt.c
 +
|  |  |  periph_ctrl.c
 +
|  |  |  rmt.c
 +
|  |  |  timer.c
 +
|  |  |  uart.c
 +
|  |  | 
 +
|  |  \---include
 +
|  |      \---driver
 +
|  |              gpio.h
 +
|  |              ledc.h
 +
|  |              pcnt.h
 +
|  |              periph_ctrl.h
 +
|  |              rmt.h
 +
|  |              timer.h
 +
|  |              uart.h
 +
|  |             
 +
|  +---esp32
 +
|  |  |  abi.cpp
 +
|  |  |  brownout.c
 +
|  |  |  component.mk
 +
|  |  |  cpu_freq.c
 +
|  |  |  cpu_start.c
 +
|  |  |  cpu_util.c
 +
. .
 +
. .
 +
. .
 +
. .
 +
|  |         
 +
|  +---esptool_py
 +
|  |  |  Kconfig.projbuild
 +
|  |  |  LICENSE
 +
.  .
 +
.  .
 +
|  |                     
 +
|  +---ethernet
 +
|  |  |  component.mk
 +
.  .
 +
|  |         
 +
|  +---expat
 +
.  .
 +
|  |             
 +
|  +---freertos
 +
|  |  |  component.mk
 +
|  |  |  croutine.c
 +
|  |  |  event_groups.c
 +
|  |  |  FreeRTOS-openocd.c
 +
|  |  |  heap_regions.c
 +
.  .
 +
.  .
 +
|  |         
 +
|  +---idf_test
 +
. .
 +
. .
 +
| |
 +
|  +---newlib
 +
. .
 +
| |
 +
|  +---nghttp
 +
. .
 +
. .
 +
. .
 +
| |             
 +
|  +---nvs_flash
 +
|  |  |  .gitignore
 +
|  |  |  component.mk
 +
|  |  |  README.rst
 +
|  |  | 
 +
. .
 +
. .
 +
|  |         
 +
|  +---openssl
 +
. .
 +
. .         
 +
|  +---partition_table
  
 +
|  |         
 +
|  +---spi_flash
 +
|
 +
|  |         
 +
|  +---tcpip_adapter
 +
 +
|  |         
 +
|  +---ulp
 +
|  |         
 +
|  +---vfs
 +
|  |         
 +
|  +---wpa_supplicant
 +
 +
|  |             
 +
|  \---xtensa-debug-module
 +
|      |  component.mk
 +
|      |  eri.c
 +
|      |  trax.c
 +
|      | 
 +
|      \---include
 +
|              eri.h
 +
|              trax.h
 +
|              xtensa-debug-module.h
 +
</syntaxhighlight>
 
<syntaxhighlight>
 
<syntaxhighlight>
 
/* Hello World Example
 
/* Hello World Example

Revision as of 09:24, 24 December 2016

The Espressif Internet Development Framework (ESP-IDF) uses FreeRTOS to make better use of the two high speed processors and manage the numerous built-in peripherals. It is done by creating tasks. Let's look at the hello world, that looks a little different from the ones that you might have seen.

This hello world prints the string on UART (eventually on the computer terminal). We will first look at the ESP-IDF structure. Then look at the hello world example and modify it blink an LED while still continuously printing the 'hello world' string.

  1.  
  2. esp-idf
  3. |
  4. |
  5. + - - components
  6. |
  7. + - - docs
  8. |
  9. + - - examples
  10. |
  11. + - - make
  12. |
  13. + - - tools

The components directory holds all the 'C' code for the ESP32. It contains all the 'components' that make up the ESP32. It includes Drivers for numerous peripherals, the bootloader, bt(bluetooth), freeRTOS etc. If we expand the components the tree looks like so:

  1. +---components
  2. | +---app_update
  3. | | | component.mk
  4. | | | esp_ota_ops.c
  5. | | |
  6. | | \---include
  7. | | esp_ota_ops.h
  8. | |
  9. | +---bootloader
  10. | | | component.mk
  11. | | | README.rst
  12. | | |
  13. | | +---include
  14. | | | esp_image_format.h
  15. | | | esp_secure_boot.h
  16. | | |
  17. | | +---include_priv
  18. | | | bootloader_flash.h
  19. | | |
  20. | | \---src
  21. | | bootloader_flash.c
  22. | | esp_image_format.c
  23. | | secure_boot.c
  24. | | secure_boot_signatures.c
  25. | |
  26. | +---bt
  27. | | | bt.c
  28. | | | component.mk
  29. | | | Kconfig
  30. | | |
  31. | | +---bluedroid
  32. . .
  33. . .
  34. . .
  35. | |
  36. | +---driver
  37. | | | component.mk
  38. | | | gpio.c
  39. | | | ledc.c
  40. | | | pcnt.c
  41. | | | periph_ctrl.c
  42. | | | rmt.c
  43. | | | timer.c
  44. | | | uart.c
  45. | | |
  46. | | \---include
  47. | | \---driver
  48. | | gpio.h
  49. | | ledc.h
  50. | | pcnt.h
  51. | | periph_ctrl.h
  52. | | rmt.h
  53. | | timer.h
  54. | | uart.h
  55. | |
  56. | +---esp32
  57. | | | abi.cpp
  58. | | | brownout.c
  59. | | | component.mk
  60. | | | cpu_freq.c
  61. | | | cpu_start.c
  62. | | | cpu_util.c
  63. . .
  64. . .
  65. . .
  66. . .
  67. | |
  68. | +---esptool_py
  69. | | | Kconfig.projbuild
  70. | | | LICENSE
  71. . .
  72. . .
  73. | |
  74. | +---ethernet
  75. | | | component.mk
  76. . .
  77. | |
  78. | +---expat
  79. . .
  80. | |
  81. | +---freertos
  82. | | | component.mk
  83. | | | croutine.c
  84. | | | event_groups.c
  85. | | | FreeRTOS-openocd.c
  86. | | | heap_regions.c
  87. . .
  88. . .
  89. | |
  90. | +---idf_test
  91. . .
  92. . .
  93. | |
  94. | +---newlib
  95. . .
  96. | |
  97. | +---nghttp
  98. . .
  99. . .
  100. . .
  101. | |
  102. | +---nvs_flash
  103. | | | .gitignore
  104. | | | component.mk
  105. | | | README.rst
  106. | | |
  107. . .
  108. . .
  109. | |
  110. | +---openssl
  111. . .
  112. . .
  113. | +---partition_table
  114.  
  115. | |
  116. | +---spi_flash
  117. |
  118. | |
  119. | +---tcpip_adapter
  120.  
  121. | |
  122. | +---ulp
  123. | |
  124. | +---vfs
  125. | |
  126. | +---wpa_supplicant
  127.  
  128. | |
  129. | \---xtensa-debug-module
  130. | | component.mk
  131. | | eri.c
  132. | | trax.c
  133. | |
  134. | \---include
  135. | eri.h
  136. | trax.h
  137. | xtensa-debug-module.h
  1. /* Hello World Example
  2.  
  3. This example code is in the Public Domain (or CC0 licensed, at your option.)
  4.  
  5. Unless required by applicable law or agreed to in writing, this
  6. software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  7. CONDITIONS OF ANY KIND, either express or implied.
  8. */
  9. #include <stdio.h>
  10. #include "freertos/FreeRTOS.h"
  11. #include "freertos/task.h"
  12. #include "esp_system.h"
  13. #include "nvs_flash.h"
  14.  
  15. void hello_task(void *pvParameter)
  16. {
  17. printf("Hello world!\n");
  18. for (int i = 10; i >= 0; i--) {
  19. printf("Restarting in %d seconds...\n", i);
  20. vTaskDelay(1000 / portTICK_RATE_MS);
  21. }
  22. printf("Restarting now.\n");
  23. fflush(stdout);
  24. esp_restart();
  25. }
  26.  
  27. void app_main()
  28. {
  29. nvs_flash_init();
  30. xTaskCreate(&hello_task, "hello_task", 2048, NULL, 5, NULL);
  31. }