host-apps.rst 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. Running ESP-IDF Applications on Host
  2. ====================================
  3. :link_to_translation:`zh_CN:[中文]`
  4. .. note::
  5. Running ESP-IDF applications on host is currently still an experimental feature, thus there is no guarantee for API stability. However, user feedback via the `ESP-IDF GitHub repository <https://github.com/espressif/esp-idf>`_ or the `ESP32 forum <https://esp32.com/>`_ is highly welcome, and may help influence the future of design of the ESP-IDF host-based applications.
  6. This document provides an overview of the methods to run ESP-IDF applications on Linux, and what type of ESP-IDF applications can typically be run on Linux.
  7. Introduction
  8. ------------
  9. Typically, an ESP-IDF application is built (cross-compiled) on a host machine, uploaded (i.e., flashed) to an ESP chip for execution, and monitored by the host machine via a UART/USB port. However, execution of an ESP-IDF application on an ESP chip can be limiting in various development/usage/testing scenarios.
  10. Therefore, it is possible for an ESP-IDF application to be built and executed entirely within the same Linux host machine (henceforth referred to as "running on host"). Running ESP-IDF applications on host has several advantages:
  11. - No need to upload to a target.
  12. - Faster execution on a host machine, compared to running on an ESP chip.
  13. - No requirements for any specific hardware, except the host machine itself.
  14. - Easier automation and setup for software testing.
  15. - Large number of tools for code and runtime analysis, e.g., Valgrind.
  16. A large number of ESP-IDF components depend on chip-specific hardware. These hardware dependencies must be mocked or simulated when running on host. ESP-IDF currently supports the following mocking and simulation approaches:
  17. 1. Using the `FreeRTOS POSIX/Linux simulator <https://www.freertos.org/FreeRTOS-simulator-for-Linux.html>`_ that simulates FreeRTOS scheduling. On top of this simulation, other APIs are also simulated or implemented when running on host.
  18. 2. Using `CMock <https://www.throwtheswitch.org/cmock>`_ to mock all dependencies and run the code in complete isolation.
  19. In principle, it is possible to mix both approaches (POSIX/Linux simulator and mocking using CMock), but this has not been done yet in ESP-IDF. Note that despite the name, the FreeRTOS POSIX/Linux simulator currently also works on macOS. Running ESP-IDF applications on host machines is often used for testing. However, simulating the environment and mocking dependencies does not fully represent the target device. Thus, testing on the target device is still necessary, though with a different focus that usually puts more weight on integration and system testing.
  20. .. note::
  21. Another possibility to run applications on the host is to use the QEMU simulator. However, QEMU development for ESP-IDF applications is still a work in progress and has not been documented yet.
  22. CMock-Based Approach
  23. ^^^^^^^^^^^^^^^^^^^^
  24. This approach uses the `CMock <https://www.throwtheswitch.org/cmock>`_ framework to solve the problem of missing hardware and software dependencies. CMock-based applications running on the host machine have the added advantage that they usually only compile the necessary code, i.e., the (mostly mocked) dependencies instead of the entire system. For a general introduction to Mocks and how to configure and use them in ESP-IDF, please refer to :ref:`mocks`.
  25. POSIX/Linux Simulator Approach
  26. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  27. The `FreeRTOS POSIX/Linux simulator <https://www.freertos.org/FreeRTOS-simulator-for-Linux.html>`_ is available on ESP-IDF as a preview target already. This simulator allows ESP-IDF components to be implemented on the host, making them accessible to ESP-IDF applications when running on host. Currently, only a limited number of components are ready to be built on Linux. Furthermore, the functionality of each component ported to Linux may also be limited or different compared to the functionality when building that component for a chip target. For more information about whether the desired components are supported on Linux, please refer to :ref:`component-linux-mock-support`.
  28. .. note::
  29. The FreeRTOS POSIX/Linux simulator allows configuring the :ref:`amazon_smp_freertos` version. However, the simulation still runs in single-core mode. The main reason allowing Amazon SMP FreeRTOS is to provide API compatibility with ESP-IDF applications written for Amazon SMP FreeRTOS.
  30. Requirements for Using Mocks
  31. ----------------------------
  32. .. include:: inc/linux-host-requirements.rst
  33. If any mocks are used, then ``Ruby`` is required, too.
  34. Build and Run
  35. -------------
  36. To build the application on Linux, the target has to be set to ``linux`` and then it can be built and run:
  37. .. code-block:: bash
  38. idf.py --preview set-target linux
  39. idf.py build
  40. idf.py monitor
  41. .. _component-linux-mock-support:
  42. Component Linux/Mock Support Overview
  43. -------------------------------------
  44. Note that any "Yes" here does not necessarily mean a full implementation or mocking. It can also mean a partial implementation or mocking of functionality. Usually, the implementation or mocking is done to a point where enough functionality is provided to build and run a test application.
  45. .. list-table::
  46. :header-rows: 1
  47. :widths: 20 10 10
  48. * - Component
  49. - Mock
  50. - Simulation
  51. * - driver
  52. - Yes
  53. - No
  54. * - esp_common
  55. - No
  56. - Yes
  57. * - esp_event
  58. - Yes
  59. - Yes
  60. * - esp_hw_support
  61. - Yes
  62. - Yes
  63. * - esp_partition
  64. - Yes
  65. - No
  66. * - esp_rom
  67. - No
  68. - Yes
  69. * - esp_system
  70. - No
  71. - Yes
  72. * - esp_timer
  73. - Yes
  74. - No
  75. * - esp_tls
  76. - Yes
  77. - No
  78. * - freertos
  79. - Yes
  80. - Yes
  81. * - hal
  82. - No
  83. - Yes
  84. * - heap
  85. - No
  86. - Yes
  87. * - http_parser
  88. - Yes
  89. - No
  90. * - log
  91. - No
  92. - Yes
  93. * - lwip
  94. - Yes
  95. - No
  96. * - soc
  97. - No
  98. - Yes
  99. * - spi_flash
  100. - Yes
  101. - No
  102. * - tcp_transport
  103. - Yes
  104. - No