This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

right way to log SEGGER RTT output into file

how can I store outputs sent from JLINK SEGGER_RTT to a file?

how can I send data on RTT channel 1, is there any instruction for that?

/** loop */
sprintf (buffer, "%d;%d;%d;%d;%d;%d;%d;%d;%d\n",
            x_raw_acc, y_raw_acc, z_raw_acc,
            x_raw_ger, y_raw_ger, z_raw_ger,
            x_raw_mag, y_raw_mag, z_raw_mag);
SEGGER_RTT_WriteString(0,buffer);
nrf_delay_ms(100);

RTT Logger output

image description

  • I wanted to share the most reliable and efficient method I found, which also allows using the excellent Log Viewer Log4View. Simply create and launch 2 distinct batch files, open Log4view and start debugging!

    The first batch file starts the JLINK Commander that reliably connects (and reconnects) to a target, buffers and make log output available through telnet. Rename as "jlinkcommander.bat" and start it once only;

    REM this is to start JLINK Commander, that collects log stuff and make it available through telnet port 19021
    "C:\Program Files (x86)\SEGGER\JLink_V510d\JLink.exe" -device NRF52832_XXAA -if SWD -speed 4000 -autoconnect 1
    

    Then the 2nd batch file can be killed and restarted as desired to "cut" the log file, and store the previous log as an archive, which can be usefull for later reference. I called it "jlink_startlog.bat" :

    REM this script renames current log file, if any, to date-time format
    REM then move all logs to subfolder archive
    REM then starts a telnet receiver to localhost + stores output to a local file
    REM this file can then be read through Log4View (file receiver, log format = pattern, %m (dump all directly)
    REM Log4View could also be configured to track formatting like  UniversalTime (runtime in ms) log source, etc..
    @echo off
    echo wscript.echo year(date) ^& "-" ^& right(100+month(date),2) ^& "-" ^& right(100+day(date),2)^& "@" ^& right(100+hour(time),2) ^& "-" ^& right(100+minute(time),2) > "%temp%\dateparts.vbs"
    for /f "tokens=1 delims=" %%a in ('cscript //nologo "%temp%\dateparts.vbs"') do set yyyymmddhhmm=%%a
    echo Now you can use this in your filename: %yyyymmddhhmm%
    @echo on
    
    if EXIST rtt_debug.log (
    REN rtt_debug.log "%yyyymmddhhmm% - rtt_debug.log"
    )
    
    move %~dp0\*.log %~dp0\archive
    
    telnet localhost 19021 -f rtt_debug.log
    

    Finally I recommend viewing the log output using Log4View. Simply configure a File Receiver, using the pattern %s to output the whole file content. You can also standardize the output format of all your NRF_LOG to feed the uptime in millisecond, the log source, the severity, etc.

    [31761132] RFN0 >> [ForcedRxLoad] ignore (mode_site)
    [31761134] RFN0 >> [RxProcessRun] <<< scan >>> FreqBandIsmRxDefaultOverride
    [31770625] MODEM>> RX (12)
    [31770626] MODEM>> 0000: C3 00 00 06 6B 17 01 00 00 00 7D EE -- -- -- -- 
    [31770627] MODEM>> [ATRspProcess] app -> h_OnIpTunnelDataReceived (12)
    
  • Just a comment to discussion.

    It is possible to use PuTTY and not loose any data but RTT session must be started by JLink.exe not by JLink Viewer.

  • It seems that if the data comes faster than it can be dumped to the console, then NRF_LOG_INFO() will skip it.  The fix for me was the NRF_LOG_FLUSH() after every line.  This makes it much slower, but nothing is lost. 

  • Calling NRF_LOG_FLUSH() after every line makes no sense, then you might as well turn off deferred logging. You should consider increasing the buffer size, and changing the config NRF_LOG_ALLOW_OVERFLOW, to make sure the buffer is not overwritten.

  • Sorry to necro, but for any future readers, I use J-link RTT Viewer and hit F5 (Logging>Start Terminal Logging). It has never lost data, and puts a nice header at the top of the log file. Also, RTT viewer allows you to see ~40 lines of text as it comes through. This seems to be best solution for viewing, logging, and sending commands.

Related