Platformio.ini esp32-gateway revision

Hello,

I have a broad Olimex ESP32 Gateway and I don’t know how I can set the board revision in platformio.ini file. I need to set Revision F and this settings is available in Arduino IDE.

Thank you.

Regards,
Radu Paraleste

It looks like the board revision menu option in the Arduino IDE defines ARDUINO_ESP32_GATEWAY (actually, ESP32_GATEWAY, but the Arduino IDE then adds ARDUINO_ to the front of that) to either be either C, E or F depending on the option selected, which is then used in pins_arduino.h to change some stuff depending on board revision. It may also be used elsewhere, but that was all a quick glance through the files showed up.

You should be able add build_flags = -D ARDUINO_ESP32_GATEWAY=F to your projects platformio.ini to reproduce that behaviour on PlatformIO. More info on setting build flags is here.

Hello,

Thank you for you fast answer. I tried to add build_flags = -D ARDUINO_ESP32_GATEWAY=F but is not working as expected. When I run the build I’m receiving an warning for this flag:
> Compiling .pio\build\esp32-gateway\src\main.cpp.o
> :0:0: warning: “ARDUINO_ESP32_GATEWAY” redefined
> :0:0: note: this is the location of the previous definition

I need to add this flag because I have issues with two plugins for ETH and SD Card.

For SD Card I use this script to test and on Arduino IDE works without errors.

And for ETC I use this script which also works without errors.
https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/ETH_LAN8720/ETH_LAN8720.ino

Thank you!

Hm… annoying. Try adding -U ARDUINO_ESP32_GATEWAY to the build_flags to clear it since it looks like something else is setting it … i.e. build_flags = -U ARDUINO_ESP32_GATEWAY -D ARDUINO_ESP32_GATEWAY=F

Those errors would be right… if you have a board revision D or later, some ethernet stuff is set…

#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT
#define ETH_PHY_POWER 5

and if you have F or later, this SD flag is set…

#define BOARD_HAS_1BIT_SDMMC

So it looks like if you use either SD or ETH and the revision isn’t set right, things will break :wink:

I added build_flags = -U ARDUINO_ESP32_GATEWAY -D ARDUINO_ESP32_GATEWAY=F and now I’m receiving the following error:
:0:1: error: macro names must be identifiers
:0:2: warning: extra tokens at end of #undef directive

Please do the following:

Create a folder boards/ in your project.

Create a new file esp32-gateway-rev-f.json inside that folder.

Fill it with the contents of platform-espressif32/esp32-gateway.json at develop · platformio/platform-espressif32 · GitHub.

But then change the line

    "extra_flags": "-DARDUINO_ESP32_GATEWAY",

to

    "extra_flags": "-DARDUINO_ESP32_GATEWAY='F'",

Adapt your platformio.ini to now use

board = esp32-gateway-rev-f

This basically creates a new board definition with the correct macro value.

1 Like

Thank you for your answer. I managed to follow your instructions but I’m still getting the same errors when I’m trying to test if ETH and SD Card works on PlatformIo.

ETH Error:
E (1040) emac: Timed out waiting for PHY register 0x2 to have value 0x0007(mask 0xffff). Current value 0xffff
E (2041) emac: Timed out waiting for PHY register 0x3 to have value 0xc0f0(mask 0xfff0). Current value 0xffff
E (2042) emac: Initialise PHY device Timeout
[E][ETH.cpp:101] begin(): esp_eth_enable error: -1

SD Card error:
E (80) sdmmc_sd: sdmmc_check_scr: send_scr returned 0xffffffff
[E][SD_MMC.cpp:78] begin(): Failed to mount filesystem. If you want the card to be formatted, set format_if_mount_failed = true.

On Arduino IDE both scripts works properly. Any ideas what else I have to do in PlatformIo to make both ETH and SD Card running?

Thank you!

Okay so let’s make double sure that all the pin settings are now properly done.

Can you please add the following block of code below the sketch’s Serial.begin(115200); line (in e.g. the Ethernet sketch)

	Serial.println("ETH_CLK_MODE: Is: " + String((int)ETH_CLK_MODE) + " Expected: " + String((int)(ETH_CLOCK_GPIO17_OUT)));
	Serial.println("ETH_PHY_POWER: " + String(ETH_PHY_POWER));
	#ifdef BOARD_HAS_1BIT_SDMMC
	Serial.println("BOARD_HAS_1BIT_SDMMC enabled");
	#else
	Serial.println("BOARD_HAS_1BIT_SDMMC disabled");		
	#endif

and post the output

TH_CLK_MODE: Is: 0 Expected: 3
ETH_PHY_POWER: -1
BOARD_HAS_1BIT_SDMMC disabled
E (1041) emac: Timed out waiting for PHY register 0x2 to have value 0x0007(mask 0xffff). Current value 0xffff
E (2042) emac: Timed out waiting for PHY register 0x3 to have value 0xc0f0(mask 0xfff0). Current value 0xffff
E (2043) emac: Initialise PHY device Timeout
[E][ETH.cpp:101] begin(): esp_eth_enable error: -1

YIkes all of these are wrong. What is the exact content of your platformio.ini?

1 Like

platformio.ini

[env:esp32-gateway]
platform = espressif32
board = esp32-gateway-rev-f
framework = arduino
monitor_speed = 19200
monitor_port = COM[6]
lib_deps =
  RTC
  ArduinoJson
  ArduinoMqttClient

esp32-gateway-rev-f.json

{
   "build": {
      "arduino":{
        "ldscript": "esp32_out.ld"
      },
      "core": "esp32",
      "extra_flags": "-DARDUINO_ESP32_GATEWAY='F'",
      "f_cpu": "240000000L",
      "f_flash": "40000000L",
      "flash_mode": "dio",
      "mcu": "esp32",
      "variant": "esp32-gateway"
    },
    "connectivity": [
      "wifi",
      "bluetooth",
      "ethernet",
      "can"
    ],
    "debug": {
      "openocd_board": "esp-wroom-32.cfg"
    },
    "frameworks": [
      "arduino",
      "espidf"
    ],
    "name": "OLIMEX ESP32-GATEWAY",
    "upload": {
      "flash_size": "4MB",
      "maximum_ram_size": 327680,
      "maximum_size": 4194304,
      "require_upload_port": true,
      "speed": 460800
    },
    "url": "https://www.olimex.com/Products/IoT/ESP32-GATEWAY/open-source-hardware",
    "vendor": "OLIMEX"
  }

Looks good but still not working apparently. I’ll check on my ESP32 board.

There is a problem defining ARDUINO_ESP32_GATEWAY to a character value, -DARDUINO_ESP32_GATEWAY='F' doesn’t work, it evaluates it to F and not 'F'. Well, as a quick workaround we can just use the numerical value of the ASCII ‘F’ character, which is 70. Can you modify the board json file to say

      "extra_flags": "-DARDUINO_ESP32_GATEWAY=70",

and retry compilation?

1 Like

It works! Many thanks @maxgerhardt.

1 Like