Skip to content

Latest commit

 

History

History
173 lines (116 loc) · 4.92 KB

T2.md

File metadata and controls

173 lines (116 loc) · 4.92 KB

Migrating from PlatformIO to ESP8266 RTOS SDK

This guide will walk you through the process of transitioning your existing PlatformIO project with a single main file to an ESP8266 RTOS SDK project.

1. Install the Toolchain

First, ensure you have the ESP8266 RTOS SDK toolchain installed.

For Windows:

  1. Download the toolchain (v8.4.0) from the official Espressif website.
  2. Extract the downloaded zip file to a directory of your choice (e.g., C:\esp\).

For macOS and Linux:

  1. Open a terminal window.
  2. Run the following commands:
mkdir -p ~/esp
cd ~/esp
wget https://dl.espressif.com/dl/xtensa-lx106-elf-gcc8_4_0-esp-2020r3-macos.tar.gz
tar -xzf xtensa-lx106-elf-gcc8_4_0-esp-2020r3-macos.tar.gz

Note: Replace the URL with the appropriate one for your operating system (Linux 64-bit or 32-bit).

2. Add Toolchain to PATH

Add the toolchain's bin directory to your PATH environment variable.

For Windows:

  1. Open the Start menu and search for "Environment Variables".
  2. Click on "Edit the system environment variables".
  3. Click the "Environment Variables" button.
  4. Under "System variables", find the "Path" variable and click "Edit".
  5. Click "New" and add the path to your toolchain's bin directory (e.g., C:\esp\xtensa-lx106-elf\bin).
  6. Click "OK" to save the changes.

For macOS and Linux:

Add the following line to your ~/.profile or ~/.bash_profile file:

export PATH="$PATH:$HOME/esp/xtensa-lx106-elf/bin"

Then, reload the profile by running:

source ~/.profile

3. Get ESP8266_RTOS_SDK

Download the ESP8266 RTOS SDK:

cd ~/esp
git clone https://github.com/espressif/ESP8266_RTOS_SDK.git

4. Set up IDF_PATH

Set the IDF_PATH environment variable to point to the ESP8266_RTOS_SDK directory:

For Windows:

  1. Follow the same steps as adding to PATH, but instead of editing "Path", create a new system variable.
  2. Set the variable name as IDF_PATH and the value as the path to your SDK directory (e.g., C:\esp\ESP8266_RTOS_SDK).

For macOS and Linux:

Add the following line to your ~/.profile or ~/.bash_profile file:

export IDF_PATH="$HOME/esp/ESP8266_RTOS_SDK"

Then, reload the profile:

source ~/.profile

5. Create a New ESP8266 RTOS SDK Project

Now, let's create a new ESP8266 RTOS SDK project and migrate your PlatformIO code:

  1. Create a new directory for your ESP8266 RTOS SDK project:
mkdir ~/esp/my_esp_project
cd ~/esp/my_esp_project
  1. Copy the example project structure:
cp -r $IDF_PATH/examples/get-started/hello_world/* .
  1. Replace the contents of main/hello_world_main.c with your PlatformIO main file:
cp /path/to/your/platformio/project/src/main.cpp main/hello_world_main.c
  1. Modify your main file:
    • Change the file extension from .cpp to .c if you're using C++.
    • Replace #include <Arduino.h> with #include "esp_common.h" and #include "esp_system.h".
    • Replace Arduino-specific functions with ESP8266 RTOS SDK equivalents. For example:
      • Serial.begin(115200); becomes uart_init_new();
      • Serial.println(); becomes printf();
    • Wrap your setup() and loop() functions in a task:
void app_main(void)
{
    // Your setup code here

    while(1) {
        // Your loop code here
        vTaskDelay(10 / portTICK_PERIOD_MS);
    }
}
  1. Update CMakeLists.txt in the main directory:

    • If you've added any new source files, add them to the SRCS list.
    • If you're using C++, change hello_world_main.c to hello_world_main.cpp.
  2. Configure your project:

make menuconfig
  1. Build the project:
make all
  1. Flash the project to your ESP8266 (replace /dev/ttyUSB0 with your actual serial port):
make flash ESPPORT=/dev/ttyUSB0
  1. Monitor the output:
make monitor ESPPORT=/dev/ttyUSB0

6. Adapting PlatformIO Libraries

If your PlatformIO project uses external libraries, you'll need to port them to work with ESP8266 RTOS SDK:

  1. Check if the library is available for ESP8266 RTOS SDK. If so, you can include it in your project's components directory.

  2. If not, you may need to adapt the library yourself:

    • Copy the library files into a new directory under components/.
    • Create a CMakeLists.txt file in the library directory to define it as a component.
    • Modify the library code to use ESP8266 RTOS SDK APIs instead of Arduino APIs.
  3. Update your main code to include the adapted library headers.

Remember that migrating from PlatformIO to ESP8266 RTOS SDK often requires significant code changes due to differences in the underlying frameworks. You may need to rewrite portions of your code to work with the ESP8266 RTOS SDK APIs.

This process provides a starting point for migrating your project. Depending on the complexity of your PlatformIO project, you may need to make additional adjustments to fully port your application to the ESP8266 RTOS SDK environment.