rust-embedded / rust-embedded/cortex-m

Verify peripheral configuration support inline instead of seperate `has_` functions?

Open
#382 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1k
Forks
202
Avg merge
6d 2h
Merged PRs (30d)
2

Description

Throughout the crate I believe most (if not all) register-mutating functions are unchecked, meaning that the crate user should check for support before enabling and configurating a feature. I consider this reasonable for trivial functions such as DWT::has_exception_trace and DWT::enable_exception_tracing but less so for more complex functions like DWT::configure and ITM::configure which may enable and configure a whole set of features. For these functions it's not trivial to figure out which has_ functions must be called before configuration (presuming they are implemented in the first place).

I believe it would be a better idea to verify support in configure functions before registers are mutated (and return Err if the requested configuration cannot be applied) and offer some configure_unchecked variant when the user knows when a set of features are supported. I'm not sure if we should do the same to the more drivial functions.

Thoughts?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing DWT::configure, ITM::configure, and related has_ functions to understand their current support checks and register mutations. Then determine the intended error and unchecked-variant API, including whether simpler functions should change; the issue is complete only after that behavior and scope are agreed and covered by appropriate tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
embedded-iot
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.