-
Notifications
You must be signed in to change notification settings - Fork 187
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
defmt impl for Vec #172
defmt impl for Vec #172
Conversation
Hi, thanks for the PR! Since you have started this, do you feel like adding support for |
I think that can be arranged if that is desirable. I have largely been blocked by the probe-rs wfi bug making doing anything with RTT painful, so by extension this includes defmt. |
@korken89 In the case of Vec, I leveraged the existing slice impl because the distinction wasn't important. If i understand what defmt is doing correctly, for strings they are compile-time interned and arn't actually sent over-the-wire. I suspect defmt changes may need to be implemented for runtime strings such as those produced by heapless. At this point I offer this PR as-is. Ive done some tests working around the WFI bug and this PR appears to work correctly. Further the unit test I added is modeled after existing tests in defmt, so I have some confidence my PR works as intended. If |
Well that's for format strings and other constant strings. But there are also primitive types "byte slice" and "string slice" which are sent as-is (see https://defmt.ferrous-systems.com/primitives.html). I think you just need to call |
Wow I completely missed that! You may be right, il do some investigating. |
Tested both
Relevant code snippets, for future reference let mut some_string:heapless::String<consts::U32> = heapless::String::new();
some_string.push_str(&"hello, heapless!").unwrap();
debug!("msg: {:str}", some_string); debug!("emitting {:[u8]}", buf); |
Thanks for the update! Now we just need to await |
Or, it is behind a feature-flag so I see no issue in including as is. |
bors merge |
172: defmt impl for Vec r=korken89 a=theunkn0wn1 This PR adds support for encoding `heapless::Vec` for usage with `defmt`. `defmt` can already handle slices, so this impl simply invokes that encoder method. I chose to use the slice implementation is I did not perceive the difference between a Vec and a Slice to be of specific importance in a log file, but rather the contents of the vec / slice to be of interest. It also appeared to me as the path of least resistance. I am marking this as a draft as I have yet to be able to validate this against my local hardware, `probe-run` is giving me some grief that I am reasonably sure is unrelated to this change set. Relates to #171 Co-authored-by: joshua salzedo <thHunkn0WNd@gmail.com> Co-authored-by: Joshua Salzedo <joshuasalzedo@gmail.com>
Build failed: |
bors retry |
172: defmt impl for Vec r=korken89 a=theunkn0wn1 This PR adds support for encoding `heapless::Vec` for usage with `defmt`. `defmt` can already handle slices, so this impl simply invokes that encoder method. I chose to use the slice implementation is I did not perceive the difference between a Vec and a Slice to be of specific importance in a log file, but rather the contents of the vec / slice to be of interest. It also appeared to me as the path of least resistance. I am marking this as a draft as I have yet to be able to validate this against my local hardware, `probe-run` is giving me some grief that I am reasonably sure is unrelated to this change set. Relates to #171 Co-authored-by: joshua salzedo <thHunkn0WNd@gmail.com> Co-authored-by: Joshua Salzedo <joshuasalzedo@gmail.com>
Build failed: |
Hi @theunkn0wn1, the CI seems to be failing for 1.36. |
Wilco. Yes it's behind a feature flag. As ci hasn't executed when I opened the pr I'm guessing I need to add the feature flag to the ci run. |
@korken89 |
@thalesfragoso commented in matrix that depending on git dependencies would make this crate, to my understanding unreleasable on crates.io. Until the time Ultimately I do not see how the CI failure can be addressed without boosting this crates MSRV to at least rust stable |
This crate has a quite low MSRV, and it seems like it starts to be time to look it over. |
883cd43
to
0209b3f
Compare
Update to synchronize with current master. This causes this PR to fail to resolve in cargo, since the dependency becomes circular. |
bors try |
It seems like defmt support for heapless should be possible now:
From what I see, this PR could be integrated when changing defmt in Cargo.toml from git to version "0.2". @theunkn0wn1 do you want to update this PR or should I open another one? |
@fkohlgrueber
Looks like Presently investigating. |
Fixed this PR so it works with defmt 0.2 and I have tested it against my stm32f446 hardware. |
@theunkn0wn1 seems like there are conflicts that prevent integration. Can you try to resolve them? |
2ab171c
to
f4617ea
Compare
The merge conflicts ended up running quite deep and i had to do some minor refactors to match the features, namely const-generics, presently on master. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
@@ -24,6 +24,7 @@ x86-sync-pool = [] | |||
__trybuild = [] | |||
# Enable larger MPMC sizes. | |||
mpmc_large = [] | |||
defmt-impl = ["defmt"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could remove this line and use defmt
instead of defmt-impl
as the feature flag. I think that's that standard way of doing it (e.g. see smoltcp-rs/smoltcp#455).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed the template provided by ufmt-impl on line 20, if we change this PR we should also change the other in a follow up.
@@ -94,6 +94,8 @@ mod de; | |||
mod ser; | |||
|
|||
pub mod binary_heap; | |||
#[cfg(feature = "defmt-impl")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could use defmt
instead of defmt-impl
here (see my other comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
This PR adds support for encoding
heapless::Vec
for usage withdefmt
.defmt
can already handle slices, so this impl simply invokes that encoder method.I chose to use the slice implementation is I did not perceive the difference between a Vec and a Slice to be of specific importance in a log file, but rather the contents of the vec / slice to be of interest. It also appeared to me as the path of least resistance.
I am marking this as a draft as I have yet to be able to validate this against my local hardware,
probe-run
is giving me some grief that I am reasonably sure is unrelated to this change set.Relates to #171