-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HardFault with capnp and no_std #293
Comments
Hm... I wonder if there's some alignment problem. Have you tried enabling the capnproto-rust/capnp/Cargo.toml Line 34 in 8b8c5ec
|
Thanks for your quick response. I tried to add the unaligned feature to capnp but still the same error. capnp = { version = "0.14.9", default-features = false, features = ["unaligned"] } |
Can you successfully get and set values in the |
Sorry for the delay in the response. Yes, I can set and get values back from a Vec: #[macro_use]
extern crate alloc;
use alloc::vec::Vec;
// ...
// test if we can put value in Vec then read them back
{
let values: Vec<_> = vec![1, 2, 3, 4];
assert_eq!(values[0], 1);
assert_eq!(values[1], 2);
assert_eq!(values[2], 3);
assert_eq!(values[3], 4);
defmt::info!("Vec test complete"); // this logs appears
} |
Someone else reported a hard fault when using alloc-cortex-m last year: #221 (comment) I do happen to have a cortex M4 here. I'll try to reproduce the issue on it (but it may be slow going). If there's a way to reproduce the issue in Linux (like via an emulator) that would be potentially helpful. |
I had a look at Qemu and it seams it only support 2 boards from Ti for Cortex-M4. Mine is a NUCLEO-F446RE and I have no experience on Ti hardware. If you tell me which board you have, I may be able to help you setup the board or buy the board, set it up and modify the example code accordingly. I can also ship you the same board as mine, so you can run the firmware from the provided github repo as is. Let me know which way you prefer? |
I'm poking around on qemu right now. The two relevant pieces of hardware that I have are: a Neotrellis M4 https://www.adafruit.com/product/4020 and a Gemma M0 https://www.adafruit.com/product/3501. |
I am not at all familiar with these boards. Maybe the best course of action is me sending you the relevant hardware. |
aha! We need to check the result of capnproto-rust/capnp/src/message.rs Lines 603 to 605 in 8b8c5ec
In your example, the heap size is too small for |
Should be fixed in 8c9d41b. |
Thanks! That was it! For future reference, it looks like Cap'n Proto is trying to allocate 8kB on the heap but my heap was only 4kB in size. The fix, clearly identifies the problem with an error message. With the fix (0.14.10) and a heap of 4kB, my alloc_error_handler is called and this is the log I have:
Increasing the size on the heap in my application to a value larger than 8kB fixed the problem. I looks strange to me that 8kB is needed for such small messages but this question is for an other time. For the time beeing, I can live with it. Again, Thank you for you prompt help and fix! |
You can allocate less memory for the first segment by doing something like this (instead of let mut message = message::Builder::new(message::HeapAllocator::new().first_segment_words(256)); |
I am playing with capnp on embedded device in Rust. I have setup a playground to evaluate capnp here.
It is a no_std application with a global allocator provided by alloc-cortex-m crate. I have check that the global allocator is working: I can use alloc::vec::Vec and the oom handler is called when memory is exceeded.
The following code, leads to a hard fault but I have no clue how to fix it.
The error is the following:
Can you help me please?
The text was updated successfully, but these errors were encountered: