Esp32 CAN Bus message not receiving in platformio (but works in Arduino IDE)

Update: Solved - in platformio I had a library that the code wasn’t using but it must have redefined something critical:

lib_deps =
    git@github.com:sandeepmistry/arduino-CAN.git

Original Post:
I suspect this is a build flag or platform version issue but I need help tracking it down.

The sample below compiles, uploads and runs fine in both IDEs but only arduino prints out the Received: <frameid> message in loop() in response to a CAN message from another device on my can bus.

#include <Arduino.h>
#include <driver/can.h>
#include <driver/gpio.h>

void setup_can() {

    can_general_config_t general_config = {
        .mode = CAN_MODE_NORMAL,
        .tx_io = (gpio_num_t)GPIO_NUM_5,
        .rx_io = (gpio_num_t)GPIO_NUM_4,
        .clkout_io = (gpio_num_t)CAN_IO_UNUSED,
        .bus_off_io = (gpio_num_t)CAN_IO_UNUSED,
        .tx_queue_len = 5,
        .rx_queue_len = 5,
        .alerts_enabled = CAN_ALERT_ALL,
        .clkout_divider = 0,
    };

    can_timing_config_t timing_config = CAN_TIMING_CONFIG_250KBITS();
    can_filter_config_t filter_config = CAN_FILTER_CONFIG_ACCEPT_ALL();
    esp_err_t error;

    error = can_driver_install(&general_config, &timing_config, &filter_config);

    if(error == ESP_OK) {
        Serial.println("CAN Driver Istalllation OK");
    } else {
        Serial.println("CAN Driver Istalllation Failed");
    }

    error = can_start();

    if(error == ESP_OK) {
        Serial.println("CAN Driver Start OK");
    } else {
        Serial.println("CAN Driver Start Failed");
    }

}

void setup() {
    Serial.begin(115200);
    delay(1000);

    setup_can();
}

void loop() {
    can_message_t rx_frame;

    if (can_receive(&rx_frame, pdMS_TO_TICKS(1000))==ESP_OK) {
        Serial.print("Received: ");
        Serial.println(rx_frame.identifier);
    } else {
        Serial.print(".");
    }
}
  • In Arduino
    • boardmanager url - https://dl.espressif.com/dl/package_esp32_index.json
    • installed latest 1.0.4 of arduino-esp32
      • xtensa-esp32-elf-gcc 1.22
      • esptool_py 2.6.1
      • mkspiffs 0.2.3
  • In Platformio
    • espressif32 @ 2.1.0 (latest)
    • toolchain-xtensa32 @ ~2.50200.0
    • tool-esptoolpy @ ~1.30000.0
    • framework-arduinoespressif32 @ ~3.10004.191002

I can’t see where platformio references the arduino-esp32 version which I assume it is using. Any suggestions on how to get this sample working in platformio?

The 10004 is semver-encoded 1.0.4, the latest stable released version.

Marking as solved per

Interesting, not directly related … I had used a structure initialization like that when initialising the ledc peripheral… using that .fieldname approach and it wouldn’t compile, spitting out an error which I can’t remember, but had to solve by addressing each element using structname.fieldname =.