Skip to content

Instantly share code, notes, and snippets.

@bavensky
Last active October 9, 2023 22:30
Show Gist options
  • Save bavensky/8fe6e3e7ea09cb9c72b198912fcf2068 to your computer and use it in GitHub Desktop.
Save bavensky/8fe6e3e7ea09cb9c72b198912fcf2068 to your computer and use it in GitHub Desktop.
NORDIC nRF52 RTT debugging
c_user_include_directories="../../../../../../external/segger_rtt;
<folder Name="nRF_Log">
<file file_name="../../../../../../components/libraries/log/src/nrf_log_backend_rtt.c" />
<file file_name="../../../../../../components/libraries/log/src/nrf_log_default_backends.c" />
<file file_name="../../../../../../components/libraries/log/src/nrf_log_backend_serial.c" />
<file file_name="../../../../../../components/libraries/log/src/nrf_log_frontend.c" />
<file file_name="../../../../../../components/libraries/log/src/nrf_log_str_formatter.c" />
</folder>
<folder Name="nRF_Segger_RTT">
<file file_name="../../../../../../external/segger_rtt/SEGGER_RTT.c" />
<file file_name="../../../../../../external/segger_rtt/SEGGER_RTT_Syscalls_SES.c" />
<file file_name="../../../../../../external/segger_rtt/SEGGER_RTT_printf.c" />
</folder>
#include <stdbool.h>
#include <stdint.h>
#include "nrf_delay.h"
#include "boards.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
int main(void)
{
/* Configure NRF_LOG. */
int counter=0;
APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
NRF_LOG_DEFAULT_BACKENDS_INIT();
/* Configure board. */
bsp_board_init(BSP_INIT_LEDS);
/* Toggle LEDs. */
while (true)
{
for (int i = 0; i < LEDS_NUMBER; i++)
{
bsp_board_led_invert(i);
nrf_delay_ms(500);
}
NRF_LOG_INFO("count: %d",counter);
NRF_LOG_FLUSH();
counter++;
}
}
// </h>
//==========================================================
// <h> nRF_Log
//==========================================================
// <e> NRF_LOG_BACKEND_RTT_ENABLED - nrf_log_backend_rtt - Log RTT backend
//==========================================================
#ifndef NRF_LOG_BACKEND_RTT_ENABLED
#define NRF_LOG_BACKEND_RTT_ENABLED 1
#endif
// <o> NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE - Size of buffer for partially processed strings.
// <i> Size of the buffer is a trade-off between RAM usage and processing.
// <i> if buffer is smaller then strings will often be fragmented.
// <i> It is recommended to use size which will fit typical log and only the
// <i> longer one will be fragmented.
#ifndef NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE
#define NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE 64
#endif
// <o> NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS - Period before retrying writing to RTT
#ifndef NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS
#define NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS 1
#endif
// <o> NRF_LOG_BACKEND_RTT_TX_RETRY_CNT - Writing to RTT retries.
// <i> If RTT fails to accept any new data after retries
// <i> module assumes that host is not active and on next
// <i> request it will perform only one write attempt.
// <i> On successful writing, module assumes that host is active
// <i> and scheme with retry is applied again.
#ifndef NRF_LOG_BACKEND_RTT_TX_RETRY_CNT
#define NRF_LOG_BACKEND_RTT_TX_RETRY_CNT 3
#endif
// </e>
//==========================================================
// <e> NRF_LOG_ENABLED - nrf_log - Logger
//==========================================================
#ifndef NRF_LOG_ENABLED
#define NRF_LOG_ENABLED 1
#endif
//==========================================================
// <h> nRF_Segger_RTT
//==========================================================
// <h> segger_rtt - SEGGER RTT
//==========================================================
// <o> SEGGER_RTT_CONFIG_BUFFER_SIZE_UP - Size of upstream buffer.
// <i> Note that either @ref NRF_LOG_BACKEND_RTT_OUTPUT_BUFFER_SIZE
// <i> or this value is actually used. It depends on which one is bigger.
#ifndef SEGGER_RTT_CONFIG_BUFFER_SIZE_UP
#define SEGGER_RTT_CONFIG_BUFFER_SIZE_UP 512
#endif
// <o> SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS - Size of upstream buffer.
#ifndef SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS
#define SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS 2
#endif
// <o> SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN - Size of upstream buffer.
#ifndef SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN
#define SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN 16
#endif
// <o> SEGGER_RTT_CONFIG_MAX_NUM_DOWN_BUFFERS - Size of upstream buffer.
#ifndef SEGGER_RTT_CONFIG_MAX_NUM_DOWN_BUFFERS
#define SEGGER_RTT_CONFIG_MAX_NUM_DOWN_BUFFERS 2
#endif
// <o> SEGGER_RTT_CONFIG_DEFAULT_MODE - RTT behavior if the buffer is full.
// <i> The following modes are supported:
// <i> - SKIP - Do not block, output nothing.
// <i> - TRIM - Do not block, output as much as fits.
// <i> - BLOCK - Wait until there is space in the buffer.
// <0=> SKIP
// <1=> TRIM
// <2=> BLOCK_IF_FIFO_FULL
#ifndef SEGGER_RTT_CONFIG_DEFAULT_MODE
#define SEGGER_RTT_CONFIG_DEFAULT_MODE 0
#endif
// </h>
//==========================================================
// </h>
//==========================================================
@knud
Copy link

knud commented Oct 9, 2023

Nice. Thanks. I think I am carrying too much unnecessary stuff in sdk_config.h. This helps.

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