Description
Describe the bug
When building for the NXP MKV56F24 SoC (e.g., nxp_kv56f1m0vlx24
), the MCUX FlexCAN driver (fsl_flexcan.c
) fails to compile because the device header (MKV56F24.h
) incorrectly defines FLEXCAN2
as CAN2
, even though this SoC only has two FlexCAN instances (CAN0
, CAN1
).
Incorrect define in MKV56F24.h
:
#define FLEXCAN0 CAN0
#define FLEXCAN1 CAN1
#define FLEXCAN2 CAN2 /* <-- Should NOT exist for MKV56F24 */
Error output:
error: 'CAN2' undeclared (first use in this function); did you mean 'CAN0'?
s_flexcanIsr(FLEXCAN2, s_flexcanHandle[2]);
The SoC feature macros are otherwise correct:
#define FSL_FEATURE_SOC_FLEXCAN_COUNT 2
Expected behavior
FLEXCAN2
should not be defined inMKV56F24.h
for a SoC with only 2 FlexCAN instances.- CAN2 IRQ handlers in
fsl_flexcan.c
should compile only when:
#if (FSL_FEATURE_SOC_FLEXCAN_COUNT > 2)
Root cause
- The MCUXpresso device header (
MKV56F24.h
) incorrectly definesFLEXCAN2
asCAN2
, even though the peripheral does not exist. - Because
FLEXCAN2
is defined, the FlexCAN driver incorrectly assumes CAN2 is present and compiles the extra IRQ handler (CAN_FD2_DriverIRQHandler
), which fails.
Correct behavior should be:
#define FLEXCAN0 CAN0
#define FLEXCAN1 CAN1
/* FLEXCAN2 should NOT be defined */
Workaround
Add the following to the board’s CMakeLists.txt
:
# Workaround: prevent build failure by assigning a dummy value to CAN2.
# This compiles a dead IRQ handler but avoids modifying the SDK.
zephyr_compile_definitions(CAN2=0)
Proposed fix
The correct fix must be made upstream in the NXP MCUX SDK:
- Remove or conditionally guard the
#define FLEXCAN2 CAN2
inMKV56F24.h
.
For example:
#if (FSL_FEATURE_SOC_FLEXCAN_COUNT > 2)
#define FLEXCAN2 CAN2
#endif
- Optionally, Zephyr could add guards in
fsl_flexcan.c
as a temporary mitigation:
#if (FSL_FEATURE_SOC_FLEXCAN_COUNT > 2)
void CAN_FD2_DriverIRQHandler(void)
{
s_flexcanIsr(FLEXCAN2, s_flexcanHandle[2]);
}
#endif
Steps to reproduce
-
Build any CAN-enabled application for KV56F24:
west build -b nxp_kv56f1m0vlx24 samples/subsys/canbus
-
Enable CAN:
CONFIG_CAN=y
-
Build fails during compilation of
fsl_flexcan.c
.
Relevant log output
error: 'CAN2' undeclared (first use in this function); did you mean 'CAN0'?
s_flexcanIsr(FLEXCAN2, s_flexcanHandle[2]);
Impact
Annoyance – Minor irritation; no significant impact on functionality, but blocks CAN-enabled builds for KV56F24.
Environment
- Zephyr version: 4.1.0 (
v4.1.0
) - NXP HAL:
hal_nxp
as shipped with Zephyr (mirrored MCUX SDK) - Toolchain: Zephyr SDK 0.17.0 (
arm-zephyr-eabi-gcc 12.2.0
) - SoC: MKV56F1M0VLQ24 (KV56F24 series)
- Board: Custom KV56F24 board
Additional context
- This issue originates from the NXP MCUXpresso SDK.
- The same incorrect define exists upstream:
https://github.com/NXPmicro/mcux-sdk (latest KV56F24 header as of 2025‑07‑14). - Upstream issue tracking this problem:
[NXP MCUX SDK Issue #237]([BUG] MKV56F24 header incorrectly defines FLEXCAN2, causing build failure in Zephyr 4.1.0 nxp-mcuxpresso/mcux-sdk#237)
Tracking here for Zephyr users since it blocks KV56F24 CAN builds.