|
1 |
| -ESP-IDF as Component |
2 |
| -==================== |
| 1 | +Arduino as a ESP-IDF component |
| 2 | +============================== |
| 3 | + |
| 4 | +ESP32 Arduino lib-builder |
| 5 | +------------------------- |
| 6 | + |
| 7 | +For a simplified method, see `lib-builder <lib_builder>`_. |
| 8 | + |
| 9 | +Installation |
| 10 | +------------ |
| 11 | + |
| 12 | +- Download and install `ESP-IDF <https://github.com/espressif/esp-idf>`_. |
| 13 | +- Create blank idf project (from one of the examples). |
| 14 | +- in the project folder, create a folder called components and clone this repository inside. |
| 15 | + |
| 16 | +.. code-block:: bash |
| 17 | + |
| 18 | + mkdir -p components && \ |
| 19 | + cd components && \ |
| 20 | + git clone https://github.com/espressif/arduino-esp32.git arduino && \ |
| 21 | + cd arduino && \ |
| 22 | + git submodule update --init --recursive && \ |
| 23 | + cd ../.. && \ |
| 24 | + idf.py menuconfig |
| 25 | +
|
| 26 | +
|
| 27 | +- ```idf.py menuconfig``` has some Arduino options |
| 28 | + - "Autostart Arduino setup and loop on boot" |
| 29 | + - If you enable this options, your main.cpp should be formated like any other sketch |
| 30 | + |
| 31 | +.. code-block:: c |
| 32 | +
|
| 33 | + //file: main.cpp |
| 34 | + #include "Arduino.h" |
| 35 | +
|
| 36 | + void setup(){ |
| 37 | + Serial.begin(115200); |
| 38 | + } |
| 39 | +
|
| 40 | + void loop(){ |
| 41 | + Serial.println("loop"); |
| 42 | + delay(1000); |
| 43 | + } |
| 44 | +
|
| 45 | +- Else you need to implement ```app_main()``` and call ```initArduino();``` in it. |
| 46 | + |
| 47 | +Keep in mind that setup() and loop() will not be called in this case. |
| 48 | +If you plan to base your code on examples provided in `examples <https://github.com/espressif/esp-idf/tree/master/examples>`_, please make sure move the app_main() function in main.cpp from the files in the example. |
| 49 | + |
| 50 | +.. code-block:: cpp |
| 51 | +
|
| 52 | + //file: main.cpp |
| 53 | + #include "Arduino.h" |
| 54 | +
|
| 55 | + extern "C" void app_main() |
| 56 | + { |
| 57 | + initArduino(); |
| 58 | + pinMode(4, OUTPUT); |
| 59 | + digitalWrite(4, HIGH); |
| 60 | + //do your own thing |
| 61 | + } |
| 62 | +
|
| 63 | +- "Disable mutex locks for HAL" |
| 64 | +- If enabled, there will be no protection on the drivers from concurently accessing them from another thread/interrupt/core |
| 65 | + - "Autoconnect WiFi on boot" |
| 66 | +- If enabled, WiFi will start with the last known configuration |
| 67 | +- Else it will wait for WiFi.begin |
| 68 | + |
| 69 | +- ```idf.py -p <your-board-serial-port> flash monitor``` will build, upload and open serial monitor to your board |
| 70 | + |
| 71 | +Logging To Serial |
| 72 | +----------------- |
| 73 | + |
| 74 | +If you are writing code that does not require Arduino to compile and you want your `ESP_LOGx` macros to work in Arduino IDE, you can enable the compatibility by adding the following lines after your includes: |
| 75 | + |
| 76 | +.. code-block:: c |
| 77 | +
|
| 78 | + #ifdef ARDUINO_ARCH_ESP32 |
| 79 | + #include "esp32-hal-log.h" |
| 80 | + #endif |
| 81 | +
|
| 82 | +FreeRTOS Tick Rate (Hz) |
| 83 | +----------------------- |
| 84 | + |
| 85 | +You might notice that Arduino-esp32's `delay()` function will only work in multiples of 10ms. That is because, by default, esp-idf handles task events 100 times per second. |
| 86 | +To fix that behavior you need to set FreeRTOS tick rate to 1000Hz in `make menuconfig` -> `Component config` -> `FreeRTOS` -> `Tick rate`. |
| 87 | + |
| 88 | +Compilation Errors |
| 89 | +------------------ |
| 90 | + |
| 91 | +As commits are made to esp-idf and submodules, the codebases can develop incompatibilities which cause compilation errors. If you have problems compiling, follow the instructions in `Issue #1142 <https://github.com/espressif/arduino-esp32/issues/1142>`_ to roll esp-idf back to a known good version. |
0 commit comments