No loadable segments were found in the elf file - cargo embed

Hello everyone,

I have a very important issue. I'm encountering this error and don't know what to do. I'm using an STM32G070RBT6, and the program compiles correctly. However, when it's time to flash the program onto the microcontroller using cargo embed, this error occurs. It was supposed to work because I'm using the same configuration I used before. Can somebody help me please? Thank you a lot!
erro_loadable

maybe your memory region configs don't agree with the device.

check the memory.x and Embed.toml.

or, are using custom linker script? check the linkder script also.

I'm using the same configuration that I used for anothers projects in rust in the same board and they worked. I don't know what else to do. I'm frustrated. Now I'm facing these errors. The first one I think I solved.

and this one another

link.x only appears one time.

please show the content of your configurations, mainly, .cargo/config.toml, and build.rs if you have one. the more information you give, the easier to figure out where the problem is.

I think you put the [build] and [target.'thumbv6m-none-eabi'] in Cargo.toml rather than .cargo/config.toml.

1 Like

These are my codes:

.cargo/config.toml:

[build]
target = "thumbv6m-none-eabi"

[target.thumbv6m-none-eabi]
runner = "probe-rs run --chip STM32G070RBT6"
linker = "arm-none-eabi-ld"
rustflags = [
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=-Tdefmt.x"
]

[profile.dev]
opt-level = "s"

[profile.release]
debug = 2
opt-level = "z" # Otimização de tamanho
lto = true # Link Time Optimization

build.rs:
fn main() {
println!("cargo:rustc-link-arg-bins=--nmagic");
println!("cargo:rustc-link-arg-bins=-Tlink.x");
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
}

Cargo.toml:

[package]
name = "testeLed"
version = "0.1.0"
edition = "2021"
license = "MIT OR Apache-2.0"

[dependencies]
cortex-m = { version = "0.7.7", features = ["inline-asm", "critical-section-single-core"] }
cortex-m-rt = "0.7.3" #em vez de 3 tava 1
lilos = "1.2.0"
panic-halt = "0.2.0"
embedded-hal = "1.0.0"
stm32g0 = { version = "0.15.1", default-features = false, features = ["rt", "stm32g070"] }
stm32g0xx-hal = { version = "0.2.0", features = ["rt", "stm32g070"] }
nb = "1.1.0"
panic-probe = { version = "0.3.2", features = ["print-defmt"] }
defmt = "0.3.8"
defmt-rtt = "0.4.1"
heapless = { version = "0.8.0", default-features = false }

embed.toml:
[default.probe]
protocol = "Swd"

[default.general]
chip = "STM32G070RBTx" # bluepill
#chip = "STM32F303VCTx" # discovery-stm32f303

[default.rtt]
enabled = false

[default.gdb]
enabled = false

memory.x:
/* Linker script para STM32G070RBT6 */

MEMORY {
/* NOTE K = KiBi = 1024 bytes */
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 36K
}

It's very confusing!

these linker flags are duplicated. either put them in .cargo/config.toml, or build.rs, but NOT both places.

Yes, you're right. Thank you so much. I have been learning rust so sometimes it's confusing. The blink code isn't working though. I'll let the main.rs code here. If you could take a look I appreciate. It's basic. I intend to improve this code later.

#![no_main]
#![no_std]

use cortex_m_rt::entry;
use stm32g0xx_hal as hal;
use hal::prelude::*;
use hal::rcc::Config;
use hal::stm32;
use lilos::time::{Millis, initialize_sys_tick};
use lilos::exec::run_tasks;
use lilos::time::PeriodicGate;
use panic_halt as _; 
use defmt_rtt as _;


const PERIOD: Millis = Millis(2000);

#[entry]
fn main() -> ! {

    let dp = stm32::Peripherals::take().expect("cannot take peripherals");


    let mut rcc = dp.RCC.freeze(Config::lsi());


    let gpioa = dp.GPIOA.split(&mut rcc);
    let mut led = gpioa.pa5.into_push_pull_output();


    initialize_sys_tick(&mut cortex_m::Peripherals::take().unwrap().SYST, 16_000_000);


    let blink = core::pin::pin!(async {

        let mut gate = PeriodicGate::from(PERIOD);

        loop {

            led.toggle().unwrap();

            gate.next_time().await;
        }
    });


    run_tasks(
        &mut [blink],
        lilos::exec::ALL_TASKS,
    )
}

I'm not familiar with the lilos crate you are using, but if I'm reading the doc correctly, you are telling it the systick is running at 16MHz at this line:

but you selected the LSI as the clock source:

if I'm gonna take a guess, what you probably want is something like:

dp.RCC.freeze(Config::hsi(Prescaler::NotDivided));
1 Like

yes, you're right. It worked! Thank you so much!