Comments (3)
The problem is that core::fmt
uses a lot of memory for its formatting. For any non-trivial cases, it usually surpasses the capabilities of an AVR chip so essentially you just cannot use it at all. That's why all the examples make use of the ufmt
crate instead.
However, there is one place where core::fmt
sneaks in and cannot be replaced so easily: panic message formatting. The only real solution at the moment is to make sure that all panics do not provide a formatted message and instead simply panic with a static message / no message. For example, you need to replace all Result::unwrap()
calls with something like
trait ResultExt {
type T;
fn unwrap_avr(self) -> Self::T;
}
impl<T, E> UnwrapExt for Result<T, E> {
type T = T;
fn unwrap_avr(self) -> Self::T {
match self {
Ok(t) => t,
Err(_) => panic!(),
}
}
}
(Or alternatively follow your suggestion from #463 but that means you don't get any custom panic behavior at all)
from avr-hal.
@Rahix i thought it might be caused by insufficient sram but i didn't thought further because compiling with release profile fixed it
(maybe core::fmt heavily rely on compiler optimizations to reduce ram usage)
about immediate abort, iirc just avoiding print of error message didn't strip out all of the error messages
from avr-hal.
Relying on optimizations with core::fmt
is very hit or miss. Compiling with LTO manages to eliminate a lot of overhead a surprising number of times, but it does not always work. And when it doesn't, there is little you can do, unfortunately.
iirc just avoiding print of error message didn't strip out all of the error messages
The things is that you need to ensure all panicking code paths do not lead to a panic with a message. This is not an easy feat of course. The ResultExt
shown above just takes care of the worst offender - Result::unwrap()
which usually pulls in the full core::fmt::Debug
implementations of the error types. But to get rid of all error message strings, you'll of course need to do a lot more. A list that certainly isn't exhaustive:
Option::unwrap()
- Any uses of
ops::Index
/ops::IndexMut
where the bounds check isn't optimized away - replace with fallible.get()
/.get_mut
calls and then work around the followingOption::unwrap()
as before. - If overflow checks are enabled, you get panicking code paths from a lot of maths operations. Either disable overflow checks or use the fallible methods on integer types instead (e.g.
u32::checked_add()
)
from avr-hal.
Related Issues (20)
- Panic while trying to write to serial using `ufmt::uwriteln` HOT 4
- Add configurable board options to ravedude HOT 3
- Get pin number HOT 6
- Program freezes if compiled in debug mode.
- ravedude should check rust target against selected MCU HOT 3
- Document clock type design in more detail HOT 1
- cargo build - error[E0658] - proc_macro::Literal::byte_character(byte) HOT 9
- can't find crate for `core` HOT 12
- cargo build - error[E0658] - proc_macro::Literal::byte_character(byte) HOT 4
- Very weird error when compiling a very basic program: __addsf3 multiple defenitions HOT 8
- Ravedude freezes on programmer uploading HOT 5
- Arduino Nano: avrdude error: programmer is not responding HOT 11
- Watchdog intterupt mode HOT 1
- [Solved] Cannot find `pwm` in `embedded_hal` HOT 2
- peripherals type alias HOT 2
- Enhance `avr_hal_generic::renamed_pins! {}` to also generate type aliases for each pin
- tier 3 target and broken
- Utilising the `atmega2560`'s "USART in SPI Mode" HOT 10
- Issue with math calculations with floats to serial port output HOT 4
- Incorrect ADC readings after toolchain bump HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from avr-hal.