Skip to content

[MCXA] cdog: refactor code watchdog driver#5490

Open
felipebalbi wants to merge 1 commit intoembassy-rs:mainfrom
felipebalbi:mcxa/cdog
Open

[MCXA] cdog: refactor code watchdog driver#5490
felipebalbi wants to merge 1 commit intoembassy-rs:mainfrom
felipebalbi:mcxa/cdog

Conversation

@felipebalbi
Copy link
Contributor

@felipebalbi felipebalbi commented Feb 18, 2026

Closes OpenDevicePartnership/embassy-mcxa#139

Trying something new for the cdog. Some of the changes are highly desirable (now we can support both cdog instances), others are up for discussion. Maybe it looks too "abusive" of rust operators. Let me know

@felipebalbi felipebalbi added the e-mcxa Issues for the NXP MCX-A family of chips label Feb 19, 2026
Copy link
Contributor

@jamesmunns jamesmunns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with this as an improvement, we could potentially make this driver a bit more idiomatic though and have async methods for waiting for interrupt events, etc.

}
}

impl AddAssign<u32> for SecureCounter {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to have these as explicit increment and decrement methods, rather than operator overloading.

debug_halt: PauseControl::PauseTimer,
lock: LockControl::Unlocked,
};
let mut config = hal::cdog::Config::default();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a weak preference to actually hide these settings, and expose these as async methods, or have different Mode type states.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did consider that, yeah. However, we don't get a warning interrupt with this one. We need to feed before the interrupt triggers. There are three possibilities, actually: either you want an interrupt, or a reset, or neither.

So, let's say we want an interrupt, you seem to imply an API similar to what follows:

loop {
    cdog.instruction_counter().update(200);
    let status = cdog.wait_for_interrupt_and_get_status().await;
    do_something_with(status);
}

Sadly, that won't work. The whole idea of the code watchdog is that if the interrupt triggers, it should imply unauthorized code modification (an attack) which should be treated as sort of a critical situation. That is, we don't want the interrupt to ever trigger. Maybe we could split() the instruction counter into a writer and a waiter and dedicate a task to wait for that interrupt forever, such that applications can decide what to do if that interrupt ever comes. Or, the application could just bind their own interrupt handler instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e-mcxa Issues for the NXP MCX-A family of chips

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Audit cdog pub functions

2 participants