Questions tagged [rust-no-std]
38 questions
1
vote
1 answer
Rust no_std static lib panic_handler
I want to build a no_std static library with rust.
I got the following:
[package]
name = "nostdlb"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["staticlib"]
[profile.dev]
panic = "abort"
[profile.release]
panic =…

Curunir
- 1,186
- 2
- 13
- 30
1
vote
0 answers
Get file size in uefi-rs
I am making a basic uefi application that is supposed to load an elf kernel. I have gotten to the point that I have the fille loaded, and a buffer with the file info. But to actually read the file and do anything with it, I need to know the file…

Olle
- 81
- 5
1
vote
1 answer
error[E0463]: can't find crate for `alloc` error from imported crate when building for thumbv8m.main-none-eabi
I am trying to use a library that uses ff crate in an embedded application, but as the title says, I am getting errors from the crate used in the imported library even if I enabled alloc feature flag inside of Cargo.toml.
I also double checked that…

user76333
- 153
- 1
- 13
1
vote
1 answer
no global memory allocator found but one is required; link to std or add `#[global_allocator]` to a static item that implements the GlobalAlloc trait
I am currently working on an embedded development project using the Rust.
However, when I tried to use my own library, which I had been using individually (and as a standard library), in an application on the embedded side, an error occurred as…

user76333
- 153
- 1
- 13
1
vote
3 answers
How to test result of core::fmt::Display trait implementation in #![no_std] env
I have following struct and want to test implementation of Display trait:
use core::fmt::{Display, Formatter, Result};
struct B {}
impl Display for B {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(f, "A {} C", "B")
…

Michał Zabielski
- 344
- 2
- 14
1
vote
1 answer
How to make Debug emit hex values in no_std code?
I'm making a bare metal application in Rust. I can easily make any given struct print its debug information, but I'd like some of them to print some of their values in hex.
For example:
impl core::fmt::Debug for Task {
fn fmt(&self, fmt: &mut…

Błażej Michalik
- 4,474
- 40
- 55
1
vote
1 answer
Add str no_std Rust
I've been starting to write no_std Rust code and right now I'm trying to add strings.
This is my code:
#![no_std]
extern crate libc;
fn add_string(string: &str) {
const STRING1: &'static str = string;
const STRING2: &'static str =…

Nathan McMillan
- 47
- 2
- 9
1
vote
1 answer
How can I mutate a slice when I know that there are no more references to its current content?
On an embedded device without a heap, I want to parse input data and store the found results in an output slice. I have a reader which allows me to get the currently available data and a parser which matches the input data to the expected format and…

Binabik
- 1,013
- 11
- 24
0
votes
0 answers
strange rust-lld error in no_std environment
I'm trying to use rust-lld to link a custom kernel written in Rust and I'm getting this weird error:
error: linking with `rust-lld` failed: exit status: 1
|
= note: LC_ALL="C"…

kamkow1
- 467
- 2
- 8
0
votes
0 answers
Rust `heapless::IndexMap` implementation with custom hasher
Background
I'm fairly new to Rust, and I'm trying to set up a hash table using the CRC32 hash in a #[no_std] environment, without an allocator.
I found heapless::IndexMap which is generic around the hashing algorithm, so I was hoping to implement…

DeathDonkey387
- 35
- 6
0
votes
0 answers
Running tests in a no_std crate yeilds error `start` lang item not found
I'm writing a simple kernel/OS with help from https://os.phil-opp.com. when I got the step about testing I could not for the life of me get it working so I ended up skipping it altogether, but now my lack of testing is starting to get quite…

Gavin Niederman
- 11
- 1
- 4
0
votes
1 answer
How to convert a &str or &[u8] like "0x124" to its numerical representation in no_std rust?
I have this function created in rust that will take an input like "0x152" and return its integer value. For example, "123" would be 123 as u32. This works in a std environment, but after testing on a MCU, I realized there are functional differences…
0
votes
0 answers
How do I wrap a pub extern "C" fn such that such that I can call a method of a struct?
I have hit a wall recently. The summary would be the following: I would like to wrap a pub extern "C" fn on_sync() { ... } such that when it is called I can also call a method named pub fn on_sync(&self) { ... } defined in an impl of a struct…

Mihai Bojescu
- 13
- 5
0
votes
0 answers
Stateful embedded library in Rust
I want to develop a library in Rust for microcontrollers that holds some state information.
This state data cannot be transferred to the caller of the library. I am using #![no_std]. The library should be suitable for bare metal applications and…

Stefan
- 83
- 8
0
votes
0 answers
cargo/rustc produces no_std ELF without compiled functions (riscv32i-unknown-none-elf)
Given this .cargo/config:
[build]
target = "riscv32i-unknown-none-elf"
and this main.rs:
#![no_std]
#![no_main]
use core::arch::global_asm;
global_asm!(".globl _start
.section \".text\"
_start:
call rust_main
");
#[panic_handler]
fn…

Benni
- 1,030
- 2
- 11
- 18