Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dt-rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions qemu.sh
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion samples/zephyr-odp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
target_sources(app PRIVATE drivers/pwm_emul.c)
21 changes: 21 additions & 0 deletions samples/zephyr-odp/boards/qemu_cortex_m3.conf
Original file line number Diff line number Diff line change
@@ -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
77 changes: 77 additions & 0 deletions samples/zephyr-odp/boards/qemu_cortex_m3.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include <zephyr/dt-bindings/gpio/gpio.h>
#include <zephyr/dt-bindings/i2c/i2c.h>

/ {
/* Emulated I2C bus hosting the temperature sensor and fuel gauge. */
fake_i2c_bus: i2c@100 {
status = "okay";
compatible = "zephyr,i2c-emul-controller";
clock-frequency = <I2C_BITRATE_STANDARD>;
#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;
};
};
3 changes: 2 additions & 1 deletion samples/zephyr-odp/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down