Introduction
AUTOSAR is the de-facto standard for automotive ECU software. This post walks through writing a production MCAL CAN driver for the NXP S32K144 from scratch.
BSW Layer Architecture
The AUTOSAR BSW stack on S32K144 consists of MCAL (Microcontroller Abstraction Layer), ECU Abstraction Layer, Services Layer (COM, DCM, DEM, NVM, OS), and Complex Drivers.
ECUC Configuration with Vector DaVinci
The ECUC is the backbone of AUTOSAR configuration. In DaVinci Configurator Pro, define your CanGeneral, CanController, CanHardwareObject containers:
CanController_0:
CanCpuClockRef: McuSystemClock /* 80 MHz */
CanControllerBaudRate: 500 /* kbps */
CanControllerSeg1: 13
CanControllerSeg2: 4Writing the CAN_Init() Driver
The NXP S32K FlexCAN requires careful initialization sequence — enter freeze mode, configure clock source, set baud rate divisors, configure message buffers, exit freeze mode.
Common Pitfalls
- Clock source mismatch — S32K144 has two CAN clock sources: oscillator (8 MHz) and peripheral clock (80 MHz). Verify your CTRL1.CLKSRC bit.
- MB arbitration lost — Lower-numbered message buffers win. Structure TX MB allocation accordingly.
- BUSOFF recovery — AUTOSAR requires automatic BUSOFF recovery. Set CAN_CTRL1_BOFFREC=0 for hardware auto-recovery.
Integration with CanIf
After MCAL, the CanIf layer abstracts multiple CAN drivers. The Can_MainFunction_Read() can use polling or interrupt-based reception. For AUTOSAR OS integration, the CAN interrupt calls Can_IsrRxFifo() or Can_IsrBusOff().