From 9ebbc58930400270e8ebe4da42d3de8289ec47fb Mon Sep 17 00:00:00 2001 From: Bernhard Kirchen Date: Tue, 27 Aug 2024 21:16:48 +0200 Subject: [PATCH] Fix: Pylontech/Pytes CAN driver: user interrupts at level 2 we are running out of level 1 interrupts on ESP32-S3 boards. for that reason, until this prooves to be another sort of problem, we allocate the TWAI's interrupt for the battery CAN implementation at level 2. --- src/BatteryCanReceiver.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/BatteryCanReceiver.cpp b/src/BatteryCanReceiver.cpp index aca563bb..90ea7b33 100644 --- a/src/BatteryCanReceiver.cpp +++ b/src/BatteryCanReceiver.cpp @@ -26,6 +26,15 @@ bool BatteryCanReceiver::init(bool verboseLogging, char const* providerName) auto rx = static_cast(pin.battery_rx); twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(tx, rx, TWAI_MODE_NORMAL); + // interrupts at level 1 are in high demand, at least on ESP32-S3 boards, + // but only a limited amount can be allocated. failing to allocate an + // interrupt in the TWAI driver will cause a bootloop. we therefore + // register the TWAI driver's interrupt at level 2. level 2 interrupts + // should be available -- we don't really know. we would love to have the + // esp_intr_dump() function, but that's not available yet in our version + // of the underlying esp-idf. + g_config.intr_flags = ESP_INTR_FLAG_LEVEL2; + // Initialize configuration structures using macro initializers twai_timing_config_t t_config = TWAI_TIMING_CONFIG_500KBITS(); twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();