Skip to content

doc/guides: add guide for porting new MCUs#22173

Open
fjrdev wants to merge 1 commit into
RIOT-OS:masterfrom
fjrdev:master
Open

doc/guides: add guide for porting new MCUs#22173
fjrdev wants to merge 1 commit into
RIOT-OS:masterfrom
fjrdev:master

Conversation

@fjrdev

@fjrdev fjrdev commented Apr 2, 2026

Copy link
Copy Markdown

Contribution description

This PR features a markdown file describing the process of porting new CPUs into the RIOT ecosystem, since there is currently only a porting guide for boards but not for CPUs. The guide first gives a general overview of the process and then dives into to process of creating the file-structure for a new CPU. A description + code examples are given for the required files. Furthermore, a roadmap is given for the implementing the most important peripherals. This guide was created during the port of the Infineon PSOC-6, which is a new CPU for RIOT. A PR for this will follow in a bit.

This PR adds a new Markdown guide at doc/guides/advanced_tutorials/RIOT_CPU_PORTING.md that documents the process of porting a new CPU to RIOT.

At the moment, RIOT provides guidance for board porting, but there is no CPU porting guide. This contribution is intended to fill that gap by describing the overall CPU porting workflow, the expected file structure, the role of the main CPU-specific files and high-level descriptions for implementing core peripherals (GPIO, UART, Timer, SPI and I2C).

This guide was written during the ongoing port of the Infineon PSoC-6 CPU family to RIOT. The corresponding CPU port itself will be submitted in a separate PR in the near future. It is intended to make future CPU ports easier to structure and understand.

Scope:

  • documentation only
  • no functional code changes

Testing procedure

Issues/PRs references

None

Declaration of AI-Tools / LLMs usage:

AI-Tools / LLMs that were used are:

  • none

@github-actions github-actions Bot added the Area: doc Area: Documentation label Apr 2, 2026
@crasbe crasbe added Type: new feature The issue requests / The PR implemements a new feature for RIOT CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs labels Apr 3, 2026
@crasbe

crasbe commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

There is a compile error when trying to build the documentation:

make doc-starlight
...

11:06:27 [content] Syncing content
[InvalidContentEntryDataError] docs → advanced_tutorials/porting_cpus data does not match collection schema.

  **: [
  {
    "expected": "string",
    "code": "invalid_type",
    "path": [
      "title"
    ],
    "message": "title: Required"
  }
]

  Hint:
    See https://docs.astro.build/en/guides/content-collections/ for more information on content schemas.
  Error reference:
    https://docs.astro.build/en/reference/errors/invalid-content-entry-data-error/
  Location:
    /home/cbuec/RIOTstuff/riot-vanilla/RIOT/doc/guides/advanced_tutorials/porting_cpus.md:0:0
  Stack trace:
    at getEntryData (/home/cbuec/RIOTstuff/riot-vanilla/RIOT/doc/starlight/node_modules/astro/dist/content/utils.js:123:16)
    at async eval (/home/cbuec/RIOTstuff/riot-vanilla/RIOT/doc/starlight/node_modules/astro/dist/content/loaders/glob.js:211:13)

@crasbe crasbe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for adding this much needed guide!

The remarks about rearranging the Typical Responsibilities lists is valid for all files, I did not want to add "Same" comments for every occurance.

Once the documentation is buildable, we can perhaps think about using actual Subheadings for the Example: etc "headings" that are currently just in text style.

- documentation and tests that make the port maintainable.

This document focuses on the CPU side. For the board side, also refer to the
existing RIOT guide on porting boards.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It would be nice if you could add a link to said guide.

Comment thread doc/guides/advanced_tutorials/porting_cpus.md Outdated
└── cpu.c
```

Not every subdirectory is mandatory, but most non-trivial ports will need at

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe you could add an asterisk to the mandatory or non-mandatory files?

Comment on lines +74 to +79
Typical responsibilities:

- define `MODULE = cpu`,
- include `$(RIOTBASE)/Makefile.base`,
- optionally add subdirectories such as `periph/`, `vectors/`, or a common CPU
family directory.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This feels a bit redundant because that's exactly what's in the code below. I'd probably remove it tbh.

Comment on lines +96 to +99
Typical responsibilities:

- pull in common CPU-family dependency files,
- select required helper modules

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here.

Comment on lines +164 to +172
`cpu.c` contains `cpu_init()`, which performs the minimum hardware and runtime
initialization needed before RIOT starts normal execution.

Typical responsibilities:

- call generic core initialization for the architecture,
- set interrupt priorities and interrupt grouping if required,
- configure clocks or clock assumptions used by the CPU port,
- perform any CPU-local setup that must happen before peripherals are used.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same.

corresponding peripheral implementation.

:::note
Refer to the Technical Reference Manual of the target CPU for details on implementing the boot process.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
Refer to the Technical Reference Manual of the target CPU for details on implementing the boot process.
Refer to the Technical Reference Manual of the target CPU for details on
implementing the boot process.

Long line.

### Reuse common code

If the MCU belongs to an already supported architecture or family, reuse the
existing common code where possible. For this case, a base directory (e.g. `cpu/<CPU_FAM>_common`) should be created that contains all shared/common configurations. This drastically reduces maintenance and lowers the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Long line.


### Refer to the manual of the target CPU

Many CPUs are shipped with detailed manuals containing register-level information about peripherals, clock trees, the boot sequence, interrupt handling, and more. This information should be read, understood, and then mapped to the RIOT framework.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Long line.

Comment thread doc/guides/advanced_tutorials/porting_cpus.mdx
@crasbe crasbe changed the title add guide for porting new MCUs doc/guides: add guide for porting new MCUs Apr 3, 2026
@riot-ci

riot-ci commented Apr 3, 2026

Copy link
Copy Markdown

Murdock results

FAILED

41ff982 doc: add CPU porting guide tutorial

Artifacts

@github-actions github-actions Bot added Area: tests Area: tests and testing framework Area: build system Area: Build system Area: drivers Area: Device drivers Area: boards Area: Board ports Area: cpu Area: CPU/MCU ports Area: Kconfig Area: Kconfig integration labels Apr 7, 2026
@crasbe

crasbe commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

I think the last two commits were not meant to be added here? 👀

@fjrdev

fjrdev commented Apr 7, 2026

Copy link
Copy Markdown
Author

I think the last two commits were not meant to be added here? 👀

Oh sorry. you are right! Will fix it + your suggestions asap!

@github-actions github-actions Bot removed Area: tests Area: tests and testing framework Area: build system Area: Build system Area: drivers Area: Device drivers Area: boards Area: Board ports Area: cpu Area: CPU/MCU ports Area: Kconfig Area: Kconfig integration labels Apr 7, 2026
@crasbe

crasbe commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

To avoid this kind of issue, it is usually a good idea to create a separate branch for a pull request and not use the master branch. Every change to your fork's master branch is automatically reflected to the PR.

Unfortunately it is not possible to change the branch after opening the PR AFAIK.

Comment thread doc/guides/advanced_tutorials/porting_cpus.md Outdated
@fjrdev

fjrdev commented Apr 7, 2026

Copy link
Copy Markdown
Author

@crasbe Thanks a lot for reviewing! I have added your feedback in the latest version. I will add subheading to the corresponding sections. Can we use # levels here as well?

@crasbe

crasbe commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

@AnnsAnns: as our recently graduated CPU-porting expert, would you like to take a look at this too? 👁️👁️

@crasbe

crasbe commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

You'll have to add the guide to the Astro configuration file, otherwise it won't show up in the nagivation side bar:

diff --git a/doc/starlight/astro.config.ts b/doc/starlight/astro.config.ts
index 1d6bf1f3d4..06a48f592b 100644
--- a/doc/starlight/astro.config.ts
+++ b/doc/starlight/astro.config.ts
@@ -142,6 +142,7 @@ export default defineConfig({
                 "advanced_tutorials/unittests",
                 "advanced_tutorials/device_drivers",
                 "advanced_tutorials/porting_boards",
+                "advanced_tutorials/porting_cpus",
                 "advanced_tutorials/event_queue",
               ],
             },

@AnnsAnns

AnnsAnns commented Apr 7, 2026

Copy link
Copy Markdown
Member

For sure will take a look, I was really happy to hear that somebody was working on this when crasbe mentioned this as I wanted to also do something like this, thank you for this PR 🫡

@crasbe crasbe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Now that the documentation can be built in Starlight, I gave this a more thorough review. Nothing major, just some minor improvements here and there :)

Comment thread doc/guides/advanced_tutorials/porting_cpus.md Outdated

## Build System Files

### `Makefile`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With the Code formatting, our current style file does not respect the sublevel headings:

Image

@AnnsAnns @LasseRosenow is that something that you'd want to fix in the style file or should the use of code formatting just be avoided for sublevel headlines?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd personally say just avoid formatting in titles

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd personally say just avoid formatting in titles

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd personally say just avoid formatting in titles

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You'd personally say just avoid formatting in titles? Did I understand that correctly? 🤪

@AnnsAnns AnnsAnns Apr 7, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Most normal Github behavior, how is this the default git forge but it can't handle weird internet connections, I was legit just in an ICE on train wifi 😭

### `Makefile`

The top-level CPU `Makefile` defines the CPU module and may include common
subdirectories that are shared with other CPUs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
subdirectories that are shared with other CPUs.
subdirectories that are shared with other CPUs. `$(RIOTCPU)` is the `cpu/` subdirectory
of the RIOT basefolder `$(RIOTBASE)`.


This file declares what the CPU provides to the rest of RIOT by defining the
CPU architecture, including common family feature files as well as defining
the implemented peripherals with `FEATURES_PROVIDED`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
the implemented peripherals with `FEATURES_PROVIDED`.
the implemented peripherals with `FEATURES_PROVIDED` in alphabetical order.


### `Makefile.include`

This file contains low-level build configuration for the CPU.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
This file contains low-level build configuration for the CPU.
This file contains low-level build configuration and additional compiler and
linker search paths for the CPU.

Comment thread doc/guides/advanced_tutorials/porting_cpus.mdx
Comment thread doc/guides/advanced_tutorials/porting_cpus.mdx
Comment thread doc/guides/advanced_tutorials/porting_cpus.md Outdated
Comment thread doc/guides/advanced_tutorials/porting_cpus.md Outdated
Comment thread doc/guides/advanced_tutorials/porting_cpus.mdx

@AnnsAnns AnnsAnns left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Either the wifi is too spotty or github is having problems so I'll have to halt my review for now since I'm getting a lot of errors, so far this was a nice read though 👍

Comment thread doc/guides/advanced_tutorials/porting_cpus.md Outdated
Comment thread doc/guides/advanced_tutorials/porting_cpus.md Outdated
Comment thread doc/guides/advanced_tutorials/porting_cpus.md Outdated

## Build System Files

### `Makefile`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd personally say just avoid formatting in titles


## Build System Files

### `Makefile`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd personally say just avoid formatting in titles

Comment thread doc/guides/advanced_tutorials/porting_cpus.md Outdated
Comment thread doc/guides/advanced_tutorials/porting_cpus.md Outdated
Comment thread doc/guides/advanced_tutorials/porting_cpus.md Outdated
Comment thread doc/guides/advanced_tutorials/porting_cpus.md Outdated
Comment thread doc/guides/advanced_tutorials/porting_cpus.md Outdated
Comment thread doc/starlight/astro.config.ts Outdated
@fjrdev

fjrdev commented Apr 20, 2026

Copy link
Copy Markdown
Author

@crasbe @AnnsAnns Thanks a lot for the helpful feedback and your time! I have included your suggestions in the guide :)

@AnnsAnns AnnsAnns left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Read through it again, looks good for the most part, just one minor nitpick from my side left

Comment thread doc/guides/advanced_tutorials/porting_cpus.md Outdated
Comment thread doc/guides/advanced_tutorials/porting_cpus.mdx
Comment thread doc/guides/advanced_tutorials/porting_cpus.md Outdated

@crasbe crasbe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You know that you can run make doc-starlight locally to check if it works, right? 👀

Comment thread doc/guides/advanced_tutorials/porting_cpus.mdx Outdated
Comment thread doc/guides/advanced_tutorials/porting_cpus.mdx Outdated
Comment thread doc/guides/advanced_tutorials/porting_cpus.mdx Outdated
@AnnsAnns

Copy link
Copy Markdown
Member

I'd recommend looking at https://guide.riot-os.org/misc/how_to_doc/#how-to-run-the-site-locally if something is not working, otherwise feel free to reach out for help

@fjrdev

fjrdev commented May 4, 2026

Copy link
Copy Markdown
Author

You know that you can run make doc-starlight locally to check if it works, right? 👀

Didn't know that, thanks for pointing out! :D

@crasbe crasbe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IMO this is good to go now. Thank you!

@AnnsAnns what do you think?

@AnnsAnns AnnsAnns left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good :)

Please squash everything down and then we are good to go!

@crasbe

crasbe commented May 18, 2026

Copy link
Copy Markdown
Contributor

Unfortunately there is now a merge conflict after #22254 was merged, but that should be easy to resolve.

We have a short section about how to deal with merge conflicts in our Contibution Guidelines: https://doc.riot-os.org/general/contributing/#squash-commits-after-review

If you need additional help, let me know :)

- get `examples/basic/hello-world` running over UART,
- if UART output is missing, toggle an LED at key checkpoints in startup and
`cpu_init()` to localize where execution stops,
- validate one timer instance so `ztimer` works,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Which test would be advised to run?


- `examples/basic/hello-world` for startup and UART,
- `tests/periph_gpio` or GPIO-based samples for pin control,
- timer-based examples for `periph_timer` and `ztimer`,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
- timer-based examples for `periph_timer` and `ztimer`,
- timer-based tests for `periph_timer` and `ztimer`,
- refer to test applications in `tests/periph/timer` and `sys/ztimer*`

Something like this, to refer them to exact locations.

@AnnsAnns AnnsAnns added the State: waiting for author State: Action by the author of the PR is required label Jul 15, 2026
@AnnsAnns

Copy link
Copy Markdown
Member

This PR is fairly close to the finish line, are you still interested in getting this merged, its really useful @fjrdev

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

Labels

Area: doc Area: Documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs State: waiting for author State: Action by the author of the PR is required Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants