It is almost 5 years had passed, but I'll leave a comment in case someone would bump into this topic.
@PKavv.1wrote:
> TX FIFO is always filling up and the bus stops after 127 errors
It is correct behavior called BusOff, when there is "nobody" on the bus to receive a message. I assume that CAN controller has AutoRetransmission enabled, so it will keep trying to send message until BusOff occurred. Although FDCAN controller can't leave BusOff state by itself, so MCU need to handle that. Register `HAL_FDCAN_ErrorStatusCallback` via `HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_BUS_OFF, 0)`
during fdcan initialization. There was other topic with example, but here is the copy of the callback itself:
static void check_can_bus(FDCAN_HandleTypeDef *hfdcan)
{
FDCAN_ProtocolStatusTypeDef protocolStatus = {};
HAL_FDCAN_GetProtocolStatus(hfdcan, &protocolStatus);
if (protocolStatus.BusOff) {
CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT);
}
}
void HAL_FDCAN_ErrorStatusCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t ErrorStatusITs)
{
if (hfdcan == &hfdcan1) {
if ((ErrorStatusITs & FDCAN_IT_BUS_OFF) != RESET) {
check_can_bus(hfdcan);
}
}
}
IIRC, doing that will drop frames already in the queues, but it is fine, because in other case they would become outdated. However consider disabling AutoRetransmission, because there is still a chance for a frame to become outdated. By doing that frame is dropped if CAN controller failed to send it due to any problem, but such approach require complex handling via `HAL_FDCAN_TxBufferCompleteCallback`.
> The workaround I have is to abort the TX request.
That is legal solution, one of actually. Don't know what is Your app is doing, but if it is, for example, data from some sensor, then it shouldn't be sent over CAN, if nobody would receive it. Also, as @Karl Yamashita suggested, it make sense to implement sort of a handshake between nodes. If Jetson is the main one, then it can manage registration and so on.
@seppeltronics_vwrote:
> how to set up the CAN-Controller properly
STM32CubeIDE should have done all set up properly by default. If TX is working for You then everything is set up correctly.
> I do not get any RX Callback
Try to use `HAL_FDCAN_GetRxMessage(&hfdcan1, FDCAN_RX_FIFO0, &RxHeader, data)` from the main loop (pay attention to correct fdcan handler). To use RX callback one needed to be registered and enabled.
Cheers.