Skip to content
← Back to Blog
Watching AI Drive J-Link to Debug AUTOSAR MCAL
Product news

Watching AI Drive J-Link to Debug AUTOSAR MCAL

AutoC adds gdb-debug. On NXP S32K3 (S32K344), the AI can build, flash, set breakpoints, and step through AUTOSAR MCAL on the real MCU.

Product newsAutoCAUTOSARDebug

How it started

AI writing code is no longer news. When the firmware misbehaves, can it work like an embedded engineer: build, connect a debugger, flash, set breakpoints, step, inspect variables and the call stack, then change the code from what it sees on the board?

Yes. Here is how AutoC plus gdb-debug does that end to end. The target this time is NXP S32K3 (S32K344).

The loop is short:

change MCALbuild_firmwaregdb-connectrestart → breakpoint / step → variables, registers, backtrace → change again → verify

The AI is no longer guessing from source alone. It can attach to the board and check whether init actually ran, whether a driver is doing anything, whether a register has the expected value, and where the program is stuck.

The chain:

Debug chain

AutoC → GDB Client → J-Link GDB Server → J-Link → MCU

If you read this far, you already noticed: any debugger that speaks GDB can go through AutoC's gdb-debug skill.

The tools:

ToolWhat it does
build_firmwareBuild the current firmware
gdb-connectStart J-Link GDB Server, device=S32K344, SWD
gdb-command restartReset → Load → Break → Continue
gdb-commandbreak / step / continue / locals / print / registers / backtrace

J-Link over SWD to S32K344

Configure gdb-debug first

Open Settings → Project → Extensions → GDB Debug, and fill in the build command, ELF, GDB client, and J-Link GDB Server paths.

gdb-debug settings

What this S32K344 project used:

FieldExampleRole
Build command./build.batBuild firmware
Working directoryemptyProject root
Executable (ELF)./build/out/main.elfFile to flash and debug
GDB pathD:/NXP/S32DS.3.6.4/S32DS/tools/gdb-arm/arm32-eabi/bin/arm-none-eabi-gdb.exeArm GDB from S32DS
GDB targetemptyAutoC starts the GDB Server
GDB server pathD:/Program Files/SEGGER/JLink/JLinkGDBServerCL.exeJ-Link GDB Server
DeviceS32K344Target MCU
InterfaceSWDS32K3 debug interface

Use the paths on your machine. S32K3 uses SWD. If a GDB Server is already running, put its host:port in GDB target.

After save and reload, AutoC registers build_firmware, gdb-connect, and gdb-command.

Build, connect, flash, and run

After a MCAL driver change, run them in sequence:

text
build_firmware
gdb-connect
restart

build_firmware builds the firmware:

build_firmware building S32K3 firmware

gdb-connect attaches to S32K344 over SWD. restart does Reset / Load / Break / Continue in one shot. The GDB client stays up, so later breakpoints, steps, and variable checks share the same session.

gdb-connect and restart

If the build fails, the AI reads the error, changes the code, and builds again. After a clean build, it flashes and starts the next debug round.

An MCAL debug example

MCAL bugs are often not "it failed to compile". They are it compiled, and the hardware still does not behave.

SymptomTypical suspicion
Port init ran, pin state is wrongSIUL2 PCR, direction, mux
Dio read/write is wrongChannel mapping, Port dependency
Can / Spi / Adc / Pwm / Gpt never comes upInit never reached, clock, IRQ
An IRQ never firesVector, priority, enable bit

Those questions end on the real MCU.

Breakpoints, step, inspect

Once attached, do these together:

text
break Port_Init
break Can_Init
continue
step
locals
print xxx

First check that MCAL init actually entered. Then step through pin setup and register writes. If something is off, inspect locals, config structs, and registers. Typical questions: why is this Channel 0, why is Status still BUSY, is the init parameter wrong.

gdb-command print

Call stack

backtrace

This shows which layer you are in. On Uart_SyncSend we captured 7 frames: mainUart_SyncSendUart_StartSyncSendUart_Ipw_SyncSend → LPUART IP.

Uart_SyncSend call stack

Case: AI debugging AUTOSAR MCAL

Configure UART MCAL and send a message. AutoC already finished the earlier configuration work; that is not the point of this post.

UART MCAL task

First version of the code

First version of the code

AI starts debugging, flashes, and runs

AI starts debugging, flash and run

AI finds the problem

AI finds the problem

AI changes the MCAL code

AI changes MCAL code

Result

UART resultAI changes MCAL code

From configuration to debug

AutoC used to stop at AI configuring AUTOSAR BSW. After that came the leftover question: does the software actually run?

Now the path continues: configure MCAL → generate code → build → attach J-Link → debug → change code → verify.

The value is not a handful of GDB commands. It is using what the board shows to decide the next step. Chip quirks, timing, and low-level drivers still need an engineer. Build, flash, breakpoints, step, variables, and backtrace, the AI can already take.

AI Debug Loop

Share