[SOLVED] Segger RTT via Telnet

  • Hi
    Following up on a previous thread with the same title, I have the following scenario:

    I have a telnet client in order to collect RTT output for unit testing.

    In order to open the JLink telnet server, as I understand it, I first need to create the server, for example by connecting to the target first:

    JLinkExe -NoGui 1 -CommandFile ./connect.jlink

    Code
    > cat connect.jlink
    device ATSAMD21G18A
    si SWD
    speed 4000
    connect


    This connecdts to target and keeps the connection open.

    I then run commands likes this:

    JLinkExe -NoGui 1 -CommandFile ./test_rgb.jlink

    Code
    > cat test_rgb.jlink
    device ATSAMD21G18A
    si SWD
    speed 4000
    connect
    exec SetCompareMode = 0
    loadbin .pio/build/test_rgb/firmware.bin, 0x2000
    r
    q


    This works, but I wonder if this is supposed to be the way to use third-party applications to interact with RTT.
    There must be a simpler way ?

    Kind regards
    Peter

  • Not sure what you mean with “There must be a simpler way”.

    What do you have in mind?
    Can you describe the “simpler” setup you have in mind?
    As RTT goes through the debug interface, you need an active debug session that does all the RTT handling and you can attach to via TELNET.

    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: https://www.segger.com/ticket/

    Or you can contact us via e-mail.

  • Hi Alex

    The optimal way for me would me:

    - upload the firmware
    - while doing so, start the telnet server
    - disconnect from the target, but keep the telnet server open
    - let me connect to the telnet server to interact with the target (testing)
    - let me upload firmware again, without stopping the telnet server.

    maybe this is something that could be achieved with your SDK ?
    Kind regards
    Peter

  • Hi Peter,
    First of all:
    As Alex pointed out, an active debug connection is mandatory for RTT to work.
    If you are wondering why, please refer to the following article:
    https://wiki.segger.com/RTT

    This does not change regardless of how you retrieve the data (via TELNET channel or via SDK API calls).

    - upload the firmware

    I assume you are referring to programming the target device, correct?
    From your message it is not clear to me how exactly you are doing this,
    but I would further assume that it is either with J-Link Commander, J-Flash, or the SDK correct?
    If so:
    All of these provide the option to not disconnect on programming completion.
    You could use this option to keep the connection alive while you are using RTT via the TELNET channel.

    maybe this is something that could be achieved with your SDK ?

    As mentioned, it will not allow you to use RTT without an activte debug connection (this is physically not possible).
    However, you could of course combine all steps using it:
    - Connect to the device
    - Flash Application
    - Read / Write via RTT
    - Disconnect from the device

    Does this answer your questions?

    BR
    Fabian

    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: https://www.segger.com/ticket/

    Or you can contact us via e-mail.

  • Hi Fabian

    I apologize if my wording is not precise, I am new to this field.
    Yes, with "uploading the firmware" I mean programming the device.

    And I am using JLinkExe on Linux to do this with a JLink plus compact.
    What I am doing is a kind of unit testing:

    - compile and build the test ( I use platform.io and VSCode)
    - upload the binary with the following commands:

    ===================
    > /usr/bin/JLinkExe -NoGui 1 -CommandFile ./upload.jlink

    > cat ./upload.jlink
    device ATSAMD21G18A
    si SWD
    speed 4000
    connect
    exec SetVerifyDownload = 0
    loadbin .pio/build/target_test_wm_min/firmware.bin, 0x2000
    r
    h
    q
    ===================

    Note that I quit (q) the connection at the end to be able to do this over and over again.

    After the upload, I run the unit tests:
    - connect to the telnet server with a telnet client
    - interact with the target via RTT.
    - reset the target
    - next test ....

    All this works very well and fast, and I am very pleased. Embedded programming starts to look like Java desktop.

    BUT: As I understand it, for this to work, I need to open _another_ connection (lets call it perma-connection) to the target that I keep open indefinitely ( until I stop work on the project)

    ========================================
    > JLinkExe -NoGui 1 -CommandFile ./connect.jlink
    > cat ./connect.jlink
    device ATSAMD21G18A
    si SWD
    speed 4000
    connect
    ==============================================

    Note that there is no q at the end.

    So during target programming I have to parallel connections, during unit testing with the telnet client I use only the perma-connection to maintain the telnet socket.

    Sorry if this sounds contrived.

    As far I understand you, there is no way around this. I need the perma connection to stay open in order to be able to connect to the server.

    Kind regards
    Peter

  • Hi Peter,

    As far I understand you, there is no way around this. I need the perma connection to stay open in order to be able to connect to the server.

    This is correct.
    As long as you want to use RTT, you will have to have an active debug connection.
    Otherwise it is not possible to retrieve the RTT data from the target.

    However..

    So during target programming I have to parallel connections, during unit testing with the telnet client I use only the perma-connection to maintain the telnet socket.

    ...this is not entirely correct.
    Yes, you need an active debug connection for RTT, but you could simply continue using the J-Link Commander session used for the application download.
    Example:

    Note:I removed the "h" because reset implicitly halts the device & the device is released from reset on "q" anyway.

    BR
    Fabian

    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: https://www.segger.com/ticket/

    Or you can contact us via e-mail.

  • Thanks Fabian
    This is exactly what I meant with "simpler way", sorry for the roundabout nature of my question.
    I didn't realize that you can continue to do loadbin ... without a prior connect.

    Kind regards
    Peter

  • Hi Peter,
    No worries! :)

    Best regards
    Fabian

    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: https://www.segger.com/ticket/

    Or you can contact us via e-mail.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!