I have read in the MCUXpresso docs that "When you have linked with the semihosting library, your application will no longer work standalone – it will only work when connected to the debugger"
Elsewhere on the forums, I read, "semihosting only works when there is an active debug connection to the device." - this sounds like it is ok to leave it in the code when deploying because it will simply (and obviously) not provide console output when not in an active debug session.
I have an LPC845-based system that uses the console for PRINTF, super handy for developing code. It seems to work perfectly when disconnected from the Multilink, working as "stand alone", so I am confused by the #MCUXpresso document statement
So, I am asking for a definitive answer on this:
What needs to be done to the code or to the IDE settings to properly go from DEBUGGING to Production release regarding the use of semi hosting, if anything? Do I need to remove or disable the PRINTF statements? Can I leave then as-is, they are automatically "removed" when not connected to a debug session?
Cheers!
Solved! Go to Solution.
The statement about 'does not work without a debugger attached' is because semihosting throws an exception with a breakpoint, and this will end up in a hardfault if no debug session is active.
The easiest way is to use a hardfault handler like the one on https://github.com/ErichStyger/McuOnEclipseLibrary/blob/master/lib/src/McuHardFault.c (check around line 176 or for McuHardFault_CONFIG_SETTING_SEMIHOSTING). A similar handler might be already be present in your project (NXP delivers similar handlers by default for years for many devices). So the above statement is true for earlier years or if you don't use such a handler.
With the above handler, if your application uses a semihosting call, it will just ignore it.
The other (even better) solution is that for your release version you remove these PRINTF (say using a macro defining them as empty): that way you get rid of the output call. Or not using the built-in printf but a custom semihosting implementation like I do (see https://mcuoneclipse.com/2023/03/09/using-semihosting-the-direct-way/
I hope this helps,
Erich
The statement about 'does not work without a debugger attached' is because semihosting throws an exception with a breakpoint, and this will end up in a hardfault if no debug session is active.
The easiest way is to use a hardfault handler like the one on https://github.com/ErichStyger/McuOnEclipseLibrary/blob/master/lib/src/McuHardFault.c (check around line 176 or for McuHardFault_CONFIG_SETTING_SEMIHOSTING). A similar handler might be already be present in your project (NXP delivers similar handlers by default for years for many devices). So the above statement is true for earlier years or if you don't use such a handler.
With the above handler, if your application uses a semihosting call, it will just ignore it.
The other (even better) solution is that for your release version you remove these PRINTF (say using a macro defining them as empty): that way you get rid of the output call. Or not using the built-in printf but a custom semihosting implementation like I do (see https://mcuoneclipse.com/2023/03/09/using-semihosting-the-direct-way/
I hope this helps,
Erich