mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
Merge branch 'feat/remove_make' into 'master'
Build & config: Remove the "make" build system Closes IDF-4272 See merge request espressif/esp-idf!15818
This commit is contained in:
@@ -481,20 +481,15 @@ Compiler Option
|
||||
|
||||
In order to obtain code coverage data in a project, one or more source files within the project must be compiled with the ``--coverage`` option. In ESP-IDF, this can be achieved at the component level or the individual source file level:
|
||||
|
||||
To cause all source files in a component to be compiled with the ``--coverage`` option.
|
||||
- Add ``target_compile_options(${COMPONENT_LIB} PRIVATE --coverage)`` to the ``CMakeLists.txt`` file of the component if using CMake.
|
||||
- Add ``CFLAGS += --coverage`` to the ``component.mk`` file of the component if using Make.
|
||||
|
||||
To cause a select number of source files (e.g. ``sourec1.c`` and ``source2.c``) in the same component to be compiled with the ``--coverage`` option.
|
||||
- Add ``set_source_files_properties(source1.c source2.c PROPERTIES COMPILE_FLAGS --coverage)`` to the ``CMakeLists.txt`` file of the component if using CMake.
|
||||
- Add ``source1.o: CFLAGS += --coverage`` and ``source2.o: CFLAGS += --coverage`` to the ``component.mk`` file of the component if using Make.
|
||||
- To cause all source files in a component to be compiled with the ``--coverage`` option, you can add ``target_compile_options(${COMPONENT_LIB} PRIVATE --coverage)`` to the ``CMakeLists.txt`` file of the component.
|
||||
- To cause a select number of source files (e.g. ``sourec1.c`` and ``source2.c``) in the same component to be compiled with the ``--coverage`` option, you can add ``set_source_files_properties(source1.c source2.c PROPERTIES COMPILE_FLAGS --coverage)`` to the ``CMakeLists.txt`` file of the component.
|
||||
|
||||
When a source file is compiled with the ``--coverage`` option (e.g. ``gcov_example.c``), the compiler will generate the ``gcov_example.gcno`` file in the project's build directory.
|
||||
|
||||
Project Configuration
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Before building a project with source code coverage, ensure that the following project configuration options are enabled by running ``idf.py menuconfig`` (or ``make menuconfig`` if using the legacy Make build system).
|
||||
Before building a project with source code coverage, ensure that the following project configuration options are enabled by running ``idf.py menuconfig``.
|
||||
|
||||
- Enable the application tracing module by choosing *Trace Memory* for the :ref:`CONFIG_APPTRACE_DESTINATION` option.
|
||||
- Enable Gcov to host via the :ref:`CONFIG_APPTRACE_GCOV_ENABLE`
|
||||
@@ -508,7 +503,7 @@ Once a project has been complied with the ``--coverage`` option and flashed onto
|
||||
|
||||
The dumping of coverage data is done via OpenOCD (see :doc:`JTAG Debugging <../api-guides/jtag-debugging/index>` on how to setup and run OpenOCD). A dump is triggered by issuing commands to OpenOCD, therefore a telnet session to OpenOCD must be opened to issue such commands (run ``telnet localhost 4444``). Note that GDB could be used instead of telnet to issue commands to OpenOCD, however all commands issued from GDB will need to be prefixed as ``mon <oocd_command>``.
|
||||
|
||||
When the target dumps code coverage data, the ``.gcda`` files are stored in the project's build directory. For example, if ``gcov_example_main.c`` of the ``main`` component was compiled with the ``--coverage`` option, then dumping the code coverage data would generate a ``gcov_example_main.gcda`` in ``build/esp-idf/main/CMakeFiles/__idf_main.dir/gcov_example_main.c.gcda`` (or ``build/main/gcov_example_main.gcda`` if using the legacy Make build system). Note that the ``.gcno`` files produced during compilation are also placed in the same directory.
|
||||
When the target dumps code coverage data, the ``.gcda`` files are stored in the project's build directory. For example, if ``gcov_example_main.c`` of the ``main`` component was compiled with the ``--coverage`` option, then dumping the code coverage data would generate a ``gcov_example_main.gcda`` in ``build/esp-idf/main/CMakeFiles/__idf_main.dir/gcov_example_main.c.gcda``. Note that the ``.gcno`` files produced during compilation are also placed in the same directory.
|
||||
|
||||
The dumping of code coverage data can be done multiple times throughout an application's life time. Each dump will simply update the ``.gcda`` file with the newest code coverage information. Code coverage data is accumulative, thus the newest data will contain the total execution count of each code path over the application's entire lifetime.
|
||||
|
||||
@@ -558,10 +553,7 @@ Adding Gcovr Build Target to Project
|
||||
|
||||
To make report generation more convenient, users can define additional build targets in their projects such report generation can be done with a single build command.
|
||||
|
||||
CMake Build System
|
||||
******************
|
||||
|
||||
For the CMake build systems, add the following lines to the ``CMakeLists.txt`` file of your project.
|
||||
Add the following lines to the ``CMakeLists.txt`` file of your project.
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
@@ -573,32 +565,3 @@ The following commands can now be used:
|
||||
|
||||
* ``cmake --build build/ --target gcovr-report`` will generate an HTML coverage report in ``$(BUILD_DIR_BASE)/coverage_report/html`` directory.
|
||||
* ``cmake --build build/ --target cov-data-clean`` will remove all coverage data files.
|
||||
|
||||
Make Build System
|
||||
*****************
|
||||
|
||||
For the Make build systems, add the following lines to the ``Makefile`` of your project.
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
GCOV := $(call dequote,$(CONFIG_SDK_TOOLPREFIX))gcov
|
||||
REPORT_DIR := $(BUILD_DIR_BASE)/coverage_report
|
||||
|
||||
gcovr-report:
|
||||
echo "Generating coverage report in: $(REPORT_DIR)"
|
||||
echo "Using gcov: $(GCOV)"
|
||||
mkdir -p $(REPORT_DIR)/html
|
||||
cd $(BUILD_DIR_BASE)
|
||||
gcovr -r $(PROJECT_PATH) --gcov-executable $(GCOV) -s --html-details $(REPORT_DIR)/html/index.html
|
||||
|
||||
cov-data-clean:
|
||||
echo "Remove coverage data files..."
|
||||
find $(BUILD_DIR_BASE) -name "*.gcda" -exec rm {} +
|
||||
rm -rf $(REPORT_DIR)
|
||||
|
||||
.PHONY: gcovr-report cov-data-clean
|
||||
|
||||
The following commands can now be used:
|
||||
|
||||
* ``make gcovr-report`` will generate an HTML coverage report in ``$(BUILD_DIR_BASE)/coverage_report/html`` directory.
|
||||
* ``make cov-data-clean`` will remove all coverage data files.
|
||||
|
||||
@@ -135,10 +135,6 @@ When using the default :ref:`CONFIG_PARTITION_TABLE_OFFSET` value 0x8000, the si
|
||||
|
||||
If the bootloader binary is too large, then the bootloader build will fail with an error "Bootloader binary size [..] is too large for partition table offset". If the bootloader binary is flashed anyhow then the {IDF_TARGET_NAME} will fail to boot - errors will be logged about either invalid partition table or invalid bootloader checksum.
|
||||
|
||||
.. note::
|
||||
|
||||
The bootloader size check only happens in the CMake Build System, when using the legacy GNU Make Build System the size is not checked but the {IDF_TARGET_NAME} will fail to boot if bootloader is too large.
|
||||
|
||||
Options to work around this are:
|
||||
|
||||
- Set :ref:`bootloader compiler optimization <CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION>` back to "Size" if it has been changed from this default value.
|
||||
@@ -163,5 +159,3 @@ The current bootloader implementation allows a project to extend it or modify it
|
||||
In the bootloader space, you cannot use the drivers and functions from other components. If necessary, then the required functionality should be placed in the project's `bootloader_components` directory (note that this will increase its size).
|
||||
|
||||
If the bootloader grows too large then it can collide with the partition table, which is flashed at offset 0x8000 by default. Increase the :ref:`partition table offset <CONFIG_PARTITION_TABLE_OFFSET>` value to place the partition table later in the flash. This increases the space available for the bootloader.
|
||||
|
||||
.. note:: Customize the bootloader by using either method is only supported with CMake build system (i.e. not supported with legacy Make build system).
|
||||
|
||||
@@ -1,535 +0,0 @@
|
||||
Build System (Legacy GNU Make)
|
||||
******************************
|
||||
:link_to_translation:`zh_CN:[中文]`
|
||||
|
||||
.. include:: ../gnu-make-legacy.rst
|
||||
|
||||
This document explains the legacy GNU Make Espressif IoT Development Framework build system and the concept of "components"
|
||||
|
||||
Read this document if you want to know how to organise an ESP-IDF project using GNU Make build system.
|
||||
|
||||
We recommend using the esp-idf-template_ project as a starting point for your project.
|
||||
|
||||
Using the Build System
|
||||
======================
|
||||
|
||||
The esp-idf README file contains a description of how to use the build system to build your project.
|
||||
|
||||
Overview
|
||||
========
|
||||
|
||||
An ESP-IDF project can be seen as an amalgamation of a number of components. For example, for a webserver that shows the current humidity, there could be:
|
||||
|
||||
- The {IDF_TARGET_NAME} base libraries (libc, rom bindings etc)
|
||||
- The Wi-Fi drivers
|
||||
- A TCP/IP stack
|
||||
- The FreeRTOS operating system
|
||||
- A webserver
|
||||
- A driver for the humidity sensor
|
||||
- Main code tying it all together
|
||||
|
||||
ESP-IDF makes these components explicit and configurable. To do that, when a project is compiled, the build environment will look up all the components in the ESP-IDF directories, the project directories and (optionally) in additional custom component directories. It then allows the user to configure the ESP-IDF project using a a text-based menu system to customize each component. After the components in the project are configured, the build process will compile the project.
|
||||
|
||||
Concepts
|
||||
--------
|
||||
|
||||
- A "project" is a directory that contains all the files and configuration to build a single "app" (executable), as well as additional supporting output such as a partition table, data/filesystem partitions, and a bootloader.
|
||||
|
||||
- "Project configuration" is held in a single file called sdkconfig in the root directory of the project. This configuration file is modified via ``make menuconfig`` to customise the configuration of the project. A single project contains exactly one project configuration.
|
||||
|
||||
- An "app" is an executable which is built by esp-idf. A single project will usually build two apps - a "project app" (the main executable, ie your custom firmware) and a "bootloader app" (the initial bootloader program which launches the project app).
|
||||
|
||||
- "components" are modular pieces of standalone code which are compiled into static libraries (.a files) and linked into an app. Some are provided by esp-idf itself, others may be sourced from other places.
|
||||
|
||||
Some things are not part of the project:
|
||||
|
||||
- "ESP-IDF" is not part of the project. Instead it is standalone, and linked to the project via the ``IDF_PATH`` environment variable which holds the path of the ``esp-idf`` directory. This allows the IDF framework to be decoupled from your project.
|
||||
|
||||
- The toolchain for compilation is not part of the project. The toolchain should be installed in the system command line PATH, or the path to the toolchain can be set as part of the compiler prefix in the project configuration.
|
||||
|
||||
Example Project
|
||||
---------------
|
||||
|
||||
An example project directory tree might look like this::
|
||||
|
||||
- myProject/
|
||||
- Makefile
|
||||
- sdkconfig
|
||||
- components/ - component1/ - component.mk
|
||||
- Kconfig
|
||||
- src1.c
|
||||
- component2/ - component.mk
|
||||
- Kconfig
|
||||
- src1.c
|
||||
- include/ - component2.h
|
||||
- main/ - src1.c
|
||||
- src2.c
|
||||
- component.mk
|
||||
|
||||
- build/
|
||||
|
||||
This example "myProject" contains the following elements:
|
||||
|
||||
- A top-level project Makefile. This Makefile sets the ``PROJECT_NAME`` variable and (optionally) defines other project-wide make variables. It includes the core ``$(IDF_PATH)/make/project.mk`` makefile which implements the rest of the ESP-IDF build system.
|
||||
|
||||
- "sdkconfig" project configuration file. This file is created/updated when "make menuconfig" runs, and holds configuration for all of the components in the project (including esp-idf itself). The "sdkconfig" file may or may not be added to the source control system of the project.
|
||||
|
||||
- Optional "components" directory contains components that are part of the project. A project does not have to contain custom components of this kind, but it can be useful for structuring reusable code or including third party components that aren't part of ESP-IDF.
|
||||
|
||||
- "main" directory is a special "pseudo-component" that contains source code for the project itself. "main" is a default name, the Makefile variable ``COMPONENT_DIRS`` includes this component but you can modify this variable (or set ``EXTRA_COMPONENT_DIRS``) to look for components in other places.
|
||||
|
||||
- "build" directory is where build output is created. After the make process is run, this directory will contain interim object files and libraries as well as final binary output files. This directory is usually not added to source control or distributed with the project source code.
|
||||
|
||||
Component directories contain a component makefile - ``component.mk``. This may contain variable definitions to control the build process of the component, and its integration into the overall project. See `Component Makefiles`_ for more details.
|
||||
|
||||
Each component may also include a ``Kconfig`` file defining the `component configuration` options that can be set via the project configuration. Some components may also include ``Kconfig.projbuild`` and ``Makefile.projbuild`` files, which are special files for `overriding parts of the project`.
|
||||
|
||||
Project Makefiles
|
||||
-----------------
|
||||
|
||||
Each project has a single Makefile that contains build settings for the entire project. By default, the project Makefile can be quite minimal.
|
||||
|
||||
Minimal Example Makefile
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
::
|
||||
|
||||
PROJECT_NAME := myProject
|
||||
|
||||
include $(IDF_PATH)/make/project.mk
|
||||
|
||||
Mandatory Project Variables
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- ``PROJECT_NAME``: Name of the project. Binary output files will use this name - ie myProject.bin, myProject.elf.
|
||||
|
||||
Optional Project Variables
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
These variables all have default values that can be overridden for custom behaviour. Look in ``make/project.mk`` for all of the implementation details.
|
||||
|
||||
- ``PROJECT_PATH``: Top-level project directory. Defaults to the directory containing the Makefile. Many other project variables are based on this variable. The project path cannot contain spaces.
|
||||
- ``BUILD_DIR_BASE``: The build directory for all objects/libraries/binaries. Defaults to ``$(PROJECT_PATH)/build``.
|
||||
- ``COMPONENT_DIRS``: Directories to search for components. Defaults to `$(IDF_PATH)/components`, `$(PROJECT_PATH)/components`, ``$(PROJECT_PATH)/main`` and ``EXTRA_COMPONENT_DIRS``. Override this variable if you don't want to search for components in these places.
|
||||
- ``EXTRA_COMPONENT_DIRS``: Optional list of additional directories to search for components.
|
||||
- ``COMPONENTS``: A list of component names to build into the project. Defaults to all components found in the COMPONENT_DIRS directories.
|
||||
- ``EXCLUDE_COMPONENTS``: Optional list of component names to exclude during the build process. Note that this decreases build time, but not binary size.
|
||||
- ``TEST_EXCLUDE_COMPONENTS``: Optional list of component names to exclude during the build process of unit tests.
|
||||
|
||||
Any paths in these Makefile variables should be absolute paths. You can convert relative paths using ``$(PROJECT_PATH)/xxx``, ``$(IDF_PATH)/xxx``, or use the Make function ``$(abspath xxx)``.
|
||||
|
||||
These variables should all be set before the line ``include $(IDF_PATH)/make/project.mk`` in the Makefile.
|
||||
|
||||
|
||||
|
||||
Component Makefiles
|
||||
-------------------
|
||||
|
||||
Each project contains one or more components, which can either be part of esp-idf or added from other component directories.
|
||||
|
||||
A component is any directory that contains a ``component.mk`` file.
|
||||
|
||||
Searching for Components
|
||||
------------------------
|
||||
|
||||
The list of directories in ``COMPONENT_DIRS`` is searched for the project's components. Directories in this list can either be components themselves (ie they contain a `component.mk` file), or they can be top-level directories whose subdirectories are components.
|
||||
|
||||
Running the ``make list-components`` target dumps many of these variables and can help debug the discovery of component directories.
|
||||
|
||||
Multiple components with the same name
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
When esp-idf is collecting all the components to compile, it will do this in the order specified by ``COMPONENT_DIRS``; by default, this means the idf components first, the project components second and optionally the components in ``EXTRA_COMPONENT_DIRS`` last. If two or more of these directories contain component subdirectories with the same name, the component in the last place searched is used. This allows, for example, overriding esp-idf components with a modified version by simply copying the component from the esp-idf component directory to the project component tree and then modifying it there.
|
||||
If used in this way, the esp-idf directory itself can remain untouched.
|
||||
|
||||
|
||||
Minimal Component Makefile
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
The minimal ``component.mk`` file is an empty file(!). If the file is empty, the default component behaviour is set:
|
||||
|
||||
- All source files in the same directory as the makefile (``*.c``, ``*.cpp``, ``*.cc``, ``*.S``) will be compiled into the component library
|
||||
- A sub-directory "include" will be added to the global include search path for all other components.
|
||||
- The component library will be linked into the project app.
|
||||
|
||||
See `example component makefiles`_ for more complete component makefile examples.
|
||||
|
||||
Note that there is a difference between an empty ``component.mk`` file (which invokes default component build behaviour) and no ``component.mk`` file (which means no default component build behaviour will occur.) It is possible for a component to have no `component.mk` file, if it only contains other files which influence the project configuration or build process.
|
||||
|
||||
.. component variables:
|
||||
|
||||
Preset Component Variables
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
The following component-specific variables are available for use inside ``component.mk``, but should not be modified:
|
||||
|
||||
- ``COMPONENT_PATH``: The component directory. Evaluates to the absolute path of the directory containing ``component.mk``. The component path cannot contain spaces.
|
||||
- ``COMPONENT_NAME``: Name of the component. Defaults to the name of the component directory.
|
||||
- ``COMPONENT_BUILD_DIR``: The component build directory. Evaluates to the absolute path of a directory inside `$(BUILD_DIR_BASE)` where this component's source files are to be built. This is also the Current Working Directory any time the component is being built, so relative paths in make targets, etc. will be relative to this directory.
|
||||
- ``COMPONENT_LIBRARY``: Name of the static library file (relative to the component build directory) that will be built for this component. Defaults to ``$(COMPONENT_NAME).a``.
|
||||
|
||||
The following variables are set at the project level, but exported for use in the component build:
|
||||
|
||||
- ``PROJECT_NAME``: Name of the project, as set in project Makefile
|
||||
- ``PROJECT_PATH``: Absolute path of the project directory containing the project Makefile.
|
||||
- ``COMPONENTS``: Name of all components that are included in this build.
|
||||
- ``CONFIG_*``: Each value in the project configuration has a corresponding variable available in make. All names begin with ``CONFIG_``.
|
||||
- ``CC``, ``LD``, ``AR``, ``OBJCOPY``: Full paths to each tool from the gcc xtensa cross-toolchain.
|
||||
- ``HOSTCC``, ``HOSTLD``, ``HOSTAR``: Full names of each tool from the host native toolchain.
|
||||
- ``IDF_VER``: ESP-IDF version, retrieved from either ``$(IDF_PATH)/version.txt`` file (if present) else using git command ``git describe``. Recommended format here is single liner that specifies major IDF release version, e.g. ``v2.0`` for a tagged release or ``v2.0-275-g0efaa4f`` for an arbitrary commit. Application can make use of this by calling :cpp:func:`esp_get_idf_version`.
|
||||
- ``IDF_VERSION_MAJOR``, ``IDF_VERSION_MINOR``, ``IDF_VERSION_PATCH``: Components of ESP-IDF version, to be used in conditional expressions. Note that this information is less precise than that provided by ``IDF_VER`` variable. ``v4.0-dev-*``, ``v4.0-beta1``, ``v4.0-rc1`` and ``v4.0`` will all have the same values of ``ESP_IDF_VERSION_*`` variables, but different ``IDF_VER`` values.
|
||||
- ``PROJECT_VER``: Project version.
|
||||
|
||||
* If :ref:`CONFIG_APP_PROJECT_VER_FROM_CONFIG` option is set, the value of :ref:`CONFIG_APP_PROJECT_VER` will be used.
|
||||
* Else, if ``PROJECT_VER`` variable is set in project Makefile file, its value will be used.
|
||||
* Else, if the ``$PROJECT_PATH/version.txt`` exists, its contents will be used as ``PROJECT_VER``.
|
||||
* Else, if the project is located inside a Git repository, the output of git describe will be used.
|
||||
* Otherwise, ``PROJECT_VER`` will be "1".
|
||||
|
||||
If you modify any of these variables inside ``component.mk`` then this will not prevent other components from building but it may make your component hard to build and/or debug.
|
||||
|
||||
|
||||
|
||||
Optional Project-Wide Component Variables
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
The following variables can be set inside ``component.mk`` to control build settings across the entire project:
|
||||
|
||||
- ``COMPONENT_ADD_INCLUDEDIRS``: Paths, relative to the component directory, which will be added to the include search path for all components in the project. Defaults to ``include`` if not overridden. If an include directory is only needed to compile this specific component, add it to ``COMPONENT_PRIV_INCLUDEDIRS`` instead.
|
||||
- ``COMPONENT_ADD_LDFLAGS``: Add linker arguments to the LDFLAGS for the app executable. Defaults to ``-l$(COMPONENT_NAME)``. If adding pre-compiled libraries to this directory, add them as absolute paths - ie $(COMPONENT_PATH)/libwhatever.a
|
||||
- ``COMPONENT_DEPENDS``: Optional list of component names that should be compiled before this component. This is not necessary for link-time dependencies, because all component include directories are available at all times. It is necessary if one component generates an include file which you then want to include in another component. Most components do not need to set this variable.
|
||||
- ``COMPONENT_ADD_LINKER_DEPS``: Optional list of component-relative paths to files which should trigger a re-link of the ELF file if they change. Typically used for linker script files and binary libraries. Most components do not need to set this variable.
|
||||
|
||||
The following variable only works for components that are part of esp-idf itself:
|
||||
|
||||
- ``COMPONENT_SUBMODULES``: Optional list of git submodule paths (relative to COMPONENT_PATH) used by the component. These will be checked (and initialised if necessary) by the build process. This variable is ignored if the component is outside the IDF_PATH directory.
|
||||
|
||||
|
||||
Optional Component-Specific Variables
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
The following variables can be set inside ``component.mk`` to control the build of that component:
|
||||
|
||||
- ``COMPONENT_PRIV_INCLUDEDIRS``: Directory paths, must be relative to the component directory, which will be added to the include search path for this component's source files only.
|
||||
- ``COMPONENT_EXTRA_INCLUDES``: Any extra include paths used when compiling the component's source files. These will be prefixed with '-I' and passed as-is to the compiler. Similar to the ``COMPONENT_PRIV_INCLUDEDIRS`` variable, except these paths are not expanded relative to the component directory.
|
||||
- ``COMPONENT_SRCDIRS``: Directory paths, must be relative to the component directory, which will be searched for source files (``*.cpp``, ``*.c``, ``*.S``). Defaults to '.', ie the component directory itself. Override this to specify a different list of directories which contain source files.
|
||||
- ``COMPONENT_OBJS``: Object files to compile. Default value is a .o file for each source file that is found in ``COMPONENT_SRCDIRS``. Overriding this list allows you to exclude source files in ``COMPONENT_SRCDIRS`` that would otherwise be compiled. See `Specifying source files`
|
||||
- ``COMPONENT_EXTRA_CLEAN``: Paths, relative to the component build directory, of any files that are generated using custom make rules in the component.mk file and which need to be removed as part of ``make clean``. See `Source Code Generation`_ for an example.
|
||||
- ``COMPONENT_OWNBUILDTARGET`` & ``COMPONENT_OWNCLEANTARGET``: These targets allow you to fully override the default build behaviour for the component. See `Fully Overriding The Component Makefile`_ for more details.
|
||||
- ``COMPONENT_CONFIG_ONLY``: If set, this flag indicates that the component produces no built output at all (ie ``COMPONENT_LIBRARY`` is not built), and most other component variables are ignored. This flag is used for IDF internal components which contain only ``KConfig.projbuild`` and/or ``Makefile.projbuild`` files to configure the project, but no source files.
|
||||
- ``CFLAGS``: Flags passed to the C compiler. A default set of ``CFLAGS`` is defined based on project settings. Component-specific additions can be made via ``CFLAGS +=``. It is also possible (although not recommended) to override this variable completely for a component.
|
||||
- ``CPPFLAGS``: Flags passed to the C preprocessor (used for .c, .cpp and .S files). A default set of ``CPPFLAGS`` is defined based on project settings. Component-specific additions can be made via ``CPPFLAGS +=``. It is also possible (although not recommended) to override this variable completely for a component.
|
||||
- ``CXXFLAGS``: Flags passed to the C++ compiler. A default set of ``CXXFLAGS`` is defined based on project settings. Component-specific additions can be made via ``CXXFLAGS +=``. It is also possible (although not recommended) to override this variable completely for a component.
|
||||
- ``COMPONENT_ADD_LDFRAGMENTS``: Paths to linker fragment files for the linker script generation functionality. See :doc:`Linker Script Generation <linker-script-generation>`.
|
||||
|
||||
To apply compilation flags to a single source file, you can add a variable override as a target, ie::
|
||||
|
||||
apps/dhcpserver.o: CFLAGS += -Wno-unused-variable
|
||||
|
||||
This can be useful if there is upstream code that emits warnings.
|
||||
|
||||
Component Configuration
|
||||
-----------------------
|
||||
|
||||
Each component can also have a Kconfig file, alongside ``component.mk``. This contains contains configuration settings to add to the "make menuconfig" for this component.
|
||||
|
||||
These settings are found under the "Component Settings" menu when menuconfig is run.
|
||||
|
||||
To create a component KConfig file, it is easiest to start with one of the KConfig files distributed with esp-idf.
|
||||
|
||||
For an example, see `Adding conditional configuration`_.
|
||||
|
||||
Preprocessor Definitions
|
||||
------------------------
|
||||
|
||||
ESP-IDF build systems adds the following C preprocessor definitions on the command line:
|
||||
|
||||
- ``ESP_PLATFORM`` — Can be used to detect that build happens within ESP-IDF.
|
||||
- ``IDF_VER`` — ESP-IDF version, see `Preset Component Variables`_ for more details.
|
||||
|
||||
Build Process Internals
|
||||
-----------------------
|
||||
|
||||
Top Level: Project Makefile
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- "make" is always run from the project directory and the project makefile, typically named Makefile.
|
||||
- The project makefile sets ``PROJECT_NAME`` and optionally customises other `optional project variables`
|
||||
- The project makefile includes ``$(IDF_PATH)/make/project.mk`` which contains the project-level Make logic.
|
||||
- ``project.mk`` fills in default project-level make variables and includes make variables from the project configuration. If the generated makefile containing project configuration is out of date, then it is regenerated (via targets in ``project_config.mk``) and then the make process restarts from the top.
|
||||
- ``project.mk`` builds a list of components to build, based on the default component directories or a custom list of components set in `optional project variables`.
|
||||
- Each component can set some `optional project-wide component variables`_. These are included via generated makefiles named ``component_project_vars.mk`` - there is one per component. These generated makefiles are included into ``project.mk``. If any are missing or out of date, they are regenerated (via a recursive make call to the component makefile) and then the make process restarts from the top.
|
||||
- `Makefile.projbuild` files from components are included into the make process, to add extra targets or configuration.
|
||||
- By default, the project makefile also generates top-level build & clean targets for each component and sets up `app` and `clean` targets to invoke all of these sub-targets.
|
||||
- In order to compile each component, a recursive make is performed for the component makefile.
|
||||
|
||||
To better understand the project make process, have a read through the ``project.mk`` file itself.
|
||||
|
||||
Second Level: Component Makefiles
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- Each call to a component makefile goes via the ``$(IDF_PATH)/make/component_wrapper.mk`` wrapper makefile.
|
||||
- This component wrapper includes all component ``Makefile.componentbuild`` files, making any recipes, variables etc in these files available to every component.
|
||||
- The ``component_wrapper.mk`` is called with the current directory set to the component build directory, and the ``COMPONENT_MAKEFILE`` variable is set to the absolute path to ``component.mk``.
|
||||
- ``component_wrapper.mk`` sets default values for all `component variables`, then includes the `component.mk` file which can override or modify these.
|
||||
- If ``COMPONENT_OWNBUILDTARGET`` and ``COMPONENT_OWNCLEANTARGET`` are not defined, default build and clean targets are created for the component's source files and the prerequisite ``COMPONENT_LIBRARY`` static library file.
|
||||
- The ``component_project_vars.mk`` file has its own target in ``component_wrapper.mk``, which is evaluated from ``project.mk`` if this file needs to be rebuilt due to changes in the component makefile or the project configuration.
|
||||
|
||||
To better understand the component make process, have a read through the ``component_wrapper.mk`` file and some of the ``component.mk`` files included with esp-idf.
|
||||
|
||||
Running Make Non-Interactively
|
||||
------------------------------
|
||||
|
||||
When running ``make`` in a situation where you don't want interactive prompts (for example: inside an IDE or an automated build system) append ``BATCH_BUILD=1`` to the make arguments (or set it as an environment variable).
|
||||
|
||||
Setting ``BATCH_BUILD`` implies the following:
|
||||
|
||||
- Verbose output (same as ``V=1``, see below). If you don't want verbose output, also set ``V=0``.
|
||||
- If the project configuration is missing new configuration items (from new components or esp-idf updates) then the project use the default values, instead of prompting the user for each item.
|
||||
- If the build system needs to invoke ``menuconfig``, an error is printed and the build fails.
|
||||
|
||||
.. _make-size:
|
||||
|
||||
Advanced Make Targets
|
||||
---------------------
|
||||
|
||||
- ``make app``, ``make bootloader``, ``make partition table`` can be used to build only the app, bootloader, or partition table from the project as applicable.
|
||||
- ``make erase_flash`` and ``make erase_otadata`` will use esptool.py to erase the entire flash chip and the OTA selection setting from the flash chip, respectively.
|
||||
- ``make size`` prints some size information about the app. ``make size-components`` and ``make size-files`` are similar targets which print more detailed per-component or per-source-file information, respectively.
|
||||
|
||||
Debugging The Make Process
|
||||
--------------------------
|
||||
|
||||
Some tips for debugging the esp-idf build system:
|
||||
|
||||
- Appending ``V=1`` to the make arguments (or setting it as an environment variable) will cause make to echo all commands executed, and also each directory as it is entered for a sub-make.
|
||||
- Running ``make -w`` will cause make to echo each directory as it is entered for a sub-make - same as ``V=1`` but without also echoing all commands.
|
||||
- Running ``make --trace`` (possibly in addition to one of the above arguments) will print out every target as it is built, and the dependency which caused it to be built.
|
||||
- Running ``make -p`` prints a (very verbose) summary of every generated target in each makefile.
|
||||
|
||||
For more debugging tips and general make information, see the `GNU Make Manual`.
|
||||
|
||||
.. _warn-undefined-variables-legacy:
|
||||
|
||||
Warning On Undefined Variables
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
By default, the build process will print a warning if an undefined variable is referenced (like ``$(DOES_NOT_EXIST)``). This can be useful to find errors in variable names.
|
||||
|
||||
If you don't want this behaviour, it can be disabled in menuconfig's top level menu under `SDK tool configuration`.
|
||||
|
||||
Note that this option doesn't trigger a warning if ``ifdef`` or ``ifndef`` are used in Makefiles.
|
||||
|
||||
Overriding Parts of the Project
|
||||
-------------------------------
|
||||
|
||||
Makefile.projbuild
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
|
||||
For components that have build requirements that must be evaluated in the top-level project make pass, you can create a file called ``Makefile.projbuild`` in the component directory. This makefile is included when ``project.mk`` is evaluated.
|
||||
|
||||
For example, if your component needs to add to CFLAGS for the entire project (not just for its own source files) then you can set ``CFLAGS +=`` in Makefile.projbuild.
|
||||
|
||||
``Makefile.projbuild`` files are used heavily inside esp-idf, for defining project-wide build features such as ``esptool.py`` command line arguments and the ``bootloader`` "special app".
|
||||
|
||||
Note that ``Makefile.projbuild`` isn't necessary for the most common component uses - such as adding include directories to the project, or LDFLAGS to the final linking step. These values can be customised via the ``component.mk`` file itself. See `Optional Project-Wide Component Variables`_ for details.
|
||||
|
||||
Take care when setting variables or targets in this file. As the values are included into the top-level project makefile pass, they can influence or break functionality across all components!
|
||||
|
||||
KConfig.projbuild
|
||||
^^^^^^^^^^^^^^^^^
|
||||
|
||||
This is an equivalent to ``Makefile.projbuild`` for `component configuration` KConfig files. If you want to include configuration options at the top-level of menuconfig, rather than inside the "Component Configuration" sub-menu, then these can be defined in the KConfig.projbuild file alongside the ``component.mk`` file.
|
||||
|
||||
Take care when adding configuration values in this file, as they will be included across the entire project configuration. Where possible, it's generally better to create a KConfig file for `component configuration`.
|
||||
|
||||
Makefile.componentbuild
|
||||
^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
For components that e.g. include tools to generate source files from other files, it is necessary to be able to add recipes, macros or variable definitions into the component build process of every components. This is done by having a ``Makefile.componentbuild`` in a component directory. This file gets included in ``component_wrapper.mk``, before the ``component.mk`` of the component is included. As with the Makefile.projbuild, take care with these files: as they're included in each component build, a ``Makefile.componentbuild`` error may only show up when compiling an entirely different component.
|
||||
|
||||
Configuration-Only Components
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Some special components which contain no source files, only ``Kconfig.projbuild`` and ``Makefile.projbuild``, may set the flag ``COMPONENT_CONFIG_ONLY`` in the component.mk file. If this flag is set, most other component variables are ignored and no build step is run for the component.
|
||||
|
||||
|
||||
|
||||
Example Component Makefiles
|
||||
---------------------------
|
||||
|
||||
Because the build environment tries to set reasonable defaults that will work most of the time, component.mk can be very small or even empty (see `Minimal Component Makefile`_). However, overriding `component variables` is usually required for some functionality.
|
||||
|
||||
Here are some more advanced examples of ``component.mk`` makefiles:
|
||||
|
||||
Adding source directories
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
By default, sub-directories are ignored. If your project has sources in sub-directories
|
||||
instead of in the root of the component then you can tell that to the build
|
||||
system by setting ``COMPONENT_SRCDIRS``::
|
||||
|
||||
COMPONENT_SRCDIRS := src1 src2
|
||||
|
||||
This will compile all source files in the src1/ and src2/ sub-directories instead.
|
||||
|
||||
|
||||
|
||||
Specifying source files
|
||||
^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
The standard component.mk logic adds all .S and .c files in the source directories as sources to be compiled unconditionally. It is possible to circumvent that logic and hard-code the objects to be compiled by manually setting the ``COMPONENT_OBJS`` variable to the name of the objects that need to be generated::
|
||||
|
||||
COMPONENT_OBJS := file1.o file2.o thing/filea.o thing/fileb.o anotherthing/main.o
|
||||
COMPONENT_SRCDIRS := . thing anotherthing
|
||||
|
||||
Note that ``COMPONENT_SRCDIRS`` must be set as well.
|
||||
|
||||
|
||||
|
||||
Adding conditional configuration
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
The configuration system can be used to conditionally compile some files depending on the options selected in ``make menuconfig``. For this, ESP-IDF has the compile_only_if and compile_only_if_not macros:
|
||||
|
||||
``Kconfig``::
|
||||
|
||||
config FOO_ENABLE_BAR
|
||||
bool "Enable the BAR feature."
|
||||
help
|
||||
This enables the BAR feature of the FOO component.
|
||||
|
||||
``component.mk``::
|
||||
|
||||
$(call compile_only_if,$(CONFIG_FOO_ENABLE_BAR),bar.o)
|
||||
|
||||
As can be seen in the example, the ``compile_only_if`` macro takes a condition and a list of object files as parameters. If the condition is true (in this case: if the BAR feature is enabled in menuconfig) the object files (in this case: bar.o) will always be compiled. The opposite goes as well: if the condition is not true, bar.o will never be compiled. ``compile_only_if_not`` does the opposite: compile if the condition is false, not compile if the condition is true.
|
||||
|
||||
This can also be used to select or stub out an implementation, as such:
|
||||
|
||||
``Kconfig``::
|
||||
|
||||
config ENABLE_LCD_OUTPUT
|
||||
bool "Enable LCD output."
|
||||
help
|
||||
Select this if your board has a LCD.
|
||||
|
||||
config ENABLE_LCD_CONSOLE
|
||||
bool "Output console text to LCD"
|
||||
depends on ENABLE_LCD_OUTPUT
|
||||
help
|
||||
Select this to output debugging output to the lcd
|
||||
|
||||
config ENABLE_LCD_PLOT
|
||||
bool "Output temperature plots to LCD"
|
||||
depends on ENABLE_LCD_OUTPUT
|
||||
help
|
||||
Select this to output temperature plots
|
||||
|
||||
|
||||
``component.mk``::
|
||||
|
||||
# If LCD is enabled, compile interface to it, otherwise compile dummy interface
|
||||
$(call compile_only_if,$(CONFIG_ENABLE_LCD_OUTPUT),lcd-real.o lcd-spi.o)
|
||||
$(call compile_only_if_not,$(CONFIG_ENABLE_LCD_OUTPUT),lcd-dummy.o)
|
||||
|
||||
#We need font if either console or plot is enabled
|
||||
$(call compile_only_if,$(or $(CONFIG_ENABLE_LCD_CONSOLE),$(CONFIG_ENABLE_LCD_PLOT)), font.o)
|
||||
|
||||
Note the use of the Make 'or' function to include the font file. Other substitution functions, like 'and' and 'if' will also work here. Variables that do not come from menuconfig can also be used: ESP-IDF uses the default Make policy of judging a variable which is empty or contains only whitespace to be false while a variable with any non-whitespace in it is true.
|
||||
|
||||
(Note: Older versions of this document advised conditionally adding object file names to ``COMPONENT_OBJS``. While this still is possible, this will only work when all object files for a component are named explicitely, and will not clean up deselected object files in a ``make clean`` pass.)
|
||||
|
||||
|
||||
|
||||
Source Code Generation
|
||||
^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Some components will have a situation where a source file isn't supplied with the component itself but has to be generated from another file. Say our component has a header file that consists of the converted binary data of a BMP file, converted using a hypothetical tool called bmp2h. The header file is then included in as C source file called graphics_lib.c::
|
||||
|
||||
COMPONENT_EXTRA_CLEAN := logo.h
|
||||
|
||||
graphics_lib.o: logo.h
|
||||
|
||||
logo.h: $(COMPONENT_PATH)/logo.bmp
|
||||
bmp2h -i $^ -o $@
|
||||
|
||||
In this example, graphics_lib.o and logo.h will be generated in the current directory (the build directory) while logo.bmp comes with the component and resides under the component path. Because logo.h is a generated file, it needs to be cleaned when make clean is called which why it is added to the COMPONENT_EXTRA_CLEAN variable.
|
||||
|
||||
Cosmetic Improvements
|
||||
^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Adding logo.h to the ``graphics_lib.o`` dependencies causes it to be generated before ``graphics_lib.c`` is compiled.
|
||||
|
||||
If a a source file in another component included ``logo.h``, then this component's name would have to be added to the other component's ``COMPONENT_DEPENDS`` list to ensure that the components were built in-order.
|
||||
|
||||
Embedding Binary Data
|
||||
^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Sometimes you have a file with some binary or text data that you'd like to make available to your component - but you don't want to reformat the file as C source.
|
||||
|
||||
You can set a variable COMPONENT_EMBED_FILES in component.mk, giving the names of the files to embed in this way::
|
||||
|
||||
COMPONENT_EMBED_FILES := server_root_cert.der
|
||||
|
||||
Or if the file is a string, you can use the variable COMPONENT_EMBED_TXTFILES. This will embed the contents of the text file as a null-terminated string::
|
||||
|
||||
COMPONENT_EMBED_TXTFILES := server_root_cert.pem
|
||||
|
||||
The file's contents will be added to the .rodata section in flash, and are available via symbol names as follows::
|
||||
|
||||
extern const uint8_t server_root_cert_pem_start[] asm("_binary_server_root_cert_pem_start");
|
||||
extern const uint8_t server_root_cert_pem_end[] asm("_binary_server_root_cert_pem_end");
|
||||
|
||||
The names are generated from the full name of the file, as given in COMPONENT_EMBED_FILES. Characters /, ., etc. are replaced with underscores. The _binary prefix in the symbol name is added by objcopy and is the same for both text and binary files.
|
||||
|
||||
For an example of using this technique, see the "main" component of the file_serving example :example_file:`protocols/http_server/file_serving/main/component.mk` - two files are loaded at build time and linked into the firmware.
|
||||
|
||||
Code and Data Placements
|
||||
------------------------
|
||||
|
||||
ESP-IDF has a feature called linker script generation that enables components to define where its code and data will be placed in memory through linker fragment files. These files are processed by the build system, and is used to augment the linker script used for linking app binary. See :doc:`Linker Script Generation <linker-script-generation>` for a quick start guide as well as a detailed discussion of the mechanism.
|
||||
|
||||
|
||||
|
||||
Fully Overriding The Component Makefile
|
||||
---------------------------------------
|
||||
|
||||
Obviously, there are cases where all these recipes are insufficient for a certain component, for example when the component is basically a wrapper around another third-party component not originally intended to be compiled under this build system. In that case, it's possible to forego the esp-idf build system entirely by setting COMPONENT_OWNBUILDTARGET and possibly COMPONENT_OWNCLEANTARGET and defining your own targets named ``build`` and ``clean`` in ``component.mk`` target. The build target can do anything as long as it creates $(COMPONENT_LIBRARY) for the project make process to link into the app binary.
|
||||
|
||||
It is possible for the component build target to build additional libraries and add these to the linker arguments as well. It's even possible for the default $(COMPONENT_LIBRARY) to be a dummy library, however it's used to track the overall build status so the build target should always create it.
|
||||
|
||||
.. note:: When using an external build process with PSRAM, remember to add ``-mfix-esp32-psram-cache-issue`` to the C compiler arguments. See :ref:`CONFIG_SPIRAM_CACHE_WORKAROUND` for details of this flag.
|
||||
|
||||
.. _esp-idf-template: https://github.com/espressif/esp-idf-template
|
||||
.. _GNU Make Manual: https://www.gnu.org/software/make/manual/make.html
|
||||
|
||||
|
||||
.. _custom-sdkconfig-defaults-legacy:
|
||||
|
||||
Custom sdkconfig defaults
|
||||
-------------------------
|
||||
|
||||
For example projects or other projects where you don't want to specify a full sdkconfig configuration, but you do want to override some key values from the esp-idf defaults, it is possible to create a file ``sdkconfig.defaults`` in the project directory. This file will be used when running ``make defconfig``, or creating a new config from scratch.
|
||||
|
||||
To override the name of this file, set the ``SDKCONFIG_DEFAULTS`` environment variable.
|
||||
|
||||
Save flash arguments
|
||||
--------------------
|
||||
|
||||
There're some scenarios that we want to flash the target board without IDF. For this case we want to save the built binaries, esptool.py and esptool write_flash arguments. It's simple to write a script to save binaries and esptool.py. We can use command ``make print_flash_cmd``, it will print the flash arguments::
|
||||
|
||||
--flash_mode dio --flash_freq 40m --flash_size detect 0x1000 bootloader/bootloader.bin 0x10000 example_app.bin 0x8000 partition_table_unit_test_app.bin
|
||||
|
||||
Then use flash arguments as the arguemnts for esptool write_flash arguments::
|
||||
|
||||
python esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 bootloader/bootloader.bin 0x10000 example_app.bin 0x8000 partition_table_unit_test_app.bin
|
||||
|
||||
Building the Bootloader
|
||||
=======================
|
||||
|
||||
The bootloader is built by default as part of "make all", or can be built standalone via "make bootloader-clean". There is also "make bootloader-list-components" to see the components included in the bootloader build.
|
||||
|
||||
The component in IDF components/bootloader is special, as the second stage bootloader is a separate .ELF and .BIN file to the main project. However it shares its configuration and build directory with the main project.
|
||||
|
||||
This is accomplished by adding a subproject under components/bootloader/subproject. This subproject has its own Makefile, but it expects to be called from the project's own Makefile via some glue in the components/bootloader/Makefile.projectbuild file. See these files for more details.
|
||||
@@ -5,11 +5,6 @@ Build System
|
||||
|
||||
This document explains the implementation of the ESP-IDF build system and the concept of "components". Read this document if you want to know how to organize and build a new ESP-IDF project or component.
|
||||
|
||||
.. only:: esp32
|
||||
|
||||
.. note:: This document describes the CMake-based build system, which is the default since ESP-IDF V4.0. ESP-IDF also supports a :doc:`legacy build system based on GNU Make <build-system-legacy>`, which was the default before ESP-IDF V4.0.
|
||||
|
||||
|
||||
Overview
|
||||
========
|
||||
|
||||
@@ -1546,6 +1541,9 @@ Finalization
|
||||
|
||||
Browse :idf_file:`/tools/cmake/project.cmake` for more details.
|
||||
|
||||
|
||||
.. _migrating_from_make:
|
||||
|
||||
Migrating from ESP-IDF GNU Make System
|
||||
======================================
|
||||
|
||||
@@ -1554,21 +1552,7 @@ Some aspects of the CMake-based ESP-IDF build system are very similar to the old
|
||||
Automatic Conversion Tool
|
||||
-------------------------
|
||||
|
||||
.. highlight:: bash
|
||||
|
||||
An automatic project conversion tool is available in :idf_file:`/tools/cmake/convert_to_cmake.py`. Run this command line tool with the path to a project like this::
|
||||
|
||||
$IDF_PATH/tools/cmake/convert_to_cmake.py /path/to/project_dir
|
||||
|
||||
The project directory must contain a Makefile, and GNU Make (``make``) must be installed and available on the PATH.
|
||||
|
||||
The tool will convert the project Makefile and any component ``component.mk`` files to their equivalent ``CMakeLists.txt`` files.
|
||||
|
||||
It does so by running ``make`` to expand the ESP-IDF build system variables which are set by the build, and then producing equivalent CMakelists files to set the same variables.
|
||||
|
||||
.. important:: When the conversion tool converts a ``component.mk`` file, it doesn't determine what other components that component depends on. This information needs to be added manually by editing the new component ``CMakeLists.txt`` file and adding ``REQUIRES`` and/or ``PRIV_REQUIRES`` clauses. Otherwise, source files in the component will fail to compile as headers from other components are not found. See :ref:`component requirements`.
|
||||
|
||||
The conversion tool is not capable of dealing with complex Makefile logic or unusual targets. These will need to be converted by hand.
|
||||
An automatic project conversion tool is available in `tools/cmake/convert_to_cmake.py` in ESP-IDF v4.x releases. The script was removed in v5.0 because of its `make` build system dependency.
|
||||
|
||||
No Longer Available in CMake
|
||||
----------------------------
|
||||
|
||||
@@ -200,7 +200,7 @@ Generic command syntax: ``espcoredump.py [options] command [args]``
|
||||
--core-format {b64,elf,raw}, -t {b64,elf,raw}
|
||||
File specified with "-c" is an ELF ("elf"), raw (raw) or base64-encoded (b64) binary
|
||||
|
||||
--off OFF, -o OFF Offset of coredump partition in flash (type "make partition_table" to see).
|
||||
--off OFF, -o OFF Offset of coredump partition in flash (type "idf.py partition-table" to see).
|
||||
|
||||
--save-core SAVE_CORE, -s SAVE_CORE
|
||||
Save core to file. Otherwise temporary core file will be deleted. Does not work with "-c"
|
||||
|
||||
@@ -82,11 +82,6 @@ Then, in the component CMakeLists.txt, add this file as an unresolved symbol to
|
||||
|
||||
target_link_libraries(${COMPONENT_TARGET} "-u ld_include_my_isr_file")
|
||||
|
||||
If using the legacy Make build system, add the following to component.mk, instead::
|
||||
|
||||
COMPONENT_ADD_LDFLAGS := -u ld_include_my_isr_file
|
||||
|
||||
|
||||
This should cause the linker to always include a file defining ``ld_include_my_isr_file``, causing the ISR to always be linked in.
|
||||
|
||||
- High-level interrupts can be routed and handled using esp_intr_alloc and associated functions. The handler and handler arguments
|
||||
|
||||
@@ -10,7 +10,6 @@ API Guides
|
||||
:SOC_BT_SUPPORTED: BluFi <blufi>
|
||||
Bootloader <bootloader>
|
||||
Build System <build-system>
|
||||
:esp32: Build System (Legacy GNU Make) <build-system-legacy>
|
||||
Deep Sleep Wake Stubs <deep-sleep-stub>
|
||||
:SOC_USB_OTG_SUPPORTED: Device Firmware Upgrade through USB <dfu>
|
||||
Error Handling <error-handling>
|
||||
@@ -38,11 +37,9 @@ API Guides
|
||||
Thread Local Storage <thread-local-storage>
|
||||
Tools <tools/index>
|
||||
:SOC_ULP_SUPPORTED: ULP Coprocessor <ulp>
|
||||
:esp32: ULP Coprocessor (Legacy GNU Make) <ulp-legacy>
|
||||
:SOC_RISCV_COPROC_SUPPORTED: ULP-RISC-V Coprocessor <ulp-risc-v>
|
||||
Unit Testing (Target) <unit-tests>
|
||||
Unit Testing (Linux Host) <linux-host-testing>
|
||||
:esp32: Unit Testing (Legacy GNU Make) <unit-tests-legacy>
|
||||
:SOC_USB_OTG_SUPPORTED: USB OTG Console <usb-otg-console>
|
||||
:SOC_USB_SERIAL_JTAG_SUPPORTED: USB Serial/JTAG Controller Console <usb-serial-jtag-console>
|
||||
Wi-Fi Driver <wifi>
|
||||
|
||||
@@ -45,18 +45,6 @@ Creating and Specifying a Linker Fragment File
|
||||
|
||||
Before anything else, a linker fragment file needs to be created. A linker fragment file is simply a text file with a ``.lf`` extension upon which the desired placements will be written. After creating the file, it is then necessary to present it to the build system. The instructions for the build systems supported by ESP-IDF are as follows:
|
||||
|
||||
Make
|
||||
""""
|
||||
|
||||
In the component's ``component.mk`` file, set the variable ``COMPONENT_ADD_LDFRAGMENTS`` to the path of the created linker fragment file. The path can either be an absolute path or a relative path from the component directory.
|
||||
|
||||
.. code-block:: make
|
||||
|
||||
COMPONENT_ADD_LDFRAGMENTS += my_linker_fragment_file.lf
|
||||
|
||||
CMake
|
||||
"""""
|
||||
|
||||
In the component's ``CMakeLists.txt`` file, specify argument ``LDFRAGMENTS`` in the ``idf_component_register`` call. The value of ``LDFRAGMENTS`` can either be an absolute path or a relative path from the component directory to the created linker fragment file.
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
@@ -183,10 +183,6 @@ Currently these checks are performed for the following binaries:
|
||||
|
||||
Although the build process will fail if the size check returns an error, the binary files are still generated and can be flashed (although they may not work if they are too large for the available space.)
|
||||
|
||||
.. note::
|
||||
|
||||
Build system binary size checks are only performed when using the CMake build system. When using the legacy GNU Make build system, file sizes can be checked manually or an error will be logged during boot.
|
||||
|
||||
MD5 checksum
|
||||
~~~~~~~~~~~~
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ The image contains:
|
||||
- Common utilities such as git, wget, curl, zip.
|
||||
- Python 3.6 or newer.
|
||||
- A copy of a specific version of ESP-IDF (see below for information about versions). ``IDF_PATH`` environment variable is set, and points to ESP-IDF location in the container.
|
||||
- All the build tools required for the specific version of ESP-IDF: CMake, make, ninja, cross-compiler toolchains, etc.
|
||||
- All the build tools required for the specific version of ESP-IDF: CMake, ninja, cross-compiler toolchains, etc.
|
||||
- All Python packages required by ESP-IDF are installed in a virtual environment.
|
||||
|
||||
The image entrypoint sets up ``PATH`` environment variable to point to the correct version of tools, and activates the Python virtual environment. As a result, the environment is ready to use the ESP-IDF build system.
|
||||
@@ -63,27 +63,6 @@ To build with a specific docker image tag, specify it as ``espressif/idf:TAG``,
|
||||
|
||||
You can check the up-to-date list of available tags at https://hub.docker.com/r/espressif/idf/tags.
|
||||
|
||||
|
||||
Building a project with GNU Make
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Same as for CMake, except that the build command is different::
|
||||
|
||||
docker run --rm -v $PWD:/project -w /project espressif/idf make defconfig all -j4
|
||||
|
||||
|
||||
.. note::
|
||||
|
||||
If the ``sdkconfig`` file does not exist, the default behavior of GNU Make build system is to open the menuconfig UI. This may be not desired in automated build environments. To ensure that the ``sdkconfig`` file exists, ``defconfig`` target is added before ``all``.
|
||||
|
||||
If you intend to build the same project repeatedly, you may bind the ``tools/kconfig`` directory of ESP-IDF to a named volume. This will prevent Kconfig tools, located in ESP-IDF directory, from being rebuilt, causing a rebuild of the rest of the project::
|
||||
|
||||
docker run --rm -v $PWD:/project -v kconfig:/opt/esp/idf/tools/kconfig -w /project espressif/idf make defconfig all -j4
|
||||
|
||||
If you need clean up the ``kconfig`` volume, run ``docker volume rm kconfig``.
|
||||
|
||||
Binding the ``tools/kconfig`` directory to a volume is not necessary when using the CMake build system.
|
||||
|
||||
Using the image interactively
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
@@ -6,10 +6,7 @@ IDF Monitor
|
||||
|
||||
The IDF monitor tool is mainly a serial terminal program which relays serial data to and from the target device's serial port. It also provides some IDF-specific features.
|
||||
|
||||
This tool can be launched from an IDF project by running ``idf.py monitor``.
|
||||
|
||||
For the legacy GNU Make system, run ``make monitor``.
|
||||
|
||||
This tool can be launched from an IDF project by running ``idf.py monitor``.
|
||||
|
||||
Keyboard Shortcuts
|
||||
==================
|
||||
@@ -271,10 +268,10 @@ Issues Observed on Windows
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
- Arrow keys, as well as some other keys, do not work in GDB due to Windows Console limitations.
|
||||
- Occasionally, when "idf.py" or "make" exits, it might stall for up to 30 seconds before IDF Monitor resumes.
|
||||
- Occasionally, when "idf.py" exits, it might stall for up to 30 seconds before IDF Monitor resumes.
|
||||
- When "gdb" is run, it might stall for a short time before it begins communicating with the GDBStub.
|
||||
|
||||
.. _addr2line: https://sourceware.org/binutils/docs/binutils/addr2line.html
|
||||
.. _gdb: https://sourceware.org/gdb/download/onlinedocs/
|
||||
.. _pySerial: https://github.com/pyserial/pyserial
|
||||
.. _miniterm: https://pyserial.readthedocs.org/en/latest/tools.html#module-serial.tools.miniterm
|
||||
.. _miniterm: https://pyserial.readthedocs.org/en/latest/tools.html#module-serial.tools.miniterm
|
||||
|
||||
@@ -1,166 +0,0 @@
|
||||
The ULP Coprocessor (Legacy GNU Make)
|
||||
======================================
|
||||
|
||||
:link_to_translation:`zh_CN:[中文]`
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
Instruction set reference <ulp_instruction_set>
|
||||
Programming using macros (legacy) <ulp_macros>
|
||||
|
||||
.. include:: ../gnu-make-legacy.rst
|
||||
|
||||
The ULP (Ultra Low Power) coprocessor is a simple FSM (Finite State Machine) which is designed to perform measurements using the ADC, temperature sensor, and external I2C sensors, while the main processors are in deep sleep mode. The ULP coprocessor can access the RTC_SLOW_MEM memory region, and registers in RTC_CNTL, RTC_IO, and SARADC peripherals. The ULP coprocessor uses fixed-width 32-bit instructions, 32-bit memory addressing, and has 4 general-purpose 16-bit registers.
|
||||
|
||||
Installing the Toolchain
|
||||
------------------------
|
||||
|
||||
The ULP coprocessor code is written in assembly and compiled using the `binutils-esp32ulp toolchain`.
|
||||
|
||||
1. Download pre-built binaries of the latest toolchain release from:
|
||||
https://github.com/espressif/binutils-esp32ulp/releases.
|
||||
|
||||
2. Extract the toolchain into a directory, and add the path to the ``bin/`` directory of the toolchain to the ``PATH`` environment variable.
|
||||
|
||||
Compiling the ULP Code
|
||||
------------------------
|
||||
|
||||
To compile the ULP code as part of the component, the following steps must be taken:
|
||||
|
||||
1. The ULP code, written in assembly, must be added to one or more files with `.S` extension. These files must be placed into a separate directory inside the component directory, for instance `ulp/`.
|
||||
|
||||
.. note: This directory should not be added to the ``COMPONENT_SRCDIRS`` environment variable. The logic behind this is that the ESP-IDF build system will compile files found in ``COMPONENT_SRCDIRS`` based on their extensions. For ``.S`` files, ``xtensa-esp32-elf-as`` assembler is used. This is not desirable for ULP assembly files, thus the easiest way to achieve this distinction is by placing ULP assembly files into a separate directory.
|
||||
|
||||
2. Modify the component makefile, adding the following::
|
||||
|
||||
ULP_APP_NAME ?= ulp_$(COMPONENT_NAME)
|
||||
ULP_S_SOURCES = $(COMPONENT_PATH)/ulp/ulp_source_file.S
|
||||
ULP_EXP_DEP_OBJECTS := main.o
|
||||
include $(IDF_PATH)/components/ulp/component_ulp_common.mk
|
||||
|
||||
Here is each line explained:
|
||||
|
||||
ULP_APP_NAME
|
||||
Name of the generated ULP application, without an extension. This name is used for build products of the ULP application: ELF file, map file, binary file, generated header file, and generated linker export file.
|
||||
|
||||
ULP_S_SOURCES
|
||||
List of assembly files to be passed to the ULP assembler. These must be absolute paths, i.e. start with ``$(COMPONENT_PATH)``. Consider using ``$(addprefix)`` function if more than one file needs to be listed. Paths are relative to component build directory, so prefixing them is not necessary.
|
||||
|
||||
ULP_EXP_DEP_OBJECTS
|
||||
List of object files names within the component which include the generated header file. This list is needed to build the dependencies correctly and ensure that the generated header file is created before any of these files are compiled. See section below explaining the concept of generated header files for ULP applications.
|
||||
|
||||
include $(IDF_PATH)/components/ulp/component_ulp_common.mk
|
||||
Includes common definitions of ULP build steps. Defines build targets for ULP object files, ELF file, binary file, etc.
|
||||
|
||||
3. Build the application as usual (e.g. ``idf.py build`` or ``idf.py app``)
|
||||
|
||||
Inside, the build system will take the following steps to build ULP program:
|
||||
|
||||
1. **Run each assembly file** (``foo.S``) **through the C preprocessor.** This step generates the preprocessed assembly files (``foo.ulp.pS``) in the component build directory. This step also generates dependency files (``foo.ulp.d``).
|
||||
|
||||
2. **Run the preprocessed assembly sources through the assembler.** This produces object (``foo.ulp.o``) and listing (``foo.ulp.lst``) files. Listing files are generated for debugging purposes and are not used at later stages of the build process.
|
||||
|
||||
3. **Run the linker script template through the C preprocessor.** The template is located in ``components/ulp/ld`` directory.
|
||||
|
||||
4. **Link the object files into an output ELF file** (``ulp_app_name.elf``). The Map file (``ulp_app_name.map``) generated at this stage may be useful for debugging purposes.
|
||||
|
||||
5. **Dump the contents of the ELF file into a binary** (``ulp_app_name.bin``) which can then be embedded into the application.
|
||||
|
||||
6. **Generate a list of global symbols** (``ulp_app_name.sym``) in the ELF file using ``esp32ulp-elf-nm``.
|
||||
|
||||
7. **Create an LD export script and header file** (``ulp_app_name.ld`` and ``ulp_app_name.h``) containing the symbols from ``ulp_app_name.sym``. This is done using the ``esp32ulp_mapgen.py`` utility.
|
||||
|
||||
8. **Add the generated binary to the list of binary files** to be embedded into the application.
|
||||
|
||||
Accessing the ULP Program Variables
|
||||
------------------------------------
|
||||
|
||||
Global symbols defined in the ULP program may be used inside the main program.
|
||||
|
||||
For example, the ULP program may define a variable ``measurement_count`` which will define the number of the ADC measurements the program needs to make before waking up the chip from deep sleep::
|
||||
|
||||
.global measurement_count
|
||||
measurement_count: .long 0
|
||||
|
||||
/* later, use measurement_count */
|
||||
move r3, measurement_count
|
||||
ld r3, r3, 0
|
||||
|
||||
The main program needs to initialize this variable before the ULP program is started. The build system makes this possible by generating ``$(ULP_APP_NAME).h`` and ``$(ULP_APP_NAME).ld`` files which define global symbols present in the ULP program. Each global symbol defined in the ULP program is included in these files and are prefixed with ``ulp_``.
|
||||
|
||||
The header file contains the declaration of the symbol::
|
||||
|
||||
extern uint32_t ulp_measurement_count;
|
||||
|
||||
Note that all symbols (variables, arrays, functions) are declared as ``uint32_t``. For functions and arrays, take the address of the symbol and cast it to the appropriate type.
|
||||
|
||||
The generated linker script file defines locations of symbols in RTC_SLOW_MEM::
|
||||
|
||||
PROVIDE ( ulp_measurement_count = 0x50000060 );
|
||||
|
||||
To access the ULP program variables from the main program, the generated header file should be included using an ``include`` statement. This will allow the ULP program variables to be accessed as regular variables::
|
||||
|
||||
#include "ulp_app_name.h"
|
||||
|
||||
// later
|
||||
void init_ulp_vars() {
|
||||
ulp_measurement_count = 64;
|
||||
}
|
||||
|
||||
Note that the ULP program can only use lower 16 bits of each 32-bit word in RTC memory, because the registers are 16-bit, and there is no instruction to load from the high part of the word.
|
||||
|
||||
Likewise, the ULP store instruction writes register value into the lower 16 bits part of the 32-bit word. The upper 16 bits are written with a value which depends on the address of the store instruction, thus when reading variables written by the ULP, the main application needs to mask the upper 16 bits, e.g.::
|
||||
|
||||
printf("Last measurement value: %d\n", ulp_last_measurement & UINT16_MAX);
|
||||
|
||||
Starting the ULP Program
|
||||
------------------------
|
||||
|
||||
To run a ULP program, the main application needs to load the ULP program into RTC memory using the ``ulp_load_binary`` function, and then start it using the ``ulp_run`` function.
|
||||
|
||||
Note that "Enable Ultra Low Power (ULP) Coprocessor" option must be enabled in menuconfig to reserve memory for the ULP. "RTC slow memory reserved for coprocessor" option must be set to a value sufficient to store ULP code and data. If the application components contain multiple ULP programs, then the size of the RTC memory must be sufficient to hold the largest one.
|
||||
|
||||
Each ULP program is embedded into the ESP-IDF application as a binary blob. The application can reference this blob and load it in the following way (suppose ULP_APP_NAME was defined to ``ulp_app_name``)::
|
||||
|
||||
extern const uint8_t bin_start[] asm("_binary_ulp_app_name_bin_start");
|
||||
extern const uint8_t bin_end[] asm("_binary_ulp_app_name_bin_end");
|
||||
|
||||
void start_ulp_program() {
|
||||
ESP_ERROR_CHECK( ulp_load_binary(
|
||||
0 /* load address, set to 0 when using default linker scripts */,
|
||||
bin_start,
|
||||
(bin_end - bin_start) / sizeof(uint32_t)) );
|
||||
}
|
||||
|
||||
.. doxygenfunction:: ulp_load_binary
|
||||
|
||||
Once the program is loaded into RTC memory, the application can start it, passing the address of the entry point to the ``ulp_run`` function::
|
||||
|
||||
ESP_ERROR_CHECK( ulp_run(&ulp_entry - RTC_SLOW_MEM) );
|
||||
|
||||
.. doxygenfunction:: ulp_run
|
||||
|
||||
Declaration of the entry point symbol comes from the generated header file mentioned above, ``$(ULP_APP_NAME).h``. In the assembly source of the ULP application, this symbol must be marked as ``.global``::
|
||||
|
||||
.global entry
|
||||
entry:
|
||||
/* code starts here */
|
||||
|
||||
ULP Program Flow
|
||||
----------------
|
||||
|
||||
The ULP coprocessor is started by a timer. The timer is started once ``ulp_run`` is called. The timer counts the number of RTC_SLOW_CLK ticks (by default, produced by an internal 150 kHz RC oscillator). The number of ticks is set using ``SENS_ULP_CP_SLEEP_CYCx_REG`` registers (x = 0..4). When starting the ULP for the first time, ``SENS_ULP_CP_SLEEP_CYC0_REG`` will be used to set the number of timer ticks. Later the ULP program can select another ``SENS_ULP_CP_SLEEP_CYCx_REG`` register using the ``sleep`` instruction.
|
||||
|
||||
The application can set ULP timer period values (SENS_ULP_CP_SLEEP_CYCx_REG, x = 0..4) using the ``ulp_set_wakeup_period`` function.
|
||||
|
||||
.. doxygenfunction:: ulp_set_wakeup_period
|
||||
|
||||
Once the timer counts the number of ticks set in the selected ``SENS_ULP_CP_SLEEP_CYCx_REG`` register, the ULP coprocessor will power up and start running the program from the entry point set in the call to ``ulp_run``.
|
||||
|
||||
The program runs until it encounters a ``halt`` instruction or an illegal instruction. Once the program halts, ULP coprocessor will power down, and the timer will be started again.
|
||||
|
||||
To disable the timer (effectively preventing the ULP program from running again), please clear the ``RTC_CNTL_ULP_CP_SLP_TIMER_EN`` bit in the ``RTC_CNTL_STATE0_REG`` register. This can be done both from the ULP code and from the main program.
|
||||
|
||||
|
||||
.. _binutils-esp32ulp toolchain: https://github.com/espressif/binutils-esp32ulp
|
||||
@@ -20,10 +20,6 @@ The ULP coprocessor code is written in assembly and compiled using the `binutils
|
||||
|
||||
If you have already set up ESP-IDF with CMake build system according to the :doc:`Getting Started Guide <../../get-started/index>`, then the ULP toolchain will already be installed.
|
||||
|
||||
.. only:: esp32
|
||||
|
||||
If you are using ESP-IDF with the legacy GNU Make based build system, refer to the instructions on this page: :doc:`ulp-legacy`.
|
||||
|
||||
Compiling the ULP Code
|
||||
-----------------------
|
||||
|
||||
@@ -177,4 +173,4 @@ Declaration of the entry point symbol comes from the generated header file menti
|
||||
To disable the timer (effectively preventing the ULP program from running again), clear the ``RTC_CNTL_ULP_CP_SLP_TIMER_EN`` bit in the ``RTC_CNTL_STATE0_REG`` register.This can be done both from ULP code and from the main program.
|
||||
|
||||
|
||||
.. _binutils-esp32ulp toolchain: https://github.com/espressif/binutils-esp32ulp
|
||||
.. _binutils-esp32ulp toolchain: https://github.com/espressif/binutils-esp32ulp
|
||||
|
||||
@@ -1,218 +0,0 @@
|
||||
Unit Testing (Legacy GNU Make)
|
||||
==============================
|
||||
:link_to_translation:`zh_CN:[中文]`
|
||||
|
||||
.. include:: ../gnu-make-legacy.rst
|
||||
|
||||
ESP-IDF comes with a unit test application that is based on the Unity - unit test framework. Unit tests are integrated in the ESP-IDF repository and are placed in the ``test`` subdirectories of each component respectively.
|
||||
|
||||
Normal Test Cases
|
||||
------------------
|
||||
|
||||
Unit tests are located in the ``test`` subdirectory of a component.
|
||||
Tests are added in C files, a single C file can include multiple test cases.
|
||||
Test files start with the word "test".
|
||||
|
||||
Each test file should include the ``unity.h`` header and the header for the C module to be tested.
|
||||
|
||||
Tests are added in a function in the C file as follows:
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
TEST_CASE("test name", "[module name]"
|
||||
{
|
||||
// Add test here
|
||||
}
|
||||
|
||||
The first argument is a descriptive name for the test, the second argument is an identifier in square brackets.
|
||||
Identifiers are used to group related test, or tests with specific properties.
|
||||
|
||||
.. note::
|
||||
There is no need to add a main function with ``UNITY_BEGIN()`` and ``UNITY_END()`` in each test case. ``unity_platform.c`` will run ``UNITY_BEGIN()`` autonomously, and run the test cases, then call ``UNITY_END()``.
|
||||
|
||||
Each ``test`` subdirectory needs to include a ``component.mk`` file with the following line of code::
|
||||
|
||||
COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive
|
||||
|
||||
See http://www.throwtheswitch.org/unity for more information about writing tests in Unity.
|
||||
|
||||
|
||||
Multi-device Test Cases
|
||||
------------------------
|
||||
|
||||
The normal test cases will be executed on one DUT (Device Under Test). However, components that require some form of communication (e.g., GPIO, SPI) require another device to communicate with, thus cannot be tested normal test cases.
|
||||
Multi-device test cases involve writing multiple test functions, and running them on multiple DUTs.
|
||||
|
||||
The following is an example of a Multi-device test case:
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
void gpio_master_test()
|
||||
{
|
||||
gpio_config_t slave_config = {
|
||||
.pin_bit_mask = 1 << MASTER_GPIO_PIN,
|
||||
.mode = GPIO_MODE_INPUT,
|
||||
};
|
||||
gpio_config(&slave_config);
|
||||
unity_wait_for_signal("output high level");
|
||||
TEST_ASSERT(gpio_get_level(MASTER_GPIO_PIN) == 1);
|
||||
}
|
||||
|
||||
void gpio_slave_test()
|
||||
{
|
||||
gpio_config_t master_config = {
|
||||
.pin_bit_mask = 1 << SLAVE_GPIO_PIN,
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
};
|
||||
gpio_config(&master_config);
|
||||
gpio_set_level(SLAVE_GPIO_PIN, 1);
|
||||
unity_send_signal("output high level");
|
||||
}
|
||||
|
||||
TEST_CASE_MULTIPLE_DEVICES("gpio multiple devices test example", "[driver]", gpio_master_test, gpio_slave_test);
|
||||
|
||||
|
||||
The macro ``TEST_CASE_MULTIPLE_DEVICES`` is used to declare a multi-device test case.
|
||||
The first argument is test case name, the second argument is test case description.
|
||||
From the third argument, up to 5 test functions can be defined, each function will be the entry point of tests running on each DUT.
|
||||
|
||||
Running test cases from different DUTs could require synchronizing between DUTs. We provide ``unity_wait_for_signal`` and ``unity_send_signal`` to support synchronizing with UART.
|
||||
As the scenario in the above example, the slave should get GPIO level after master set level. DUT UART console will prompt and requires user interaction:
|
||||
|
||||
DUT1 (master) console::
|
||||
|
||||
Waiting for signal: [output high level]!
|
||||
Please press "Enter" key once any board send this signal.
|
||||
|
||||
DUT2 (slave) console::
|
||||
|
||||
Send signal: [output high level]!
|
||||
|
||||
Once the signal is sent from DUT2, you need to press "Enter" on DUT1, then DUT1 unblocks from ``unity_wait_for_signal`` and starts to change GPIO level.
|
||||
|
||||
Signals can also be used to pass parameters between multiple devices. For example, DUT1 want to know the MAC address of DUT2, so it can connect to DUT2.
|
||||
In this case, ``unity_wait_for_signal_param`` and ``unity_send_signal_param`` can be used:
|
||||
|
||||
DUT1 console::
|
||||
|
||||
Waiting for signal: [dut2 mac address]!
|
||||
Please input parameter value from any board send this signal and press "Enter" key.
|
||||
|
||||
DUT2 console::
|
||||
|
||||
Send signal: [dut2 mac address][10:20:30:40:50:60]!
|
||||
|
||||
Once the signal is sent from DUT2, you need to input ``10:20:30:40:50:60`` on DUT1 and press "Enter". Then DUT1 will get the MAC address string of DUT2 and unblock from ``unity_wait_for_signal_param``, then start to connect to DUT2.
|
||||
|
||||
|
||||
Multi-stage Test Cases
|
||||
-----------------------
|
||||
|
||||
The normal test cases are expected to finish without reset (or only need to check if reset happens). Sometimes we expect to run some specific tests after certain kinds of reset.
|
||||
For example, we expect to test if reset reason is correct after a wakeup from deep sleep. We need to create a deep-sleep reset first and then check the reset reason.
|
||||
To support this, we can define multi-stage test cases, to group a set of test functions::
|
||||
|
||||
static void trigger_deepsleep(void)
|
||||
{
|
||||
esp_sleep_enable_timer_wakeup(2000);
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
|
||||
void check_deepsleep_reset_reason()
|
||||
{
|
||||
soc_reset_reason_t reason = esp_rom_get_reset_reason(0);
|
||||
TEST_ASSERT(reason == RESET_REASON_CORE_DEEP_SLEEP);
|
||||
}
|
||||
|
||||
TEST_CASE_MULTIPLE_STAGES("reset reason check for deepsleep", "[esp32]", trigger_deepsleep, check_deepsleep_reset_reason);
|
||||
|
||||
Multi-stage test cases present a group of test functions to users. It need user interactions (select cases and select different stages) to run the case.
|
||||
|
||||
|
||||
Building Unit Test App
|
||||
----------------------
|
||||
|
||||
Follow the setup instructions in the top-level esp-idf README.
|
||||
Make sure that ``IDF_PATH`` environment variable is set to point to the path of esp-idf top-level directory.
|
||||
|
||||
Change into ``tools/unit-test-app`` directory to configure and build it:
|
||||
|
||||
* ``make menuconfig`` - configure unit test app.
|
||||
|
||||
* ``make TESTS_ALL=1`` - build unit test app with tests for each component having tests in the ``test`` subdirectory.
|
||||
* ``make TEST_COMPONENTS='xxx'`` - build unit test app with tests for specific components.
|
||||
* ``make TESTS_ALL=1 TEST_EXCLUDE_COMPONENTS='xxx'`` - build unit test app with all unit tests, except for unit tests of some components. (For instance: ``make TESTS_ALL=1 TEST_EXCLUDE_COMPONENTS='ulp mbedtls'`` - build all unit tests exludes ``ulp`` and ``mbedtls`` components).
|
||||
|
||||
When the build finishes, it will print instructions for flashing the chip. You can simply run ``make flash`` to flash all build output.
|
||||
|
||||
You can also run ``make flash TESTS_ALL=1`` or ``make TEST_COMPONENTS='xxx'`` to build and flash. Everything needed will be rebuilt automatically before flashing.
|
||||
|
||||
Use menuconfig to set the serial port for flashing.
|
||||
|
||||
Running Unit Tests
|
||||
------------------
|
||||
|
||||
After flashing reset the ESP32 and it will boot the unit test app.
|
||||
|
||||
When unit test app is idle, press "Enter" will make it print test menu with all available tests::
|
||||
|
||||
Here's the test menu, pick your combo:
|
||||
(1) "esp_ota_begin() verifies arguments" [ota]
|
||||
(2) "esp_ota_get_next_update_partition logic" [ota]
|
||||
(3) "Verify bootloader image in flash" [bootloader_support]
|
||||
(4) "Verify unit test app image" [bootloader_support]
|
||||
(5) "can use new and delete" [cxx]
|
||||
(6) "can call virtual functions" [cxx]
|
||||
(7) "can use static initializers for non-POD types" [cxx]
|
||||
(8) "can use std::vector" [cxx]
|
||||
(9) "static initialization guards work as expected" [cxx]
|
||||
(10) "global initializers run in the correct order" [cxx]
|
||||
(11) "before scheduler has started, static initializers work correctly" [cxx]
|
||||
(12) "adc2 work with wifi" [adc]
|
||||
(13) "gpio master/slave test example" [ignore][misc][test_env=UT_T2_1][multi_device]
|
||||
(1) "gpio_master_test"
|
||||
(2) "gpio_slave_test"
|
||||
(14) "SPI Master clockdiv calculation routines" [spi]
|
||||
(15) "SPI Master test" [spi][ignore]
|
||||
(16) "SPI Master test, interaction of multiple devs" [spi][ignore]
|
||||
(17) "SPI Master no response when switch from host1 (SPI2) to host2 (SPI3)" [spi]
|
||||
(18) "SPI Master DMA test, TX and RX in different regions" [spi]
|
||||
(19) "SPI Master DMA test: length, start, not aligned" [spi]
|
||||
(20) "reset reason check for deepsleep" [esp32][test_env=UT_T2_1][multi_stage]
|
||||
(1) "trigger_deepsleep"
|
||||
(2) "check_deepsleep_reset_reason"
|
||||
|
||||
The normal case will print the case name and description. Master-slave cases will also print the sub-menu (the registered test function names).
|
||||
|
||||
Test cases can be run by inputting one of the following:
|
||||
|
||||
- Test case name in quotation marks (for example, ``"esp_ota_begin() verifies arguments"``) to run a single test case.
|
||||
|
||||
- Test case index (for example, ``1``) to run a single test case.
|
||||
|
||||
- Module name in square brackets (for example, ``[cxx]``) to run all test cases for a specific module.
|
||||
|
||||
- An asterisk (``*``) to run all test cases
|
||||
|
||||
``[multi_device]`` and ``[multi_stage]`` tags tell the test runner whether a test case is a multi-device or multi-stage test case.
|
||||
These tags are automatically added by ```TEST_CASE_MULTIPLE_STAGES`` and ``TEST_CASE_MULTIPLE_DEVICES`` macros.
|
||||
|
||||
After you select a multi-device test case, it will print sub menu::
|
||||
|
||||
Running gpio master/slave test example...
|
||||
gpio master/slave test example
|
||||
(1) "gpio_master_test"
|
||||
(2) "gpio_slave_test"
|
||||
|
||||
You need to input a number to select the test running on the DUT.
|
||||
|
||||
Similar to multi-device test cases, multi-stage test cases will also print sub-menu::
|
||||
|
||||
Running reset reason check for deepsleep...
|
||||
reset reason check for deepsleep
|
||||
(1) "trigger_deepsleep"
|
||||
(2) "check_deepsleep_reset_reason"
|
||||
|
||||
For the first time you execute this case, please input ``1`` to run the first stage (trigger deep-sleep).
|
||||
After DUT is rebooted and test cases are available to run, select this case again and input ``2`` to run the second stage.
|
||||
The case will only pass if the last stage passes and all previous stages trigger reset.
|
||||
@@ -20,8 +20,6 @@ Application developers can open a terminal-based project configuration menu with
|
||||
|
||||
After being updated, this configuration is saved inside ``sdkconfig`` file in the project root directory. Based on ``sdkconfig``, application build targets will generate ``sdkconfig.h`` file in the build directory, and will make sdkconfig options available to the project build system and source files.
|
||||
|
||||
(For the legacy GNU Make build system, the project configuration menu is opened with ``make menuconfig``.)
|
||||
|
||||
Using sdkconfig.defaults
|
||||
========================
|
||||
|
||||
@@ -89,15 +87,6 @@ By convention, all option names are upper case with underscores. When Kconfig ge
|
||||
|
||||
.. include-build-file:: inc/kconfig.inc
|
||||
|
||||
Customisations
|
||||
==============
|
||||
|
||||
Because IDF builds by default with :ref:`warn-undefined-variables`, when the Kconfig tool generates Makefiles (the ``auto.conf`` file) its behaviour has been customised. In normal Kconfig, a variable which is set to "no" is undefined. In IDF's version of Kconfig, this variable is defined in the Makefile but has an empty value.
|
||||
|
||||
(Note that ``ifdef`` and ``ifndef`` can still be used in Makefiles, because they test if a variable is defined *and has a non-empty value*.)
|
||||
|
||||
When generating header files for C & C++, the behaviour is not customised - so ``#ifdef`` can be used to test if a boolean config item is set or not.
|
||||
|
||||
.. _Kconfig: https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt
|
||||
.. _kconfiglib: https://github.com/ulfalizer/Kconfiglib
|
||||
.. _kconfiglib extentions: https://pypi.org/project/kconfiglib/#kconfig-extensions
|
||||
|
||||
@@ -22,7 +22,7 @@ In addition it is possible to specify a path to a certificate file or a director
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
Most configuration is done through menuconfig. Make and CMake will generate the bundle according to the configuration and embed it.
|
||||
Most configuration is done through menuconfig. CMake will generate the bundle according to the configuration and embed it.
|
||||
|
||||
* :ref:`CONFIG_MBEDTLS_CERTIFICATE_BUNDLE`: automatically build and attach the bundle.
|
||||
* :ref:`CONFIG_MBEDTLS_DEFAULT_CERTIFICATE_BUNDLE`: decide which certificates to include from the complete root list.
|
||||
|
||||
@@ -79,11 +79,11 @@ There are two ways to use wolfssl in your project
|
||||
|
||||
git clone https://github.com/espressif/esp-wolfssl.git
|
||||
|
||||
* Include esp-wolfssl in ESP-IDF with setting EXTRA_COMPONENT_DIRS in CMakeLists.txt/Makefile of your project as done in `wolfssl/examples <https://github.com/espressif/esp-wolfssl/tree/master/examples>`_. For reference see Optional Project variables in :doc:`build-system.</api-guides/build-system>`
|
||||
* Include esp-wolfssl in ESP-IDF with setting EXTRA_COMPONENT_DIRS in CMakeLists.txt of your project as done in `wolfssl/examples <https://github.com/espressif/esp-wolfssl/tree/master/examples>`_. For reference see Optional Project variables in :doc:`build-system.</api-guides/build-system>`
|
||||
|
||||
After above steps, you will have option to choose wolfssl as underlying SSL/TLS library in configuration menu of your project as follows::
|
||||
|
||||
idf.py/make menuconfig -> ESP-TLS -> choose SSL/TLS Library -> mbedtls/wolfssl
|
||||
idf.py menuconfig -> ESP-TLS -> choose SSL/TLS Library -> mbedtls/wolfssl
|
||||
|
||||
Comparison between mbedtls and wolfssl
|
||||
--------------------------------------
|
||||
|
||||
@@ -42,49 +42,21 @@ These optional arguments correspond to a possible SPIFFS build configuration. To
|
||||
|
||||
When the image is created, it can be flashed using ``esptool.py`` or ``parttool.py``.
|
||||
|
||||
Aside from invoking the ``spiffsgen.py`` standalone by manually running it from the command line or a script, it is also possible to invoke ``spiffsgen.py`` directly from the build system by calling ``spiffs_create_partition_image``.
|
||||
|
||||
Make::
|
||||
|
||||
SPIFFS_IMAGE_FLASH_IN_PROJECT := ...
|
||||
SPIFFS_IMAGE_DEPENDS := ...
|
||||
$(eval $(call spiffs_create_partition_image,<partition>,<base_dir>))
|
||||
|
||||
CMake::
|
||||
Aside from invoking the ``spiffsgen.py`` standalone by manually running it from the command line or a script, it is also possible to invoke ``spiffsgen.py`` directly from the build system by calling ``spiffs_create_partition_image``::
|
||||
|
||||
spiffs_create_partition_image(<partition> <base_dir> [FLASH_IN_PROJECT] [DEPENDS dep dep dep...])
|
||||
|
||||
This is more convenient as the build configuration is automatically passed to the tool, ensuring that the generated image is valid for that build. An example of this is while the *image_size* is required for the standalone invocation, only the *partition* name is required when using ``spiffs_create_partition_image`` -- the image size is automatically obtained from the project's partition table.
|
||||
|
||||
Due to the differences in structure between Make and CMake, it is important to note that:
|
||||
``spiffs_create_partition_image`` must be called from one of the component CMakeLists.txt files.
|
||||
|
||||
- for Make ``spiffs_create_partition_image`` must be called from the project Makefile
|
||||
- for CMake ``spiffs_create_partition_image`` must be called from one of the component CMakeLists.txt files
|
||||
|
||||
Optionally, user can opt to have the image automatically flashed together with the app binaries, partition tables, etc. on ``idf.py flash`` or ``make flash`` by specifying ``FLASH_IN_PROJECT``. For example,
|
||||
|
||||
in Make::
|
||||
|
||||
SPIFFS_IMAGE_FLASH_IN_PROJECT := 1
|
||||
$(eval $(call spiffs_create_partition_image,<partition>,<base_dir>))
|
||||
|
||||
in CMake::
|
||||
Optionally, users can opt to have the image automatically flashed together with the app binaries, partition tables, etc. on ``idf.py flash`` by specifying ``FLASH_IN_PROJECT``. For example::
|
||||
|
||||
spiffs_create_partition_image(my_spiffs_partition my_folder FLASH_IN_PROJECT)
|
||||
|
||||
If FLASH_IN_PROJECT/SPIFFS_IMAGE_FLASH_IN_PROJECT is not specified, the image will still be generated, but you will have to flash it manually using ``esptool.py``, ``parttool.py``, or a custom build system target.
|
||||
|
||||
There are cases where the contents of the base directory itself is generated at build time. Users can use DEPENDS/SPIFFS_IMAGE_DEPENDS to specify targets that should be executed before generating the image.
|
||||
|
||||
in Make::
|
||||
|
||||
dep:
|
||||
...
|
||||
|
||||
SPIFFS_IMAGE_DEPENDS := dep
|
||||
$(eval $(call spiffs_create_partition_image,<partition>,<base_dir>))
|
||||
|
||||
in CMake::
|
||||
There are cases where the contents of the base directory itself is generated at build time. Users can use DEPENDS/SPIFFS_IMAGE_DEPENDS to specify targets that should be executed before generating the image::
|
||||
|
||||
add_custom_target(dep COMMAND ...)
|
||||
|
||||
|
||||
@@ -101,14 +101,9 @@ The following pattern can be used to add a custom structure to your image:
|
||||
|
||||
Offset for custom structure is sizeof(:cpp:type:`esp_image_header_t`) + sizeof(:cpp:type:`esp_image_segment_header_t`) + sizeof(:cpp:type:`esp_app_desc_t`).
|
||||
|
||||
To guarantee that the custom structure is located in the image even if it is not used, you need to add:
|
||||
|
||||
* For Make: add ``COMPONENT_ADD_LDFLAGS += -u custom_app_desc`` into ``component.mk``
|
||||
* For Cmake: add ``target_link_libraries(${COMPONENT_TARGET} "-u custom_app_desc")`` into ``CMakeLists.txt``
|
||||
To guarantee that the custom structure is located in the image even if it is not used, you need to add ``target_link_libraries(${COMPONENT_TARGET} "-u custom_app_desc")`` into ``CMakeLists.txt``.
|
||||
|
||||
API Reference
|
||||
-------------
|
||||
|
||||
.. include-build-file:: inc/esp_app_format.inc
|
||||
|
||||
|
||||
|
||||
@@ -196,8 +196,6 @@ To set version in your project manually you need to set ``PROJECT_VER`` variable
|
||||
|
||||
* In application CMakeLists.txt put ``set(PROJECT_VER "0.1.0.1")`` before including ``project.cmake``.
|
||||
|
||||
(For legacy GNU Make build system: in application Makefile put ``PROJECT_VER = "0.1.0.1"`` before including ``project.mk``.)
|
||||
|
||||
If :ref:`CONFIG_APP_PROJECT_VER_FROM_CONFIG` option is set, the value of :ref:`CONFIG_APP_PROJECT_VER` will be used. Otherwise if ``PROJECT_VER`` variable is not set in the project then it will be retrieved from either ``$(PROJECT_PATH)/version.txt`` file (if present) else using git command ``git describe``. If neither is available then ``PROJECT_VER`` will be set to "1". Application can make use of this by calling :cpp:func:`esp_ota_get_app_description` or :cpp:func:`esp_ota_get_partition_description` functions.
|
||||
|
||||
API Reference
|
||||
|
||||
@@ -23,7 +23,7 @@ Checklist
|
||||
|
||||
Checklist before submitting a new example:
|
||||
|
||||
* Example project name (in ``Makefile`` and ``README.md``) uses the word "example". Use "example" instead of "demo", "test" or similar words.
|
||||
* Example project name (in ``README.md``) uses the word "example". Use "example" instead of "demo", "test" or similar words.
|
||||
* Example does one distinct thing. If the example does more than one thing at a time, split it into two or more examples.
|
||||
* Example has a ``README.md`` file which is similar to the :idf_file:`template example README <docs/TEMPLATE_EXAMPLE_README.md>`.
|
||||
* Functions and variables in the example are named according to :ref:`naming section of the style guide <style-guide-naming>`. (For non-static names which are only specific to the example's source files, you can use ``example`` or something similar as a prefix.)
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
Add IDF_PATH to User Profile (Legacy GNU Make)
|
||||
==============================================
|
||||
:link_to_translation:`zh_CN:[中文]`
|
||||
|
||||
.. include:: ../gnu-make-legacy.rst
|
||||
|
||||
To preserve setting of ``IDF_PATH`` environment variable between system restarts, add it to the user profile, following instructions below.
|
||||
|
||||
|
||||
.. _add-idf_path-to-profile-windows-legacy:
|
||||
|
||||
Windows
|
||||
-------
|
||||
|
||||
The user profile scripts are contained in ``C:/msys32/etc/profile.d/`` directory. They are executed every time you open an MSYS2 window.
|
||||
|
||||
#. Create a new script file in ``C:/msys32/etc/profile.d/`` directory. Name it ``export_idf_path.sh``.
|
||||
|
||||
#. Identify the path to ESP-IDF directory. It is specific to your system configuration and may look something like ``C:\msys32\home\user-name\esp\esp-idf``
|
||||
|
||||
#. Add the ``export`` command to the script file, e.g.::
|
||||
|
||||
export IDF_PATH="C:/msys32/home/user-name/esp/esp-idf"
|
||||
|
||||
Remember to replace back-slashes with forward-slashes in the original Windows path.
|
||||
|
||||
#. Save the script file.
|
||||
|
||||
#. Close MSYS2 window and open it again. Check if ``IDF_PATH`` is set, by typing::
|
||||
|
||||
printenv IDF_PATH
|
||||
|
||||
The path previusly entered in the script file should be printed out.
|
||||
|
||||
If you do not like to have ``IDF_PATH`` set up permanently in user profile, you should enter it manually on opening of an MSYS2 window::
|
||||
|
||||
export IDF_PATH="C:/msys32/home/user-name/esp/esp-idf"
|
||||
|
||||
If you got here from section :ref:`get-started-setup-path-legacy`, while installing s/w for ESP32 development, then go back to section :ref:`get-started-start-project-legacy`.
|
||||
|
||||
|
||||
.. _add-idf_path-to-profile-linux-macos-legacy:
|
||||
|
||||
Linux and MacOS
|
||||
---------------
|
||||
|
||||
Set up ``IDF_PATH`` by adding the following line to ``~/.profile`` file::
|
||||
|
||||
export IDF_PATH=~/esp/esp-idf
|
||||
|
||||
Log off and log in back to make this change effective.
|
||||
|
||||
.. note::
|
||||
|
||||
If you have ``/bin/bash`` set as login shell, and both ``.bash_profile`` and ``.profile`` exist, then update ``.bash_profile`` instead.
|
||||
|
||||
Run the following command to check if ``IDF_PATH`` is set::
|
||||
|
||||
printenv IDF_PATH
|
||||
|
||||
The path previously entered in ``~/.profile`` file (or set manually) should be printed out.
|
||||
|
||||
If you do not like to have ``IDF_PATH`` set up permanently, you should enter it manually in terminal window on each restart or logout::
|
||||
|
||||
export IDF_PATH=~/esp/esp-idf
|
||||
|
||||
If you got here from section :ref:`get-started-setup-path-legacy`, while installing s/w for ESP32 development, then go back to section :ref:`get-started-start-project-legacy`.
|
||||
@@ -1,111 +0,0 @@
|
||||
**************************************************
|
||||
Build and Flash with Eclipse IDE (Legacy GNU Make)
|
||||
**************************************************
|
||||
:link_to_translation:`zh_CN:[中文]`
|
||||
|
||||
.. include:: ../gnu-make-legacy.rst
|
||||
|
||||
.. _eclipse-install-steps-legacy:
|
||||
|
||||
Installing Eclipse IDE
|
||||
======================
|
||||
|
||||
The Eclipse IDE gives you a graphical integrated development environment for writing, compiling and debugging ESP-IDF projects.
|
||||
|
||||
* Start by installing the esp-idf for your platform (see files in this directory with steps for Windows, OS X, Linux).
|
||||
|
||||
* We suggest building a project from the command line first, to get a feel for how that process works. You also need to use the command line to configure your esp-idf project (via ``make menuconfig``), this is not currently supported inside Eclipse.
|
||||
|
||||
* Download the Eclipse Installer for your platform from eclipse.org_.
|
||||
|
||||
* When running the Eclipse Installer, choose "Eclipse for C/C++ Development" (in other places you'll see this referred to as CDT.)
|
||||
|
||||
Setting up Eclipse
|
||||
==================
|
||||
|
||||
Once your new Eclipse installation launches, follow these steps:
|
||||
|
||||
Import New Project
|
||||
------------------
|
||||
|
||||
* Eclipse makes use of the Makefile support in ESP-IDF. This means you need to start by creating an ESP-IDF project. You can use the idf-template project from github, or open one of the examples in the esp-idf examples subdirectory.
|
||||
|
||||
* Once Eclipse is running, choose File -> Import...
|
||||
|
||||
* In the dialog that pops up, choose "C/C++" -> "Existing Code as Makefile Project" and click Next.
|
||||
|
||||
* On the next page, enter "Existing Code Location" to be the directory of your IDF project. Don't specify the path to the ESP-IDF directory itself (that comes later). The directory you specify should contain a file named "Makefile" (the project Makefile).
|
||||
|
||||
* On the same page, under "Toolchain for Indexer Settings" choose "Cross GCC". Then click Finish.
|
||||
|
||||
|
||||
Project Properties
|
||||
------------------
|
||||
|
||||
* The new project will appear under Project Explorer. Right-click the project and choose Properties from the context menu.
|
||||
|
||||
* Click on the "Environment" properties page under "C/C++ Build". Click "Add..." and enter name ``BATCH_BUILD`` and value ``1``.
|
||||
|
||||
* Click "Add..." again, and enter name ``IDF_PATH``. The value should be the full path where ESP-IDF is installed. Windows users can copy the ``IDF_PATH`` from windows explorer.
|
||||
|
||||
* Edit the ``PATH`` environment variable. Keep the current value, and append the path to the Xtensa toolchain installed as part of IDF setup, if this is not already listed on the PATH. A typical path to the toolchain looks like ``/home/user-name/esp/xtensa-esp32-elf/bin``. Note that you need to add a colon ``:`` before the appended path. Windows users will need to prepend ``C:\msys32\mingw32\bin;C:\msys32\opt\xtensa-esp32-elf\bin;C:\msys32\usr\bin`` to ``PATH`` environment variable (If you installed msys32 to a different directory then you’ll need to change these paths to match).
|
||||
|
||||
* On macOS, add a ``PYTHONPATH`` environment variable and set it to ``/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages``. This is so that the system Python, which has pyserial installed as part of the setup steps, overrides any built-in Eclipse Python.
|
||||
|
||||
**ADDITIONAL NOTE**: If either the IDF_PATH directory or the project directory is located outside ``C:\msys32\home`` directory, you will have to give custom build command in C/C++ Build properties as: ``python ${IDF_PATH}/tools/windows/eclipse_make.py`` (Please note that the build time may get significantly increased by this method.)
|
||||
|
||||
Navigate to "C/C++ General" -> "Preprocessor Include Paths" property page:
|
||||
|
||||
* Click the "Providers" tab
|
||||
|
||||
* In the list of providers, click "CDT Cross GCC Built-in Compiler Settings". Change "Command to get compiler specs" to ``xtensa-esp32-elf-gcc ${FLAGS} -std=c++11 -E -P -v -dD "${INPUTS}"``.
|
||||
|
||||
* In the list of providers, click "CDT GCC Build Output Parser" and change the "Compiler command pattern" to ``xtensa-esp32-elf-(gcc|g\+\+|c\+\+|cc|cpp|clang)``
|
||||
|
||||
Navigate to "C/C++ General" -> "Indexer" property page:
|
||||
|
||||
* Check "Enable project specific settings" to enable the rest of the settings on this page.
|
||||
|
||||
* Uncheck "Allow heuristic resolution of includes". When this option is enabled Eclipse sometimes fails to find correct header directories.
|
||||
|
||||
Navigate to "C/C++ Build" -> "Behavior" property page:
|
||||
|
||||
* Check "Enable parallel build" to enable multiple build jobs in parallel.
|
||||
|
||||
.. _eclipse-build-project-legacy:
|
||||
|
||||
Building in Eclipse
|
||||
-------------------
|
||||
|
||||
Before your project is first built, Eclipse may show a lot of errors and warnings about undefined values. This is because some source files are automatically generated as part of the esp-idf build process. These errors and warnings will go away after you build the project.
|
||||
|
||||
* Click OK to close the Properties dialog in Eclipse.
|
||||
|
||||
* Outside Eclipse, open a command line prompt. Navigate to your project directory, and run ``make menuconfig`` to configure your project's esp-idf settings. This step currently has to be run outside Eclipse.
|
||||
|
||||
*If you try to build without running a configuration step first, esp-idf will prompt for configuration on the command line - but Eclipse is not able to deal with this, so the build will hang or fail.*
|
||||
|
||||
* Back in Eclipse, choose Project -> Build to build your project.
|
||||
|
||||
**TIP**: If your project had already been built outside Eclipse, you may need to do a Project -> Clean before choosing Project -> Build. This is so Eclipse can see the compiler arguments for all source files. It uses these to determine the header include paths.
|
||||
|
||||
Flash from Eclipse
|
||||
------------------
|
||||
|
||||
You can integrate the "make flash" target into your Eclipse project to flash using esptool.py from the Eclipse UI:
|
||||
|
||||
* Right-click your project in Project Explorer (important to make sure you select the project, not a directory in the project, or Eclipse may find the wrong Makefile.)
|
||||
|
||||
* Select Build Targets -> Create... from the context menu.
|
||||
|
||||
* Type "flash" as the target name. Leave the other options as their defaults.
|
||||
|
||||
* Now you can use Project -> Build Target -> Build (Shift+F9) to build the custom flash target, which will compile and flash the project.
|
||||
|
||||
Note that you will need to use "make menuconfig" to set the serial port and other config options for flashing. "make menuconfig" still requires a command line terminal (see the instructions for your platform.)
|
||||
|
||||
Follow the same steps to add ``bootloader`` and ``partition_table`` targets, if necessary.
|
||||
|
||||
|
||||
.. _eclipse.org: https://www.eclipse.org/
|
||||
|
||||
@@ -1,154 +0,0 @@
|
||||
Establish Serial Connection with ESP32 (Legacy GNU Make)
|
||||
========================================================
|
||||
:link_to_translation:`zh_CN:[中文]`
|
||||
|
||||
.. include:: ../gnu-make-legacy.rst
|
||||
|
||||
This section provides guidance how to establish serial connection between ESP32 and PC.
|
||||
|
||||
|
||||
Connect ESP32 to PC
|
||||
--------------------
|
||||
|
||||
Connect the ESP32 board to the PC using the USB cable. If device driver does not install automatically, identify USB to serial converter chip on your ESP32 board (or external converter dongle), search for drivers in internet and install them.
|
||||
|
||||
Below are the links to drivers for ESP32 and other boards produced by Espressif:
|
||||
|
||||
|
||||
.. csv-table::
|
||||
:header: Development Board, USB Driver, Remarks
|
||||
:widths: 40, 20, 40
|
||||
|
||||
ESP32-DevKitC, `CP210x`_
|
||||
`ESP32-LyraT <https://www.espressif.com/en/products/hardware/esp32-lyrat>`_, `CP210x`_
|
||||
`ESP32-LyraTD-MSC <https://www.espressif.com/en/products/hardware/esp32-lyratd-msc>`_, `CP210x`_
|
||||
ESP32-PICO-KIT, `CP210x`_
|
||||
ESP-WROVER-KIT, `FTDI`_
|
||||
ESP32 Demo Board, `FTDI`_
|
||||
`ESP-Prog`_, `FTDI`_, Programmer board (w/o ESP32)
|
||||
`ESP32-MeshKit-Sense <https://github.com/espressif/esp-dev-kits/blob/master/esp32-meshkit-sensor/docs/ESP32-MeshKit-Sense_guide_en.md>`_, n/a, Use with `ESP-Prog`_
|
||||
`ESP32-Sense-Kit <https://github.com/espressif/esp-dev-kits/blob/master/esp32-sense-kit/docs/esp32_sense_kit_guide_en.md>`_, n/a, Use with `ESP-Prog`_
|
||||
|
||||
.. _CP210x: https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers
|
||||
.. _FTDI: https://www.ftdichip.com/Drivers/VCP.htm
|
||||
.. _ESP-Prog: https://github.com/espressif/esp-dev-kits/blob/master/esp-prog/docs/ESP-Prog_guide_en.md
|
||||
|
||||
* CP210x: `CP210x USB to UART Bridge VCP Drivers <https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers>`_
|
||||
* FTDI: `FTDI Virtual COM Port Drivers <https://www.ftdichip.com/Drivers/VCP.htm>`_
|
||||
|
||||
The drivers above are primarily for reference. Under normal circumstances, the drivers should be bundled with and operating system and automatically installed upon connecting one of the listed boards to the PC.
|
||||
|
||||
|
||||
Check port on Windows
|
||||
---------------------
|
||||
|
||||
Check the list of identified COM ports in the Windows Device Manager. Disconnect ESP32 and connect it back, to verify which port disappears from the list and then shows back again.
|
||||
|
||||
Figures below show serial port for ESP32 DevKitC and ESP32 WROVER KIT
|
||||
|
||||
.. figure:: ../../_static/esp32-devkitc-in-device-manager.png
|
||||
:align: center
|
||||
:alt: USB to UART bridge of ESP32-DevKitC in Windows Device Manager
|
||||
:figclass: align-center
|
||||
|
||||
USB to UART bridge of ESP32-DevKitC in Windows Device Manager
|
||||
|
||||
.. figure:: ../../_static/esp32-wrover-kit-in-device-manager.png
|
||||
:align: center
|
||||
:alt: Two USB Serial Ports of ESP-WROVER-KIT in Windows Device Manager
|
||||
:figclass: align-center
|
||||
|
||||
Two USB Serial Ports of ESP-WROVER-KIT in Windows Device Manager
|
||||
|
||||
|
||||
Check port on Linux and MacOS
|
||||
-----------------------------
|
||||
|
||||
To check the device name for the serial port of your ESP32 board (or external converter dongle), run this command two times, first with the board / dongle unplugged, then with plugged in. The port which appears the second time is the one you need:
|
||||
|
||||
Linux ::
|
||||
|
||||
ls /dev/tty*
|
||||
|
||||
MacOS ::
|
||||
|
||||
ls /dev/cu.*
|
||||
|
||||
|
||||
.. _linux-dialout-group-legacy:
|
||||
|
||||
Adding user to ``dialout`` on Linux
|
||||
-----------------------------------
|
||||
|
||||
The currently logged user should have read and write access the serial port over USB. On most Linux distributions, this is done by adding the user to ``dialout`` group with the following command::
|
||||
|
||||
sudo usermod -a -G dialout $USER
|
||||
|
||||
on Arch Linux this is done by adding the user to ``uucp`` group with the following command::
|
||||
|
||||
sudo usermod -a -G uucp $USER
|
||||
|
||||
Make sure you re-login to enable read and write permissions for the serial port.
|
||||
|
||||
|
||||
Verify serial connection
|
||||
------------------------
|
||||
|
||||
Now verify that the serial connection is operational. You can do this using a serial terminal program. In this example we will use `PuTTY SSH Client <http://www.putty.org/>`_ that is available for both Windows and Linux. You can use other serial program and set communication parameters like below.
|
||||
|
||||
Run terminal, set identified serial port, baud rate = 115200, data bits = 8, stop bits = 1, and parity = N. Below are example screen shots of setting the port and such transmission parameters (in short described as 115200-8-1-N) on Windows and Linux. Remember to select exactly the same serial port you have identified in steps above.
|
||||
|
||||
.. figure:: ../../_static/putty-settings-windows.png
|
||||
:align: center
|
||||
:alt: Setting Serial Communication in PuTTY on Windows
|
||||
:figclass: align-center
|
||||
|
||||
Setting Serial Communication in PuTTY on Windows
|
||||
|
||||
.. figure:: ../../_static/putty-settings-linux.png
|
||||
:align: center
|
||||
:alt: Setting Serial Communication in PuTTY on Linux
|
||||
:figclass: align-center
|
||||
|
||||
Setting Serial Communication in PuTTY on Linux
|
||||
|
||||
|
||||
Then open serial port in terminal and check, if you see any log printed out by ESP32. The log contents will depend on application loaded to ESP32. An example log by ESP32 is shown below.
|
||||
|
||||
.. highlight:: none
|
||||
|
||||
::
|
||||
|
||||
ets Jun 8 2016 00:22:57
|
||||
|
||||
rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
|
||||
ets Jun 8 2016 00:22:57
|
||||
|
||||
rst:0x7 (TG0WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
|
||||
configsip: 0, SPIWP:0x00
|
||||
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
|
||||
mode:DIO, clock div:2
|
||||
load:0x3fff0008,len:8
|
||||
load:0x3fff0010,len:3464
|
||||
load:0x40078000,len:7828
|
||||
load:0x40080000,len:252
|
||||
entry 0x40080034
|
||||
I (44) boot: ESP-IDF v2.0-rc1-401-gf9fba35 2nd stage bootloader
|
||||
I (45) boot: compile time 18:48:10
|
||||
|
||||
...
|
||||
|
||||
If you see some legible log, it means serial connection is working and you are ready to proceed with installation and finally upload of application to ESP32.
|
||||
|
||||
.. note::
|
||||
|
||||
For some serial port wiring configurations, the serial RTS & DTR pins need to be disabled in the terminal program before the ESP32 will boot and produce serial output. This depends on the hardware itself, most development boards (including all Espressif boards) *do not* have this issue. The issue is present if RTS & DTR are wired directly to the EN & GPIO0 pins. See the `esptool documentation`_ for more details.
|
||||
|
||||
.. note::
|
||||
|
||||
Close serial terminal after verification that communication is working. In next step we are going to use another application to upload ESP32. This application will not be able to access serial port while it is open in terminal.
|
||||
|
||||
If you got here from section :ref:`get-started-connect-legacy` when installing s/w for ESP32 development, then go back to section :ref:`get-started-configure-legacy`.
|
||||
|
||||
|
||||
.. _esptool documentation: https://github.com/espressif/esptool/wiki/ESP32-Boot-Mode-Selection#automatic-bootloader
|
||||
@@ -1,464 +0,0 @@
|
||||
*****************************
|
||||
Get Started (Legacy GNU Make)
|
||||
*****************************
|
||||
|
||||
:link_to_translation:`zh_CN:[中文]`
|
||||
|
||||
.. include:: ../gnu-make-legacy.rst
|
||||
|
||||
This document is intended to help you set up the software development environment for the hardware based on Espressif ESP32.
|
||||
|
||||
After that, a simple example will show you how to use ESP-IDF (Espressif IoT Development Framework) for menu configuration, then for building and flashing firmware onto an ESP32 board.
|
||||
|
||||
.. include-build-file:: inc/version-note.inc
|
||||
|
||||
Introduction
|
||||
============
|
||||
|
||||
ESP32 is a system on a chip that integrates the following features:
|
||||
|
||||
* Wi-Fi (2.4 GHz band)
|
||||
* Bluetooth
|
||||
* Dual high performance cores
|
||||
* Ultra Low Power co-processor
|
||||
* Several peripherals
|
||||
|
||||
Powered by 40 nm technology, ESP32 provides a robust, highly integrated platform, which helps meet the continuous demands for efficient power usage, compact design, security, high performance, and reliability.
|
||||
|
||||
Espressif provides basic hardware and software resources to help application developers realize their ideas using the ESP32 series hardware. The software development framework by Espressif is intended for development of Internet-of-Things (IoT) applications with Wi-Fi, Bluetooth, power management and several other system features.
|
||||
|
||||
What You Need
|
||||
=============
|
||||
|
||||
Hardware:
|
||||
|
||||
* An **ESP32** board
|
||||
* **USB cable** - USB A / micro USB B
|
||||
* **Computer** running Windows, Linux, or macOS
|
||||
|
||||
Software:
|
||||
|
||||
* **Toolchain** to build the **Application** for ESP32
|
||||
* **ESP-IDF** that essentially contains API (software libraries and source code) for ESP32 and scripts to operate the **Toolchain**
|
||||
* **Text editor** to write programs (**Projects**) in C, e.g., `Eclipse <https://www.eclipse.org/>`_
|
||||
|
||||
Development Board Overviews
|
||||
===========================
|
||||
|
||||
If you have one of ESP32 development boards listed below, you can click on the link to learn more about its hardware.
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
ESP32-DevKitC <../hw-reference/esp32/get-started-devkitc>
|
||||
ESP-WROVER-KIT <../hw-reference/esp32/get-started-wrover-kit>
|
||||
ESP32-PICO-KIT <../hw-reference/esp32/get-started-pico-kit>
|
||||
ESP32-Ethernet-Kit <../hw-reference/esp32/get-started-ethernet-kit>
|
||||
ESP32-DevKit-S(-R) <../hw-reference/esp32/user-guide-devkits-r-v1.1>
|
||||
.. _get-started-step-by-step-legacy:
|
||||
|
||||
Installation Step by Step
|
||||
=========================
|
||||
|
||||
This is a detailed roadmap to walk you through the installation process.
|
||||
|
||||
Setting up Development Environment
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* :ref:`get-started-setup-toolchain-legacy` for :doc:`Windows <windows-setup>`, :doc:`Linux <linux-setup>` or :doc:`macOS <macos-setup>`
|
||||
* :ref:`get-started-get-esp-idf-legacy`
|
||||
* :ref:`get-started-setup-path-legacy`
|
||||
* :ref:`get-started-get-packages-legacy`
|
||||
|
||||
Creating Your First Project
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* :ref:`get-started-start-project-legacy`
|
||||
* :ref:`get-started-connect-legacy`
|
||||
* :ref:`get-started-configure-legacy`
|
||||
* :ref:`get-started-build-and-flash-legacy`
|
||||
* :ref:`get-started-monitor-legacy`
|
||||
|
||||
|
||||
.. _get-started-setup-toolchain-legacy:
|
||||
|
||||
Step 1. Set up the Toolchain
|
||||
============================
|
||||
|
||||
The toolchain is a set of programs for compiling code and building applications.
|
||||
|
||||
The quickest way to start development with ESP32 is by installing a prebuilt toolchain. Pick up your OS below and follow the provided instructions.
|
||||
|
||||
.. toctree::
|
||||
:hidden:
|
||||
|
||||
Windows <windows-setup>
|
||||
Linux <linux-setup>
|
||||
macOS <macos-setup>
|
||||
|
||||
+-----------------+---------------+---------------+
|
||||
| |windows-logo| | |linux-logo| | |macos-logo| |
|
||||
+-----------------+---------------+---------------+
|
||||
| Windows_ | Linux_ | `macOS`_ |
|
||||
+-----------------+---------------+---------------+
|
||||
|
||||
.. |windows-logo| image:: ../../_static/windows-logo.png
|
||||
:target: ../get-started-legacy/windows-setup.html
|
||||
|
||||
.. |linux-logo| image:: ../../_static/linux-logo.png
|
||||
:target: ../get-started-legacy/linux-setup.html
|
||||
|
||||
.. |macos-logo| image:: ../../_static/macos-logo.png
|
||||
:target: ../get-started-legacy/macos-setup.html
|
||||
|
||||
.. _Windows: ../get-started-legacy/windows-setup.html
|
||||
.. _Linux: ../get-started-legacy/linux-setup.html
|
||||
.. _macOS: ../get-started-legacy/macos-setup.html
|
||||
|
||||
.. note::
|
||||
|
||||
This guide uses the directory ``~/esp`` on Linux and macOS or ``%userprofile%\esp`` on Windows as an installation folder for ESP-IDF. You can use any directory, but you will need to adjust paths for the commands respectively. Keep in mind that ESP-IDF does not support spaces in paths.
|
||||
|
||||
Depending on your experience and preferences, you may want to customize your environment instead of using a prebuilt toolchain. To set up the system your own way go to Section :ref:`get-started-customized-setup-legacy`.
|
||||
|
||||
|
||||
.. _get-started-get-esp-idf-legacy:
|
||||
|
||||
Step 2. Get ESP-IDF
|
||||
===================
|
||||
|
||||
Besides the toolchain, you also need ESP32-specific API (software libraries and source code). They are provided by Espressif in `ESP-IDF repository <https://github.com/espressif/esp-idf>`_.
|
||||
|
||||
To get a local copy of ESP-IDF, navigate to your installation directory and clone the repository with ``git clone``.
|
||||
|
||||
Open Terminal, and run the following commands:
|
||||
|
||||
.. include-build-file:: inc/git-clone-bash.inc
|
||||
|
||||
ESP-IDF will be downloaded into ``~/esp/esp-idf``.
|
||||
|
||||
Consult :doc:`/versions` for information about which ESP-IDF version to use in a given situation.
|
||||
|
||||
.. include-build-file:: inc/git-clone-notes.inc
|
||||
|
||||
.. note::
|
||||
|
||||
Do not miss the ``--recursive`` option. If you have already cloned ESP-IDF without this option, run another command to get all the submodules::
|
||||
|
||||
cd esp-idf
|
||||
git submodule update --init
|
||||
|
||||
|
||||
.. _get-started-setup-path-legacy:
|
||||
|
||||
Step 3. Set Environment Variables
|
||||
=================================
|
||||
|
||||
The toolchain uses the environment variable ``IDF_PATH`` to access the ESP-IDF directory. This variable should be set up on your computer, otherwise projects will not build.
|
||||
|
||||
These variables can be set temporarily (per session) or permanently. Please follow the instructions specific to :ref:`Windows <add-idf_path-to-profile-windows-legacy>` , :ref:`Linux and macOS <add-idf_path-to-profile-linux-macos-legacy>` in Section :doc:`add-idf_path-to-profile`.
|
||||
|
||||
|
||||
.. _get-started-get-packages-legacy:
|
||||
|
||||
Step 4. Install the Required Python Packages
|
||||
============================================
|
||||
|
||||
The python packages required by ESP-IDF are located in ``IDF_PATH/requirements.txt``. You can install them by running::
|
||||
|
||||
python -m pip install --user -r $IDF_PATH/requirements.txt
|
||||
|
||||
.. note::
|
||||
|
||||
Please check the version of the Python interpreter that you will be using with ESP-IDF. For this, run
|
||||
the command ``python --version`` and depending on the result, you might want to use ``python3``, ``python3.7``
|
||||
or similar instead of just ``python``, e.g.::
|
||||
|
||||
python3 -m pip install --user -r $IDF_PATH/requirements.txt
|
||||
|
||||
|
||||
.. _get-started-start-project-legacy:
|
||||
|
||||
Step 5. Start a Project
|
||||
=======================
|
||||
|
||||
Now you are ready to prepare your application for ESP32. You can start with :example:`get-started/hello_world` project from :idf:`examples` directory in IDF.
|
||||
|
||||
Copy :example:`get-started/hello_world` to the ``~/esp`` directory:
|
||||
|
||||
Linux and macOS
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
cd ~/esp
|
||||
cp -r $IDF_PATH/examples/get-started/hello_world .
|
||||
|
||||
Windows
|
||||
~~~~~~~
|
||||
|
||||
.. code-block:: batch
|
||||
|
||||
cd %userprofile%\esp
|
||||
xcopy /e /i %IDF_PATH%\examples\get-started\hello_world hello_world
|
||||
|
||||
There is a range of example projects in the :idf:`examples` directory in ESP-IDF. You can copy any project in the same way as presented above and run it.
|
||||
|
||||
It is also possible to build examples in-place, without copying them first.
|
||||
|
||||
.. important::
|
||||
|
||||
The esp-idf build system does not support spaces in the paths to either esp-idf or to projects.
|
||||
|
||||
.. _get-started-connect-legacy:
|
||||
|
||||
Step 6. Connect Your Device
|
||||
===========================
|
||||
|
||||
Now connect your ESP32 board to the computer and check under what serial port the board is visible.
|
||||
|
||||
Serial ports have the following patterns in their names:
|
||||
|
||||
- **Windows**: names like ``COM1``
|
||||
- **Linux**: starting with ``/dev/tty``
|
||||
- **macOS**: starting with ``/dev/cu.``
|
||||
|
||||
If you are not sure how to check the serial port name, please refer to :doc:`establish-serial-connection` for full details.
|
||||
|
||||
.. note::
|
||||
|
||||
Keep the port name handy as you will need it in the next steps.
|
||||
|
||||
|
||||
.. _get-started-configure-legacy:
|
||||
|
||||
Step 7. Configure
|
||||
=================
|
||||
|
||||
Navigate to your ``hello_world`` directory from :ref:`get-started-start-project-legacy` and run the project configuration utility ``menuconfig``.
|
||||
|
||||
Linux and macOS
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
cd ~/esp/hello_world
|
||||
make menuconfig
|
||||
|
||||
Windows
|
||||
~~~~~~~
|
||||
|
||||
.. code-block:: batch
|
||||
|
||||
cd %userprofile%\esp\hello_world
|
||||
make menuconfig
|
||||
|
||||
If the previous steps have been done correctly, the following menu appears:
|
||||
|
||||
.. figure:: ../../_static/project-configuration.png
|
||||
:align: center
|
||||
:alt: Project configuration - Home window
|
||||
:figclass: align-center
|
||||
|
||||
Project configuration - Home window
|
||||
|
||||
In the menu, navigate to ``Serial flasher config`` > ``Default serial port`` to configure the serial port, where project will be loaded to. Confirm selection by pressing enter, save configuration by selecting ``< Save >`` and then exit ``menuconfig`` by selecting ``< Exit >``.
|
||||
|
||||
To navigate and use ``menuconfig``, press the following keys:
|
||||
|
||||
* Arrow keys for navigation
|
||||
* ``Enter`` to go into a submenu
|
||||
* ``Esc`` to go up one level or exit
|
||||
* ``?`` to see a help screen. Enter key exits the help screen
|
||||
* ``Space``, or ``Y`` and ``N`` keys to enable (Yes) and disable (No) configuration items with checkboxes "``[*]``"
|
||||
* ``?`` while highlighting a configuration item to display help about that item
|
||||
* ``/`` to find configuration items
|
||||
|
||||
.. attention::
|
||||
|
||||
If you use ESP32-DevKitC board with the **ESP32-SOLO-1** module, enable single core mode (:ref:`CONFIG_FREERTOS_UNICORE`) in menuconfig before flashing examples.
|
||||
|
||||
.. _get-started-build-and-flash-legacy:
|
||||
|
||||
Step 8. Build and Flash
|
||||
=======================
|
||||
|
||||
Build and flash the project by running::
|
||||
|
||||
make flash
|
||||
|
||||
This command will compile the application and all ESP-IDF components, then it will generate the bootloader, partition table, and application binaries. After that, these binaries will be flashed onto your ESP32 board.
|
||||
|
||||
|
||||
Encountered Issues While Flashing?
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
If you run the given command and see errors such as "Failed to connect", there might be several reasons for this. One of the reasons might be issues encountered by ``esptool.py``, the utility that is called by the build system to reset the chip, interact with the ROM bootloader, and flash firmware. One simple solution to try is manual reset described below, and if it does not help you can find more details about possible issues in `Troubleshooting <https://github.com/espressif/esptool#bootloader-wont-respond>`_.
|
||||
|
||||
``esptool.py`` resets {IDF_TARGET_NAME} automatically by asserting DTR and RTS control lines of the USB to serial converter chip, i.e., FTDI or CP210x (for more information, see :doc:`establish-serial-connection`). The DTR and RTS control lines are in turn connected to ``GPIO0`` and ``CHIP_PU`` (EN) pins of {IDF_TARGET_NAME}, thus changes in the voltage levels of DTR and RTS will boot {IDF_TARGET_NAME} into Firmware Download mode. As an example, check the `schematic <https://dl.espressif.com/dl/schematics/esp32_devkitc_v4-sch-20180607a.pdf>`_ for ESP32-DevKitC development board.
|
||||
|
||||
In general, you should have no problems with the official esp-idf development boards. However, ``esptool.py`` is not able to reset your hardware automatically in the following cases:
|
||||
|
||||
- Your hardware does not have the DTR and RTS lines connected to ``GPIO0`` and ``CHIP_PU``
|
||||
- The DTR and RTS lines are configured differently
|
||||
- There are no such serial control lines at all
|
||||
|
||||
Depending on the kind of hardware you have, it may also be possible to manually put your {IDF_TARGET_NAME} board into Firmware Download mode (reset).
|
||||
|
||||
- For development boards produced by Espressif, this information can be found in the respective getting started guides or user guides. For example, to manually reset an esp-idf development board, hold down the **Boot** button (``GPIO0``) and press the **EN** button (``CHIP_PU``).
|
||||
- For other types of hardware, try pulling ``GPIO0`` down.
|
||||
|
||||
|
||||
Normal Operation
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
If there are no issues by the end of the flash process, you will see the output log similar to the one given below. Then the board will reboot and start up the "hello_world" application.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
esptool.py v3.0-dev
|
||||
Flashing binaries to serial port /dev/ttyUSB0 (app at offset 0x10000)...
|
||||
esptool.py v3.0-dev
|
||||
Serial port /dev/cu.SLAB_USBtoUART
|
||||
Connecting........____
|
||||
Chip is ESP32D0WDQ6 (revision 1)
|
||||
Features: WiFi, BT, Dual Core, Coding Scheme None
|
||||
Crystal is 40MHz
|
||||
MAC: 30:ae:a4:15:21:b4
|
||||
Uploading stub...
|
||||
Running stub...
|
||||
Stub running...
|
||||
Configuring flash size...
|
||||
Auto-detected Flash size: 4MB
|
||||
Flash params set to 0x0220
|
||||
Compressed 26704 bytes to 15930...
|
||||
Wrote 26704 bytes (15930 compressed) at 0x00001000 in 1.4 seconds (effective 151.9 kbit/s)...
|
||||
Hash of data verified.
|
||||
Compressed 147984 bytes to 77738...
|
||||
Wrote 147984 bytes (77738 compressed) at 0x00010000 in 6.9 seconds (effective 172.7 kbit/s)...
|
||||
Hash of data verified.
|
||||
Compressed 3072 bytes to 103...
|
||||
Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.0 seconds (effective 1607.9 kbit/s)...
|
||||
Hash of data verified.
|
||||
|
||||
Leaving...
|
||||
Hard resetting via RTS pin...
|
||||
|
||||
|
||||
If you'd like to use the Eclipse IDE instead of running ``make``, check out the :doc:`Eclipse guide <eclipse-setup>`.
|
||||
|
||||
|
||||
.. _get-started-monitor-legacy:
|
||||
|
||||
Step 9. Monitor
|
||||
===============
|
||||
|
||||
To check if "hello_world" is indeed running, type ``make monitor``.
|
||||
|
||||
This command launches the :doc:`IDF Monitor <../api-guides/tools/idf-monitor>` application::
|
||||
|
||||
$ make monitor
|
||||
MONITOR
|
||||
--- idf_monitor on /dev/ttyUSB0 115200 ---
|
||||
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
|
||||
ets Jun 8 2016 00:22:57
|
||||
|
||||
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
|
||||
ets Jun 8 2016 00:22:57
|
||||
...
|
||||
|
||||
After startup and diagnostic logs scroll up, you should see "Hello world!" printed out by the application.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
...
|
||||
Hello world!
|
||||
This is esp32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 1, 4MB external flash
|
||||
Restarting in 10 seconds...
|
||||
Restarting in 9 seconds...
|
||||
Restarting in 8 seconds...
|
||||
Restarting in 7 seconds...
|
||||
|
||||
To exit IDF monitor use the shortcut ``Ctrl+]``.
|
||||
|
||||
If IDF monitor fails shortly after the upload, or if instead of the messages above you see a random garbage similar to what is given below, your board is likely using a 26MHz crystal. Most development board designs use 40MHz, so ESP-IDF uses this frequency as a default value.
|
||||
|
||||
.. figure:: ../../_static/get-started-garbled-output.png
|
||||
:align: center
|
||||
:alt: Garbled output
|
||||
:figclass: align-center
|
||||
|
||||
If you have such a problem, do the following:
|
||||
|
||||
1. Exit the monitor.
|
||||
2. Go back to :ref:`menuconfig <get-started-configure-legacy>`.
|
||||
3. Go to Component config --> ESP32-specific --> Main XTAL frequency, then change :ref:`CONFIG_ESP32_XTAL_FREQ_SEL` to 26MHz.
|
||||
4. After that, :ref:`build and flash <get-started-build-and-flash-legacy>` the application again.
|
||||
|
||||
.. note::
|
||||
|
||||
You can combine building, flashing and monitoring into one step by running::
|
||||
|
||||
make flash monitor
|
||||
|
||||
See also :doc:`IDF Monitor <../api-guides/tools/idf-monitor>` for handy shortcuts and more details on using IDF monitor.
|
||||
|
||||
**That's all that you need to get started with ESP32!**
|
||||
|
||||
Now you are ready to try some other :idf:`examples`, or go straight to developing your own applications.
|
||||
|
||||
|
||||
Environment Variables
|
||||
=====================
|
||||
|
||||
Some environment variables can be specified whilst calling ``make`` allowing users to **override arguments without the need to reconfigure them using** ``make menuconfig``.
|
||||
|
||||
+-----------------+--------------------------------------------------------------+
|
||||
| Variables | Description & Usage |
|
||||
+=================+==============================================================+
|
||||
| ``ESPPORT`` | Overrides the serial port used in ``flash`` and ``monitor``. |
|
||||
| | |
|
||||
| | Examples: ``make flash ESPPORT=/dev/ttyUSB1``, |
|
||||
| | ``make monitor ESPPORT=COM1`` |
|
||||
+-----------------+--------------------------------------------------------------+
|
||||
| ``ESPBAUD`` | Overrides the serial baud rate when flashing the ESP32. |
|
||||
| | |
|
||||
| | Example: ``make flash ESPBAUD=9600`` |
|
||||
+-----------------+--------------------------------------------------------------+
|
||||
| ``MONITORBAUD`` | Overrides the serial baud rate used when monitoring. |
|
||||
| | |
|
||||
| | Example: ``make monitor MONITORBAUD=9600`` |
|
||||
+-----------------+--------------------------------------------------------------+
|
||||
|
||||
.. note::
|
||||
|
||||
You can export environment variables (e.g. ``export ESPPORT=/dev/ttyUSB1``).
|
||||
All subsequent calls of ``make`` within the same terminal session will use
|
||||
the exported value given that the variable is not simultaneously overridden.
|
||||
|
||||
|
||||
Updating ESP-IDF
|
||||
================
|
||||
|
||||
You should update ESP-IDF from time to time, as newer versions fix bugs and provide new features. The simplest way to do the update is to delete the existing ``esp-idf`` folder and clone it again, as if performing the initial installation described in :ref:`get-started-get-esp-idf-legacy`.
|
||||
|
||||
If downloading to a new path, remember to :doc:`add-idf_path-to-profile` so that the toolchain scripts can find ESP-IDF in its release specific location.
|
||||
|
||||
Another solution is to update only what has changed. :ref:`The update procedure depends on the version of ESP-IDF you are using <updating>`.
|
||||
|
||||
Related Documents
|
||||
=================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
add-idf_path-to-profile
|
||||
establish-serial-connection
|
||||
make-project
|
||||
eclipse-setup
|
||||
../api-guides/tools/idf-monitor
|
||||
toolchain-setup-scratch
|
||||
|
||||
.. Note: These two targets may be used from git-clone-notes.inc depending on version, don't remove
|
||||
.. _Stable version: https://docs.espressif.com/projects/esp-idf/en/stable/
|
||||
.. _Releases page: https://github.com/espressif/esp-idf/releases
|
||||
@@ -1,77 +0,0 @@
|
||||
****************************************************
|
||||
Setup Linux Toolchain from Scratch (Legacy GNU Make)
|
||||
****************************************************
|
||||
:link_to_translation:`zh_CN:[中文]`
|
||||
|
||||
.. include:: ../gnu-make-legacy.rst
|
||||
|
||||
.. note::
|
||||
|
||||
Standard process for installing the toolchain is described :doc:`here <linux-setup>`. See :ref:`Customized Setup of Toolchain <get-started-customized-setup-legacy>` section for some of the reasons why installing the toolchain from scratch may be necessary.
|
||||
|
||||
Install Prerequisites
|
||||
=====================
|
||||
|
||||
To compile with ESP-IDF you need to get the following packages:
|
||||
|
||||
- Ubuntu and Debian::
|
||||
|
||||
sudo apt-get install gcc git wget make libncurses-dev flex bison gperf python python-pip python-setuptools python-serial python-cryptography python-future python-pyparsing python-pyelftools libffi-dev libssl-dev
|
||||
|
||||
- Arch::
|
||||
|
||||
sudo pacman -S --needed gcc git make ncurses flex bison gperf python-pyserial python-cryptography python-future python-pyparsing python-pyelftools
|
||||
|
||||
.. note::
|
||||
|
||||
Some older (pre-2014) Linux distributions may use ``pyserial`` version 2.x which is not supported by ESP-IDF.
|
||||
In this case please install a supported version via ``pip`` as it is described in section
|
||||
:ref:`get-started-get-packages-legacy`.
|
||||
|
||||
Compile the Toolchain from Source
|
||||
=================================
|
||||
|
||||
- Install dependencies:
|
||||
|
||||
- CentOS 7::
|
||||
|
||||
sudo yum install gawk gperf grep gettext ncurses-devel python python-devel automake bison flex texinfo help2man libtool
|
||||
|
||||
- Ubuntu pre-16.04::
|
||||
|
||||
sudo apt-get install gawk gperf grep gettext libncurses-dev python python-dev automake bison flex texinfo help2man libtool
|
||||
|
||||
- Ubuntu 16.04 or newer::
|
||||
|
||||
sudo apt-get install gawk gperf grep gettext python python-dev automake bison flex texinfo help2man libtool libtool-bin
|
||||
|
||||
- Debian 9::
|
||||
|
||||
sudo apt-get install gawk gperf grep gettext libncurses-dev python python-dev automake bison flex texinfo help2man libtool libtool-bin
|
||||
|
||||
- Arch::
|
||||
|
||||
TODO
|
||||
|
||||
Create the working directory and go into it::
|
||||
|
||||
mkdir -p ~/esp
|
||||
cd ~/esp
|
||||
|
||||
Download ``crosstool-NG`` and build it:
|
||||
|
||||
.. include-build-file:: inc/scratch-build-code.inc
|
||||
|
||||
Build the toolchain::
|
||||
|
||||
./ct-ng xtensa-esp32-elf
|
||||
./ct-ng build
|
||||
chmod -R u+w builds/xtensa-esp32-elf
|
||||
|
||||
Toolchain will be built in ``~/esp/crosstool-NG/builds/xtensa-esp32-elf``. Follow :ref:`instructions for standard setup <setup-linux-toolchain-add-it-to-path-legacy>` to add the toolchain to your ``PATH``.
|
||||
|
||||
|
||||
Next Steps
|
||||
==========
|
||||
|
||||
To carry on with development environment setup, proceed to section :ref:`get-started-get-esp-idf-legacy`.
|
||||
@@ -1,104 +0,0 @@
|
||||
*******************************************************
|
||||
Standard Setup of Toolchain for Linux (Legacy GNU Make)
|
||||
*******************************************************
|
||||
:link_to_translation:`zh_CN:[中文]`
|
||||
|
||||
.. include:: ../gnu-make-legacy.rst
|
||||
|
||||
Install Prerequisites
|
||||
=====================
|
||||
|
||||
To compile with ESP-IDF you need to get the following packages:
|
||||
|
||||
- CentOS 7::
|
||||
|
||||
sudo yum install gcc git wget make flex bison gperf python python2-cryptography
|
||||
|
||||
- Ubuntu and Debian::
|
||||
|
||||
sudo apt-get install gcc git wget make flex bison gperf python python-pip python-setuptools python-serial python-cryptography python-future python-pyparsing python-pyelftools libffi-dev libssl-dev
|
||||
|
||||
- Arch::
|
||||
|
||||
sudo pacman -S --needed gcc git make flex bison gperf python-pyserial python-cryptography python-future python-pyparsing python-pyelftools
|
||||
|
||||
.. note::
|
||||
|
||||
Some older Linux distributions may be missing some of the Python packages listed above (or may use ``pyserial`` version 2.x which is not supported by ESP-IDF). It is possible to install these packages via ``pip`` instead - as described in section :ref:`get-started-get-packages-legacy`.
|
||||
|
||||
Toolchain Setup
|
||||
===============
|
||||
|
||||
.. include-build-file:: inc/download-links.inc
|
||||
|
||||
ESP32 toolchain for Linux is available for download from Espressif website:
|
||||
|
||||
- for 64-bit Linux:
|
||||
|
||||
|download_link_linux64|
|
||||
|
||||
- for 32-bit Linux:
|
||||
|
||||
|download_link_linux32|
|
||||
|
||||
1. Download this file, then extract it in ``~/esp`` directory:
|
||||
|
||||
- for 64-bit Linux:
|
||||
|
||||
.. include-build-file:: inc/unpack-code-linux64.inc
|
||||
|
||||
- for 32-bit Linux:
|
||||
|
||||
.. include-build-file:: inc/unpack-code-linux32.inc
|
||||
|
||||
.. _setup-linux-toolchain-add-it-to-path-legacy:
|
||||
|
||||
2. The toolchain will be extracted into ``~/esp/xtensa-esp32-elf/`` directory.
|
||||
|
||||
To use it, you will need to update your ``PATH`` environment variable in ``~/.profile`` file. To make ``xtensa-esp32-elf`` available for all terminal sessions, add the following line to your ``~/.profile`` file::
|
||||
|
||||
export PATH="$HOME/esp/xtensa-esp32-elf/bin:$PATH"
|
||||
|
||||
Alternatively, you may create an alias for the above command. This way you can get the toolchain only when you need it. To do this, add different line to your ``~/.profile`` file::
|
||||
|
||||
alias get_esp32='export PATH="$HOME/esp/xtensa-esp32-elf/bin:$PATH"'
|
||||
|
||||
Then when you need the toolchain you can type ``get_esp32`` on the command line and the toolchain will be added to your ``PATH``.
|
||||
|
||||
.. note::
|
||||
|
||||
If you have ``/bin/bash`` set as login shell, and both ``.bash_profile`` and ``.profile`` exist, then update ``.bash_profile`` instead. In CentOS, ``alias`` should set in ``.bashrc``.
|
||||
|
||||
3. Log off and log in back to make the ``.profile`` changes effective. Run the following command to verify if ``PATH`` is correctly set::
|
||||
|
||||
printenv PATH
|
||||
|
||||
You are looking for similar result containing toolchain's path at the beginning of displayed string::
|
||||
|
||||
$ printenv PATH
|
||||
/home/user-name/esp/xtensa-esp32-elf/bin:/home/user-name/bin:/home/user-name/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
|
||||
|
||||
Instead of ``/home/user-name`` there should be a home path specific to your installation.
|
||||
|
||||
|
||||
Permission issues /dev/ttyUSB0
|
||||
------------------------------
|
||||
|
||||
With some Linux distributions you may get the ``Failed to open port /dev/ttyUSB0`` error message when flashing the ESP32. :ref:`This can be solved by adding the current user to the dialout group<linux-dialout-group-legacy>`.
|
||||
|
||||
Next Steps
|
||||
==========
|
||||
|
||||
To carry on with development environment setup, proceed to section :ref:`get-started-get-esp-idf-legacy`.
|
||||
|
||||
|
||||
Related Documents
|
||||
=================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
linux-setup-scratch
|
||||
|
||||
|
||||
.. _AUR: https://wiki.archlinux.org/index.php/Arch_User_Repository
|
||||
@@ -1,74 +0,0 @@
|
||||
*********************************************************
|
||||
Setup Toolchain for Mac OS from Scratch (Legacy GNU Make)
|
||||
*********************************************************
|
||||
:link_to_translation:`zh_CN:[中文]`
|
||||
|
||||
.. include:: ../gnu-make-legacy.rst
|
||||
|
||||
.. note::
|
||||
|
||||
Standard process for installing the toolchain is described :doc:`here <macos-setup>`. See :ref:`Customized Setup of Toolchain <get-started-customized-setup-legacy>` section for some of the reasons why installing the toolchain from scratch may be necessary.
|
||||
|
||||
Install Prerequisites
|
||||
=====================
|
||||
|
||||
- install pip::
|
||||
|
||||
sudo easy_install pip
|
||||
|
||||
.. note::
|
||||
|
||||
``pip`` will be used later for installing :ref:`the required Python packages <get-started-get-packages-legacy>`.
|
||||
|
||||
Compile the Toolchain from Source
|
||||
=================================
|
||||
|
||||
- Install dependencies:
|
||||
|
||||
- Install either MacPorts_ or homebrew_ package manager. MacPorts needs a full XCode installation, while homebrew only needs XCode command line tools.
|
||||
|
||||
.. _homebrew: https://brew.sh/
|
||||
.. _MacPorts: https://www.macports.org/install.php
|
||||
|
||||
- with MacPorts::
|
||||
|
||||
sudo port install gsed gawk binutils gperf grep gettext wget libtool autoconf automake
|
||||
|
||||
- with homebrew::
|
||||
|
||||
brew install gnu-sed gawk binutils gperftools gettext wget help2man libtool autoconf automake
|
||||
|
||||
Create a case-sensitive filesystem image::
|
||||
|
||||
hdiutil create ~/esp/crosstool.dmg -volname "ctng" -size 10g -fs "Case-sensitive HFS+"
|
||||
|
||||
Mount it::
|
||||
|
||||
hdiutil mount ~/esp/crosstool.dmg
|
||||
|
||||
Create a symlink to your work directory::
|
||||
|
||||
mkdir -p ~/esp
|
||||
ln -s /Volumes/ctng ~/esp/ctng-volume
|
||||
|
||||
Go into the newly created directory::
|
||||
|
||||
cd ~/esp/ctng-volume
|
||||
|
||||
Download ``crosstool-NG`` and build it:
|
||||
|
||||
.. include-build-file:: inc/scratch-build-code.inc
|
||||
|
||||
Build the toolchain::
|
||||
|
||||
./ct-ng xtensa-esp32-elf
|
||||
./ct-ng build
|
||||
chmod -R u+w builds/xtensa-esp32-elf
|
||||
|
||||
Toolchain will be built in ``~/esp/ctng-volume/crosstool-NG/builds/xtensa-esp32-elf``. Follow :ref:`instructions for standard setup <setup-macos-toolchain-add-it-to-path-legacy>` to add the toolchain to your ``PATH``.
|
||||
|
||||
|
||||
Next Steps
|
||||
==========
|
||||
|
||||
To carry on with development environment setup, proceed to section :ref:`get-started-get-esp-idf-legacy`.
|
||||
@@ -1,59 +0,0 @@
|
||||
********************************************************
|
||||
Standard Setup of Toolchain for Mac OS (Legacy GNU Make)
|
||||
********************************************************
|
||||
:link_to_translation:`zh_CN:[中文]`
|
||||
|
||||
.. include:: ../gnu-make-legacy.rst
|
||||
|
||||
Install Prerequisites
|
||||
=====================
|
||||
|
||||
- install pip::
|
||||
|
||||
sudo easy_install pip
|
||||
|
||||
.. note::
|
||||
|
||||
``pip`` will be used later for installing :ref:`the required Python packages <get-started-get-packages-legacy>`.
|
||||
|
||||
Toolchain Setup
|
||||
===============
|
||||
|
||||
.. include-build-file:: inc/download-links.inc
|
||||
|
||||
ESP32 toolchain for macOS is available for download from Espressif website:
|
||||
|
||||
|download_link_osx|
|
||||
|
||||
Download this file, then extract it in ``~/esp`` directory:
|
||||
|
||||
.. include-build-file:: inc/unpack-code-osx.inc
|
||||
|
||||
.. _setup-macos-toolchain-add-it-to-path-legacy:
|
||||
|
||||
The toolchain will be extracted into ``~/esp/xtensa-esp32-elf/`` directory.
|
||||
|
||||
To use it, you will need to update your ``PATH`` environment variable in ``~/.profile`` file. To make ``xtensa-esp32-elf`` available for all terminal sessions, add the following line to your ``~/.profile`` file::
|
||||
|
||||
export PATH=$HOME/esp/xtensa-esp32-elf/bin:$PATH
|
||||
|
||||
Alternatively, you may create an alias for the above command. This way you can get the toolchain only when you need it. To do this, add different line to your ``~/.profile`` file::
|
||||
|
||||
alias get_esp32="export PATH=$HOME/esp/xtensa-esp32-elf/bin:$PATH"
|
||||
|
||||
Then when you need the toolchain you can type ``get_esp32`` on the command line and the toolchain will be added to your ``PATH``.
|
||||
|
||||
|
||||
Next Steps
|
||||
==========
|
||||
|
||||
To carry on with development environment setup, proceed to section :ref:`get-started-get-esp-idf-legacy`.
|
||||
|
||||
|
||||
Related Documents
|
||||
=================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
macos-setup-scratch
|
||||
@@ -1,77 +0,0 @@
|
||||
Build and Flash with Make (Legacy GNU Make)
|
||||
===========================================
|
||||
:link_to_translation:`zh_CN:[中文]`
|
||||
|
||||
.. include:: ../gnu-make-legacy.rst
|
||||
|
||||
|
||||
Finding a project
|
||||
-----------------
|
||||
|
||||
As well as the `esp-idf-template <https://github.com/espressif/esp-idf-template>`_ project, ESP-IDF comes with some example projects on github in the :idf:`examples` directory.
|
||||
|
||||
Once you've found the project you want to work with, change to its directory and you can configure and build it.
|
||||
|
||||
|
||||
Configuring your project
|
||||
------------------------
|
||||
|
||||
::
|
||||
|
||||
make menuconfig
|
||||
|
||||
|
||||
Compiling your project
|
||||
----------------------
|
||||
|
||||
::
|
||||
|
||||
make all
|
||||
|
||||
... will compile app, bootloader and generate a partition table based on the config.
|
||||
|
||||
|
||||
Flashing your project
|
||||
---------------------
|
||||
|
||||
When ``make all`` finishes, it will print a command line to use esptool.py to flash the chip. However you can also do this from make by running::
|
||||
|
||||
make flash
|
||||
|
||||
This will flash the entire project (app, bootloader and partition table) to a new chip. Also if partition table has ota_data then this command will flash a initial ota_data.
|
||||
It allows to run the newly loaded app from a factory partition (or the first OTA partition, if factory partition is not present).
|
||||
The settings for serial port flashing can be configured with `make menuconfig`.
|
||||
|
||||
You don't need to run ``make all`` before running ``make flash``, ``make flash`` will automatically rebuild anything which needs it.
|
||||
|
||||
|
||||
Compiling & Flashing Just the App
|
||||
---------------------------------
|
||||
|
||||
After the initial flash, you may just want to build and flash just your app, not the bootloader and partition table:
|
||||
|
||||
* ``make app`` - build just the app.
|
||||
* ``make app-flash`` - flash just the app.
|
||||
|
||||
``make app-flash`` will automatically rebuild the app if it needs it.
|
||||
|
||||
There's no downside to reflashing the bootloader and partition table each time, if they haven't changed.
|
||||
|
||||
|
||||
The Partition Table
|
||||
-------------------
|
||||
|
||||
Once you've compiled your project, the "build" directory will contain a binary file with a name like "my_app.bin". This is an ESP32 image binary that can be loaded by the bootloader.
|
||||
|
||||
A single ESP32's flash can contain multiple apps, as well as many kinds of data (calibration data, filesystems, parameter storage, etc). For this reason, a partition table is flashed to offset 0x8000 in the flash.
|
||||
|
||||
Each entry in the partition table has a name (label), type (app, data, or something else), subtype and the offset in flash where the partition is loaded.
|
||||
|
||||
The simplest way to use the partition table is to `make menuconfig` and choose one of the simple predefined partition tables:
|
||||
|
||||
* "Single factory app, no OTA"
|
||||
* "Factory app, two OTA definitions"
|
||||
|
||||
In both cases the factory app is flashed at offset 0x10000. If you `make partition_table` then it will print a summary of the partition table.
|
||||
|
||||
For more details about :doc:`partition tables <../api-guides/partition-tables>` and how to create custom variations, view the :doc:`documentation <../api-guides/partition-tables>`.
|
||||
@@ -1,27 +0,0 @@
|
||||
.. _get-started-customized-setup-legacy:
|
||||
|
||||
***********************************************
|
||||
Customized Setup of Toolchain (Legacy GNU Make)
|
||||
***********************************************
|
||||
|
||||
Instead of downloading binary toolchain from Espressif website (see :ref:`get-started-setup-toolchain-legacy`) you may build the toolchain yourself.
|
||||
|
||||
.. include:: ../gnu-make-legacy.rst
|
||||
|
||||
If you can't think of a reason why you need to build it yourself, then probably it's better to stick with the binary version. However, here are some of the reasons why you might want to compile it from source:
|
||||
|
||||
- if you want to customize toolchain build configuration
|
||||
- if you want to use a different GCC version (such as 4.8.5)
|
||||
- if you want to hack gcc or newlib or libstdc++
|
||||
- if you are curious and/or have time to spare
|
||||
- if you don't trust binaries downloaded from the Internet
|
||||
|
||||
In any case, here are the instructions to compile the toolchain yourself.
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
windows-setup-scratch
|
||||
linux-setup-scratch
|
||||
macos-setup-scratch
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
******************************************************
|
||||
Setup Windows Toolchain from Scratch (Legacy GNU Make)
|
||||
******************************************************
|
||||
|
||||
.. include:: ../gnu-make-legacy.rst
|
||||
|
||||
Setting up the environment gives you some more control over the process, and also provides the information for advanced users to customize the install. The :doc:`pre-built environment <windows-setup>`, addressed to less experienced users, has been prepared by following these steps.
|
||||
|
||||
To quickly setup the toolchain in standard way, using a prebuilt environment, proceed to section :doc:`windows-setup`.
|
||||
|
||||
|
||||
.. _configure-windows-toolchain-from-scratch-legacy:
|
||||
|
||||
Configure Toolchain & Environment from Scratch
|
||||
==============================================
|
||||
|
||||
This process involves installing MSYS2_, then installing the MSYS2_ and Python packages which ESP-IDF uses, and finally downloading and installing the Xtensa toolchain.
|
||||
|
||||
* Navigate to the MSYS2_ installer page and download the ``msys2-i686-xxxxxxx.exe`` installer executable (we only support a 32-bit MSYS environment, it works on both 32-bit and 64-bit Windows.) At time of writing, the latest installer is ``msys2-i686-20161025.exe``.
|
||||
|
||||
* Run through the installer steps. **Uncheck the "Run MSYS2 32-bit now" checkbox at the end.**
|
||||
|
||||
* Once the installer exits, open Start Menu and find "MSYS2 MinGW 32-bit" to run the terminal.
|
||||
|
||||
*(Why launch this different terminal? MSYS2 has the concept of different kinds of environments. The default "MSYS" environment is Cygwin-like and uses a translation layer for all Windows API calls. We need the "MinGW" environment in order to have a native Python which supports COM ports.)*
|
||||
|
||||
* The ESP-IDF repository on github contains a script in the tools directory titled ``windows_install_prerequisites.sh``. If you haven't got a local copy of the ESP-IDF yet, that's OK - you can just download that one file in Raw format from here: :idf_raw:`tools/windows/windows_install_prerequisites.sh`. Save it somewhere on your computer.
|
||||
|
||||
* Type the path to the shell script into the MSYS2 terminal window. You can type it as a normal Windows path, but use forward-slashes instead of back-slashes. ie: ``C:/Users/myuser/Downloads/windows_install_prerequisites.sh``. You can read the script beforehand to check what it does.
|
||||
|
||||
* The ``windows_install_prerequisites.sh`` script will download and install packages for ESP-IDF support, and the ESP32 toolchain.
|
||||
|
||||
|
||||
Troubleshooting
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
* While the install script runs, MSYS may update itself into a state where it can no longer operate. You may see errors like the following::
|
||||
|
||||
*** fatal error - cygheap base mismatch detected - 0x612E5408/0x612E4408. This problem is probably due to using incompatible versions of the cygwin DLL.
|
||||
|
||||
If you see errors like this, close the terminal window entirely (terminating the processes running there) and then re-open a new terminal. Re-run ``windows_install_prerequisites.sh`` (tip: use the up arrow key to see the last run command). The update process will resume after this step.
|
||||
|
||||
* MSYS2 is a "rolling" distribution so running the installer script may install newer packages than what is used in the prebuilt environments. If you see any errors that appear to be related to installing MSYS2 packages, please check the `MSYS2-packages issues list`_ for known issues. If you don't see any relevant issues, please `raise an IDF issue`_.
|
||||
|
||||
|
||||
MSYS2 Mirrors in China
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
There are some (unofficial) MSYS2 mirrors inside China, which substantially improves download speeds inside China.
|
||||
|
||||
To add these mirrors, edit the following two MSYS2 mirrorlist files before running the setup script. The mirrorlist files can be found in the ``/etc/pacman.d`` directory (i.e. ``c:\msys2\etc\pacman.d``).
|
||||
|
||||
Add these lines at the top of ``mirrorlist.mingw32``::
|
||||
|
||||
Server = https://mirrors.ustc.edu.cn/msys2/mingw/i686/
|
||||
Server = http://mirror.bit.edu.cn/msys2/REPOS/MINGW/i686
|
||||
|
||||
Add these lines at the top of ``mirrorlist.msys``::
|
||||
|
||||
Server = http://mirrors.ustc.edu.cn/msys2/msys/$arch
|
||||
Server = http://mirror.bit.edu.cn/msys2/REPOS/MSYS2/$arch
|
||||
|
||||
|
||||
HTTP Proxy
|
||||
~~~~~~~~~~
|
||||
|
||||
You can enable an HTTP proxy for MSYS and PIP downloads by setting the ``http_proxy`` variable in the terminal before running the setup script::
|
||||
|
||||
export http_proxy='http://http.proxy.server:PORT'
|
||||
|
||||
Or with credentials::
|
||||
|
||||
export http_proxy='http://user:password@http.proxy.server:PORT'
|
||||
|
||||
Add this line to ``/etc/profile`` in the MSYS directory in order to permanently enable the proxy when using MSYS.
|
||||
|
||||
|
||||
Alternative Setup: Just download a toolchain
|
||||
============================================
|
||||
|
||||
.. include-build-file:: inc/download-links.inc
|
||||
|
||||
If you already have an MSYS2 install or want to do things differently, you can download just the toolchain here:
|
||||
|
||||
|download_link_win32|
|
||||
|
||||
.. note::
|
||||
|
||||
If you followed instructions :ref:`configure-windows-toolchain-from-scratch-legacy`, you already have the toolchain and you won't need this download.
|
||||
|
||||
.. important::
|
||||
|
||||
Just having this toolchain is *not enough* to use ESP-IDF on Windows. You will need GNU make, bash, and sed at minimum. The above environments provide all this, plus a host compiler (required for menuconfig support).
|
||||
|
||||
|
||||
Next Steps
|
||||
==========
|
||||
|
||||
To carry on with development environment setup, proceed to section :ref:`get-started-get-esp-idf-legacy`.
|
||||
|
||||
.. _updating-existing-windows-environment-legacy:
|
||||
|
||||
Updating The Environment
|
||||
========================
|
||||
|
||||
When IDF is updated, sometimes new toolchains are required or new system requirements are added to the Windows MSYS2 environment.
|
||||
|
||||
Rather than setting up a new environment, you can update an existing Windows environment & toolchain:
|
||||
|
||||
- Update IDF to the new version you want to use.
|
||||
- Run the ``tools/windows/windows_install_prerequisites.sh`` script inside IDF. This will install any new software packages that weren't previously installed, and download and replace the toolchain with the latest version.
|
||||
|
||||
The script to update MSYS2 may also fail with the same errors mentioned under Troubleshooting_.
|
||||
|
||||
If you need to support multiple IDF versions concurrently, you can have different independent MSYS2 environments in different directories. Alternatively you can download multiple toolchains and unzip these to different directories, then use the PATH environment variable to set which one is the default.
|
||||
|
||||
.. _MSYS2: https://www.msys2.org/
|
||||
.. _MSYS2-packages issues list: https://github.com/Alexpux/MSYS2-packages/issues/
|
||||
.. _raise an IDF issue: https://github.com/espressif/esp-idf/issues/new
|
||||
@@ -1,76 +0,0 @@
|
||||
*********************************************************
|
||||
Standard Setup of Toolchain for Windows (Legacy GNU Make)
|
||||
*********************************************************
|
||||
:link_to_translation:`zh_CN:[中文]`
|
||||
|
||||
.. include:: ../gnu-make-legacy.rst
|
||||
|
||||
Introduction
|
||||
============
|
||||
|
||||
Windows doesn't have a built-in "make" environment, so as well as installing the toolchain you will need a GNU-compatible environment. We use the MSYS2_ environment to provide this. You don't need to use this environment all the time (you can use :doc:`Eclipse <eclipse-setup>` or some other front-end), but it runs behind the scenes.
|
||||
|
||||
|
||||
Toolchain Setup
|
||||
===============
|
||||
|
||||
The quick setup is to download the Windows all-in-one toolchain & MSYS2 zip file from dl.espressif.com:
|
||||
|
||||
https://dl.espressif.com/dl/esp32_win32_msys2_environment_and_esp2020r2_toolchain-20200601.zip
|
||||
|
||||
Unzip the zip file to ``C:\`` (or some other location, but this guide assumes ``C:\``) and it will create an ``msys32`` directory with a pre-prepared environment.
|
||||
|
||||
.. important::
|
||||
|
||||
If another toolchain location is used (different than the default ``C:\msys32``), please ensure that the path where the all-in-one toolchain gets unzipped is a plain ASCII, contains no spaces, symlinks or accents.
|
||||
|
||||
|
||||
Check it Out
|
||||
============
|
||||
|
||||
Open a MSYS2 MINGW32 terminal window by running ``C:\msys32\mingw32.exe``. The environment in this window is a bash shell. Create a directory named ``esp`` that is a default location to develop ESP32 applications. To do so, run the following shell command::
|
||||
|
||||
mkdir -p ~/esp
|
||||
|
||||
By typing ``cd ~/esp`` you can then move to the newly created directory. If there are no error messages you are done with this step.
|
||||
|
||||
.. figure:: ../../_static/msys2-terminal-window.png
|
||||
:align: center
|
||||
:alt: MSYS2 MINGW32 shell window
|
||||
:figclass: align-center
|
||||
|
||||
MSYS2 MINGW32 shell window
|
||||
|
||||
Use this window in the following steps setting up development environment for ESP32.
|
||||
|
||||
|
||||
Next Steps
|
||||
==========
|
||||
|
||||
To carry on with development environment setup, proceed to section :ref:`get-started-get-esp-idf-legacy`.
|
||||
|
||||
Updating The Environment
|
||||
========================
|
||||
|
||||
When IDF is updated, sometimes new toolchains are required or new requirements are added to the Windows MSYS2 environment. To move any data from an old version of the precompiled environment to a new one:
|
||||
|
||||
- Take the old MSYS2 environment (ie ``C:\msys32``) and move/rename it to a different directory (ie ``C:\msys32_old``).
|
||||
- Download the new precompiled environment using the steps above.
|
||||
- Unzip the new MSYS2 environment to ``C:\msys32`` (or another location).
|
||||
- Find the old ``C:\msys32_old\home`` directory and move this into ``C:\msys32``.
|
||||
- You can now delete the ``C:\msys32_old`` directory if you no longer need it.
|
||||
|
||||
You can have independent different MSYS2 environments on your system, as long as they are in different directories.
|
||||
|
||||
There are :ref:`also steps to update the existing environment without downloading a new one <updating-existing-windows-environment-legacy>`, although this is more complex.
|
||||
|
||||
Related Documents
|
||||
=================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
windows-setup-scratch
|
||||
|
||||
|
||||
.. _MSYS2: https://www.msys2.org/
|
||||
@@ -11,7 +11,3 @@ There is a new ESP-IDF Eclipse Plugin that works with the CMake-based build syst
|
||||
.. note::
|
||||
|
||||
In `Espressif IDF Eclipse Plugins <https://github.com/espressif/idf-eclipse-plugin/blob/master/README.md>`_, though screenshots are captured from macOS, installation instructions are applicable for Windows, Linux and macOS.
|
||||
|
||||
.. only:: esp32
|
||||
|
||||
If you require Eclipse IDE support for legacy ESP_IDF Make build system, you can follow the :doc:`legacy GNU Make build system Getting Started guide </get-started-legacy/index>` which has steps for :doc:`Building and Flashing with Eclipse IDE </get-started-legacy/eclipse-setup>`.
|
||||
|
||||
@@ -818,7 +818,6 @@ Related Documents
|
||||
vscode-setup
|
||||
../api-guides/tools/idf-monitor
|
||||
toolchain-setup-scratch
|
||||
:esp32: ../get-started-legacy/index
|
||||
|
||||
.. _Stable version: https://docs.espressif.com/projects/esp-idf/en/stable/
|
||||
.. _Releases page: https://github.com/espressif/esp-idf/releases
|
||||
|
||||
@@ -8,9 +8,6 @@ This is a step-by-step alternative to running the :doc:`ESP-IDF Tools Installer
|
||||
|
||||
To quickly setup the toolchain and other tools in standard way, using the ESP-IDF Tools installer, proceed to section :doc:`windows-setup`.
|
||||
|
||||
.. note::
|
||||
The GNU Make based build system requires the MSYS2_ Unix compatibility environment on Windows. The CMake-based build system does not require this environment.
|
||||
|
||||
.. _get-esp-idf-windows-command-line:
|
||||
|
||||
Get ESP-IDF
|
||||
@@ -54,7 +51,7 @@ Ninja build
|
||||
^^^^^^^^^^^
|
||||
|
||||
.. note::
|
||||
Ninja currently only provides binaries for 64-bit Windows. It is possible to use CMake and ``idf.py`` with other build tools, such as mingw-make, on 32-bit windows. However this is currently undocumented.
|
||||
Ninja currently only provides binaries for 64-bit Windows.
|
||||
|
||||
Download the Ninja_ latest stable Windows release from the (`download page <ninja-dl_>`_).
|
||||
|
||||
@@ -85,10 +82,6 @@ Unzip the zip file to ``C:\Program Files`` (or some other location). The zip fil
|
||||
|
||||
Next, the ``bin`` subdirectory of this directory must be :ref:`added to your Path <add-directory-windows-path>`. For example, the directory to add may be ``C:\Program Files\{IDF_TARGET_TOOLCHAIN_PREFIX}\bin``.
|
||||
|
||||
.. note::
|
||||
If you already have the MSYS2 environment (for use with the "GNU Make" build system) installed, you can skip the separate download and add the directory ``C:\msys32\opt\{IDF_TARGET_TOOLCHAIN_PREFIX}\bin`` to the Path instead, as the toolchain is included in the MSYS2 environment.
|
||||
|
||||
|
||||
.. _add-directory-windows-path:
|
||||
|
||||
Adding Directory to Path
|
||||
@@ -110,8 +103,7 @@ To carry on with development environment setup, proceed to :ref:`get-started-set
|
||||
.. _Ninja: https://ninja-build.org/
|
||||
.. _ninja-dl: https://github.com/ninja-build/ninja/releases
|
||||
.. _Python: https://www.python.org/downloads/windows/
|
||||
.. _MSYS2: https://www.msys2.org/
|
||||
.. _kconfig-frontends releases page: https://github.com/espressif/kconfig-frontends/releases
|
||||
.. Note: These two targets may be used from git-clone-notes.inc depending on version, don't remove
|
||||
.. _Stable version: https://docs.espressif.com/projects/esp-idf/en/stable/
|
||||
.. _Releases page: https://github.com/espressif/esp-idf/releases
|
||||
.. _Releases page: https://github.com/espressif/esp-idf/releases
|
||||
|
||||
@@ -4,11 +4,6 @@ Standard Setup of Toolchain for Windows
|
||||
|
||||
:link_to_translation:`zh_CN:[中文]`
|
||||
|
||||
.. only:: esp32
|
||||
|
||||
.. note::
|
||||
Currently only 64-bit versions of Windows are supported. 32-bit Windows can use the :doc:`Legacy GNU Make Build System<../get-started-legacy/windows-setup>`.
|
||||
|
||||
Introduction
|
||||
============
|
||||
|
||||
@@ -16,11 +11,6 @@ ESP-IDF requires some prerequisite tools to be installed so you can build firmwa
|
||||
|
||||
For this Getting Started we're going to use the Command Prompt, but after ESP-IDF is installed you can use :doc:`Eclipse <eclipse-setup>` or another graphical IDE with CMake support instead.
|
||||
|
||||
.. only:: esp32
|
||||
|
||||
.. note::
|
||||
Previous versions of ESP-IDF used the :doc:`Legacy GNU Make Build System<../get-started-legacy/windows-setup>` and MSYS2_ Unix compatibility environment. This is no longer required, ESP-IDF can be used from the Windows Command Prompt.
|
||||
|
||||
.. note::
|
||||
Limitations:
|
||||
- The installation path of ESP-IDF and ESP-IDF Tools must not be longer than 90 characters. Too long installation paths might result in a failed build.
|
||||
@@ -127,4 +117,4 @@ For advanced users who want to customize the install process:
|
||||
.. _Ninja: https://ninja-build.org/
|
||||
.. _Python: https://www.python.org/downloads/windows/
|
||||
.. _Git for Windows: https://gitforwindows.org/
|
||||
.. _Github Desktop: https://desktop.github.com/
|
||||
.. _Github Desktop: https://desktop.github.com/
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
.. note:: Since ESP-IDF V4.0, the default build system is based on CMake. This documentation is for the legacy build system based on GNU Make. Support for this build system may be removed in future major releases.
|
||||
@@ -0,0 +1,4 @@
|
||||
Migrate Build System to ESP-IDF 5.0
|
||||
===================================
|
||||
|
||||
Please follow the :ref:`build system <migrating_from_make>` guide for migrating make-based projects no longer supported in ESP-IDF v5.0.
|
||||
@@ -6,3 +6,4 @@ ESP-IDF 5.0 Migration Guides
|
||||
:maxdepth: 1
|
||||
|
||||
Peripherals <peripherals>
|
||||
Build System <build-system>
|
||||
|
||||
@@ -225,7 +225,7 @@ How To Enable Secure Boot V2
|
||||
|
||||
5. Set other menuconfig options (as desired). Pay particular attention to the "Bootloader Config" options, as you can only flash the bootloader once. Then exit menuconfig and save your configuration.
|
||||
|
||||
6. The first time you run ``make`` or ``idf.py build``, if the signing key is not found then an error message will be printed with a command to generate a signing key via ``espsecure.py generate_signing_key``.
|
||||
6. The first time you run ``idf.py build``, if the signing key is not found then an error message will be printed with a command to generate a signing key via ``espsecure.py generate_signing_key``.
|
||||
|
||||
.. important::
|
||||
A signing key generated this way will use the best random number source available to the OS and its Python installation (`/dev/urandom` on OSX/Linux and `CryptGenRandom()` on Windows). If this random number source is weak, then the private key will be weak.
|
||||
@@ -366,7 +366,7 @@ The following sections contain low-level reference descriptions of various Secur
|
||||
Manual Commands
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
Secure boot is integrated into the esp-idf build system, so ``make`` or ``idf.py build`` will sign an app image and ``idf.py bootloader`` will produce a signed bootloader if secure signed binaries on build is enabled.
|
||||
Secure boot is integrated into the esp-idf build system, so ``idf.py build`` will sign an app image and ``idf.py bootloader`` will produce a signed bootloader if secure signed binaries on build is enabled.
|
||||
|
||||
However, it is possible to use the ``espsecure.py`` tool to make standalone signatures and digests.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user