Defmt Logging#393
Draft
bjackson312006 wants to merge 12 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds support for this library, which replicates the functionality of the defmt Rust crate, but for C projects.
Aside from just including the library as a submodule, this PR adds a new
ner cdefmtcommand to run the decoder for you. The first time you runner cdefmt, it will have to actually build the decoder for you, so you'll need to have cargo installed. Also, make sure to turn off any existing printf()->UART before trying to use cdefmt, since the decoder has no idea how to interpret normal printf()s and you'll get an error when you runner cdefmt.Here's a copy of the README I made to explain how to actually start using cdefmt logging in NER projects:
Setting Up cdefmt
To set up CDEFMT logging in an existing project, there are a few steps you need to follow.
First, make sure the project has Embedded-Base as a submodule, on a commit that has cdefmt_port included. You'll need to run
git submodule update --init --recursiveto make sure the cdefmt library is pulled.Then, add this to the parent project's top-level
CMakeLists.txt:After that, add the cdefmt routing code to your project's
main.c:(Obviously, you should use whatever UART your project has available, rather than specifically
huart2. Also, make sure nothing else is using this UART aside from cdefmt; if you also have printf() routed to this same UART or something, you'll get errors when trying to runner cdefmt.)Also, add
cdefmt_init()to themain()function in yourmain.c, after your UART initialization code has ran.Usage
Now, you should be ready to use cdefmt. In any file where you want to log stuff, add
#include <cdefmt/include/cdefmt.h>to the top. Then, you can use the following cdefmt macros:Here's an example of how formatting data works in these macros:
That macro call produced this log when I ran the code and viewed logging output (via
ner cdefmt):As shown above, the logs are automatically prepended with the filename, function name, line number, and logging level (e.g., Debug, Warning, Error, etc) corresponding to the macro call.
Other Important Stuff
ner cdefmt --rebuildif you run into issues, since this will rebuild the decoder on your device.ner cdefmtto work. Ifner cdefmtencounters non-defmt prints when trying to decode, it will fail.