Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Update to latest versions of HALs and esp-wifi, simplify Rhai script #123

Merged
merged 1 commit into from
Nov 2, 2023
Merged
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
4 changes: 2 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ rustflags = [
# NOTE: May negatively impact performance of produced code
"-C", "force-frame-pointers",
{% endif -%}
{%- if atomic_emulation == "riscv" %}
{%- if atomic_emulation and arch == "riscv" %}
# comment the cfgs below if you do _not_ wish to emulate atomics.
# enable the atomic codegen option for RISCV
"-C", "target-feature=+a",
Expand All @@ -37,7 +37,7 @@ rustflags = [
"--cfg", 'target_has_atomic="32"',
"--cfg", 'target_has_atomic="ptr"',
{% endif -%}
{%- if atomic_emulation == "esp32s2" %}
{%- if atomic_emulation and arch == "xtensa" %}
# enable the atomic codegen option for Xtensa
"-C", "target-feature=+s32c1i",

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ esp-println = { version = "0.7.0", features = ["{{ mcu }}"] }
esp-alloc = { version = "0.3.0" }
{% endif -%}
{% if wifi -%}
esp-wifi = { git = "https://github.com/esp-rs/esp-wifi/", rev = "fbb8417", features = ["{{ mcu }}", "wifi"] }
esp-wifi = { git = "https://github.com/esp-rs/esp-wifi/", rev = "7632e74", features = ["{{ mcu }}", "wifi"] }
smoltcp = { version = "0.10.0", default-features=false, features = ["proto-igmp", "proto-ipv4", "socket-tcp", "socket-icmp", "socket-udp", "medium-ethernet", "proto-dhcpv4", "socket-raw", "socket-dhcpv4"] }
embedded-svc = { version = "0.25.0", default-features = false, features = [] }
embedded-io = "0.4.0"
Expand Down
132 changes: 51 additions & 81 deletions pre-script.rhai
Original file line number Diff line number Diff line change
@@ -1,101 +1,71 @@
let targets = #{
let metadata = #{
// Xtensa devices:
esp32: #{
arch: "xtensa",
has_swd: false,
has_tg1: true,
sys_peripheral: "DPORT",
rct_peripheral: "RTC_CNTL",
toolchain: "esp",
rust_target: "xtensa-esp32-none-elf",
atomic_emulation: "none",
gcc_target: "xtensa-esp32-elf",
hal_version: "0.15.0",
hal_version: "0.16.0",
wokwi_board: "board-esp32-devkit-c-v4",
},
esp32s2: #{
atomic_emulation: true,
hal_version: "0.13.0",
wokwi_board: "board-esp32-s2-devkitm-1",
},
esp32s3: #{
hal_version: "0.13.0",
wokwi_board: "board-esp32-s3-devkitc-1",
},

// RISC-V devices:
esp32c2: #{
arch: "riscv",
has_swd: true,
has_tg1: false,
sys_peripheral: "SYSTEM",
rct_peripheral: "RTC_CNTL",
toolchain: "nightly",
rust_target: "riscv32imc-unknown-none-elf",
atomic_emulation: "riscv",
gcc_target: "riscv32-esp-elf",
hal_version: "0.10.0",
atomic_emulation: true,
extensions: "imc",
hal_version: "0.11.0",
wokwi_board: "",
},
esp32c3: #{
arch: "riscv",
has_swd: true,
has_tg1: true,
sys_peripheral: "SYSTEM",
rct_peripheral: "RTC_CNTL",
toolchain: "nightly",
rust_target: "riscv32imc-unknown-none-elf",
atomic_emulation: "riscv",
gcc_target: "riscv32-esp-elf",
hal_version: "0.12.0",
atomic_emulation: true,
extensions: "imc",
hal_version: "0.13.0",
wokwi_board: "board-esp32-c3-devkitm-1",
},
esp32c6: #{
arch: "riscv",
has_swd: true,
has_tg1: true,
sys_peripheral: "PCR",
rct_peripheral: "LP_CLKRST",
toolchain: "nightly",
rust_target: "riscv32imac-unknown-none-elf",
atomic_emulation: "none",
gcc_target: "riscv32-esp-elf",
hal_version: "0.5.0",
extensions: "imac",
hal_version: "0.6.0",
wokwi_board: "board-esp32-c6-devkitc-1",
},
esp32h2: #{
arch: "riscv",
has_swd: true,
has_tg1: true,
sys_peripheral: "PCR",
rct_peripheral: "LP_CLKRST",
toolchain: "nightly",
rust_target: "riscv32imac-unknown-none-elf",
atomic_emulation: "none",
gcc_target: "riscv32-esp-elf",
hal_version: "0.3.0",
extensions: "imac",
hal_version: "0.4.0",
wokwi_board: "board-esp32-h2-devkitm-1",
},
esp32s2: #{
arch: "xtensa",
has_swd: false,
has_tg1: true,
sys_peripheral: "SYSTEM",
rct_peripheral: "RTC_CNTL",
toolchain: "esp",
rust_target: "xtensa-esp32s2-none-elf",
atomic_emulation: "esp32s2",
gcc_target: "xtensa-esp32s2-elf",
hal_version: "0.12.0",
wokwi_board: "board-esp32-s2-devkitm-1",
},
esp32s3: #{
arch: "xtensa",
has_swd: false,
has_tg1: true,
sys_peripheral: "SYSTEM",
rct_peripheral: "RTC_CNTL",
toolchain: "esp",
rust_target: "xtensa-esp32s3-none-elf",
atomic_emulation: "none",
gcc_target: "xtensa-esp32s3-elf",
hal_version: "0.12.0",
wokwi_board: "board-esp32-s3-devkitc-1",
},
};

let target = variable::get("mcu");
let target_properties = targets.get(target);
for key in target_properties.keys() {
variable::set(key, target_properties.get(key));
let mcu = variable::get("mcu");
let meta = metadata.get(mcu);

if meta.contains("atomic_emulation") {
variable::set("atomic_emulation", meta.get("atomic_emulation"));
} else {
variable::set("atomic_emulation", false);
}

variable::set("hal_version", meta.get("hal_version"));

if mcu in ["esp32", "esp32s2", "esp32s3"] {
// Xtensa devices:
variable::set("arch", "xtensa");
variable::set("gcc_target", `xtensa-${mcu}-elf`);
variable::set("has_swd", false);
variable::set("rust_target", `xtensa-${mcu}-none-elf`);
variable::set("toolchain", "esp");
} else {
// RISC-V devices:
let extensions = meta.get("extensions");

variable::set("arch", "riscv");
variable::set("gcc_target", "riscv32-esp-elf");
variable::set("has_swd", true);
variable::set("rust_target", `riscv32${extensions}-unknown-none-elf`);
variable::set("toolchain", "nightly");
}

let advanced = variable::get("advanced");
Expand Down
15 changes: 3 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,9 @@ fn init_heap() {
fn main() -> ! {
{%- if alloc %}
init_heap();
{%- endif %}
{%- endif %}
let peripherals = Peripherals::take();
{% if arch == "xtensa" and wifi-%}
let mut system = peripherals.{{ sys_peripheral }}.split();
{% else -%}
let system = peripherals.{{ sys_peripheral }}.split();
{% endif -%}
let system = peripherals.SYSTEM.split();

let clocks = ClockControl::max(system.clock_control).freeze();
let mut delay = Delay::new(&clocks);
Expand All @@ -60,12 +56,7 @@ fn main() -> ! {
{% if arch == "riscv" -%}
let timer = SystemTimer::new(peripherals.SYSTIMER).alarm0;
{% else -%}
let timer = TimerGroup::new(
peripherals.TIMG1,
&clocks,
&mut system.peripheral_clock_control,
)
.timer0;
let timer = TimerGroup::new(peripherals.TIMG1, &clocks).timer0;
{% endif -%}
let _init = initialize(
EspWifiInitFor::Wifi,
Expand Down