ESP8266_RTOS_SDK V3を使ってみる

IDF_PATH環境変数


ESP8266_RTOS_SDKをインストールする際にIDF_PATH環境変数を設定します。
この変数をだれがどのように使うのか、すごく疑問でしたが、こ ちらのページに説明が有りました。

出展:https://docs.espressif.com/projects/esp-idf/en/latest/api-guides /build-system.html

“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.

最近はGoogle翻訳ばかり使っています。

「ESP-IDF」はプロジェクトの一部ではありません。代わりにそれはスタンドアロンで、esp-idfディレクトリのパスを保持する IDF_PATH環境変数を介してプロジェクトにリンクされています。
これにより、IDFフレームワークをプロジェクトから切り離すことができます。
コンパイルのためのツールチェーンはプロジェクトの一部ではありません。
ツールチェーンは、システムコマンドラインのPATHにインストールする必要があります。または、ツールチェーンへのパスをプロジェクト設定のコ ンパイラプレフィックスの一部として設定できます。

各プロジェクトのMakefileを見るともっとわかります。
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#

PROJECT_NAME := simple_wifi

include $(IDF_PATH)/make/project.mk

Makefileの中で「$(IDF_PATH)/make/project.mk」をincludeしています。
「esp-idfディレクトリのパスを保持する IDF_PATH環境変数を介してプロジェクトにリンクされています」なんて言わないで、
「各プロジェクトのMakefileは IDF_PATH環境変数が示す先のMakefileをincludeしてからビルドを行います」の方が分かりやすいのに...

IDF_PATH環境変数を使うことで、プロジェクトを格納するパスと、IDFフレームワーク(今回はESP8266_RTOS_SDK)を格納 するパスは完全に切り離すことができます。
こ のページの「Development of applications for ESP32」の図も、ESP-IDFとProjectは全く独立しています。

以下のソースはインストールされているコンポーネントのバージョンを表示するコードですが、IDF_PATH環境変数を変えるだけで、
esp8266でもesp32でもビルドできます。
→ESP32-S2のサポート追加に伴い、ESP32の開発環境が大きく変わっています。
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#include "lwip/init.h"

void app_main(void)
{
    printf("IDF version:%s\n", esp_get_idf_version());
    printf("freeRTOS version:%s\n", tskKERNEL_VERSION_NUMBER);
    printf("NEWLIB version:%s\n", _NEWLIB_VERSION);
    printf("lwIP version string:%s\n", LWIP_VERSION_STRING);
    printf("lwIP version:%d-%d-%d-%d\n",
      LWIP_VERSION_MAJOR,LWIP_VERSION_MINOR,
      LWIP_VERSION_REVISION,LWIP_VERSION_RC);
}

続く....