LibreSolar / bms-firmware

Firmware for LibreSolar BMS boards based on bq769x0, bq769x2 or ISL94202
https://libre.solar/bms-firmware/
Apache License 2.0
146 stars 67 forks source link

QEMU Build Target #44

Open seandheath opened 7 months ago

seandheath commented 7 months ago

I'm working on a project where I would like to be able to use a VM to run this BMS. I know ZephyrOS supports QEMU VMs as targets, but I'm not sure of the steps required to get a LibreSolar BMS VM. I tried just building it using west build -b qemu_x86 but a series of errors from #define statements in devicetree.h cause the build to fail. I'm going to start working through the errors and see how far I get but wanted to check on here to see if anyone already has some knowledge that might help me out. Thanks!

Edit: forgot to mention, I'm building against v23.1, I noticed that commit f0ff664 from two weeks ago does some refactoring and the error messages are different between v23.1 and f0ff664, perhaps someone with more insight can weigh in and point me in the right direction here?

martinjaeger commented 7 months ago

Hi @seandheath,

That sound like a cool idea. I haven't tried it so far, but running the BMS in QEMU should be possible without too much work. So far we are only using native_posix for testing on a Linux host.

Most probably your Devicetree issues are because you need an overlay for the features necessary for the BMS. Have a look at tests/boards/native_posix.overlay as a starting point.

The recent refactoring should have made it easier to run with qemu, as we are now following the typical Zephyr way of doing things more closely (especially for the BMS IC drivers).

For the bq769x2 driver we have an emulation layer, which is used for the unit tests. This will also be helpful for qemu. With the emulated driver it should at least be possible to build and run the firmware successfully without actual hardware. The emulation does not simulate the behaviour of the actual chip, though. It just provides in interface to read/write its register contents, which can then be accessed through the bms_ic API.

martinjaeger commented 5 months ago

@seandheath I have just added a native_sim build target to allow running the BMS application on a Linux host.

Commit: c921b4d3ca64c0e19b41f9f452df2d382e0c5b7e