Caution
work in progress - it may contains bugs or incorrect simulators behaviour.
This repository contains RP2040 MCU simulation description for Renode. Currently supported peripherals described in peripherals section.
It is a framework to build your own board level simulations that uses RP2040. There is predefined Raspberry Pico board description in: 'boards/raspberry_pico.repl'
Peripheral | Supported | Known Limitations |
---|---|---|
SIO | Partially supported (multicore, dividers), limitations to be filled when known | |
IRQ | Propagation from some peripherals is implemented | |
DMA | DMA implemented with ringing and control blocks support | |
Clocks | Clocks are mostly just stubs, but with tree propagation, but virtual time is always correct | |
GPIO | Pins manipulation implemented, with interrupts support. PIO may needs to be manually reevaluated due to CPU emulation (it's not step by step). Look for RP2040_SPI (PL022) peripheral as an example. Statuses may not be adequate to simplify simulation for now . | |
XOSC | ||
ROSC | ||
PLL | ||
SysConfig | ||
SysInfo | ||
PIO | Manual reevaluation may be neccessary to synchronize PIO together with actions on MCU. IRQ and DMA not yet supported | |
USB | ||
UART | Reimplemented PL011 to support DREQ generation for DMA and PIO interworking (in the future, not done yet) | |
SPI | Clock configuration not yet supported. Only master mode implemented with only one mode. Interworking with PIO is implemented! | |
I2C | ||
PWM | ||
Timers | Alarms implemented, but not all registers | |
Watchdog | fully implemented, but tick generator is stubbed with just LimitTimer | |
RTC | ||
ADC | Implemented, but RESD files were not verified. Resets and IRQs to be checked and to be added in all cases. | |
SSI | Implemented, XIP support/caches are stubbed. Resets/IRQs/DMA requests to be filled | |
XIP | Partially implemented, bootrom correctly starts firmware | |
Resets | Device resetting works, added to support watchdog fully | |
PSM | Just a stub, doesn't reset anything, but model states |
PIO is implemented as external simulator written in C++: piosim
directory. Decision was made due to performance issues with C# implementation.
Due to that PIO is modelled as additional CPU.
Renode executes more than 1 step at once on given CPU, so manual synchronization is necessary in some cases, like interworking between SPI and PIO.
Important
For Windows piosim.dll must be compiled inside msys environment: If you want to modify you have to setup msys environment with mingw-gcc and mingw-make. Exactly the same as for Verilator modules: CoSimulation Renode. Otherwise expect segmentation faults or Renode crashing on reading file header.
To use Raspberry Pico simulation clone Renode_RP2040 repository, then add path to it and include boards/initialize_raspberry_pico.resc
.
Example use:
(monitor) path add @repos/Renode_RP2040
(monitor) include @boards/initialize_raspberry_pico.resc
(raspberry_pico) sysbus LoadELF @repos/Renode_RP2040/pico-examples/build/hello_world/serial/
hello_serial.elf
(raspberry_pico) showAnalyzer sysbus.uart0
(raspberry_pico) start
Note
set VectorTableOffset to valid address for your firmware, for pico-examples it can be __VECTOR_TABLE symbol.
You may use it inside your simulation scripts, look at tests/prepare.resc
as an example.
Raspberry Pico configuration may be extended to configure board connections.
As an example you can check tests/pio/clocked_input/raspberry_pico_with_redirected_spi.repl
.
Then you can include boards/initalize_custom_board.resc
after setting $platform_file variable that points to your board.
$platform_file=@my_board.repl
include @boards/initialize_custom_board.resc
In the root of repository, there is the run_firmware.resc
script that configures RP2040 with specified firmware in ELF file.
Just define your script or use renode console to use it.
$global.FIRMWARE=my_awesome_binary.elf
include @run_firmware.resc
If you need to use your own board:
$platform_file=@my_awesome_board.repl
$global.FIRMWARE=my_awesome_binary.elf
include @run_firmware.resc
There is possibility to visualize board using python visualization plugin.
Important
Only Raspberry Pico based boards are currently supported You can add buttons or leds and they will be automatically registered But totally different boards are not supported yet
To use it create python virtual env, then inside virtualenv:
pip3 install -r visualization/requirements.txt
renode --console your_simulation.resc
inside renode console:
(rasbperry_pico) startVisualization 8080
and open localhost:8080 in your web browser.
Layouts are defined by user and can be saved in JSON file with save
button inside layout
section.
Loading is supported from website or with visualizationLoadLayout @path_to_file
command.
Elements on PCB can be marked as board elements with visualizationSetBoardElement <name>
command.
But they are not rendered yet. This is planned feature.
Example GUI may look like shown below:
There is a bug that sometimes 7-segment display is not rendered correctly. Zooming or refreshing browser seems to fix the problem as a workaround.
Many RP2040 simulators may interwork together. I am using that possibility in full MSPC simulation. To interwork between them GPIOConnector may be used, please check existing usage (simulation
directory):
MSPC Board Simulation
Renode is using optimizations to speed up emulation executing huge number of instructions at once per core.
This leads to accuracy problems which may be visible in some testing scenarios.
To improve accuracy you can use command:
emulation SetGlobalQuantum "0.000001"
With value necessary for your needs.
You can check example usages inside tests/pio/pio_blink/pio_blink.resc or tests/adc/adc_console/adc_console.resc.
This respository is highly coupled with Renode version. Use this repository with stable Renode 1.15.3
On linux only mono version is supported. For some reason dotnet version reports problems with IronPython, but it may be issue visible only on my machine.
I am testing simulator code using official pico-examples and some custom made build on top of pico-examples. For more informations look at pico_example_patches. Current tests list with statuses:
Example | Passed |
---|---|
adc_console | |
dma_capture | |
hello_adc | |
joystick_display | |
microphone_adc | |
onboard_temperature | |
read_vsys |
Example | Passed |
---|---|
blink |
Example | Passed |
---|---|
detached_clk_peri | |
hello_48MHz | |
hello_gpout | |
hello_resus |
Example | Passed |
---|---|
divider |
Example | Passed |
---|---|
channel_irq | |
control_blocks | |
hello_dma | |
sniff_crc |
Example | Passed |
---|---|
cache_perfctr | |
nuke | |
program | |
ssi_dma | |
xip_stream |
Example | Passed |
---|---|
dht_sensor | |
hello_7segment | |
hello_gpio_irq |
Example | Passed |
---|---|
serial | |
usb |
Example | Passed |
---|---|
bmp280_i2c | |
bus_scan | |
ht16k33_i2c | |
lcd_1602_i2c | |
lis3dh_i2c | |
mpc9808_i2c | |
mma8451_i2c | |
mpl3115a2_i2c | |
mpu6050_i2c | |
pa1010d_i2c | |
pcf8523_i2c | |
slave_mem_i2c | |
ssd1306_i2c |
Example | Passed |
---|---|
hello_interp |
Example | Passed |
---|---|
hello_multicore | |
multicore_fifo_irqs | |
multicore_runners | |
multicore_runner_queue |
Example | Passed |
---|---|
addition | |
apa102 | |
clocked_input | |
differential_manchester | |
hello_pio | |
hub75 | |
i2c | |
ir_nec | |
logic_analyser | |
manchester_encoding | |
onewire | |
pio_blink | |
pwm | |
quadrature_encoder | |
spi | |
squarewave | |
st7789_lcd | |
uart_rx | |
uart_tx | |
ws2812 |
Example | Passed |
---|---|
hello_pwm | |
led_fade | |
measure_duty_cycle |
Example | Passed |
---|---|
hello_reset |
Example | Passed |
---|---|
hello_rtc | |
rtc_alarm | |
rtc_alarm_repeat |
Example | Passed |
---|---|
bme280_spi | |
max7219_32x8_spi | |
max7219_8x7seg_spi | |
mpu9250_spi | |
spi_dma | |
spi_flash | |
spi_master_slave |
Example | Passed |
---|---|
hello_double_tap | |
narrow_io_write | |
unique_board_id |
Example | Passed |
---|---|
hello_timer | |
periodic_sampler | |
timer_lowlevel |
Example | Passed |
---|---|
device | |
dual | |
host |
Example | Passed |
---|---|
hello_watchdog |
MIT License
Copyright (c) 2024 Mateusz Stadnik (matgla@live.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.