Open zevv opened 2 years ago
It happens at our setup as well. Assert in twai.c line 189. It happens during busoff quite often. IDF 4.3, almost latest (dd62e3bb9bee4fed7f1a20922d6c0378fc45eb27). Our idea is that it happens when user calls twai_initiate_recovery() after busoff event while frames are awaiting in the tx queue. tx_msg_count gets zeroed in twai_initiate_recovery() and this causes the assert in the interrupt handler that checks if this same message count is zero. A way to solve it is to set object state in twai_initiate_recovery() BEFORE zeroing msg count:
esp_err_t twai_initiate_recovery(void)
{
TWAI_ENTER_CRITICAL();
//Check state
TWAI_CHECK_FROM_CRIT(p_twai_obj != NULL, ESP_ERR_INVALID_STATE);
TWAI_CHECK_FROM_CRIT(p_twai_obj->state == TWAI_STATE_BUS_OFF, ESP_ERR_INVALID_STATE);
p_twai_obj->state = TWAI_STATE_RECOVERING;
//Reset TX Queue/Counters
if (p_twai_obj->tx_queue != NULL) {
xQueueReset(p_twai_obj->tx_queue);
}
p_twai_obj->tx_msg_count = 0;
//Trigger start of recovery process
twai_hal_start_bus_recovery(&twai_context);
TWAI_EXIT_CRITICAL();
return ESP_OK;
}
And then check object stat in interrupt handler, in twai_handle_tx_buffer_frame() and simply return if in recovering.
Please confirm.
Thanks, Viktor
Environment
chip ESP32-D0WD idf 4.3 custom board
Problem Description
Our application occasionaly crashes because of a failed assertion in
twai_handle_tx_buffer_frame()
.Expected Behavior
Program does not crash on assertions in interrupt handlers :)
Actual Behavior
During normal program operation the application gets aborted on an assertion with the below stack trace.
Steps to reproduce
We are not sure yet what triggers this situation, as it is hard to reproduce. If I find a way to reproduce I can try to provide a minimal application showing the behavior, but it is likely related to other traffic on the bus.
Debug Logs