knurling-rs / probe-run

Run embedded programs just like native ones
Apache License 2.0
645 stars 75 forks source link

Cannot flash to XMC4500 #386

Open KRACK-BIT opened 1 year ago

KRACK-BIT commented 1 year ago

Cannot run probe-run on an XMC4500 microcontroller; memory ranges are apparently incorrect I am currently trying to flash a very basic hello world program as a proof-of-concept for running on my microcontroller; however, this fails to run.

To Reproduce Steps to reproduce the behavior:

Example

  1. Install dependencies (snippet from my dockerfile):
    
    RUN apt install -y libusb-1.0-0-dev libudev-dev
    RUN apt install -y libudev-dev
    RUN sudo apt install -y acl less man-db nano
    RUN cargo install cargo-generate cargo-binutils
    RUN cargo install cargo-flash probe-rs probe-rs-cli probe-run

RUN rustup target add thumbv7em-none-eabihf RUN rustup component add llvm-tools-preview RUN rustup component add rustfmt

2. Write `example/hello.rs`
``` rust
//! Prints "Hello, world!" on the host console using semihosting

#![no_main]
#![no_std]

use panic_semihosting as _;

use cortex_m_rt::entry;
use cortex_m_semihosting::hprintln;

#[entry]
fn main() -> ! {
    hprintln!("Hello, world!");

    // exit QEMU
    // NOTE do not run this on hardware; it can corrupt OpenOCD state
    // debug::exit(debug::EXIT_SUCCESS);

    loop {}
}
  1. Run it with cargo run --example hello

Expected and observed behavior I was expecting it to successfully execute and print hello world

Resulting behavior however was

root@996f111a2f2d:/workspaces/kybe-rs# cargo run --example hello
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running `probe-run --chip XMC4500-F100x1024 target/thumbv7em-none-eabihf/debug/examples/hello`
Error: Error while flashing

Caused by:
    No flash memory contains the entire requested memory range 0x0c000000.. 0xc000400.

config.toml

[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = "probe-run --chip XMC4500-F100x1024"

rustflags = [
  # This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x
  # See https://github.com/rust-embedded/cortex-m-quickstart/pull/95
  "-C",
  "link-arg=--nmagic",

  # LLD (shipped with the Rust toolchain) is used as the default linker
  "-C",
  "link-arg=-Tlink.x",
]

[build]
target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU)

Probe details

The following devices were found:
[0]: J-Link (J-Link) (VID: 1366, PID: 0101, Serial: 000551022083, JLink)

Operating System: Docker Desktop on Windows (i.e. Linux VM on Windows); I've got USB pass-through set up, am doing everything within Linux, and it was working without issue when flashing with GDB, so should be working indistinguishable to a Linux box.

ELF file (attachment) I am happy to upload this, but rn GitHub isn't letting me upload things which are not a specific file type; what is the recommended way of uploading ELF files here?

Urhengulas commented 1 year ago

Hi @KRACK-BIT,

Did you do all the steps listed in the README of our app-template (https://github.com/knurling-rs/app-template)? Which HAL did you specify (maybe share your Cargo.toml)?

Is there a specific reason you use cortex-m-semihosting and not defmt? I don't know how the semihosting works and if it is maybe causing the issue.

KRACK-BIT commented 1 year ago

Hi @KRACK-BIT,

Did you do all the steps listed in the README of our app-template (https://github.com/knurling-rs/app-template)? Which HAL did you specify (maybe share your Cargo.toml)?

Is there a specific reason you use cortex-m-semihosting and not defmt? I don't know how the semihosting works and if it is maybe causing the issue.

Thanks for the reply @Urhengulas

I've gone through and switched my code to comply with the template; however, the code still does not work.

KRACK-BIT commented 1 year ago

Moreover, even when I downgrade and switch to using xmc4-hal, it does not work:

Current Cargo.toml

[package]
authors = ["KRACKY <46194176+KRACK-BIT@users.noreply.github.com>"]
name = "kybe-rs"
edition = "2021"
version = "0.1.0"

[lib]
harness = false

# needed for each integration test
[[test]]
name = "integration"
harness = false

[dependencies]
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
cortex-m-rt = "0.6"
# cortex-m-rt = "0.7"
# defmt = "0.2"
defmt = "0.3"
# defmt-rtt = "0.2"
defmt-rtt = "0.4"
# panic-probe = { version = "0.2", features = ["print-defmt"] }
panic-probe = { version = "0.3", features = ["print-defmt"] }
xmc4-hal = { version = "0.0.1", features = ["xmc4500"] }
# xmc4500 = "0.6.0"

# Rust crypto primities
sha3 = { version = "0.10.6", default-features = false }
kem = "0.2.0"
# hex-literal = "0.3.4"

# Uncomment for the allocator example.
# alloc-cortex-m = "0.4.0"

[dev-dependencies]
# defmt-test = "0.3"
# defmt-test = "0.2.3"

# [[bin]]
# name = "kybe-rs"
# test = false
# bench = false

# cargo build/run
[profile.dev]
codegen-units = 1
debug = 2
debug-assertions = true # <-
incremental = false
opt-level = 'z'         # <-
overflow-checks = true  # <-

# cargo test
[profile.test]
codegen-units = 1
debug = 2
debug-assertions = true # <-
incremental = false
opt-level = 3           # <-
overflow-checks = true  # <-

# cargo build/run --release
[profile.release]
codegen-units = 1
debug = 2
debug-assertions = false # <-
incremental = false
lto = 'fat'
opt-level = 3            # <-
overflow-checks = false  # <-

# cargo test --release
[profile.bench]
codegen-units = 1
debug = 2
debug-assertions = false # <-
incremental = false
lto = 'fat'
opt-level = 3            # <-
overflow-checks = false  # <-

# uncomment this to switch from the crates.io version of defmt to its git version
# check app-template's README for instructions
# [patch.crates-io]
# defmt = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version reported by `probe-run --version`" }
# defmt-rtt = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version reported by `probe-run --version`" }
# defmt-test = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version reported by `probe-run --version`" }
# panic-probe = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version reported by `probe-run --version`" }
KRACK-BIT commented 1 year ago

@Urhengulas do you (or anyone who is reading this) know if there are any examples of XMC devices successfully using this template for probe-run? It claims to be officially supported by probe-run, but I can't find any articles or issues giving a successful example of it running

Urhengulas commented 1 year ago

@Urhengulas do you (or anyone who is reading this) know if there are any examples of XMC devices successfully using this template for probe-run? It claims to be officially supported by probe-run, but I can't find any articles or issues giving a successful example of it running

I am not aware of any.

Urhengulas commented 1 year ago

Maybe you can open an issue on one of the HALs and ask if they have experience?