Skip to content

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

Open
fjrdev wants to merge 11 commits into
RIOT-OS:masterfrom
fjrdev:master
Open

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

Conversation

@fjrdev
Copy link
Copy Markdown

@fjrdev fjrdev commented Apr 2, 2026

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
Copy link
Copy Markdown
Contributor

crasbe commented Apr 3, 2026

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)

Copy link
Copy Markdown
Contributor

@crasbe crasbe left a comment

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
Copy link
Copy Markdown

riot-ci commented Apr 3, 2026

Murdock results

✔️ PASSED

f6c6376 doc: resolved build issues

Success Failures Total Runtime
1 0 1 03m:54s

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
Copy link
Copy Markdown
Contributor

crasbe commented Apr 7, 2026

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

@fjrdev
Copy link
Copy Markdown
Author

fjrdev commented Apr 7, 2026

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
Comment thread doc/guides/advanced_tutorials/porting_cpus.md Outdated
@fjrdev
Copy link
Copy Markdown
Author

fjrdev commented Apr 7, 2026

@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
Copy link
Copy Markdown
Contributor

crasbe commented Apr 7, 2026

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

@crasbe
Copy link
Copy Markdown
Contributor

crasbe commented Apr 7, 2026

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
Copy link
Copy Markdown
Member

AnnsAnns commented Apr 7, 2026

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 🫡

Copy link
Copy Markdown
Contributor

@crasbe crasbe left a comment

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? 🤪

Copy link
Copy Markdown
Member

@AnnsAnns AnnsAnns Apr 7, 2026

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
Copy link
Copy Markdown
Member

@AnnsAnns AnnsAnns left a comment

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
Copy link
Copy Markdown
Author

fjrdev commented Apr 20, 2026

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

Copy link
Copy Markdown
Member

@AnnsAnns AnnsAnns left a comment

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
Copy link
Copy Markdown
Contributor

@crasbe crasbe left a comment

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
Copy link
Copy Markdown
Author

fjrdev commented May 4, 2026

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

Copy link
Copy Markdown
Contributor

@crasbe crasbe left a comment

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?

Copy link
Copy Markdown
Member

@AnnsAnns AnnsAnns left a comment

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!

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 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.

4 participants