Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32 crashes when irq pin set to -1 and inInterruptServiceRoutine is NULL #40

Open
ElektroBOXua opened this issue Mar 3, 2023 · 1 comment

Comments

@ElektroBOXua
Copy link

ElektroBOXua commented Mar 3, 2023

When there are no IRQ pin specified, acan2515 requires inInterruptServiceRoutine to be NULL

There is no check for mINT != 255 thus this task is still created

    #ifdef ARDUINO_ARCH_ESP32
      xTaskCreate (myESP32Task, "ACAN2515Handler", 1024, this, 256, NULL) ;
    #endif

It also seems that 1024 is not enough stack size for the task on my esp32 because i've got stack cannary watchpoint triggered before noticing the main issue(Probably stack overflow).

After i fixed the problem it appeared that attachMCP2515InterruptPin
attaches NULL to -1 pin which causes crash.

#ifdef ARDUINO_ARCH_ESP32
  static void myESP32Task (void * pData) {
    ACAN2515 * canDriver = (ACAN2515 *) pData ;
    while (1) {
      canDriver->attachMCP2515InterruptPin () ;
      xSemaphoreTake (canDriver->mISRSemaphore, portMAX_DELAY) ;
      bool loop = true ;
      while (loop) {
        loop = canDriver->isr_core () ;
      }
    }
  }
#endif

I tried to remove iterrupt task at all, but then i noticed that there are no mechanisms to poll messages, so it would not work anyway.

I didn't look more throught the code, so i am curious how to use this library without an IRQ pin on ESP32?

@ElektroBOXua
Copy link
Author

ElektroBOXua commented Mar 3, 2023

Oh, i have found a solution for the issue by replacing:

#ifdef ARDUINO_ARCH_ESP32
  void ACAN2515::attachMCP2515InterruptPin (void) {
    attachInterrupt (digitalPinToInterrupt (mINT), mInterruptServiceRoutine, ONLOW) ;
  }
#endif

to

#ifdef ARDUINO_ARCH_ESP32
  void ACAN2515::attachMCP2515InterruptPin (void) {
    if (mINT != 255) {
	attachInterrupt (digitalPinToInterrupt (mINT), mInterruptServiceRoutine, ONLOW) ;
    }
  }
#endif

Also i've noticed that there's a poll function, which is actually what i've needed.
Issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant