doc/guides: add guide for porting new MCUs#22173
Conversation
|
There is a compile error when trying to build the documentation: |
crasbe
left a comment
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
It would be nice if you could add a link to said guide.
| └── cpu.c | ||
| ``` | ||
|
|
||
| Not every subdirectory is mandatory, but most non-trivial ports will need at |
There was a problem hiding this comment.
Maybe you could add an asterisk to the mandatory or non-mandatory files?
| Typical responsibilities: | ||
|
|
||
| - define `MODULE = cpu`, | ||
| - include `$(RIOTBASE)/Makefile.base`, | ||
| - optionally add subdirectories such as `periph/`, `vectors/`, or a common CPU | ||
| family directory. |
There was a problem hiding this comment.
This feels a bit redundant because that's exactly what's in the code below. I'd probably remove it tbh.
| Typical responsibilities: | ||
|
|
||
| - pull in common CPU-family dependency files, | ||
| - select required helper modules |
| `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. |
| corresponding peripheral implementation. | ||
|
|
||
| :::note | ||
| Refer to the Technical Reference Manual of the target CPU for details on implementing the boot process. |
There was a problem hiding this comment.
| 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 |
|
|
||
| ### 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. |
|
I think the last two commits were not meant to be added here? 👀 |
Oh sorry. you are right! Will fix it + your suggestions asap! |
|
@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? |
|
@AnnsAnns: as our recently graduated CPU-porting expert, would you like to take a look at this too? 👁️👁️ |
|
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",
],
}, |
|
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
left a comment
There was a problem hiding this comment.
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 :)
|
|
||
| ## Build System Files | ||
|
|
||
| ### `Makefile` |
There was a problem hiding this comment.
With the Code formatting, our current style file does not respect the sublevel headings:
@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?
There was a problem hiding this comment.
I'd personally say just avoid formatting in titles
There was a problem hiding this comment.
I'd personally say just avoid formatting in titles
There was a problem hiding this comment.
I'd personally say just avoid formatting in titles
There was a problem hiding this comment.
You'd personally say just avoid formatting in titles? Did I understand that correctly? 🤪
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
| 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`. |
There was a problem hiding this comment.
| 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. |
There was a problem hiding this comment.
| 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. |
AnnsAnns
left a comment
There was a problem hiding this comment.
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 👍
|
|
||
| ## Build System Files | ||
|
|
||
| ### `Makefile` |
There was a problem hiding this comment.
I'd personally say just avoid formatting in titles
|
|
||
| ## Build System Files | ||
|
|
||
| ### `Makefile` |
There was a problem hiding this comment.
I'd personally say just avoid formatting in titles
AnnsAnns
left a comment
There was a problem hiding this comment.
Read through it again, looks good for the most part, just one minor nitpick from my side left
crasbe
left a comment
There was a problem hiding this comment.
You know that you can run make doc-starlight locally to check if it works, right? 👀
|
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 |
Didn't know that, thanks for pointing out! :D |
AnnsAnns
left a comment
There was a problem hiding this comment.
Looks good :)
Please squash everything down and then we are good to go!
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.mdthat 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:
Testing procedure
Issues/PRs references
None
Declaration of AI-Tools / LLMs usage:
AI-Tools / LLMs that were used are: