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

nRF52 2832 debug log via UART to PuTTY

Hello,

I'm using nRF52 2832 with SDK 12.3.0 and I want to know if there is a simple way to log via UART to PuTTY for debug.

Thanks for your answers.

  • Hello,

    Most of the SDK examples include the logger module that lets you print debug messages over UART or RTT. Just make sure that UART is selected in your sdk_config file:

  • UART is enabled in my sdk_config file, my configuration is the following:

    #ifndef UART_ENABLED
    #define UART_ENABLED 1
    #endif
    
    #if  UART_ENABLED
    
    #ifndef UART_DEFAULT_CONFIG_HWFC
    #define UART_DEFAULT_CONFIG_HWFC 0
    #endif
    
    #ifndef UART_DEFAULT_CONFIG_PARITY
    #define UART_DEFAULT_CONFIG_PARITY 0
    #endif
    
    // UART_DEFAULT_CONFIG_BAUDRATE set to 230400
    
    #ifndef UART_DEFAULT_CONFIG_BAUDRATE
    #define UART_DEFAULT_CONFIG_BAUDRATE 61865984
    #endif
    
    
    #ifndef UART_DEFAULT_CONFIG_IRQ_PRIORITY
    #define UART_DEFAULT_CONFIG_IRQ_PRIORITY 7
    #endif
    
    #ifndef UART_EASY_DMA_SUPPORT
    #define UART_EASY_DMA_SUPPORT 1
    #endif
    
    #ifndef UART_LEGACY_SUPPORT
    #define UART_LEGACY_SUPPORT 1
    #endif
    
    
    #ifndef UART0_ENABLED
    #define UART0_ENABLED 1
    #endif
    
    #if  UART0_ENABLED
     
    #ifndef UART0_CONFIG_USE_EASY_DMA
    #define UART0_CONFIG_USE_EASY_DMA 1
    #endif
    
    #endif //UART0_ENABLED
    
    
    #ifndef UART_CONFIG_LOG_ENABLED
    #define UART_CONFIG_LOG_ENABLED 1
    #endif
    #if  UART_CONFIG_LOG_ENABLED
    // UART_CONFIG_LOG_LEVEL  - To see all levels of log from debug to error
    
    #ifndef UART_CONFIG_LOG_LEVEL
    #define UART_CONFIG_LOG_LEVEL 4
    #endif
    
    #endif //UART_CONFIG_LOG_ENABLED
    
    #endif //UART_ENABLED
    
    
    #ifndef NRF_LOG_ENABLED
    #define NRF_LOG_ENABLED 1
    #endif
    
    #if  NRF_LOG_ENABLED
    
    #ifndef NRF_LOG_USES_COLORS
    #define NRF_LOG_USES_COLORS 0
    #endif
    
    // NRF_LOG_DEFAULT_LEVEL  - To see all levels of log from debug to error
    
    #ifndef NRF_LOG_DEFAULT_LEVEL
    #define NRF_LOG_DEFAULT_LEVEL 4
    #endif
    
    #ifndef NRF_LOG_DEFERRED
    #define NRF_LOG_DEFERRED 0
    #endif
    
    #ifndef NRF_LOG_USES_TIMESTAMP
    #define NRF_LOG_USES_TIMESTAMP 0
    #endif
    
    #endif //NRF_LOG_ENABLED
    
    
    #ifndef NRF_LOG_BACKEND_MAX_STRING_LENGTH
    #define NRF_LOG_BACKEND_MAX_STRING_LENGTH 256
    #endif
    
    #ifndef NRF_LOG_TIMESTAMP_DIGITS
    #define NRF_LOG_TIMESTAMP_DIGITS 8
    #endif
    
    #ifndef NRF_LOG_BACKEND_SERIAL_USES_UART
    #define NRF_LOG_BACKEND_SERIAL_USES_UART 1
    #endif
    
    #if  NRF_LOG_BACKEND_SERIAL_USES_UART
    
    // NRF_LOG_BACKEND_SERIAL_UART_BAUDRATE  - set to 230400
    
    #ifndef NRF_LOG_BACKEND_SERIAL_UART_BAUDRATE
    #define NRF_LOG_BACKEND_SERIAL_UART_BAUDRATE 61865984
    #endif
    
    #ifndef NRF_LOG_BACKEND_SERIAL_UART_TX_PIN
    #define NRF_LOG_BACKEND_SERIAL_UART_TX_PIN 12
    #endif
    
    #ifndef NRF_LOG_BACKEND_SERIAL_UART_RX_PIN
    #define NRF_LOG_BACKEND_SERIAL_UART_RX_PIN 5
    #endif
    
    #ifndef NRF_LOG_BACKEND_SERIAL_UART_RTS_PIN
    #define NRF_LOG_BACKEND_SERIAL_UART_RTS_PIN 5
    #endif
    
    #ifndef NRF_LOG_BACKEND_SERIAL_UART_CTS_PIN
    #define NRF_LOG_BACKEND_SERIAL_UART_CTS_PIN 7
    #endif
    
    
    #ifndef NRF_LOG_BACKEND_SERIAL_UART_FLOW_CONTROL
    #define NRF_LOG_BACKEND_SERIAL_UART_FLOW_CONTROL 0
    #endif
    
    
    #ifndef NRF_LOG_BACKEND_UART_INSTANCE
    #define NRF_LOG_BACKEND_UART_INSTANCE 0
    #endif
    
    #endif //NRF_LOG_BACKEND_SERIAL_USES_UART

    My main is the following:

    #include <stdbool.h>
    #include <stdint.h>
    
    #include "mmt_display.h"
    #include "nrf_log_ctrl.h"
    
    int main(void)
    {
    		
    	ret_code_t err_code = NRF_LOG_INIT(NULL);
    	char string_on_stack[] = "stack";
        NRF_LOG_INFO("%s",nrf_log_push(string_on_stack));
    
        while (true)
        {
            /* Do nothing */
        }
    }

    I opened a PuTTY serial connexion with 230400 baudrate, no HFWC, no parity, 8 data bits and 1 stop bit.

    But I can't print anything on PuTTY. Am I missing something ?

  • Hi, 

    default baudrate is 115200, but is configurable in sdk_config.h. Also, the log buffer must be processed in main context if you have deferred logging enabled (default).

    You can include this macro in your main loop to process the log buffers:

    int main()

    {

        ...

        for(;;)

        {

           NRF_LOG_PROCESS();

        }

    }

  • Hi,

    As you can see in the configuration (sdk_config.h) I shared in my precedent post, I haven't activated deffered logging:

    #ifndef NRF_LOG_DEFERRED
    #define NRF_LOG_DEFERRED 0
    #endif

    Also in my config I have configured the baudrate to 230400:

    // UART_DEFAULT_CONFIG_BAUDRATE set to 230400
    
    #ifndef UART_DEFAULT_CONFIG_BAUDRATE
    #define UART_DEFAULT_CONFIG_BAUDRATE 61865984
    #endif
    
    
    #if  NRF_LOG_BACKEND_SERIAL_USES_UART
    
    // NRF_LOG_BACKEND_SERIAL_UART_BAUDRATE  - set to 230400
    
    #ifndef NRF_LOG_BACKEND_SERIAL_UART_BAUDRATE
    #define NRF_LOG_BACKEND_SERIAL_UART_BAUDRATE 61865984
    #endif
    
    #endif //NRF_LOG_BACKEND_SERIAL_USES_UART

    I still can't print log in PuTTY.

  • I overlooked your config settings for some reason. See now that you are using a different pinout so I guess you are not using the nRF52 DK as I thought. What are you using to connect the UART interface to the PC? 

Related