diff --git a/dt-rust.yaml b/dt-rust.yaml index ca7be6ee..b2d53309 100644 --- a/dt-rust.yaml +++ b/dt-rust.yaml @@ -163,7 +163,8 @@ rules: - !Compatible names: - - "nxp,lpc-usart" + - "nxp,lpc-usart" # u_Note: Should probably pull in more eventually but this is what i have + - "zephyr,uart-emul" - "zephyr,native-pty-uart" level: 0 actions: diff --git a/qemu.sh b/qemu.sh new file mode 100755 index 00000000..e94b90da --- /dev/null +++ b/qemu.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# Builds and runs the QEMU build. + +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +BUILD_DIR="${BUILD_DIR:-$(west topdir)/build-qemu}" + +if command -v rustup >/dev/null 2>&1; then + rustup target add thumbv7m-none-eabi +fi + +# Build for QEMU (pass -p always via WEST_BUILD_ARGS for a pristine build). +west build -b qemu_cortex_m3 "$SCRIPT_DIR/samples/zephyr-odp" -d "$BUILD_DIR" ${WEST_BUILD_ARGS} + +# Launch the image in QEMU. +west build -t run -d "$BUILD_DIR" diff --git a/samples/zephyr-odp/CMakeLists.txt b/samples/zephyr-odp/CMakeLists.txt index e2f0bc0d..8f621642 100644 --- a/samples/zephyr-odp/CMakeLists.txt +++ b/samples/zephyr-odp/CMakeLists.txt @@ -12,4 +12,4 @@ rust_cargo_application() # Compile the C mock drivers target_sources(app PRIVATE drivers/fuel_gauge_emul.c) -target_sources(app PRIVATE drivers/pwm_emul.c) \ No newline at end of file +target_sources(app PRIVATE drivers/pwm_emul.c) diff --git a/samples/zephyr-odp/boards/qemu_cortex_m3.conf b/samples/zephyr-odp/boards/qemu_cortex_m3.conf new file mode 100644 index 00000000..1f00b400 --- /dev/null +++ b/samples/zephyr-odp/boards/qemu_cortex_m3.conf @@ -0,0 +1,21 @@ +# qemu_cortex_m3 configuration for the zephyr-odp sample. + +# Use QEMU UART instead of RTT +CONFIG_LOG_BACKEND_RTT=n +CONFIG_USE_SEGGER_RTT=n +CONFIG_RTT_CONSOLE=n +CONFIG_LOG_BACKEND_UART=y +CONFIG_UART_CONSOLE=y +CONFIG_STDOUT_CONSOLE=y + +# No DMA +CONFIG_DMA=n +CONFIG_DMA_MCUX_LPC=n # Disable NXP MCUX-specific stuff since QEMU + +# The emulators +CONFIG_EMUL=y +CONFIG_I2C_EMUL=y +CONFIG_GPIO_EMUL=y +CONFIG_UART_EMUL=y +CONFIG_F75303=y +CONFIG_EMUL_F75303=y diff --git a/samples/zephyr-odp/boards/qemu_cortex_m3.overlay b/samples/zephyr-odp/boards/qemu_cortex_m3.overlay new file mode 100644 index 00000000..4ab9d916 --- /dev/null +++ b/samples/zephyr-odp/boards/qemu_cortex_m3.overlay @@ -0,0 +1,77 @@ +#include +#include + +/ { + /* Emulated I2C bus hosting the temperature sensor and fuel gauge. */ + fake_i2c_bus: i2c@100 { + status = "okay"; + compatible = "zephyr,i2c-emul-controller"; + clock-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x100 4>; + + temperature_sensor_0: f75303@4c { + compatible = "fintek,f75303"; + reg = <0x4c>; + }; + + fuel_gauge: sbs-gauge@b { + compatible = "sbs,sbs-gauge-new-api"; + reg = <0x0b>; + status = "okay"; + }; + }; + + /* Emulated GPIO controller used for the tachometer input pin. */ + gpio_emul0: gpio-emul { + status = "okay"; + compatible = "zephyr,gpio-emul"; + rising-edge; + falling-edge; + high-level; + low-level; + gpio-controller; + #gpio-cells = <2>; + ngpios = <32>; + }; + tachometer: tachometer { + compatible = "zephyr,tach-gpio"; + gpios = <&gpio_emul0 15 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; + pulses-per-round = <2>; + }; + + /* Emulated PWM driver used by PWM Fan */ + pwm_emul0: pwm-emul { + status = "okay"; + compatible = "zephyr,pwm-emul"; + #pwm-cells = <3>; + frequency = <1000000>; + }; + fan0: my-fan { + compatible = "pwm-fan"; + pwms = <&pwm_emul0 7 40000 0>; + max-rpm = <5000>; + min-rpm = <0>; + min-start-rpm = <3000>; + }; + + /* Emulated RTC */ + rtc_emul: rtc_emul { + compatible = "zephyr,rtc-emul"; + status = "okay"; + }; + rs_rtc0: rs-rtc { + compatible = "rs,rtc"; + rtc = <&rtc_emul>; + resolution-hz = <1>; + }; + + /* Emulated UART */ + flexcomm0: uart-emul0 { + status = "okay"; + compatible = "zephyr,uart-emul"; + current-speed = <115200>; + loopback; + }; +}; diff --git a/samples/zephyr-odp/sample.yaml b/samples/zephyr-odp/sample.yaml index 1014ca7a..1ea92fff 100644 --- a/samples/zephyr-odp/sample.yaml +++ b/samples/zephyr-odp/sample.yaml @@ -6,8 +6,9 @@ common: tags: rust filter: CONFIG_RUST_SUPPORTED platform_allow: - - nrf52840dk/nrf52840' + - 'nrf52840dk/nrf52840' - 'mimxrt685_evk/mimxrt685s/cm33' + - 'qemu_cortex_m3' - 'native_sim/native/64' tests: sample.rust.helloworld: