-
Notifications
You must be signed in to change notification settings - Fork 3k
NRF5x: redirect NRF logging to mbed stdout #6889
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
Conversation
I would like @donatieng 's opinion on whether this is a feature we want. From what I could glance it required adding some dummy files and mixing NRF51 macros with NRF52. We finally got the NRF51 and NRF52 separated, it would be a shame to mix them up again. |
The implementation for nrf51 (sdk11) is really very separate from nrf52 (sdk14) with no shared files. The two take very different approaches, but that's just due to the massive changes nordic made to their logging subsystem. The only shared element is the name of the define set by the config system to enable logging. If it's not enable (the default) there should be no change to existing functionality. |
Modify the SDK11 softdevice_enable() logging to not dependent on Segger RTT being present & enabled. This change is not required in any later versions of SDK
… stdout (when enabled with softdevice.nrf_enable_logging config entry)
4c481f7
to
0b3df53
Compare
@donatieng I removed the 5.9 label, please correct it if this is not the case. This PR still needs review |
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.
Hi @andrewleech, thanks for submitting this PR.
Let me start by saying that I like the intent being able to enable proper logging in the NRF SDK sounds great.
Couple points:
- For the SDK14+, there's a 'log backend' feature that I think we should use
- For SDK11 I guess things will have to be a bit patchy
- I agree with @marcuschangarm that we shouldn't recouple implementations if not required
- In both cases I don't think new files should live in the target's root directory and files need proper naming
} | ||
else if (err_code != NRF_SUCCESS) | ||
{ | ||
SD_HANDLER_LOG("sd_ble_enable: error 0x%x\r\n", err_code); | ||
while(1); |
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 don't think we should remove this
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.
Newer versions of the SDK don't hang here, but I guess it would also be more useful to redirect this to mbed_error()... though that would being in even more changes and dependencies so perhaps leaving it in place would be ok.
@@ -0,0 +1,98 @@ | |||
/* mbed Microcontroller Library |
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.
This seems to be a copy of the app_uart module from the Nordic SDK
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.
Not quite. Much of it was cherry picked from the original Nordic SDK file to satisfy minimum requirements of the SDK logging interface, the rest is re-implemented to suit the redirection to stdin/stdout.
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.
Sure, Nordic's license header should be kept though
#define NRF_LOG_DEBUG(x, ...) \ | ||
if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_DEBUG)) \ | ||
{ \ | ||
printf("[NRF_DBG] "x"\r\n", ##__VA_ARGS__); \ |
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 don't think this is portable (won't work if you do NRF_LOG_DEBUG("I don't have parameters");
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.
Oh, don't the other compilers handle these kind of optional macro arguments? They really are substandard for the money you pay for them :-(
#else | ||
#define NRF_LOG_MODULE_REGISTER() /*lint -save -e19*/ /*lint -restore*/ | ||
#endif | ||
// #if NRF_LOG_ENABLED |
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.
That's a lot of commented-out code!
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.
True, I forgot about them. Wasn't sure if they were actually needed/used in the SDK code we have.... it compiles without them though.
I started down the logging backend path and it was a massive amount of extra work for little visible gain. As soon as I started enabling the logging system as it stood I needed to being in a lot of extra fiels from the original SDK pack, including some of the third party code they bundle (the fprintf reimplementation) which I think started to conflict with builtin libraries. I switched to this path of replacing the logging from the top level interface (macros) down and it was a much simpler and smaller solution. If there's a strong desire to keep the entire nordic logging framework though I can look at that again, although it will probably be a few weeks away before I'll be back on the nrf52 project here.
Yeah there's more patches required, however if we ever upgrade nrf51 to SDK12 (the last with nrf51 support) these changes wouldn't be needed there as they changed the files used significantly.
I'm pretty sure there's nothing coupled/shared between the two, I never intended to do this at all. They simply use the same name for the logging enable define for consistency, not dependency.
Hah, I just looked at it again and it took me a while to find my files.... I never intended them to be in that sort of top level folder. When I first did this it was before the TARGET_NRF51 and TARGET_NRF52 folders were refactored under TARGET_NRF5x. My files were very much sitting alongside a bunch of NRF52 implementation files. The file naming was done to satisfy file includes in the SDK files, the alternative is modifying SDK files which I was attempting to avoid. Would it be ok for |
@marcuschangarm @donatieng Mind answering this? |
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.
Hi @andrewleech, thanks for your response. It addresses most of might comments. The reason why I asked these files to be put in a separate directory is that the naming is not explicit. bsp.h
is a bit of a hack (which might be required to keep the Nordic SDK happy) and app_uart.h
does not convey that it's being used for a logging subsystem. If they can be renamed to something more explicit then that's fine having them here, however it'd be good to use a logging
subfolder as you suggested.
@@ -0,0 +1,98 @@ | |||
/* mbed Microcontroller Library |
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.
Sure, Nordic's license header should be kept though
} data; | ||
} app_uart_evt_t; | ||
|
||
//#define APP_IRQ_PRIORITY_LOW -1, |
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.
Please remove :)
#ifndef DUMMY_BSP_H_ | ||
#define DUMMY_BSP_H_ | ||
|
||
const int RX_PIN_NUMBER = -1; |
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'm afraid these dummy defines will clash with already declared variables, can we just get rid of this bsp.h
file altogether?
@andrewleech Any progress? |
Sorry no I haven't progressed on this, running a bit behind here working on my nRF52810 support |
@andrewleech If this is still deprioritized in comparison to the nRF52910 PR, we'll be closing this PR within a couple of days. Once work is restarted on this PR, it can be reopened. |
Sorry yes, that sounds fine. I'm jumping back and forth between a few projects at work, it will likely be a little while before I can finish this off |
Description
The Nordic SDK libraries have a significant amount of logging available that can be very useful during development and debugging.
Unfortunately the provided logging engines expect the NRF5 SDK to be in direct control of the hardware which makes it unsuitable for most mbed use cases.
This PR replaces Nordic's logging backend/outputs with simple printf style log entries when the config entry
softdevice.nrf_enable_logging
is set to1
As such the logs will go to the standard serial stdout provided by mbed.
This changeset was originally added in a slightly different form to #6860 but is complex enough to warrant its own PR
If/when #5965 is finished this nordic logging wrapper could be extended to take advantage of the log configuration / levels provided in that feature.
Pull request type