Renode: import custom peripheral through plugin

Keywords: simulator emulator

Renode: import custom peripheral through plugin

The include command of Renode can dynamically load. cs files. With this feature, you can import custom peripherals. You can write your own peripherals that are not included in the Renode installation package, and then import them with the include command.

https://blog.csdn.net/zoomdy/article/details/95492804
zoomdy at 163 dot com

Write a custom peripheral

Use C ා to write a custom peripheral simulator, which should follow certain rules, you can refer to the C ා source file under the directory of renode/src/Infrastructure/src/Emulator/Peripherals/Peripherals /.

// STM32_UART2.cs
using System;
using Antmicro.Renode.Core;
using Antmicro.Renode.Logging;
using Antmicro.Renode.Peripherals.Bus;
using System.Collections.Generic;
using Antmicro.Migrant;
using Antmicro.Renode.Core.Structure.Registers;

namespace Antmicro.Renode.Peripherals.UART
{
    [AllowedTranslations(AllowedTranslation.WordToDoubleWord | AllowedTranslation.ByteToDoubleWord)]
    public class STM32_UART2 : STM32_UART
    {
        public STM32_UART2(Machine machine, uint frequency = 8000000) : base(machine)
        {
            this.frequency = frequency;
        }



        public override void Reset()
        {
            base.Reset();
            // receiveFifo.Clear();
            this.Log(LogLevel.Warning, "Reseting...");
        }

        private readonly uint frequency;
    }
}

Import custom peripheral cs file in Monitor

include @STM32_UART2.cs

Referencing custom peripherals in platform definition files

Edit the test-plugin.repl file, reference STM32? UART2, and then import the corresponding repl file in Monitor.

// test-plugin.repl
fscmBank1: Memory.MappedMemory @ sysbus 0x60000000
    size: 0x10000000

sram: Memory.MappedMemory @ sysbus 0x20000000
    size: 0x00040000

flash: Memory.MappedMemory @ sysbus 0x08000000
    size: 0x200000

uart1: UART.STM32_UART @ sysbus <0x40011000, +0x100>
    -> nvic@37

uart2: UART.STM32_UART @ sysbus <0x40004400, +0x100>
    -> nvic@38

uart3: UART.STM32_UART2 @ sysbus <0x40004500, +0x100>
    -> nvic@38
   
nvic: IRQControllers.NVIC @ sysbus 0xE000E000
    systickFrequency: 72000000
    IRQ -> cpu@0

cpu: CPU.CortexM @ sysbus
    cpuType: "cortex-m4"
    nvic: nvic

Create machine

Create a machine and introduce a platform definition file that uses a custom peripheral.

mach create 
machine LoadPlatformDescription @test-plugin.repl

View custom peripherals

Use the peripherals command to view the peripherals. The last uart3 is the custom peripherals.

(machine-0) peripherals 
Available peripherals:
  sysbus (SystemBus)
  │   
  ├── cpu (CortexM)
  │     Slot: 0
  │       
  ├── flash (MappedMemory)
  │     <0x08000000, 0x081FFFFF>
  │       
  ├── fscmBank1 (MappedMemory)
  │     <0x60000000, 0x6FFFFFFF>
  │       
  ├── nvic (NVIC)
  │     <0xE000E000, 0xE000EFFF>
  │       
  ├── sram (MappedMemory)
  │     <0x20000000, 0x2003FFFF>
  │       
  ├── uart1 (STM32_UART)
  │     <0x40011000, 0x400110FF>
  │       
  ├── uart2 (STM32_UART)
  │     <0x40004400, 0x400044FF>
  │       
  └── uart3 (STM32_UART2)
        <0x40004500, 0x400045FF>

Perform custom peripheral operations

Call the Reset operation of uart3, and you can see that the output of the log window is exactly the same as that written in the source file of the custom peripheral.

(machine-0) sysbus.uart3 Reset

Log window output

16:59:03.4677 [WARNING] uart3: Reseting.

Posted by riddhi on Wed, 30 Oct 2019 10:23:38 -0700