2

I am trying out this MCU / SoC emulator, Renode.

I loaded their existing model template under platforms/cpus/stm32l072.repl, which just includes the repl file for stm32l071 and adds one little thing.

When I then load & run a program binary built with STM32CubeIDE and ST's LL library, and the code hits the initial function of SystemClock_Config(), where the Flash:ACR register is being probed in a loop, to observe an expected change in value, it gets stuck there, as the Renode Monitor window is outputting:

[WARNING] sysbus: Read from an unimplemented register Flash:ACR (0x40022000), returning a value from SVD: 0x0

This seems to be expected, not all existing templates model nearly everything out of the box. I also found that the stm32L071 model is missing some of the USARTs and NVIC channels. I saw how, probably, the latter might be added, but there seems to be not a single among the default models defining that Flash:ACR register that I could use as example.

How would one add such a missing register for this particular MCU model?

Note1: For this test, I'm using a STM32 firmware binary which works as intended on actual hardware, e.g. a devboard for this MCU.

Note2: The stated advantage of Renode over QEMU, which does apparently not emulate peripherals, is also allowing to stick together a more complex system, out of mocked external e.g. I2C and other devices (apparently C# modules, not yet looked into it). They say "use the same binary as on the real system". Which is my reason for trying this out - sounds like a lot of potential for implementing systems where the hardware is not yet fully available, and also automatted testing. So the obvious thing, commenting out a lot of parts in init code, to only test some hardware-independent code while sidestepping such issues, would defeat the purpose here.

1 Answer 1

3

If you want to just provide the ACR register for the flash to pass your init, use a tag.

You can either provide it via REPL (recommended, like here https://github.com/renode/renode/blob/master/platforms/cpus/stm32l071.repl#L175) or via RESC.

Assuming that your software would like to read value 0xDEADBEEF. In the repl you'd use:

sysbus:
    init:
        Tag <0x40022000, 0x40022003> "ACR" 0xDEADBEEF

In the resc or in the Monitor it would be just:

sysbus Tag <0x40022000, 0x40022003> "ACR" 0xDEADBEEF

If you want more complex logic, you can use a Python peripheral, as described in the docs (https://renode.readthedocs.io/en/latest/basic/using-python.html#python-peripherals-in-a-platform-description):

flash: Python.PythonPeripheral @ sysbus 0x40022000
    size: 0x1000
    initable: false
    filename: "script_with_complex_python_logic.py"
```

If you really need advanced implementation, then you need to create a complete C# model.

As you correctly mentioned, we do not want you to modify your binary. But we're ok with mocking some parts we're not interested in for a particular use case if the software passes with these mocks.

Disclaimer: I'm one of the Renode developers.
6
  • 1
    I don't know about needing, but I'd definitely prefer to do anything in C# than Python ;) But if it's less effort to get "some logic" in Python...
    – sktpin
    Commented Nov 2, 2022 at 12:17
  • Where would I actually put a C# file that implements a peripheral to make it usable in a repl file? I found the "Peripheral modeling guide", which shows how to write those, but not how to use. The only *.cs files in the renode folder are unit tests.
    – sktpin
    Commented Nov 21, 2022 at 16:28
  • 1
    You can include it from your script. So put it in the same directory and in the script write include $ORIGIN/your_file.cs, then load the repl Commented Nov 22, 2022 at 9:14
  • Any idea (or how to find out?) what's wrong when, on loading the .cs file, I get the output: "Errors during compilation or loading: Could not compile assembly: ......\Renode\Peripherals\MyFile.cs(15,39): Antmicro.Renode.Peripherals.CRC " So I put my own sub namespace there the end, CRC, and to test whether this would maybe not be accepted, I used one that I saw in an example, "Miscellaneous", but same error. It does not give more details. Before that, I had some syntax errors in some places that it complained about that I fixed, so it did compile more than the first few lines.
    – sktpin
    Commented Nov 23, 2022 at 15:49
  • 1
    This is quite interesting. We usually show compilation errors, but this you discovered a single case where we failed. enum CRsubRegMasks : UInt32 didn't compile because you're missing using System; on top of the file. This will show additional errors, but they will be printed out by the Monitor Commented Nov 24, 2022 at 21:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.