Nordic SDK打印到串口 [英] Nordic SDK printing to serial

查看:857
本文介绍了Nordic SDK打印到串口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行在Nordic SDK上的Arduino设备(它是一个Red Bear Lab BLE nano)。我想能够在GTKTerm中进行串行打印,以便能够调试我的代码中发生了什么。为此,我有以下代码:

  / * 
*版权所有(c)2014北欧半导体。版权所有。
*
*此处包含的信息是Nordic Semiconductor的保密资料。禁止使用
*复制,转让或披露此类信息,除非与Nordic Semiconductor签署明确的书面
*协议。
*
* /

/ **
* @brief BLE心率收集器应用程序主文件。
*
*此文件包含样本心率收集器的源代码。
* /

#include< stdint.h>
#include< stdio.h>
#include< string.h>
#includenordic_common.h
#includenrf_sdm.h
#includeble.h
#includeble_hci.h
#include
#includesoftdevice_handler.h
#includeapp_util.h
#includeapp_error.h
#includeboards.h
#includenrf_gpio.h
#includepstorage.h
#includedevice_manager.h
#includeapp_trace.h
#include
#includeble_bas_c.h
#includeapp_util.h
#includeapp_timer.h
#includebsp.h
#includebsp_btn_ble.h

#define UART_TX_BUF_SIZE 256 / **< UART TX缓冲区大小。 * /
#define UART_RX_BUF_SIZE 1 / **< UART RX缓冲区大小。 * /

#define STRING_BUFFER_LEN 50
#define BOND_DELETE_ALL_BUTTON_ID 0 / **<用于在启动期间删除所有粘合中心的按钮。 * /

#define APP_TIMER_PRESCALER 0 / **< RTC1 PRESCALER寄存器的值。 * /
#define APP_TIMER_MAX_TIMERS(2 + BSP_APP_TIMERS_NUMBER)/ **<同时创建的定时器的最大数量。 * /
#define APP_TIMER_OP_QUEUE_SIZE 2 / **<定时器操作队列的大小* /

#define APPL_LOG app_trace_log / **<将在此文件中使用的调试记录宏将通过UART记录调试信息。 * /

#define SEC_PARAM_BOND 1 / **<执行粘合。 * /
#define SEC_PARAM_MITM 1 / **<中层保护人员不需要。 * /
#define SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_NONE / **<没有I / O功能。 * /
#define SEC_PARAM_OOB 0 / **<带外数据不可用。 * /
#define SEC_PARAM_MIN_KEY_SIZE 7 / **<最小加密密钥大小。 * /
#define SEC_PARAM_MAX_KEY_SIZE 16 / **<最大加密密钥大小。 * /

#define SCAN_INTERVAL 0x00A0 / **<以0.625毫秒为单位确定扫描间隔。 * /
#define SCAN_WINDOW 0x0050 / **<以0.625毫秒为单位确定扫描窗口。 * /

#define MIN_CONNECTION_INTERVAL MSEC_TO_UNITS(7.5,UNIT_1_25_MS)/ **<确定最小连接间隔(以毫秒为单位)。 * /
#define MAX_CONNECTION_INTERVAL MSEC_TO_UNITS(30,UNIT_1_25_MS)/ **<确定最大连接间隔(以毫秒为单位)。 * /
#define SLAVE_LATENCY 0 / **<确定连接事件计数中的从属延迟。 * /
#define SUPERVISION_TIMEOUT MSEC_TO_UNITS(4000,UNIT_10_MS)/ **<以10毫秒为单位确定监控超时。 * /

#define TARGET_UUID 0x180D / **<应用程序正在查找的目标设备名称。 * /
#define MAX_PEER_COUNT DEVICE_MANAGER_MAX_CONNECTIONS / **<同级应用程序的最大数量打算管理。 * /
#define UUID16_SIZE 2 / **< 16位的大小UUID * /

/ ** @ breif宏从八位字节流解压缩16位无符号UUID。 * /
#define UUID16_EXTRACT(DST,SRC)\
do \
{\
(*(DST))=(SRC)[1] \
(*(DST))<< = 8; \
(*(DST))| =(SRC)[0]; \
} while(0)

/ ** @ brief根据长度和数据指针的可变长度数据封装* /
typedef struct
{
uint8_t * p_data; / ** LT;数据指针* /
uint16_t data_len; / ** LT;数据长度* /
} data_t;

typedef枚举
{
BLE_NO_SCAN,/ **<没有广告运行。 * /
BLE_WHITELIST_SCAN,/ **<广告白名单。 * /
BLE_FAST_SCAN,/ **<快速广告运行。 * /
} ble_scan_mode_t;

static ble_db_discovery_t m_ble_db_discovery; / ** LT;用于标识DB Discovery模块的结构。 * /
static ble_hrs_c_t m_ble_hrs_c; / ** LT;用于识别心率客户端模块的结构。 * /
static ble_bas_c_t m_ble_bas_c; / ** LT;用于识别电池服务客户端模块的结构。 * /
static ble_gap_scan_params_t m_scan_param; / ** LT;扫描和连接请求扫描参数。 * /
static dm_application_instance_t m_dm_app_id; / ** LT;应用标识符* /
static dm_handle_t m_dm_device_handle; / ** LT;设备标识符标识符* /
static uint8_t m_peer_count = 0; / ** LT;同侪数量相连。 * /
static ble_scan_mode_t m_scan_mode = BLE_FAST_SCAN; / ** LT;应用程序使用的扫描模式。 * /
static uint16_t m_conn_handle; / ** LT;当前连接手柄。 * /
static volatile bool m_whitelist_temporarily_disabled = false; / ** LT;如果白名单暂时被禁用,则为真。 * /

static bool m_memory_access_in_progress = false; / ** LT;标记持续记忆的持续操作。 * /

/ **
* @brief要连接的连接参数。
* /
static const ble_gap_conn_params_t m_connection_param =
{
(uint16_t)MIN_CONNECTION_INTERVAL,//最小连接
(uint16_t)MAX_CONNECTION_INTERVAL,//最大连接数
0,//从属延迟
(uint16_t)SUPERVISION_TIMEOUT //监督超时
};

static void scan_start(void);

#define APPL_LOG app_trace_log / **<将在此文件中使用的调试记录宏将通过UART记录调试信息。 * /


/ ** @ brief初始化UART的功能。
* /
static void uart_init(void)
{
uint32_t err_code;

const app_uart_comm_params_t comm_params =
{
RX_PIN_NUMBER,
TX_PIN_NUMBER,
RTS_PIN_NUMBER,
CTS_PIN_NUMBER,
APP_UART_FLOW_CONTROL_ENABLED,
false,
UART_BAUDRATE_BAUDRATE_Baud38400
};

APP_UART_FIFO_INIT(& comm_params,
UART_RX_BUF_SIZE,
UART_TX_BUF_SIZE,
uart_error_handle,
APP_IRQ_PRIORITY_LOW,
err_code)

APP_ERROR_CHECK(err_code);

app_trace_init();
}

/ ** @brief电源管理器的功能。
* /
static void power_manage(void)
{
uint32_t err_code = sd_app_evt_wait();

APP_ERROR_CHECK(err_code);
}


int main(void)
{
bool erase_bonds;

//初始化
uart_init();
printf(心率收集器示例(这是一个自定义日志)\r\\\
);

for(;;)
{
power_manage();
}
}

我遇到的问题是,只有有时我会看GTKterm中的输出。我无法找到一个什么时候工作的模式,何时没有。我如何调试这个?

解决方案


我将如何调试这个? p>

有关初学者的一些建议:



确保您的终端软件正在断言DTR信号。这是找到的解决方案这里



暂时删除 power_manage()的调用,以确保不是问题的一部分。 / p>

更改 APP_UART_FLOW_CONTROL_ENABLED APP_UART_FLOW_CONTROL_DISABLED 以确定它是否为流控问题。在任何情况下,您不需要输出到PC的流量控制。如果您正在输入设备(特别是缓冲区长度为1),或者您正在向缓慢的缓冲设备发送数据,可能需要此功能。



调用 ERR_CODE %2Fgroup__app__uart.html& cp = 4_0_0_6_8_29_4& anchor = ga25b7b23e541732b945b5992b5519a10frel =nofollow> APP_UART_FIFO_INIT ,以确保在该阶段没有发生问题。定义可能的错误代码这里


I have an Arduino device that runs on the Nordic SDK (it's a Red Bear Lab BLE nano). I want to be able to do a serial print into GTKTerm to be able to debug what is going on in my code. To do this I have the following code:

/*
 * Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
 *
 * The information contained herein is confidential property of Nordic Semiconductor. The use,
 * copying, transfer or disclosure of such information is prohibited except by express written
 * agreement with Nordic Semiconductor.
 *
 */

/** 
 * @brief BLE Heart Rate Collector application main file.
 *
 * This file contains the source code for a sample heart rate collector.
 */

#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "nordic_common.h"
#include "nrf_sdm.h"
#include "ble.h"
#include "ble_hci.h"
#include "ble_db_discovery.h"
#include "softdevice_handler.h"
#include "app_util.h"
#include "app_error.h"
#include "boards.h"
#include "nrf_gpio.h"
#include "pstorage.h"
#include "device_manager.h"
#include "app_trace.h"
#include "ble_hrs_c.h"
#include "ble_bas_c.h"
#include "app_util.h"
#include "app_timer.h"
#include "bsp.h"
#include "bsp_btn_ble.h"

#define UART_TX_BUF_SIZE           256                                /**< UART TX buffer size. */
#define UART_RX_BUF_SIZE           1                                  /**< UART RX buffer size. */

#define STRING_BUFFER_LEN          50
#define BOND_DELETE_ALL_BUTTON_ID  0                                  /**< Button used for deleting all bonded centrals during startup. */

#define APP_TIMER_PRESCALER        0                                  /**< Value of the RTC1 PRESCALER register. */
#define APP_TIMER_MAX_TIMERS       (2+BSP_APP_TIMERS_NUMBER)          /**< Maximum number of simultaneously created timers. */
#define APP_TIMER_OP_QUEUE_SIZE    2                                  /**< Size of timer operation queues. */

#define APPL_LOG                   app_trace_log                      /**< Debug logger macro that will be used in this file to do logging of debug information over UART. */

#define SEC_PARAM_BOND             1                                  /**< Perform bonding. */
#define SEC_PARAM_MITM             1                                  /**< Man In The Middle protection not required. */
#define SEC_PARAM_IO_CAPABILITIES  BLE_GAP_IO_CAPS_NONE               /**< No I/O capabilities. */
#define SEC_PARAM_OOB              0                                  /**< Out Of Band data not available. */
#define SEC_PARAM_MIN_KEY_SIZE     7                                  /**< Minimum encryption key size. */
#define SEC_PARAM_MAX_KEY_SIZE     16                                 /**< Maximum encryption key size. */

#define SCAN_INTERVAL              0x00A0                             /**< Determines scan interval in units of 0.625 millisecond. */
#define SCAN_WINDOW                0x0050                             /**< Determines scan window in units of 0.625 millisecond. */

#define MIN_CONNECTION_INTERVAL    MSEC_TO_UNITS(7.5, UNIT_1_25_MS)   /**< Determines minimum connection interval in millisecond. */
#define MAX_CONNECTION_INTERVAL    MSEC_TO_UNITS(30, UNIT_1_25_MS)    /**< Determines maximum connection interval in millisecond. */
#define SLAVE_LATENCY              0                                  /**< Determines slave latency in counts of connection events. */
#define SUPERVISION_TIMEOUT        MSEC_TO_UNITS(4000, UNIT_10_MS)    /**< Determines supervision time-out in units of 10 millisecond. */

#define TARGET_UUID                0x180D                             /**< Target device name that application is looking for. */
#define MAX_PEER_COUNT             DEVICE_MANAGER_MAX_CONNECTIONS     /**< Maximum number of peer's application intends to manage. */
#define UUID16_SIZE                2                                  /**< Size of 16 bit UUID */

/**@breif Macro to unpack 16bit unsigned UUID from octet stream. */
#define UUID16_EXTRACT(DST, SRC) \
    do                           \
    {                            \
        (*(DST))   = (SRC)[1];   \
        (*(DST)) <<= 8;          \
        (*(DST))  |= (SRC)[0];   \
    } while (0)

/**@brief Variable length data encapsulation in terms of length and pointer to data */
typedef struct
{
    uint8_t     * p_data;                                             /**< Pointer to data. */
    uint16_t      data_len;                                           /**< Length of data. */
}data_t;

typedef enum
{
    BLE_NO_SCAN,                                                     /**< No advertising running. */
    BLE_WHITELIST_SCAN,                                              /**< Advertising with whitelist. */
    BLE_FAST_SCAN,                                                   /**< Fast advertising running. */
} ble_scan_mode_t;

static ble_db_discovery_t           m_ble_db_discovery;                  /**< Structure used to identify the DB Discovery module. */
static ble_hrs_c_t                  m_ble_hrs_c;                         /**< Structure used to identify the heart rate client module. */
static ble_bas_c_t                  m_ble_bas_c;                         /**< Structure used to identify the Battery Service client module. */
static ble_gap_scan_params_t        m_scan_param;                        /**< Scan parameters requested for scanning and connection. */
static dm_application_instance_t    m_dm_app_id;                         /**< Application identifier. */
static dm_handle_t                  m_dm_device_handle;                  /**< Device Identifier identifier. */
static uint8_t                      m_peer_count = 0;                    /**< Number of peer's connected. */
static ble_scan_mode_t              m_scan_mode = BLE_FAST_SCAN;         /**< Scan mode used by application. */
static uint16_t                     m_conn_handle;                       /**< Current connection handle. */
static volatile bool                m_whitelist_temporarily_disabled = false; /**< True if whitelist has been temporarily disabled. */

static bool                         m_memory_access_in_progress = false; /**< Flag to keep track of ongoing operations on persistent memory. */

/**
 * @brief Connection parameters requested for connection.
 */
static const ble_gap_conn_params_t m_connection_param =
{
    (uint16_t)MIN_CONNECTION_INTERVAL,   // Minimum connection
    (uint16_t)MAX_CONNECTION_INTERVAL,   // Maximum connection
    0,                                   // Slave latency
    (uint16_t)SUPERVISION_TIMEOUT        // Supervision time-out
};

static void scan_start(void);

#define APPL_LOG                        app_trace_log             /**< Debug logger macro that will be used in this file to do logging of debug information over UART. */


/**@brief Function for initializing the UART.
 */
static void uart_init(void)
{
    uint32_t err_code;

    const app_uart_comm_params_t comm_params =
       {
           RX_PIN_NUMBER,
           TX_PIN_NUMBER,
           RTS_PIN_NUMBER,
           CTS_PIN_NUMBER,
           APP_UART_FLOW_CONTROL_ENABLED,
           false,
           UART_BAUDRATE_BAUDRATE_Baud38400
       };

    APP_UART_FIFO_INIT(&comm_params,
                          UART_RX_BUF_SIZE,
                          UART_TX_BUF_SIZE,
                          uart_error_handle,
                          APP_IRQ_PRIORITY_LOW,
                          err_code);

    APP_ERROR_CHECK(err_code);

    app_trace_init();
}

/** @brief Function for the Power manager.
 */
static void power_manage(void)
{
    uint32_t err_code = sd_app_evt_wait();

    APP_ERROR_CHECK(err_code);
}


int main(void)
{
    bool erase_bonds;

    // Initialize.
    uart_init();
    printf("Heart rate collector example (this is a custom log)\r\n");

    for (;; )
    {
        power_manage();
    }
}

The problem I am having is that only sometimes I will see an output in GTKterm. I am unable to find a pattern for when it works and when it doesn't. How would I go about debugging this?

解决方案

How would I go about debugging this?

Some suggestions for starters:

Ensure that your terminal software is asserting the DTR signal. That was the solution found here.

Temporarily remove the call to power_manage() to ensure that is not part of the problem.

Change APP_UART_FLOW_CONTROL_ENABLED for APP_UART_FLOW_CONTROL_DISABLED to determine whether it is a flow control issue. You will not need flow control for output to a PC in any case. It may be needed if you are inputting to the device (especially with a buffer length of 1) or if you are sending to data to a slow device with limited buffering.

Verify ERR_CODE after calling APP_UART_FIFO_INIT to ensure no problems occurred at that stage. Possible error codes are defined here.

这篇关于Nordic SDK打印到串口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆