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?
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.