Qemu STM32

Development environment specific, Arduino, Eclipse, VS2013, Em::Blocks etc
Post Reply
ag123
Posts: 467
Joined: Thu Dec 19, 2019 5:30 am
Answers: 1

Qemu STM32

Post by ag123 »

i tried this out in linux, it need to be built from sources
http://beckus.github.io/qemu_stm32/
https://github.com/beckus/qemu_stm32
the sources are somewhat old but someone has contributed a 'machine' for stm32f103, back in the times during old stm32duino forums i think.
the emulation features are rather rudimentary, mainly providing text output on the command line
an emulation session looks like this:
> arm-softmmu/qemu-system-arm -machine stm32-f103c8 -kernel image.bin -s

STM32_UART: ADC1 clock is set to 0 Hz.
STM32_UART: ADC1 BRR set to 0.
STM32_UART: ADC1 Baud is set to 0 bits per sec.
STM32_UART: ADC2 clock is set to 0 Hz.
STM32_UART: ADC2 BRR set to 0.
...
CLKTREE: HSI Output Change (SrcClk:None InFreq:8000000 OutFreq:8000000 Mul:1 Div:1 Enabled:1)
CLKTREE: HSI/2 Output Change (SrcClk:HSI InFreq:8000000 OutFreq:4000000 Mul:1 Div:2 Enabled:1)
CLKTREE: SYSCLK Output Change (SrcClk:HSI InFreq:8000000 OutFreq:8000000 Mul:1 Div:1 Enabled:1)
...
LED On
LED Off
LED On
LED Off
I don't think usb-serial is there but it seemed hardware uart is implemented, i've not tried out that.
gdb connects and i'm able to step the instructions, it apparently works even if the usb-dfu stm32duino bootloader is installed before it.
i need to use this shell script to patch the bins together into a single file

Code: Select all

if [ "$1" == "" ]; then
  echo $0 binfile.bin
  exit 0
fi
dd if=/dev/zero bs=1024 count=128 of=image.bin
dd if=maple_mini_boot20.bin bs=1024 conv=nocreat,notrunc of=image.bin
dd if=$1 bs=1024 conv=nocreat,notrunc seek=8 of=image.bin
there is another implementation at pebble github repository
https://github.com/pebble/qemu
this is more complete and apparently has F2 and F4 support but is based around pebble obviously
the sources of qemu is huge and pretty complex, i've not gotten a grasp of that
but it seem to be in the hw/arm folder
https://github.com/pebble/qemu/tree/master/hw/arm
https://github.com/pebble/qemu/blob/mas ... m/pebble.c
https://github.com/pebble/qemu/blob/mas ... tm32f1xx.c
https://github.com/pebble/qemu/blob/mas ... tm32f4xx.c
these emulators normally won't be able to handle real time time sensitive stuff, but i'm not too sure if it could help to debug those complicated memory and such problems. i've not tried out the pebble repository but that seem to be a better qemu stm32 implementation

mrburnette
Posts: 201
Joined: Thu Dec 19, 2019 1:23 am

Re: Qemu STM32

Post by mrburnette »

ag123 wrote:
Tue Jun 02, 2020 5:52 pm
...
these emulators normally won't be able to handle real time time sensitive stuff, but i'm not too sure if it could help to debug those complicated memory and such problems. i've not tried out the pebble repository but that seem to be a better qemu stm32 implementation
This is interesting, but I try very, very hard to avoid complicated memory and such problems. :shock:

When real debugging is needed, a real (professional) tool set and environment such as STM's is a good starting place and then augment as needed. I'm fairly certain that STM has a true emulator that doesn't get outside their workarea, but blackmagic is probably all most of us will need, IMO.

In my world, I have found that my investment in a decent storage oscilloscope and a Saleae 16-input logic analyzer to be the best investments, beyond a decent DVM. Those hardware tools do not get used often, but they always come through since I seem to be able to do the software side OK but making downstream I2C and SPI stuff work the way it should is not always straight forward with taking a picture of the communication streams. If one balks at the investment, perhaps getting some friends together with similar interests and sharing the cost would be workable. I do not belong to a Make group, but there are several around, and I understand they have Arduino interest groups.


Ray

ag123
Posts: 467
Joined: Thu Dec 19, 2019 5:30 am
Answers: 1

Re: Qemu STM32

Post by ag123 »

thanks ray, i think most of us has been able to make do without an emulator as debug support on real devices is very good.
i can think of a few uses for the emulator. memory is one of them, i think the emulator probably can set fences so that the moment the stack overwrites global variables, or it overwrites some fenced regions, it sound out an error, this is near impossible to diagnose on real hardware as the condition may be data dependent. the other one which is a reason i originally played with qemu is i hope to make it possible to emulate an lcd connected at SPI, e.g. ILI9341.
i'm not too sure how difficult is it to achieve that. that can be very useful if one is building a 'gui' on these little devices.

the other pieces of equipment are very valuable indeed, but i'd guess they address different purposes.

mrburnette
Posts: 201
Joined: Thu Dec 19, 2019 1:23 am

Re: Qemu STM32

Post by mrburnette »

ag123 wrote:
Tue Jun 02, 2020 6:45 pm
...
the other pieces of equipment are very valuable indeed, but i'd guess they address different purposes.
There are two (2) very different investments in this game: money and time and against the belief that they are the same, in this game they are distinct. If one has an old Windows XT computer, one can play in this field for around $2 assuming they have the USB cable :D

But there is an investment in time that is generally split (my experience) between specific research on a particular architecture (ESP8266, ESP32, STM32F103, etc.) and the general investment in just coding, debugging, and porting.

The test equipment is that investment in the whole art: electronic designing, prototyping, protocol study and proficiency, and just tinkering around with electronics beyond what can be done in an simulator such as falstad.com. I, for one, have been around this hobby for years and can attest that an emulator only gets one partially through the door ... the physical prototype is required to put things into the "real world."

Whether one is investing time or money or both, everyone wants to get the biggest-bang for the buck$ spent. Proficiency in one uC simply does not translate well to another unless one has a firm grip on all of the surrounding technology: electronics, coding, vocabulary (both electronics and software), and some not-so-small dexterity in prototyping which generally involves soldering, gluing, cutting metal and plastic and wood, and so-on. But time is finite, then we die. :cry:

The reality is, with Arduino at least, I simply have not had a stack-fault or memory overrun. But, I spend a good deal of time in planning my software ideas, doing calculations on memory usage, and avoiding dynamic objects as much as possible ... this does not translate to my PC coding style where virtual memory is a godsend.

I believe Arduino, as a company, can do a lots better giving us some profiling tools and runtime diagnostics. Where they are going as a company is somewhat obscured by the fragmentation of the IDE into an installed version and a web-version. Now, the installed version is splitting into a consumer grade and a pro-grade and I wonder if the pro-grade will remain "free"? Clearly, the proliferation of hardware boards is not in keeping with a simply, educational, artsy-fartsy need, but rather a need to provide a variety of new hardware: as represented by the new Nano 33 flavors, the Protenta H7, the MKR series, and the Yun.

Continuing the idea from above, I think it is great that Arduino provides lots of useful products for a variety of needs; but this is not how the Arduino paradigm started. It is a commercialized approach at building a brand and a technology enabler. Once, the Maple Mini and other 'clone' boards with hacked cores filled in the gaps - to a big degree, they still do if one is looking at the buy-in cost$ for true-Arduino hardware. It is, in my mind, simply ridiculous: $40+ for a Mega2560 or $32+ for an MKR WiFi. We are seriously entering the pricing domain of the Raspberry Pi 4 w/2G.

What bothers me with processor emulators is that they are rather complex, often buggy, do not teach good coding skills, often have limited support for modeling peripherals, and the better ones are not free. Most times the user approach is: simulate it, prototype it, and go to the forum when things get ugly. Even as a hobbyist, the 'art' requires study and perseverance with research and mental thought experiments necessary to uncover root causes. These learned skills are cross-platform and are valuable for future reuse; they become reinforced with usage and the skill-set and overall understanding is continuously enhanced.

But, I will completely agree with you that in certain circumstances, emulators can provide valuable insight into the inner workings of stuff. That along does not compel me to recommend to novice users to expend the energy to learn to use them; in my opinion, there are better things to use your free time... like pizza and beer.

Ray

ag123
Posts: 467
Joined: Thu Dec 19, 2019 5:30 am
Answers: 1

Re: Qemu STM32

Post by ag123 »

well, just my 2 cents, i messed with emulators as i hoped i'd be able to get an lcd simulation into it. not so much the other hardware aspects of it.
building a GUI can be rather complex. And i often find myself flashing the firmware over and over while 'perfecting' the codes.
with an emulator, the process becomes nearly code and just 'run'. it is quite similar to doing so on real hardware just that it reduces repeated flashes on the flash mem.

mrburnette
Posts: 201
Joined: Thu Dec 19, 2019 1:23 am

Re: Qemu STM32

Post by mrburnette »

ag123 wrote:
Wed Jun 03, 2020 6:45 am
well, just my 2 cents, i messed with emulators as i hoped i'd be able to get an lcd simulation into it. not so much the other hardware aspects of it.
building a GUI can be rather complex. And i often find myself flashing the firmware over and over while 'perfecting' the codes.
with an emulator, the process becomes nearly code and just 'run'. it is quite similar to doing so on real hardware just that it reduces repeated flashes on the flash mem.
Ah, ha! Having followed your postings for a long time, I wondered what the fascination was with the 'emulation stuff' and now I think I can see a little through the fog. Development methodology based upon The Calculus... successive approximation, that is :lol:

I think that even old folk like me that learned to write FORTRAN on old green coding sheets and submitting that to be keypunched have now fallen prey to the quick recompile and upload methodology. Example: The output of the Serial.print is not lined up correctly, just edit the spacing, recompile, upload, and observe the change. No one ever seems to have enough free time. With fast computers and tools that permit near instant turnaround time, it is likely that returning to a code on paper first will never happen again - it is just a flash in the history of digital computing.

The above being said, is it prudent to spend time learning the ins and the outs of a emulator when the prototype board is under $2? So what if the flash wears out in 10K program cycles? That is $2 divided by 10000 = $0.0002 = 20 milli-cents per upload cycle. And you may get more than 10K writes on the embedded flash further lowering the depreciation per write cycle. And when the F103 dies from old age, just hot-air that bad boy off the board and put on an F4... those boards can easily be recycled.

But, in complete transparency, I too am guilty of The Calculus of writing programs ... I am embarrassed somewhat because giving a bit more attention to reviewing the code before upload would catch 80% of my errors. The human need for immediate feedback outweighs the few minutes it would take to review the code. It is the way we live in these times.

I just felt the need to be the Devil's Advocate and get people into thinking about the investment and return on the emulator in the current state of the technology (free, open source.) I have used these products before and I think playing around is great fun, but I really never got to the point where I felt that my time investment returned a dividend... I always gave more than I got, or so it seemed.


Ray

ag123
Posts: 467
Joined: Thu Dec 19, 2019 5:30 am
Answers: 1

Re: Qemu STM32

Post by ag123 »

well, what you mentioned makes sense, in a sense, normally i do without an emulator. but situations sometimes gets tight especially that after all stm32f103c8 has 20k sram it'd be great if an emulator can be used to diagnose memory overruns. And occasionally, i find myself lazy to patch together all those wires necessary to get an lcd going, it is quite a few more than just 3 lanes on SPI (MOSI,MISO, CLK) so occasionally i kind of wish that i can still simulate the same without patching up the wires, but of course this isn't real so it may just break the moment it gets tested on a real device :lol:

Post Reply

Return to “IDE's”