Skip to content

Guru Meditation Error due to incorrect pin declaration for ESP32-C3 #90

@brightproject

Description

@brightproject

I used this library with the ESP32-S3 and SN65HVD230D.
To define the CTX and CRX pins, I did this:

CAN0.setCANPins(GPIO_NUM_3, GPIO_NUM_4);

The code worked perfectly.
This didn't work for the ESP32-C3 microcontroller. The code compiled, but when running, it generated an intermittent serial port error, causing the microcontroller to reboot:

Guru Meditation Error: Core 0 panicked (Load access fault). Exception was unhandled.
Core 0 register dump:
MEPC: 0x4200204a RA: 0x42006726 SP: 0x3fc990e0 GP: 0x3fc8da00
Stack memory:
3fc990e0: 0x00000000 0x3c04d000 0x00000000 0x420024e8 0x00000000 0x3fc8f000

The pseudocode is:

#include <esp32_can.h>

TaskHandle_t canRXHandle = NULL;
TaskHandle_t canTXHandle = NULL;

CAN_FRAME message;

static void twai_receive_task(void *arg)
{

  twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(GPIO_NUM_4, GPIO_NUM_5, TWAI_MODE_NORMAL);
  // twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT((gpio_num_t)D2, (gpio_num_t)D3, TWAI_MODE_LISTEN_ONLY);
  twai_timing_config_t t_config = TWAI_TIMING_CONFIG_500KBITS();
  twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();

  // Install TWAI driver
  if (twai_driver_install(&g_config, &t_config, &f_config) == ESP_OK)
  {
    printf("Driver installed\n");
  }
  else
  {
    printf("Failed to install driver\n");
    return;
  }
  // Start TWAI driver
  if (twai_start() == ESP_OK)
  {
    printf("Driver started\n");
  }
  else
  {
    printf("Failed to start driver\n");
    return;
  }

  // while (1)
  while (true)
  {
    twai_message_t message;
    if (twai_receive(&message, pdMS_TO_TICKS(10000)) == ESP_OK)
    {
      //printf("Message received\n");
      // Process received message
     /* if (message.extd)
      {
        printf("Message is in Extended Format\n");
      }
      else
      {
        printf("Message is in Standard Format\n");
      }*/
      printf("0x%03x :", message.identifier);
      if (!(message.rtr))
      {
        for (int i = 0; i < message.data_length_code; i++)
        {
          printf("0x%02x ", message.data[i]);
        }
        printf("\n");
      }
    }
    vTaskDelay(5 / portTICK_RATE_MS);
  }
}

void canTX(void *pvParameters) {
CAN0.setCANPins(GPIO_NUM_4, GPIO_NUM_5); 

  if(CAN0.begin(500000)) 
  { 
  Serial.println("Builtin CAN Init OK"); 
  } else { 
  Serial.println("BuiltIn CAN Init Failed"); 
  } 

  while (true) { 
  message.id = HEADING_ANGLE_ID; 
  message.length = 8; 
  message.extended = false; 
  message.data.byte[0] = 0x01; // flag for ADC 
  // message.data.byte[1] = BaroCorrQnh; 
  // message.data.byte[2] = BaroCorrQnh >> 8; 
  // CAN0.sendFrame(message); 
  
  CAN0.sendFrame(message);
  
  vTaskDelay(5 / portTICK_PERIOD_MS); 
  }
}

void setup(void) {
  Wire.begin();
  xTaskCreate(&twai_receive_task, "CAN RX Task", 2048 + 1024, NULL, 5, &canRXHandle);
  // xTaskCreate(canTX, "CAN TX Task", 2048 + 1024, NULL, 2, &canTXHandle);
}

void loop(void) {
// NOTHING
}

When you use twai_general_config_t and specify:

twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT((gpio_num_t)D2, (gpio_num_t)D3, TWAI_MODE_NORMAL);

Then there are no reboots or errors.
For the esp32_can library, specifying pins like this doesn't help:

// CAN0.setCANPins(GPIO_NUM_4, GPIO_NUM_5);
CAN0.setCANPins((gpio_num_t)D2, (gpio_num_t)D3);

The error is similar to those that occur when specifying the following in the ESP IDF:

twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT((gpio_num_t)D2, (gpio_num_t)D3, TWAI_MODE_LISTEN_ONLY);

I think we need to consider adapting the esp32_can library for the RISK-V esp32-c3 microcontroller.😀

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions