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

Log show only the first few lines

Hi,

I have a custom board with nrf52832 mcu and I use FreeRTOS with SDK 16.

I tried the logging feature with NRF_LOG_XX() functions, but only the first few lines showed after booting.

I tested it from a task:

while(true){
  //SEGGER_RTT_WriteString(0, "Hello World!\n");
  //SEGGER_RTT_printf(0, "variable value: %d\n", test++);
  TEST_LED_TOGGLE(TLED_1);
  NRF_LOG_INFO("info\r\n");
  //NRF_LOG_ERROR("error\r\n");
  //NRF_LOG_FLUSH();
  vTaskDelay(pdMS_TO_TICKS(1000));
}

I tried with UART and with RTT (not the same time)  with the same result.

If I used the SEGGER_RTT_printf() function, it worked well, I saw all of the logs.

The relevant parts in sdkconfig:

#define NRF_LOG_ENABLED 1

#define NRF_LOG_DEFAULT_LEVEL 4

UART:

#define NRF_LOG_BACKEND_UART_ENABLED 1
#define NRF_LOG_BACKEND_UART_TX_PIN 9 
#define NRF_LOG_BACKEND_UART_BAUDRATE 30801920
#define NRF_LOG_BACKEND_UART_TEMP_BUFFER_SIZE 64

RTT:
#define NRF_LOG_BACKEND_RTT_ENABLED 1
#define NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE 64
#define NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS 1
#define NRF_LOG_BACKEND_RTT_TX_RETRY_CNT 3

#define SEGGER_RTT_CONFIG_BUFFER_SIZE_UP 256
#define SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS 2
#define SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN 16
#define SEGGER_RTT_CONFIG_MAX_NUM_DOWN_BUFFERS 2
#define SEGGER_RTT_CONFIG_DEFAULT_MODE 1

The log FreeRTOS task:


#include <stdint.h>
#include <string.h>
#include "nordic_common.h"
#include "nrf.h"
#include "app_error.h"
#include "nrf_sdh_freertos.h"
#include "nrf_gpio.h"
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#include "main.h"

#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"

#if NRF_LOG_ENABLED

#define LOG_STACK_SIZE (configMINIMAL_STACK_SIZE + 200)
#define LOG_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )


/**
* @name Task data
* @{
*/
TaskHandle_t logTaskHandle = NULL;

// The TCB and stack of the task.
static StaticTask_t xLogTaskBuffer;
static StackType_t xStackLog[ LOG_STACK_SIZE ];

/**@brief Thread for handling the logger.
*
* @details This thread is responsible for processing log entries if logs are deferred.
* Thread flushes all log entries and suspends. It is resumed by idle task hook.
*
* @param[in] arg Pointer used for passing some arbitrary information (context) from the
* osThreadCreate() call to the thread.
*/
static void logTask(void * arg)
{
UNUSED_PARAMETER(arg);

while (1)
{
NRF_LOG_FLUSH();

vTaskSuspend(NULL); // Suspend myself
}
}

uint32_t getTimeStamp(void)
{
return xTaskGetTickCount() << 5;
}


/**@brief Function for initializing the nrf log module.
*/
void logInit(void)
{
// log TX pin: sdk_config: NRF_LOG_BACKEND_UART_TX_PIN

// log GND
/*nrf_gpio_pin_clear(10);
nrf_gpio_cfg_output(10);*/

ret_code_t err_code = NRF_LOG_INIT(getTimeStamp);
APP_ERROR_CHECK(err_code);

NRF_LOG_DEFAULT_BACKENDS_INIT();

// create thread
logTaskHandle = xTaskCreateStatic(
logTask, /* Function that implements the task. */
"log", /* Text name for the task. */
LOG_STACK_SIZE, /* Number of indexes in the xStack array. */
NULL, /* Parameter passed into the task. */
LOG_TASK_PRIORITY,/* Priority at which the task is created. */
xStackLog, /* Array to use as the task's stack. */
&xLogTaskBuffer ); /* Variable to hold the task's data structure. */

NRF_LOG_INFO("Restart");
}

#endif

/**@brief A function which is hooked to idle task.
* @note Idle hook must be enabled in FreeRTOS configuration (configUSE_IDLE_HOOK).
*/
void vApplicationIdleHook( void )
{
#if NRF_LOG_ENABLED
vTaskResume(logTaskHandle);
#endif
}

Parents Reply Children
No Data
Related