0
点赞
收藏
分享

微信扫一扫

Renode:通过插件(plugin)导入自定义外设


Renode:通过插件(plugin)导入自定义外设

Renode 的 include 命令可以动态加载 .cs 文件,使用这个特性可以导入自定义外设,可以自行编写 Renode 安装包未包含的外设,然后通过 include 命令导入就可以使用了。

zoomdy at 163 dot com

编写自定义外设

用 C# 编写自定义外设模拟器,这要按照一定的规则,可以参考 renode/src/Infrastructure/src/Emulator/Peripherals/Peripherals/ 目录下的 C# 源文件编写。

// 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;
}
}

在 Monitor 中导入自定义外设 cs 文件

include @STM32_UART2.cs

在平台定义文件中引用自定义外设

编辑 test-plugin.repl 文件,引用 STM32_UART2,然后在 Monitor 中引入对应的 repl 文件。

// 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

创建 machine

创建 machine 并引入使用了自定义外设的平台定义文件。

mach create 
machine LoadPlatformDescription @test-plugin.repl

查看自定义外设

使用 peripherals 命令查看外设,最后的 uart3 是自定义外设。

(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>

执行自定义外设的操作

调用 uart3 的 Reset 操作,可以看到日志窗口输出正是自定义外设源文件中编写的那样。

(machine-0) sysbus.uart3 Reset

日志窗口输出

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

可能发生的错误

执行 include 命令时可能会发生错误:

Error running mcs: Cannot find the specified file

如果是 renode-1.11.0.linux-portable ,这个版本没有包含编译环境,因此报告这个错误,这个版本需要安装 mono 开发环境才可以 ​​include *.cs​​​。
换成 renode-1.12.0.linux-portable 就可以了,这个版本包含了编译环境了。
1.12.0 的发行日志是这么描述的:

ad hoc C# compilation now uses the same, bundled compiler on all OSes, also allowing for compilation in the portable Linux package.


举报

相关推荐

0 条评论