xTaskCreatePinnedToCore doesn't return after starting task
Posted: Sat Aug 26, 2023 3:19 am
I have a really odd story I need help with. I'm using an ESP32 with CAN Bus to emulate a CAN Bus device in my truck so that I can do development on a different board without having to buy two of the expensive vehicle boxes. It has been working great for the past 18 months. For the CAN stuff I've been using Collin Kidder's esp32_can and can_common libraries. Until last week I had been doing all my development work on an older Arduino IDE (1.8.13). Last week I decided to upgrade to 2.1.1. Along with that came, I believe, upgraded compiler and other tools. And my application broke. It crashed on a completely (to me) innocuous line in can_common. I upgraded both libraries to the lastest. They are fairly significantly changed because he's using the official TWAI drivers now. No more crash but now it hangs. I struggled for a bit then decided maybe I'd have better luck with a different IDE and compiler and I switched to VSCode with ESP-IDF (and have also tried platformio). I know where the problem is but I can't for the life of me figure out why.
esp_can_builtin.cpp has this code:
The xTaskCreate goes fine. The first xTaskCreatePinnedToCore hangs. Sort of. I stuck a print statement in task_LowLevelRX and it is running just fine. But for some reason xTaskCreatePinnedToCore isn't returning so the next xTaskCreatePinnedToCore never runs.
Here's that task:
To make things even more mysterious, I get the same behavior on two different brands of boards (Fusion and SKPang). And I've talked to Collin and he can't reproduce it. I am also using WiFi in case that matters. The Fusion board uses pins 4 and 5 for CAN and pin 16 has to be pulled low. The other board is 24 and 25 and no other pins are involved and I'm not using any other pins for anything.
Anyone have any idea why xTaskCreatePinnedToCore wouldn't return after it starts the task?
esp_can_builtin.cpp has this code:
Code: Select all
// func desc stack, params, priority, handle to task
xTaskCreate(&task_CAN, "CAN_RX", 8192, this, 15, NULL);
// this next task implements our better filtering on top of the TWAI library. Accept all frames then filter in here VVVVV
xTaskCreatePinnedToCore(&task_LowLevelRX, "CAN_LORX", 8192, this, 19, NULL, 1);
xTaskCreatePinnedToCore(&CAN_WatchDog_Builtin, "CAN_WD_BI", 4096, this, 10, NULL, 1);
initializedResources = true;
Here's that task:
Code: Select all
void task_LowLevelRX(void *pvParameters)
{
ESP32CAN *espCan = (ESP32CAN *)pvParameters;
while (1)
{
twai_message_t message;
if (twai_receive(&message, pdMS_TO_TICKS(100)) == ESP_OK)
{
espCan->processFrame(message);
}
}
}
Anyone have any idea why xTaskCreatePinnedToCore wouldn't return after it starts the task?