When the CAN transceivers are not connected or in a error state the CAN transmit part of the driver emits continuous debug prints. This causes a debug UART port ownership issue and a race condition between SPE and BLs, breaking the flashing process.
One way to solve such a problem is to rate-limit or disable the debug messages from tegra-can.c. Specifically, rate-limit or disable the messages from tegra_can_irq_handler() and tegra_add_msg_ctlr_list().
tegra_can_irq_handler() has many if conditions which test various interrupt status bits, but when the CAN transceivers are not connected the function mainly prints debug messages from the if((ir & MIT_IR_PED_MASK) || (ir & MIT_IR_PEA_MASK)) block. Rate-limiting such debug messages with a simple counter, or commenting them out, generally solves the issue. Below are the changes you can experiment with in ADDITION to above changes in tegra-can.c file.
- Add line $(FREERTOS_COMMON_DIR)/code-common/irqapi-cortex-r5.c \ in Makefile to compile irqapi-cortex-r5.c.
$(FREERTOS_COMMON_DIR)/code-common/irqapi-vic.c \
-
$(FREERTOS_COMMON_DIR)/code-common/irqapi-cortex-r5.c \ $(FREERTOS_COMMON_DIR)/code-common/tke-tegra.c \
- Rate limit error debug messages or remove them completely both in the can-app.c.
case MTTCAN_MSG_BERR_CHG:
if (i++ < PRINTF_RATE_LIMIT)
printf(“Bus Error\r\n”);
Or
you can remove “Bus Error” line completely.