Need to do anything specifically to disable Semihosting 'printf' to console before deployment?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Need to do anything specifically to disable Semihosting 'printf' to console before deployment?

ソリューションへジャンプ
1,406件の閲覧回数
jmullen_condose
Contributor III

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!

0 件の賞賛
返信
1 解決策
1,389件の閲覧回数
ErichStyger
Specialist I

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/ that way I can easily completely switch it off with a simple define if needed.

I hope this helps,

Erich

 

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
1,390件の閲覧回数
ErichStyger
Specialist I

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/ that way I can easily completely switch it off with a simple define if needed.

I hope this helps,

Erich

 

0 件の賞賛
返信
1,382件の閲覧回数
jmullen_condose
Contributor III
This is exactly perfect information. Once again, thank you, thank you, Erich!
0 件の賞賛
返信