Skip to content

Commit a0e22db

Browse files
aentingerfacchinm
authored andcommitted
Configure the correct global error channel upon CANx.begin().
1 parent d008b9b commit a0e22db

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

libraries/CAN/src/R7FA6M5_CAN.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ bool R7FA6M5_CAN::begin(CanBitRate const /* can_bitrate */)
116116
int const max_index = g_pin_cfg_size / sizeof(g_pin_cfg[0]);
117117
auto [cfg_init_ok, cfg_channel] = cfg_pins(max_index, _can_tx_pin, _can_rx_pin);
118118
init_ok &= cfg_init_ok;
119-
_canfd_cfg.channel = cfg_channel;
119+
_canfd_cfg.channel = cfg_channel;
120120

121121
/* Configure the interrupts.
122122
*/
@@ -127,6 +127,19 @@ bool R7FA6M5_CAN::begin(CanBitRate const /* can_bitrate */)
127127
};
128128
init_ok &= IRQManager::getInstance().addPeripheral(IRQ_CANFD, &irq_req);
129129

130+
/* There is only one global error channel shared between both CAN0 and CAN1
131+
* peripheral. If you are using e2Studio the error channel is configured via
132+
* a project-wide define, however this is an issue for as as we do not know
133+
* if both CAN instances are actually going to be used by the end-user. It may
134+
* happen that only CAN1.begin() is called, if in this scenario CAN0 is configured
135+
* as the source of the global error channel a hard-fault occurs as soon as
136+
* an error occurs (this is a design-issue with the FSP layer). The line below
137+
* ensures that there's always a valid error channel and that no hard-fault
138+
* can occur.
139+
*/
140+
_canfd_extended_cfg.global_err_channel = cfg_channel;
141+
142+
/* Initialize the peripheral's FSP driver. */
130143
if (R_CANFD_Open(&_canfd_ctrl, &_canfd_cfg) != FSP_SUCCESS)
131144
init_ok = false;
132145

0 commit comments

Comments
 (0)