-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segger RTT: support CONFIG_SEGGER_RTT_INIT_MODE and optimizations #17
base: master
Are you sure you want to change the base?
Conversation
Expected to fix Issue #53544 with PR #53569 in Zephyr repo |
0f2d763
to
4d3b32a
Compare
4d3b32a
to
71e53e6
Compare
SEGGER/SEGGER_RTT.c
Outdated
@@ -167,6 +167,26 @@ Additional information: | |||
#endif | |||
#endif | |||
|
|||
#ifndef SEGGER_RTT_MEMCMP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this a new segger version or your modifications?
I'm afraid that those changes may get lost if someone updates with new version of segger_rtt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's my modifications. I was assuming that Segger people follow this repo and approve these changes so that they become they also take them.
If not, what do you suggest? Contact them through their official website?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I look in previous commits, they don't seem to be done by Segger, like my one. Are there some additional rules to coordinate with Segger?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how to push it to segger.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe @sigvartmh or @carlescufi can help?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Segger is not part of the zephyrproject-rtos Git-Repo.
However, we will review the changes and extend the official RTT sources if we
come to the conclusion that it is a good addition to the current RTT state.
I will keep you posted.
I got this reply after opening a ticket in Segger support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After opening a ticket in support.segger.com, they proposed the update V7.86h that gives equivalent changes and improved initialization. I tried to leave the SEGGER_RTT.c
untouched and follow their suggestion to not call at all SEGGER_RTT_Init()
in the chained application, but, even if working, I saw that the APIs using use INIT()
aren't used in Zephyr log backend. So I added a change only in SEGGER_RTT_Init()
, using the configuration I'm aware of that distinguish the cases when we want to to a forced init of CB or just check if it's already done.
SEGGER/SEGGER_RTT.c
Outdated
|
||
#ifndef SEGGER_RTT_MEMSET | ||
#ifdef MEMSET | ||
#define SEGGER_RTT_MEMSET(pDest, FillChar, NumBytes) MEMCPY((pDest), (FillChar), (NumBytes)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy paste error. MEMCPY
-> MEMSET
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for spotting this, fixed.
SEGGER/SEGGER_RTT.c
Outdated
@@ -167,6 +167,26 @@ Additional information: | |||
#endif | |||
#endif | |||
|
|||
#ifndef SEGGER_RTT_MEMCMP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how to push it to segger.
71e53e6
to
5c21108
Compare
5c21108
to
76a9690
Compare
Can we get this reviewed? This is causing me issues also |
@sigvartmh please review this as part of this change |
SEGGER/SEGGER_RTT.c
Outdated
* Segger code using _DoInit() is used. For applications started by | ||
* bootloader, Segger recommends not calling this function, as all the | ||
* recommended APIs use INIT(). Unfortunately Zephyr log backend uses | ||
* SEGGER_RTT_WriteSkipNoLock() that doesn't call INT(), so we need |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: INIT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could add a dedicated Kconfig option to let user decide if Zephyr application should actually force overwrite of the RTT structures during initialization. The current approach cannot support e.g. other bootloaders.
That would also allow to preserve RTT content during e.g. software reboot that does not clear RAM content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also wonder if it wouldn't be reasonable to check whole acID
right before initialization (instead of checking just the first byte) to ensure no false positives in case RAM content is not zero-initialized (with current implementation chance of false positive when checking if structure is initialized is quite high - ~1/255
).
Actually after we improve the check, we may event consider to always call INIT
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are going to rely on bootloader to initialize the RTT structures, we need to ensure backwards compatibility of the initialization operation (many embedded applications rely on immutable bootloader that cannot be updated once flashed).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your suggestions. Unfortunately I was too busy and I'll be out now for a couple of weeks, but afterwards I'll try to follow them.
The Kconfig option is a good idea, I was not very satisfied with my #ifdefs
that are less general. I just have to figure out where such a Kconfig can be placed.
I also agree on the whole acID
check, the INIT()
macro can be used like it is only for other functions than SEGGER_RTT_Init()
. I tried not to touch the SEGGER module, then trying with minimal change, but this is indeed reasonable.
I'll even rebase to RTT 3.40.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With latest release I tried to take account of all above suggestions:
- Rebased to SystemView V340
- Managed dedicated CONFIG_SEGGER_RTT_INIT_MODE to have different init behaviours
The second change gives more flexibility: application level configs can force initialization of control block without condition or have a complete or partial check on acID to have a contitional init. Yet this requires some more changes in Segger code.
The SystemView V340 code misses some minor changes (safer INIT(), const _aTerminalId) tht are provided by latest SystemView V352a: I've added them, as in previous version.
The CONFIG_SEGGER_RTT_INIT_MODE is defined in PR #53569 in Zephyr repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all your changes looks good :) I've done similar modifications but haven't pushed changes to Zephyr due to having it interop with other parts of downstream Nordic Fork, which I couldn't figure out how to handle in a nice way. However having this upstream would definitely be a good addition.
fc79836
to
7194d9b
Compare
44e7b52
to
0a02f8b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally think this looks good, but it could benefit from either a more elaborate Git commit message describing the changes in detail, or more code comments - or both.
0a02f8b
to
0ff9539
Compare
I tried to have the commit messages clearer. |
SEGGER/SEGGER_RTT.c
Outdated
volatile SEGGER_RTT_CB* p; | ||
p = (volatile SEGGER_RTT_CB*)((char*)&_SEGGER_RTT + SEGGER_RTT_UNCACHED_OFF); | ||
unsigned i; | ||
bool DoInit = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed to include <stdbool.h>
at the top of this file to avoid this error when building against v3.6-branch
SEGGER/SEGGER_RTT.c:1906:3: error: unknown type name 'bool'
1906 | bool DoInit = false;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @cfriedt, for signalling this issue. It probably depends on the toolchain, as I didn't have it.
Yet, looking at Seger code, they seem not to use boolean, so I changed it to int without using false/true values.
SEGGER/SEGGER_RTT.c
Outdated
RTT__DMB(); // Force order of memory accesses for cores that may perform out-of-order memory accesses | ||
for (i = 0; i < sizeof(_aInitStr) - 1; ++i) { | ||
if (p->acID[i] != _aInitStr[sizeof(_aInitStr) - 2 - i]) { // Skip terminating \0 at the end of the array | ||
DoInit = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar error / need for <stdbool.h>
SEGGER/SEGGER_RTT.c:1913:16: error: 'true' undeclared (first use in this function)
1913 | DoInit = true;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above
Support Zephyr "RTT Initialization mode" config choice, allowing Control Block initialization to be retained from another program (e.g. bootloader). It includes conditional CB init with full check on Control Block ID or partial one that checks only the first byte, yet improving its logic. Minor optimizations with static const added. Signed-off-by: Giancarlo Stasi <giancarlo.stasi.co@gmail.com>
Allow to define the name of custom RTT section both when it's configured to be placed at RAM start and when its address is defined by a memory region in DTS. Signed-off-by: Giancarlo Stasi <giancarlo.stasi.co@gmail.com>
0ff9539
to
fe8fb43
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes #53544.