Professional Documents
Culture Documents
Gu 03 WG Renode Platformio
Gu 03 WG Renode Platformio
Currently supports:
• 48 platforms (STM32, raspberrypi etc)
• 25 development frameworks (STM32Cube, Zephyr)
• 1438 boards
• User can extend the support.
Currently Provides:
• 222 examples
• 13008 libraries (for specific components or tasks, like sensor
management)
Outline
https://github.com/renode/renode/issues/173
https://github.com/antmicro/TermSharp/issues/5
neon:~/.platformio/penv$ renode
15:37:27.4942 [INFO] Loaded monitor
commands from:
/opt/renode/scripts/monitor.py
Getting PlatformIO
There are two options for installation:
https://platformio.org/install
PlatformIO Core Only
PlatformIO is a python package, so for installation, as usual:
● Create a virtual Env
● Install the package with pip.
PlatformIO provides a script for this task, but you can also do it manually,
with your env manager of choice (conda or venv).
For MacOS you can use HomeBrew as well.
https://docs.platformio.org/en/latest/core/installation/methods/installer-script.html
https://docs.platformio.org/en/latest/core/installation/methods/pypi.html
https://docs.platformio.org/en/latest/core/installation/methods/brew.html
PlatformIO Plugin for IDEs (VSCode)
Search and install the Platformio IDE extension.
Reboot VSCode.
https://docs.platformio.org/en/latest/integration/ide/vscode.html
The PlatformIO IDE extension will also create a venv and install the PlatformIO core. In
Linux, this venv will be under:
/home/user/.platformio/penv
You can also access the core directly from VSCode, using the command:
PlatformIO: Open PlatformIO Core CLI
This will automatically open a VSCode terminal with the penv activated.
To discover where the penv is, you can use which from this terminal:
$ which platformio
/home/user/.platformio/penv/bin/platformio
PlatformIO CLI commands
After you have installed PlatformIO following one of the two
methods, you can check if platformIO is working. From a terminal
with the penv activated you can use the platformio or pio
commands:
(penv) neon:~/.platformio/penv$ pio --help
Usage: pio [OPTIONS] COMMAND [ARGS]...
Options:
--version Show the version and exit.
-c, --caller TEXT Caller ID (service)
--no-ansi Do not print ANSI control characters
-h, --help Show this message and exit.
Commands:
access Manage resource access
account Manage PlatformIO account
boards Board Explorer
PlatformIO CLI / IDE commands.
Any of the PlatformIO IDE commands that you use from VSCode actually
executes a CLI command. You will not interact directly with the CLI most of
the time, but it is good to know at least some basic commands:
# Build project
$ pio run
# Upload firmware
$ pio run --target upload
● Name
● Board
● Framework
● Location
PlatformIO project structure
● .pio folder use for build files
● platformio.ini
platformio.ini
Main configuration file for platformio.
INI format.
https://docs.platformio.org/en/latest/projectconf/index.html#
[env:frdm_k64f]
platform = freescalekinetis
board = frdm_k64f
framework = zephyr
Sources
We now implement our app. It is a simple echo app, based on the zephyr
example “console_getline”.
https://docs.zephyrproject.org/2.6.0/samples/subsys/console/getline/README.html
The app will simply read lines from an UART, and will echo the lines back to the
user with some additional info.
main.c To be modified
prj.conf
CONFIG_CONSOLE_SUBSYS=y
CONFIG_CONSOLE_GETLINE=y
sources
main.c
#include <zephyr.h>
#include <version.h>
#include <string.h>
#include <sys/printk.h>
#include <console/console.h>
void main(void)
{
printk("Hello! I'm running Zephyr %s on %s, a %s board.\n\n ",
KERNEL_VERSION_STRING, CONFIG_BOARD, CONFIG_ARCH);
console_getline_init();
printk("Enter a line finishing with Enter:\n");
while (1)
{
printk("> ");
char *s = console_getline();
printk("Typed line: %s\n", s);
printk("Last char was: 0x%x\n", s[strlen(s) - 1]);
}
}
Outline
At the end , all are going to execute the run command. You should see in the terminal the
following output:
. . . . .
. . . . .
Linking .pio/build/frdm_k64f/firmware.elf
Checking size .pio/build/frdm_k64f/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [ ] 1.7% (used 4420 bytes from 262144 bytes)
Flash: [ ] 1.7% (used 17362 bytes from 1048576 bytes)
Building .pio/build/frdm_k64f/firmware.bin
After a successful build, you should have a firmware.elf file in the .pio/build/env/ folder.
Outline
basic_k64f.repl
The absolute minimum The K64F has:
1MB of flash
components that we need to cpu: CPU.CortexM @ sysbus 256 KB of RAM
cpuType: "cortex-m4f"
describe a soc: nvic: nvic The size is expressed in bytes.
Once a machine is created, it contains only one peripheral - the system bus called simply
sysbus. There is no memory or CPU, so the machine is not yet ready to execute any code.
https://renode.readthedocs.io/en/latest/basic/machines.html#working-with-machines
(name) peripherals
(name) sysbus.<peripheral>
Creating a machine
(monitor) help
Available commands:
Name | Description
================================================================================
alias : sets ALIAS.
allowPrivates : allow private fields and properties manipulation.
analyzers : shows available analyzers for peripheral.
commandFromHistory: executes command from history.
createPlatform : creates a platform.
currentTime : prints out and logs the current emulation virtual and real time
displayImage : Displays image in Monitor
execute : executes a command or the content of a VARIABLE.
help : prints this help message or info about specified command.
history : prints command history.
include : loads a monitor script, python code or a plugin class.
lastLog : Logs last n logs.
log : logs messages.
logFile : sets the output file for logger.
logLevel : sets logging level for backends.
mach : list and manipulate machines available in the environment.
macro : sets MACRO.
numbersMode : sets the way numbers are displayed.
path : allows modification of internal 'PATH' variable.
pause : pauses the emulation.
peripherals : prints list of registered and named peripherals.
python : executes the provided python command.
quit : quits the emulator.
require : verifies the existence of a variable.
runMacro : executes a command or the content of a MACRO.
set : sets VARIABLE.
showAnalyzer : opens a peripheral backend analyzer.
start : starts the emulation.
string : treat given arguments as a single string.
using : expose a prefix to avoid typing full object names.
verboseMode : controls the verbosity of the Monitor.
version : shows version information.
Creating a machine
Renode, version 1.13.2.18007 (9ab53ff7-202210031000)
(basic_k64f_mach) peripherals
Available peripherals:
sysbus (SystemBus)
│
├── cpu (CortexM)
│ Slot: 0
│
├── flash (MappedMemory)
│ <0x00000000, 0x000FFFFF>
│
├── mcg (K6xF_MCG)
│ <0x40064000, 0x40065000>
│
├── nvic (NVIC)
│ <0xE000E000, 0xE000EFFF>
│
├── sram (MappedMemory)
│ <0x20000000, 0x2002FFFF>
│
├── sram_l (MappedMemory)
│ <0x1FFF0000, 0x1FFFFFFF>
│
└── uart0 (K6xF_UART)
<0x4006A000, 0x4006AFFF>
Creating a machine
(basic_k64f_mach) sysbus.mcg
Usage:
sysbus.mcg MethodName param1 param2 ...
https://renode.readthedocs.io/en/latest/basic/machines.html#working-with-machines
(basic_k64f_mach) start
Starting emulation...
Interact with the application: analyzers
The application is running, but nothing happened.
We need to open a communication with the UART. The easiest way is to use the
Analyzer capabilities of the UART peripheral.
(basic_k64f_mach) help analyzers
Usage:
------
analyzers [peripheral]
lists ids of available analyzer for [peripheral]
[externalName] (optional) - if set, command will create external named [externalName]; this can be used
only for analyzers implementing IExternal interface
[typeName] (optional) - if set, command will select analyzer provided in class [typeName]; this must be
used when there are more than one analyzers available and no default is set
https://renode.readthedocs.io/en/latest/host-integration/uart.html
For this reason we can access either our own platform descriptions, or the ones provided
by renode by default.
Renode scripts and platforms: Examples
https://github.com/renode/renode
:load binary
sysbus LoadELF @Documents/polito/courses/soc-
arch/tests/ConsoleEcho_k64f/.pio/build/frdm_k64f/firmware.elf
:create socket for uart0 so that we can interact with it from the host
emulation CreateServerSocketTerminal 3456 "term"
connector Connect uart0 term
:start simulation
start
Renode scripts | include command
To call the script, simply use the include command.
Options:
. . .
[env:frdm_k64f]
platform = freescalekinetis
board = frdm_k64f
framework = zephyr
NOTE: in the previous example I had to modify the paths to make it work.
1. We have described a .resc file that we can not reuse for other apps that use
the same platform.
Solution:
● Common to the board: put it in the .resc file
● Specific to the application: put it in platformio.ini file
Integration: resc script with only what is common
k64f.resc
:name: K64F
:description: This script creates a machine and loads the K64F platform
We need a place to put our script file so that it can be accessed by renode easily.
You can discover the default renode path with:
In our case is simply the installation folder. We can place our general k64f.resc file under:
/opt/renode/scripts/single-node/
Integration: platformio.ini with specific commands.
NOTE:
$PROG_PATH resolves to our firmware.elf file.
In some platforms, $SOURCE resolves to firmware.elf
[env]
platform = freescalekinetis
board = frdm_k64f
framework = zephyr
[env:frdm_k64f_renode]
; Custom upload settings for renode integration
upload_protocol = custom
upload_command = renode $UPLOAD_FLAGS
upload_flags =
-e include @scripts/single-node/k64f.resc
-e sysbus LoadELF @$PROG_PATH
-e showAnalyzer uart0
-e emulation CreateServerSocketTerminal 3456 \"term\"
-e connector Connect uart0 term
-e start
[env:frdm_k64f_board]
; empty as by default it will upload to the board.
platformio.ini for board
The sources for the example that we have seen today are
available at:
https://github.com/SoC-Arch-polito/ex22-pio-renode-uart