-
Notifications
You must be signed in to change notification settings - Fork 2.1k
doc/guides: Add Getting Started guide #21436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Teufelchen1
merged 2 commits into
RIOT-OS:master
from
AnnsAnns:tutorials/getting_started
Apr 29, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| --- | ||
| title: Building an Example | ||
| description: Building an example application with RIOT | ||
| --- | ||
|
|
||
| import Contact from '@components/contact.astro'; | ||
|
|
||
| <Contact /> | ||
|
|
||
| :::note | ||
| This guide uses the `samr21-xpro` board as an example. | ||
| You can replace it with the name of any other supported board, | ||
| as learned in the previous section, by replacing `samr21-xpro` | ||
| with the name of your board. | ||
| ::: | ||
|
|
||
| RIOT provides a number of examples in the `examples/` directory. Every example | ||
| has a README that documents its usage and its purpose. You can build them by | ||
| opening a shell, navigating to an example (e.g. `examples/default`), and | ||
| running: | ||
|
|
||
| ```bash | ||
| make BOARD=samr21-xpro | ||
| ``` | ||
|
|
||
| or | ||
|
|
||
| ```bash | ||
| make all BOARD=samr21-xpro | ||
| ``` | ||
|
|
||
| To flash the application to a board just run: | ||
|
|
||
| ```bash | ||
| make flash BOARD=samr21-xpro | ||
| ``` | ||
|
|
||
| You can then access the board via the serial interface: | ||
|
|
||
| ```bash | ||
| make term BOARD=samr21-xpro | ||
| ``` | ||
|
|
||
| If you are using multiple boards you can use the `PORT` macro to specify the | ||
| serial interface: | ||
|
|
||
| ```bash | ||
| make term BOARD=samr21-xpro PORT=/dev/ttyACM1 | ||
| ``` | ||
|
|
||
| For flashing and accessing the board via the serial interface, the current user | ||
| needs to have the correct access rights on the serial device. | ||
| The easiest way to ensure this is to add the current user to the group that is | ||
| owning the serial device. For example, this can be achieved on Linux by issuing | ||
| the following line, logging out and logging in again: | ||
|
|
||
| ```bash | ||
| sudo usermod -aG $(stat --format="%G" /dev/ttyACM0) $USER | ||
| ``` | ||
|
|
||
| Note that the `PORT` macro has a slightly different semantic in `native`. Here | ||
| it is used to provide the name of the TAP interface you want to use for the | ||
| virtualized networking capabilities of RIOT. | ||
|
|
||
| We use `pyterm` as the default terminal application. It is shipped with RIOT in | ||
| the `dist/tools/pyterm/` directory. If you choose to use another terminal | ||
| program you can set `TERMPROG` (and if need be the `TERMFLAGS`) macros: | ||
|
|
||
| ```bash | ||
| make -C examples/gnrc_networking/ term \ | ||
| BOARD=samr21-xpro \ | ||
| TERMPROG=gtkterm \ | ||
| TERMFLAGS="-s 115200 -p /dev/ttyACM0 -e" | ||
| ``` | ||
|
|
||
| You may not see the greeting | ||
|
|
||
| ```plaintext title="The greeting message from the board" | ||
| main(): This is RIOT! | ||
| ``` | ||
|
|
||
| when you flash the board. In this case, type `reboot` in the command line or reboot manually. | ||
|
|
||
| :::tip[Using the native port with networking] | ||
| If you compile RIOT for the native cpu and include the `netdev_tap` module, | ||
| you can specify a network interface like this: `PORT=tap0 make term` | ||
|
|
||
| *Setting up a tap network* | ||
|
|
||
| There is a shell script in `RIOT/dist/tools/tapsetup` called `tapsetup` which | ||
| you can use to create a network of tap interfaces. | ||
|
|
||
| *USAGE* | ||
|
|
||
| To create a bridge and two (or `count` at your option) tap interfaces: | ||
| ```shell | ||
| sudo ./dist/tools/tapsetup/tapsetup [-c [<count>]] | ||
| ``` | ||
|
|
||
| A detailed example can be found in `examples/gnrc_networking`. | ||
| ::: | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| --- | ||
| title: Finding and Using Modules | ||
| description: This tutorial will explain how to use modules in RIOT. | ||
| --- | ||
|
|
||
| import Contact from '@components/contact.astro'; | ||
|
|
||
| A core concept in RIOT is the use of modules. | ||
| Modules are a way to organize code and data in a way that makes it easy to reuse and share. | ||
| In the previous tutorial, we created a simple hello world program and you might have noticed that we included a module called `ztimer`. | ||
| `ztimer` is one of the core modules in RIOT and provides a way to work with timers,l both software and hardware timers are supported. | ||
|
|
||
| Lets take a look at how we can use modules in RIOT and where to find them. | ||
|
|
||
| ## Step 1: Finding modules | ||
|
|
||
| RIOT provides a number of modules that you can use in your application, including modules for networking, sensors, and more. | ||
| Depending on the goal of your application, you might need to use different modules and sometimes even create your own. So where can you find these modules? | ||
|
|
||
| There are several approaches to this and none of them are wrong. | ||
|
|
||
| ### Approach 1: The API Documentation | ||
|
|
||
|  | ||
|
|
||
| The first approach is to look at the API documentation. The API documentation provides a list of all modules and functions that are available in RIOT and can be found [here](https://doc.riot-os.org/topics.html). | ||
|
|
||
| It can be a bit overwhelming to find the right module in the API documentation, but it is a good starting point if you know what you are looking for. | ||
|
|
||
| ### Approach 2: The Examples | ||
|
|
||
|  | ||
|
Teufelchen1 marked this conversation as resolved.
|
||
|
|
||
| Another approach is to look at the examples that are provided with RIOT. The examples are a great way to learn how to use a module and see it in action. | ||
|
|
||
| You can find the examples in the `examples` directory of the RIOT repository, most of them come with a `Makefile` that you can use to build the example and a ReadMe file that explains what the example does. | ||
|
|
||
| ### Approach 3: The Source Code | ||
|
|
||
|  | ||
|
|
||
| The last approach is to look at the source code of RIOT. This can be a bit more challenging, but sometimes it does provide the best insight into how a module works. | ||
|
|
||
| Let's say I want to use base64 encoding in my application. I can search the RIOT repository for `base64` and see if there is a module that provides this functionality. | ||
|
|
||
| ### Approach 4: Asking for Help | ||
|
|
||
| <Contact/> | ||
|
|
||
| ## Step 2: Using modules | ||
|
|
||
| Using modules in RIOT is quite simple. You just need to list any modules that you want to use in your application in the `Makefile` of your application. | ||
|
|
||
| If we look back at our hello world program, we can see that we included the `ztimer` module in the `Makefile` like this: | ||
|
|
||
| ```make | ||
| USEMODULE += ztimer_sec | ||
| ``` | ||
|
|
||
| After that we were able to simply include the `ztimer` module in our `main.c` file like this: | ||
|
|
||
| ```c | ||
| #include "ztimer.h" | ||
| ``` | ||
|
|
||
| and then use the `ztimer_sleep` function in our program to sleep for 3 seconds. | ||
|
|
||
| ```c | ||
| ztimer_sleep(ZTIMER_SEC, 3); | ||
| ``` | ||
|
|
||
| That's it! You have successfully used a module in RIOT with just a few lines of code. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| --- | ||
| title: Flashing a RIOT Application | ||
| description: Flash a RIOT application to a real hardware device | ||
| --- | ||
|
|
||
| import Contact from '@components/contact.astro'; | ||
|
|
||
| <Contact /> | ||
|
|
||
| After all of the previous sections are completed, we can finally flash some | ||
| real hardware. In this case, we use an `esp32-mh-et-live-minikit` development | ||
| board. The guide should mostly apply to all other boards as well. | ||
|
|
||
| :::note | ||
| Some boards require extra steps to be flashed, such as pressing a button | ||
| to enter a bootloader or attaching an external programmer. Refer to the | ||
| documentation of the board to check if extra steps are required. | ||
| ::: | ||
|
|
||
| :::tip[Flashing under WSL] | ||
| If you are using Windows, this assumes that the USB UART bridge of the ESP32 development board has | ||
| been attached to WSL and VS Code has been launched from within WSL by running | ||
| `code .` inside the RIOT repository from the Ubuntu terminal. | ||
| ::: | ||
|
|
||
|  | ||
|
|
||
| 1. Open the `examples` folder | ||
| 2. Open the `default` folder within `examples` | ||
| 3. Open the `main.c` file in the `default` folder | ||
| 4. Select the "Terminal" tab at the bottom | ||
| 5. Enter `cd ~/RIOT/examples/default` to enter the `default` folder also in the terminal | ||
| 6. Run `make BOARD=esp32-mh-et-live-minikit compile-commands` | ||
| - You can replace `esp32-mh-et-live-minikit` with the name of any other supported board | ||
|
|
||
| :::note | ||
| Did you notice that IntelliSense did not find headers in `main.c` when you | ||
| opened it? This should be fixed after the command in 6 has completed. | ||
| ::: | ||
|
|
||
|  | ||
|
|
||
| 1. Now run `make BOARD=esp32-mh-et-live-minikit BUILD_IN_DOCKER=1 flash term` | ||
|
|
||
| :::note | ||
| Tired of typing `BOARD=<NAME_OF_THE_BOARD>` and `BUILD_IN_DOCKER=1`? You can | ||
| add those to the `Makefile` of your app or run | ||
| `export BOARD=BUILD_IN_DOCKER=1` in the shell. The `export` will not persist | ||
| needs to be repeated for every new terminal window. | ||
| ::: | ||
|
|
||
| :::tip | ||
| Running `BOARD=<INSERT_TARGET_BOARD_HERE> make info-programmers-supported` in your | ||
| application folder lists the programmers supported by RIOT for the given board. | ||
| ::: | ||
|
|
||
|
|
||
|  | ||
|
|
||
| When compiling with `BUILD_IN_DOCKER=1`, the toolchains distributed in the | ||
| [`riot/riotbuild`](https://hub.docker.com/r/riot/riotbuild/) docker image will | ||
| be used for compilation. This image contains toolchains for all supported RIOT | ||
| board and is extensively tested in our CI. | ||
|
|
||
| The first time you build with `BUILD_IN_DOCKER=1`, the image is pulled | ||
| automatically. | ||
|
|
||
|  | ||
|
|
||
| This may take a while ... | ||
|
|
||
|  | ||
|
|
||
| ... until eventually the docker image is pulled and the build will start. | ||
| Subsequent builds will no longer need to download the toolchain and be a lot | ||
| quicker. | ||
|
|
||
|  | ||
|
|
||
| After building and flashing the firmware has succeeded, a shell will open. | ||
|
|
||
| 1. Wait for the boot message to appear. | ||
| - The board may boot faster than your PC is able to connect to the serial. | ||
| If you see nothing after "Welcome to pyterm!" for 5 seconds, try hitting | ||
| the reset button on the board to boot it again. | ||
| 2. You are now connected to the RIOT shell running on the board. Try running | ||
| the `help` command to get a list of commands supported by the board. | ||
| 3. You can drop out of the RIOT serial by pressing `Ctrl` + `C` and return | ||
| to the Linux shell. | ||
|
|
||
| :::tip[Flashing under Windows] | ||
| It is also possible to install a native Windows flash application and invoke that from within WSL. | ||
| However, the setup is too board specific to be covered here. Please refer to the documentation of the board you are using. | ||
| ::: | ||
|
|
||
| :::caution[Known Issues under Windows] | ||
| The Linux Kernel in WSL currently has | ||
| [`CONFIG_USB_HIDDEV` disabled][wsl-hid-issue]. Hence, programmers using HID | ||
| as transport do not work for now and fail to flash. The (non-conclusive) list of affected | ||
| programmers is: | ||
|
|
||
| - Atmel/Microchip eDBG | ||
| - Atmel/Microchip ICE | ||
| - Any ARM CMSIS DAP compatible programmers | ||
|
|
||
| The (non-conclusive) list of programmers that work with WSL out of the box is: | ||
|
|
||
| - ST-Link (any version), including [cheap clones](https://www.aliexpress.com/wholesale?SearchText=ST-Link+V2) | ||
| - Segger J-Link, including the [J-Link EDU Mini](https://www.segger.com/products/debug-probes/j-link/models/j-link-edu-mini/) | ||
| - Any serial based bootloader (e.g. ESP boards, Arduino Bootloaders, ...) | ||
| - [Black Magic Probe](https://black-magic.org) | ||
| - [Jeff Probe](https://flirc.com/more/flirc-jeff-probe-bmp-jtag-black-magic-probe) | ||
| - Any other non HID USB programmer | ||
|
|
||
|
|
||
| [wsl-hid-issue]: https://github.com/microsoft/WSL/issues/10581 | ||
| ::: |
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.