Artefacts in output when debugging via *UART* and *Build Configuration* is set to *Release*

We see artefacts in the output when debugging via UART when the Build Configuration is set to Release. This can also be seen in the sample code of ble_android_asha.

With the following configuration of ble_android_asha the artefacts can be seen.

  • Set RSL10_DEBUG to DBG_UART (in file app_trace.h, line 38).
  • Set Build Configuration to Release (in context menu of project > Build Configurations > Set Active).

Then the startup code produces the following output. Note that non-printable characters are displayed within <> as their C Escape Sequence equivalent.

<\0><\r><\n>
==============================================<\0><\r><\n>
===== Initializing ble_android_asha LEFT =====<\0><\r><\n>
==============================================<\r><\0><\r><\n>
 sending GAPM_LEPSM_REG_CMD..<\0><\r><\n>
 GAPM_LEPSM_REG: LEPSM registered successfull

Here is the same output with the Build Configuration set to Debug (for comparison).

<\r><\n>
==============================================<\n><\r><\n>
===== Initializing ble_android_asha LEFT =====<\n><\r><\n>
==============================================<\r><\n>
<\r><\n>
 sending GAPM_LEPSM_REG_CMD...<\r><\n>
 GAPM_LEPSM_REG: LEPSM registered successfully

Going through the code I would expect the output as produced with the Build Configuration set to Debug.

In the startup code of ble_android_asha the output is still quite readable, but in our code the output gets jumbled in ways that make debugging harder than it already is. Can you think of something causing the artefacts in the Release configuration?

P. S.: In our custom application the UART output got jumbled only when the RTE_BLE_L2CC_ENABLE flag was set, before we did not see any artefacts. This flag is also set in ble_android_asha. There seems to be some kind of connection between the artefacts and this flag.

@we.f

As a first suggestion, can you try and use our newer ‘printf’ utility instead of the older ‘app_trace’ implementation to see if there are any differences?

Another thing we can suggest to you to check is, if there are any differences in the optimizations applied between the Release and Debug builds.

Thank you for using our community forum!

Thanks @martin.bela for your suggestions. I was on holiday for the last two weeks so could check on it just today. Here are my findings.

Do you mean the printf module within source/firmware/printf with newer printf utility? I modified the code to use this module instead of app_trace without luck, still the output looks like this.

<\0><\r><\n>
==============================================<\0><\r><\n>
===== Initializing ble_android_asha LEFT =====<\0><\r><\n>
==============================================<\r><\0><\r><\n>
 sending GAPM_LEPSM_REG_CMD..<\0><\r><\n>
 GAPM_LEPSM_REG: LEPSM registered successfull

Right, the optimisation level is one factor in the game.

  • When the Build configuration is set to Release the optimisation level-Os (optimise size) is used, the artefacts occur.
  • When the Build configuration is set to Debug the optimisation level -Og (optimise for debugging) is used, the artefacts do not occur.

We would like to stick to an optimisation for size and still use the UART. Do you think this is possible without seeing the artefacts?

@we.f
Could you please check if the same issues occurs with any other optimization levels? Perhaps -O1 as a starting point.

If you find that this only occurs while using the -Os optimization level, the best suggestion would likely be to setup the project to prevent optimization of the specific Print utility files, while allowing all other to optimize as expected, and seeing if this addresses the problem.