34

I am writing a code for Cortex-M3 cpu and I am performing unit testing using qemu-arm binary. For now everything works just fine. But I am wondering If I am able to test whole system using qemu-system-arm? I mean, I want to write custom "machine" for qemu where I will define desired memory map and eventually some software imitation of desired peripherals, are there some examples of such module? I found very little amount of information about this. I have read some source code in hw directory in qemu source tree but it is almost all uncommented, and I am still not sure if I understand how to add new machine to the qemu and how append peripheral to the address space?

mucka
  • 1,159
  • 2
  • 20
  • 28
  • 1
    What do you see as a benefit to do it on an arm emulator? It might be easier if you worked on your favorite dev-system, after all. Just stick to C, don't use anything specific which is not available on Arm and you can simulate the target hardware probably in a more straightforward way. – BitTickler May 04 '16 at 13:21
  • 3
    Too broad. If you want to write a custom machine for qemu, then do that. there are many there already use one of them as a starting point and the others as reference. If you end up with a specific problem, some code that doesnt work the way you think it should, then that is what stackoverflow is for. – old_timer May 04 '16 at 13:54
  • 1
    I've toyed with this idea for years, but in general, you would have to model the hardware peripherals you're talking to (which is really the interesting part of embedded work), and that isn't easy, and definitely isn't easy to be correct and is nearly impossible to model the quirks of the hardware peripherals. In short, I've always come to the conclusion that it's a fools errand. – Russ Schultz May 04 '16 at 23:05
  • 1
    Yeah, it is one of those things like climb the mountain "because its there" or just go around. Restore a classic car but then never drive it. Depending on the accuracy this could be a major task or not, and balance that with what you get vs just running on the hardware (you do get better visibility). It often becomes the mountain climbing hobby, or restoring a car, etc, not because I needed this tool, but more of I enjoyed the act of making the tool. – old_timer May 06 '16 at 11:32
  • 1
    I wouldnt assume that qemu's cpu cores are perfect nor constantly maintained, so you would have to start there. – old_timer May 06 '16 at 11:32

3 Answers3

40

In order to add your own machine, you need at least create one source file, containing the parameters and peripherals of your machine. After that, add a entry inside Makefile.objs, under qemu/hw/arm/. STM32 P103 machine entry.

Let's take as example Olimex STM32 P103 Development Board: Olimex STM32 P103 Development Board code. In lines 105 and 106, we have flash_size and ram_size. In lines 114 and 115 the code add a LED connect to GPIO A pin 0. In line 130 we have machine description, "Olimex STM32 p103 Dev Board". In line 131, the machine init function: stm32_p103_init. Another example of a machine more complete: Pebble machine code.

About peripherals, they are instantiated in each family code, considering stm32 case. stm32f1 family: stm32f1xx.c, stm32f2 family: stm32f2xx.c, stm32f4 family: stm32f4xx.c. The peripheral itself is implemented in a driver which typically has a suggestive name: stm32f2xx_adc.c, stm32f2xx_crc.c and so on. Example of a patch that add new peripheral: Addition of ADC to STM32.

ViniCoder
  • 589
  • 6
  • 14
  • 2
    Thank you very much for this answer. I have needed exactly that kind of a tip! – mucka Jul 22 '16 at 10:58
  • 2
    Ok, good! And sorry, I forgot to mention about peripherals. So I edited the post to include more informations. – ViniCoder Jul 22 '16 at 11:58
0

You can use Jumper Virtual Lab for simulation, check out this blog post from ARM mBed.

s__
  • 7,382
  • 2
  • 19
  • 40
0

For posterity, back in 2014, v3wwg created a new arm machine by making changes to Stellaris, an existing machine. Others who find this post can track his work by reading his thread on the [PRJC forum][1] and reviewing commits made to his qemu fork: https://github.com/ve3wwg/teensy3_qemu/commits/master

harrolee
  • 41
  • 5