Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Printing fault information fails if console is not initialized #10344
I am experiencing some issues where fault information is not printed in certain cases. It doesn't matter if it is an assert or a hardfault that needs to be printed.
I am testing on an nRF52840 but as far as I can tell it is not target related.
The test code could be as simple as:
This issue is that the default console is a singleton and as such gets constructed on the first use:
The singleton guards in IAR use a system mutex that eventually goes to the mbed mutex implementation. It tries to acquire a mutex by calling
If I put a
This could be an issue only for IAR because of the way the singleton is handled but I have no means to verify that easily.
Issue request type
I think this may be IAR-only if IAR doesn't actually open stdin or stdout until first use. I've never been terribly clear on what the C libraries do, but I know some have reported power increase after first print, which would be consistent with that.
I guess we could ignore the mutex error if
It certainly does look like a C library issue. It is only when I print a newline to printf that it actually fixed the issue because default it only flushes to stdout on the newline.
The second call to mbed_error from EvrRtxMutexError does not try to print because there is an error in progress so it just halts the system.
Wouldn't it be a better solution to force the construction during startup by making the object global? This should work for all compilers. The optimizer can't remove the memory if not used now anyway which is already being solved by you in #10328. This can still apply to the following example:
From the point of view of "we need this to be on so we can print to it when we crash", yes, that would make sense. Also would improve reception behaviour.
But at the cost of power - any application not currently printing is currently saving power by the fact it isn't opened.
After #10328, I think you could make this change, but I'm a bit wary about impacting run-time behaviour for the crash case, which is why I'm suggesting a change that would only affect the crash.
I totally agree with this, I have been working with some applications requiring an absolute minimum consumption so this is an hot issue. On the other hand, if the other compilers open the stdout during init, would it change anything for those compilers? It seems to me it will only result in the same behaviour and would also include IAR this time.
In the end it doesn't matter to me which way too go. For now I'm using the mbed_override_console function as a fix for the issue.