I find it a useful tool. Maybe you will, too!
Emulation is a lie
flash: Memory.MappedMemory @ sysbus 0x00000000
size: 0x00008000
sram: Memory.MappedMemory @ sysbus 0x20000000
size: 0x00001000
nvic: IRQControllers.NVIC @ sysbus 0xE000E000
IRQ -> cpu@0
cpu: CPU.CortexM @ sysbus
cpuType: "cortex-m0+"
PerformanceInMips: 24
nvic: nvic
bluenrg-1.repl
Firmware is a series of instructions executed by the CPU in order to accomplish a task
Firmware is Memory
sysbus LoadELF @firmware.elf
sysbus LoadBinary @rom.bin 0x20000000
LoadBinary
!
sysbus LoadBinary @rom.bin 0x20000000
sysbus.cpu VectorTableOffset 0x20000000
sysbus.cpu SP `sysbus ReadDoubleWord 0x20000000`
sysbus.cpu PC `sysbus ReadDoubleWord 0x20000004`
start
flash: Memory.MappedMemory @ sysbus 0x00000000
size: 0x00008000
sram: Memory.MappedMemory @ sysbus 0x20000000
size: 0x00001000
nvic: IRQControllers.NVIC @ sysbus 0xE000E000
IRQ -> cpu@0
// 👇 Add a UART with IRQ #10 at address 0x40300000
uart: UART.PL011 @ sysbus 0x40300000
-> nvic@10
cpu: CPU.CortexM @ sysbus
nvic: nvic
cpuType: "cortex-m0+"
PerformanceInMips: 24
bluenrg-1.repl
machine LoadPlatformDescription @bluenrg-1.repl
sysbus LoadBinary @BLE_Chat_Server.bin 0x10040000
cpu VectorTableOffset 0x10040000
cpu SP `sysbus ReadDoubleWord 0x10040000`
cpu PC `sysbus ReadDoubleWord 0x10040004`
start
//
// Copyright (c) 2010-2018 Antmicro
//
// This file is licensed under the MIT License.
// Full license text is available in 'licenses/MIT.txt'.
//
using System;
using Antmicro.Renode.Peripherals.Bus;
using System.Collections.Generic;
using Antmicro.Renode.Core;
using Antmicro.Renode.Logging;
using Antmicro.Renode.Peripherals.Miscellaneous;
using Antmicro.Migrant;
namespace Antmicro.Renode.Peripherals.UART
{
[AllowedTranslations(AllowedTranslation.ByteToDoubleWord)]
public class AxiUartLite : IDoubleWordPeripheral, IUART, IKnownSize
{
public AxiUartLite()
{
readFifo = new Queue<uint>();
}
public void WriteChar(byte value)
{
readFifo.Enqueue(value);
}
public void Reset()
{
readFifo.Clear();
}
public uint ReadDoubleWord(long offset)
{
switch((Register)offset)
{
case Register.RxFIFO:
if(readFifo.Count == 0)
{
this.Log(LogLevel.Warning, "Trying to read from empty fifo.");
return 0;
}
return readFifo.Dequeue();
case Register.Status:
// Tx FIFO Empty | Rx FIFO Valid Data
return (1u << 2) | (readFifo.Count == 0 ? 0 : 1u);
default:
this.LogUnhandledRead(offset);
return 0;
}
}
public void WriteDoubleWord(long offset, uint value)
{
switch((Register)offset)
{
case Register.TxFIFO:
CharReceived?.Invoke((byte)value);
break;
default:
this.LogUnhandledWrite(offset, value);
break;
}
}
[field: Transient]
public event Action<byte> CharReceived;
public long Size { get { return 0x10; } }
public Bits StopBits { get { return Bits.One; } }
public Parity ParityBit { get { return Parity.None; } }
public uint BaudRate { get { return 0; } }
private readonly Queue<uint> readFifo;
private enum Register
{
RxFIFO = 0x0,
TxFIFO = 0x4,
Status = 0x8,
Control = 0xC
}
}
}
AxiUartLite.cs
Hackaday Supercon 2019
Betrusted ENGINE
*** Settings ***
Suite Setup Setup
Suite Teardown Teardown
Test Setup Reset Emulation
Test Teardown Test Teardown
Resource ${RENODEKEYWORDS}
*** Variables ***
${UART} sysbus.uart0
${URI} @https://dl.antmicro.com/projects/renode
${LIS2DS12}= SEPARATOR=
... """ ${\n}
... using "platforms/cpus/nrf52840.repl" ${\n}
... ${\n}
... lis2ds12: Sensors.LIS2DS12 @ twi1 0x1c ${\n}
... ${SPACE*4}IRQ -> gpio0@28 ${\n}
... """
*** Keywords ***
Create Machine
Execute Command mach create
Execute Command machine
... LoadPlatformDescriptionFromString ${LIS2DS12}
Execute Command sysbus LoadELF
... ${URI}/nrf52840--zephyr_lis2dh.elf-s_747800-163b7e7cc986d4b1115f06b5f3df44ed0defc1fa
*** Test Cases ***
Should Read Acceleration
Create Machine
Create Terminal Tester ${UART}
Execute Command sysbus.twi1.lis2ds12 AccelerationX 10
Execute Command sysbus.twi1.lis2ds12 AccelerationY 5
Execute Command sysbus.twi1.lis2ds12 AccelerationZ -5
Start Emulation
Wait For Line On Uart
... x 9.997213 , y 4.997410 , z -4.999803
LIS2DS12.robot
BlueNRG2.svd
sysbus ApplySVD @BlueNRG2.svd