Skip to content

Conversation

@henrygab
Copy link
Collaborator

@henrygab henrygab commented Jan 16, 2020

[EDIT: Please see new PR #431.]

Resolves #416

At its core, this PR does three things, but does _ not_ change the default build behavior (CFG_DEBUG=0).

  1. Separates the concept of CFG_DEBUG (debug level in UI) from whether or not SysView is enabled. As noted in Split debug menu and add Segger RTT as option for logging output #416, only enabling SysView with CFG_DEBUG set to 3+ can prevent SysView from being used to find Heisenbugs. Now, SysView can be enabled even when CFG_DEBUG is set to zero.

  2. Exposes a "default" logger that derives from the Stream class. This default logger is used for all built-in board logging output, and is exposed for use by libraries if they choose to use it. By default, this is still Serial, and thus has no appreciable effect when using default build configuration.

  3. Add support for Segger RTT as the default data log, helping to track Heisenbugs that otherwise would be hidden when logging levels are increased. Serial remains the default, and a new menu option is provided to select the use of RTT for board-level logging.

Tested on nRF52840 Feather Express hardware with various option combinations, and RTT tested both with and without JLink attached.

NOTE:

  • Serial.begin() is no-op. Why does main.cpp call it (around line 50)?
    [edit: not a no-op on nrf52832, which uses hardware uart]

[edit Also tested building using arduino-builder.exe … made life so much easier!]

1. separate debug level from systemview enable/disable
   This allows enabling systemview without also setting
   really high debug level.  High debug level caused
   lots of serial output, which slowed things down and
   added Heisenbugs.

2. Add option to redirect output via Segger RTT instead
   of serial output.  Updates to Segger RTT v6.60d.

Boards.txt / platform.txt are used to allow UI to show
the new options, which causes the following to be
defined during build:

* CFG_DEBUG   := As before, from 0 (disabled) to 3 (very verbose)
* CFG_LOGGER  := Where to output logs / printf; either 1 (serial) or 2 (RTT)
* CFG_SYSVIEW := Enables SysView APIs if set to non-zero value
Add additional functions to Segger_RTT_Stream_t,
so callers do not need to change code if they
are expecting a serial port.

Per Arduino web page, serialEvent() is not
supported on all boards.  RTT also has no
interrupt-based notification when the host
writes data, so for now, not implementing
a serialEvent workaround (e.g., timer or
loop-based manual check for available data).
This function is identical to SEGGER_RTT_TerminalOut(),
except that it sends the caller-specified arbitrary bytes
to the terminal.

This makes it much easier to use the multiple terminals
as a replacement for STDERR, STDOUT, etc., because the
function handles all the edges cases, and just needs
the formatted string to be provided.
Added distinct header and implementation files.
Also redirected _write() to RTT when logging to RTT.
If RTT mode is set to `SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL`,
then the program will halt when the buffer fills unless
a JLink is connected and draining the buffer.
Fix by setting to `SEGGER_RTT_MODE_NO_BLOCK_SKIP`.

Always define `Adalog_Default_Logger`, even when
CFG_DEBUG is not defined.
@henrygab henrygab requested review from hathach and ladyada and removed request for ladyada January 17, 2020 20:06
@henrygab henrygab requested a review from ladyada January 25, 2020 18:12
In case later have a logger that requires begin().
Also makes conversion from Serial easier, as don't
need to special-case calls to begin().
Compile-time assertions are awesome,
whether via static_assert() or #if blocks,
as they can show when assumptions are false,
and they catch new changes that make prior
assumptions no longer true.
for Adalog_Default_Logger.
@hathach
Copy link
Member

hathach commented Jan 31, 2020

Thanks @henrygab your reason is all valid, however, I don't prefer to have 2 extra menu options just to deal with this. Especially there is only 5% of people will ever use it. This Arduino repo still primarily target beginner, most don't ever have a jlink to begin with.

To sum up, I think we should still keep the menu as it is with a simple modification to automatically enabled CFG_SYSVIEW when CFG_DEBUG=3, else you could just modify the source to manually enable CFG_SYSVIEW alone while keeping debug level = 0. Same with logger with SYSVIEW, please add CFG_SYSVIEW_LOG somewhere in the source where you could just toggle 0/1 when needed.

I am really like your work, unfortunately, this PR will be only used by a very small users and could cause confusion to the vast majority.

@henrygab
Copy link
Collaborator Author

Hi @hathach , and welcome back. I hope your time off was excellent.

Based on your review, I am removing the menu options as requested. I also updated .gitignore to ignore platform.local.txt and boards.local.txt, as they should never be checked in (at least to master).

In this way, if desiring to use the Segger RTT and/or Segger SysView, it is now easily done using either platform.local.txt (for always changed) or boards.local.txt (for menu-options in Arduino UI).

Copy link
Member

@hathach hathach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert the original RTT sources files, we will only use it as it is.

@hathach
Copy link
Member

hathach commented Jan 31, 2020

Hi @hathach , and welcome back. I hope your time off was excellent.

Thank you very much, it is indeed excellent, except for the Coronavirus ~ . ~

Based on your review, I am removing the menu options as requested. I also updated .gitignore to ignore platform.local.txt and boards.local.txt, as they should never be checked in (at least to master).

In this way, if desiring to use the Segger RTT and/or Segger SysView, it is now easily done using either platform.local.txt (for always changed) or boards.local.txt (for menu-options in Arduino UI).

I don't really like this approach either, but it is doable. I would expect advanced user modify the source file directly without the help of IDE e.g

#if CFG_DEBUG > 3
#define CFG_SEGGER    1
#endif

#ifndef  CFG_SEGGER
#define CFG_SEGGER    0 // change to 1 to use with SYSVIEW without logging
#endif 

@henrygab
Copy link
Collaborator Author

I will have to think about how to meet all the changes you would like.
Some things are easy. Some less so.

Copy link
Member

@hathach hathach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for not being clear. I mean we should leave the Segger RTT source code untouched.

Per Hathach request, using the files provided under SysView
rather than provided with JLink.
Do not use Assembly version.
Hathach requested not to modify any SEGGER-provided
files.  However, it is not possible to avoid some
type of modification.  This is the closest without
some type of modification.
This hack is brought to you by letters 'Q' and 'Z',
and by the numbers '0' and '1'.
@henrygab
Copy link
Collaborator Author

henrygab commented Feb 1, 2020

Please see new PR #431.

It is a squashed merge from this branch, and thus will provide a cleaner history.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Split debug menu and add Segger RTT as option for logging output

2 participants