3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Lチカから次の一歩 - printf / NRF_LOG_INFO が使えるようにする - (SEGGER + nRF52840)

Last updated at Posted at 2019-02-18

SEGGER + nRF52840 で Lチカ
https://qiita.com/nanbuwks/items/408e07ca36da25928686

の続きです。
sdk_config.h の使い方や SEGGER Embedded Studio からの設定方法などを学びます。

blinky

SDK/myProjects/peripheral/blinky_NRFLOG/pca10056/mbr/ses/blinky_pca10056_mbr.emProjectを開いた時の、オリジナルのコードです。(コード部分のみ抜粋)



# include <stdbool.h>
# include <stdint.h>
# include "nrf_delay.h"
# include "boards.h"

int main(void)
{
    bsp_board_init(BSP_INIT_LEDS);
    while (true)
    {
        for (int i = 0; i < LEDS_NUMBER; i++)
        {
            bsp_board_led_invert(i);
            nrf_delay_ms(500);
        }
    }
}

printf を実現

これの while 部分を以下のようにします。

    int counter=0;
    while (true)
    {
        for (int i = 0; i < LEDS_NUMBER; i++)
        {
            bsp_board_led_invert(i);
            nrf_delay_ms(50);
        }
        printf("count:%d\n",counter);
        counter++;
    }

とします。

これを実行すると、


count:0
count:1
count:2
count:3
count:4
count:5

と出力されます。Debugモード時にはprintfの出力先がDebug Terminalなどに出力されます。
左上のBuild ConfigurationはReleaseになってますが、J-LinkとSEGGER Embedded StudioがつながっているとDebugモードになります。

NRF_LOG_INFOを追加する

これを、NRF_LOG_INFOを使って取得できるようにします。


        printf("count:%d\n",counter);
        NRF_LOG_INFO("%d",counter);
        NRF_LOG_FLUSH();

とします。NRF_LOG_INFOはデバッグ用に記録を送ります。NRF_LOG_FLUSHはバッファを吐き出させます。

さて、これでコンパイルしても


1> /home/nanbuwks/Downloads/Nordic/SDK/myProjects/peripheral/blinky_NRFLOG/main.c:28: undefined reference to `NRF_LOG_INFO'
1> /home/nanbuwks/Downloads/Nordic/SDK/myProjects/peripheral/blinky_NRFLOG/main.c:29: undefined reference to `NRF_LOG_FLUSH'
Build failed

と出ます。なので定義ファイルをインクルードします。更に、NRF_LOG機能を使うための初期化ルーチンも追加します。


# 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)
{
    int counter=0;
    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();
//    uart_init();
    bsp_board_init(BSP_INIT_LEDS);

    while (true)
    {
        for (int i = 0; i < LEDS_NUMBER; i++)
        {
            bsp_board_led_invert(i);
            nrf_delay_ms(50);
        }
//        printf("count:%d\n",counter);
        NRF_LOG_INFO("%d",counter);
        NRF_LOG_FLUSH();
        counter++;
    }
}


これでコンパイルエラーは出なくなりましたが、実行しても何も出力されません。

NRF_LOG_INFOの処理を調べる

NRF_LOG_INFOは、components/libraries/log/nrf_log.h
で以下のように定義されています。


# define NRF_LOG_ERROR(...)                     NRF_LOG_INTERNAL_ERROR(__VA_ARGS__)
# define NRF_LOG_WARNING(...)                   NRF_LOG_INTERNAL_WARNING( __VA_ARGS__)
# define NRF_LOG_INFO(...)                      NRF_LOG_INTERNAL_INFO( __VA_ARGS__)
# define NRF_LOG_DEBUG(...)                     NRF_LOG_INTERNAL_DEBUG( __VA_ARGS__)

更に、NRF_LOG_INTERNAL_INFO は components/libraries/log/src/nrf_log_internal.h で


# define NRF_LOG_INTERNAL_INFO(...) \
        NRF_LOG_INTERNAL_MODULE(NRF_LOG_SEVERITY_INFO, NRF_LOG_SEVERITY_INFO, __VA_ARGS__)

となっており、更に同じファイル内で


# define NRF_LOG_INTERNAL_MODULE(level, level_id, ...)                                    \
    if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= level) &&                                   \
        (level <= NRF_LOG_DEFAULT_LEVEL))                                                \
    {                                                                                    \
        if (NRF_LOG_FILTER >= level)                                                     \
        {                                                                                \
            LOG_INTERNAL(LOG_SEVERITY_MOD_ID(level_id), __VA_ARGS__);                    \
        }                                                                                \
    }

となっていて、NRF_LOG_ENABLEDが真でなければ処理がされないことがわかります。

sdk_config.h の NRF_LOG を有効にする

NRF_LOG_ENABLED が真になっていないと出力されないと書きましたが、
それについての設定は sdk_config.h で行うようになります。

CMISIS Configuration Wizardを使って設定してみましょう。
起動すると以下のように表示されるので、

image.png

NRF_LOG_ENABLEDを以下のように探します。

image.png

上図のようにチェックが外れているので、チェックを入れて保存ボタンを押します。
しかしながら、このようにしてもNRF_LOGの出力にはなりません。実際のCの処理が入っていないためです。

そのうえで、nRF_Log関係のCライブラリをリンクするように設定していきます。
設定は、blinky_pca10056_mbr.emProjectを開き、

    <folder Name="nRF_Log">
      <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_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>

更に、これらについての設定を sdk_config.h に追加するようになります。
CMISIS Configuration Wizardは既にある項目値の設定変更しか出来ないので、sdk_config.hを直接開きます。


// </h> 
//==========================================================

// <h> nRF_Log 
//==========================================================
// <e> NRF_LOG_ENABLED - nrf_log - Logger
//==========================================================
# ifndef NRF_LOG_ENABLED
# define NRF_LOG_ENABLED 1
# endif

先程変更した NRF_LOG_ENABLEDが1になっているのがわかります。
この箇所を、以下のようにします


// </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 0
# endif

NRF_LOGの処理を更に調べる

さきほど、NRF_LOG_INFOの処理内容としてLOG_INTERNALまで追跡しましたが、更に辿っていきます。
同じ components/libraries/log/src/nrf_log_internal.h ファイル内で、


# define LOG_INTERNAL_X(N, ...)          CONCAT_2(LOG_INTERNAL_, N) (__VA_ARGS__)
# define LOG_INTERNAL(type, ...) LOG_INTERNAL_X(NUM_VA_ARGS_LESS_1( \
                                                           __VA_ARGS__), type, __VA_ARGS__)
                                                           __VA_ARGS__), type, __VA_ARGS__)
# if NRF_LOG_ENABLED
# define NRF_LOG_INTERNAL_LOG_PUSH(_str) nrf_log_push(_str)
# define LOG_INTERNAL_0(type, str) \
    nrf_log_frontend_std_0(type, str)
# define LOG_INTERNAL_1(type, str, arg0) \
    /*lint -save -e571*/nrf_log_frontend_std_1(type, str, (uint32_t)(arg0))/*lint -restore*/
# define LOG_INTERNAL_2(type, str, arg0, arg1) \
    /*lint -save -e571*/nrf_log_frontend_std_2(type, str, (uint32_t)(arg0), \
            (uint32_t)(arg1))/*lint -restore*/
# define LOG_INTERNAL_3(type, str, arg0, arg1, arg2) \
    /*lint -save -e571*/nrf_log_frontend_std_3(type, str, (uint32_t)(arg0), \
            (uint32_t)(arg1), (uint32_t)(arg2))/*lint -restore*/
# define LOG_INTERNAL_4(type, str, arg0, arg1, arg2, arg3) \
    /*lint -save -e571*/nrf_log_frontend_std_4(type, str, (uint32_t)(arg0), \
            (uint32_t)(arg1), (uint32_t)(arg2), (uint32_t)(arg3))/*lint -restore*/
# define LOG_INTERNAL_5(type, str, arg0, arg1, arg2, arg3, arg4) \
    /*lint -save -e571*/nrf_log_frontend_std_5(type, str, (uint32_t)(arg0), \
            (uint32_t)(arg1), (uint32_t)(arg2), (uint32_t)(arg3), (uint32_t)(arg4))/*lint -restore*/
# define LOG_INTERNAL_6(type, str, arg0, arg1, arg2, arg3, arg4, arg5) \
    /*lint -save -e571*/nrf_log_frontend_std_6(type, str, (uint32_t)(arg0), \
            (uint32_t)(arg1), (uint32_t)(arg2), (uint32_t)(arg3), (uint32_t)(arg4), (uint32_t)(arg5))/*lint -restore*/

というようになっています。

nrf_log_frontend_std_0
などは
components/libraries/log/src/nrf_log_frontend.c
において


static inline void std_header_set(uint32_t severity_mid,
                                      char const * const p_str,
                                      uint32_t nargs,
                                      uint32_t wr_idx,
                                      uint32_t mask)
{


    //Prepare header - in reverse order to ensure that packet type is validated (set to STD as last action)
    uint32_t module_id = severity_mid >> NRF_LOG_MODULE_ID_POS;
    uint32_t dropped   = dropped_sat16_get();
    ASSERT(module_id < nrf_log_module_cnt_get());
    m_log_data.buffer[(wr_idx + 1) & mask] = module_id | (dropped << 16);

    if (NRF_LOG_USES_TIMESTAMP)
    {
        m_log_data.buffer[(wr_idx + 2) & mask] = m_log_data.timestamp_func();
    }

    nrf_log_header_t * p_header    = (nrf_log_header_t *)&m_log_data.buffer[wr_idx & mask];
    p_header->base.std.severity    = severity_mid & NRF_LOG_LEVEL_MASK;
    p_header->base.std.nargs       = nargs;
    p_header->base.std.addr        = ((uint32_t)(p_str) & STD_ADDR_MASK);
    p_header->base.std.type        = HEADER_TYPE_STD;
    p_header->base.std.in_progress = 0;
}


static inline void std_n(uint32_t           severity_mid,
                         char const * const p_str,
                         uint32_t const *   args,
                         uint32_t           nargs)
{
    uint32_t mask   = m_log_data.mask;
    uint32_t wr_idx;

    if (buf_prealloc(nargs, &wr_idx, true))
    {
        // Proceed only if buffer was successfully preallocated.

        uint32_t data_idx = wr_idx + HEADER_SIZE;
        uint32_t i;
        for (i = 0; i < nargs; i++)
        {
            m_log_data.buffer[data_idx++ & mask] =args[i];
        }
        std_header_set(severity_mid, p_str, nargs, wr_idx, mask);
    }
    if (m_log_data.autoflush)
    {
        NRF_LOG_FLUSH();
    }

}

void nrf_log_frontend_std_0(uint32_t severity_mid, char const * const p_str)
{
    std_n(severity_mid, p_str, NULL, 0);
}

というように続いていって、どうやら NRF_LOG_MODULE というのが複数あり、それらに出力されるような感じです。

NRF_LOG_MODULE を登録する

今はモジュールが何も登録されていない状態と推測できます。以下のようにして、機能を入れていきます。

sdk_config.h の最後の箇所に以下を入れます。



//==========================================================

// <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> 
//==========================================================

blinky_pca10056_mbr.emProjectを開き、以下を追加します。

   <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>

これで実行すると、Debug_Terminalに、


<info> app: 0
<info> app: 1
<info> app: 2
<info> app: 3
<info> app: 4
<info> app: 5
・
・
・

と出るようになります。

NRF_LOG_INFO を UART にも出力する

同じ内容を、 UARTにも出力するようにしてみます。
先にsdk_config.hに追加した箇所のうち、

# 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

の箇所を↓のように追加します


# ifndef NRF_LOG_BACKEND_RTT_TX_RETRY_CNT
# define NRF_LOG_BACKEND_RTT_TX_RETRY_CNT 3
# endif

// </e>

// <e> NRF_LOG_BACKEND_UART_ENABLED - nrf_log_backend_uart - Log UART backend
//==========================================================
# ifndef NRF_LOG_BACKEND_UART_ENABLED
# define NRF_LOG_BACKEND_UART_ENABLED 0
# endif
// <o> NRF_LOG_BACKEND_UART_TX_PIN - UART TX pin 
# ifndef NRF_LOG_BACKEND_UART_TX_PIN
# define NRF_LOG_BACKEND_UART_TX_PIN 4
# endif

// <o> NRF_LOG_BACKEND_UART_BAUDRATE  - Default Baudrate
 
// <323584=> 1200 baud 
// <643072=> 2400 baud 
// <1290240=> 4800 baud 
// <2576384=> 9600 baud 
// <3862528=> 14400 baud 
// <5152768=> 19200 baud 
// <7716864=> 28800 baud 
// <10289152=> 38400 baud 
// <15400960=> 57600 baud 
// <20615168=> 76800 baud 
// <30801920=> 115200 baud 
// <61865984=> 230400 baud 
// <67108864=> 250000 baud 
// <121634816=> 460800 baud 
// <251658240=> 921600 baud 
// <268435456=> 1000000 baud 

# ifndef NRF_LOG_BACKEND_UART_BAUDRATE
# define NRF_LOG_BACKEND_UART_BAUDRATE 30801920
# endif

// <o> NRF_LOG_BACKEND_UART_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_UART_TEMP_BUFFER_SIZE
# define NRF_LOG_BACKEND_UART_TEMP_BUFFER_SIZE 64
# endif

// </e>

//==========================================================
// <e> NRF_LOG_ENABLED - nrf_log - Logger
//==========================================================
# ifndef NRF_LOG_ENABLED
# define NRF_LOG_ENABLED 1
# endif

これで保存して、書き換えでフォーマットを崩していないかの確認を兼ねて、CMSIS Configuratin Wizard
で設定をします。以下の「NRF_LOG_DEFAULT_BACKEND」を ENABLE にします。

image.png

階層構造などの表示が上記のようになっていなければ、書き換えミスでしょうから確認をしてください。
保存ボタンを押してからCMSIS Configuratin Wizardを終了して、

更に、blinky_pca10056_mbr.emProject を開き、nRF_Logの項目を以下のように変更します。


    <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_backend_uart.c" />
      <file file_name="../../../../../../components/libraries/log/src/nrf_log_backend_serial.c" />
      <file file_name="../../../../../../components/libraries/log/src/nrf_log_default_backends.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>

また、依存関係にあるUARTドライバ、競合を管理するドライバなどをインストールします。


     <folder Name="nRF_Drivers">
      <file file_name="../../../../../../integration/nrfx/legacy/nrf_drv_uart.c" />
      <file file_name="../../../../../../modules/nrfx/drivers/src/prs/nrfx_prs.c" />
      <file file_name="../../../../../../modules/nrfx/drivers/src/nrfx_uart.c" />
      <file file_name="../../../../../../modules/nrfx/drivers/src/nrfx_uarte.c" />
    </folder>

ヘッダファイルのインクルード設定を追加します。


      c_user_include_directories="../../../../../../components;../..


      c_user_include_directories="../../../../../../modules/nrfx/drivers/include;../../../../../../integration/nrfx/legacy;../../../../../../external/segger_rtt;../../../../../../components;../..

sdk_config.hの冒頭に、必要な設定と共にnRF_Driversハイブを作り、以下のようにします。

以下のようになっているところを、


# ifndef SDK_CONFIG_H
# define SDK_CONFIG_H
// <<< Use Configuration Wizard in Context Menu >>>\n
# ifdef USE_APP_CONFIG
# include "app_config.h"
# endif


// <h> nRF_Libraries 

↓のように書き換えます。

# ifndef SDK_CONFIG_H
# define SDK_CONFIG_H
// <<< Use Configuration Wizard in Context Menu >>>\n
# ifdef USE_APP_CONFIG
# include "app_config.h"
# endif


// <h> nRF_Drivers 

//==========================================================
// <e> NRFX_PRS_ENABLED - nrfx_prs - Peripheral Resource Sharing module
//==========================================================
# ifndef NRFX_PRS_ENABLED
# define NRFX_PRS_ENABLED 1
# endif
// <q> NRFX_PRS_BOX_0_ENABLED  - Enables box 0 in the module.
 

# ifndef NRFX_PRS_BOX_0_ENABLED
# define NRFX_PRS_BOX_0_ENABLED 0
# endif

// <q> NRFX_PRS_BOX_1_ENABLED  - Enables box 1 in the module.
 

# ifndef NRFX_PRS_BOX_1_ENABLED
# define NRFX_PRS_BOX_1_ENABLED 0
# endif

// <q> NRFX_PRS_BOX_2_ENABLED  - Enables box 2 in the module.
 

# ifndef NRFX_PRS_BOX_2_ENABLED
# define NRFX_PRS_BOX_2_ENABLED 0
# endif

// <q> NRFX_PRS_BOX_3_ENABLED  - Enables box 3 in the module.
 

# ifndef NRFX_PRS_BOX_3_ENABLED
# define NRFX_PRS_BOX_3_ENABLED 0
# endif

// <q> NRFX_PRS_BOX_4_ENABLED  - Enables box 4 in the module.
 

# ifndef NRFX_PRS_BOX_4_ENABLED
# define NRFX_PRS_BOX_4_ENABLED 1
# endif

// <e> NRFX_PRS_CONFIG_LOG_ENABLED - Enables logging in the module.
//==========================================================
# ifndef NRFX_PRS_CONFIG_LOG_ENABLED
# define NRFX_PRS_CONFIG_LOG_ENABLED 0
# endif
// <o> NRFX_PRS_CONFIG_LOG_LEVEL  - Default Severity level
 
// <0=> Off 
// <1=> Error 
// <2=> Warning 
// <3=> Info 
// <4=> Debug 

# ifndef NRFX_PRS_CONFIG_LOG_LEVEL
# define NRFX_PRS_CONFIG_LOG_LEVEL 3
# endif

// <o> NRFX_PRS_CONFIG_INFO_COLOR  - ANSI escape code prefix.
 
// <0=> Default 
// <1=> Black 
// <2=> Red 
// <3=> Green 
// <4=> Yellow 
// <5=> Blue 
// <6=> Magenta 
// <7=> Cyan 
// <8=> White 

# ifndef NRFX_PRS_CONFIG_INFO_COLOR
# define NRFX_PRS_CONFIG_INFO_COLOR 0
# endif

// <o> NRFX_PRS_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.
 
// <0=> Default 
// <1=> Black 
// <2=> Red 
// <3=> Green 
// <4=> Yellow 
// <5=> Blue 
// <6=> Magenta 
// <7=> Cyan 
// <8=> White 

# ifndef NRFX_PRS_CONFIG_DEBUG_COLOR
# define NRFX_PRS_CONFIG_DEBUG_COLOR 0
# endif

// </e>

// </e>
//==========================================================
// <e> NRFX_UARTE_ENABLED - nrfx_uarte - UARTE peripheral driver
//==========================================================
# ifndef NRFX_UARTE_ENABLED
# define NRFX_UARTE_ENABLED 1
# endif
// <o> NRFX_UARTE0_ENABLED - Enable UARTE0 instance 
# ifndef NRFX_UARTE0_ENABLED
# define NRFX_UARTE0_ENABLED 0
# endif

// <o> NRFX_UARTE1_ENABLED - Enable UARTE1 instance 
# ifndef NRFX_UARTE1_ENABLED
# define NRFX_UARTE1_ENABLED 0
# endif

// <o> NRFX_UARTE_DEFAULT_CONFIG_HWFC  - Hardware Flow Control
 
// <0=> Disabled 
// <1=> Enabled 

# ifndef NRFX_UARTE_DEFAULT_CONFIG_HWFC
# define NRFX_UARTE_DEFAULT_CONFIG_HWFC 0
# endif

// <o> NRFX_UARTE_DEFAULT_CONFIG_PARITY  - Parity
 
// <0=> Excluded 
// <14=> Included 

# ifndef NRFX_UARTE_DEFAULT_CONFIG_PARITY
# define NRFX_UARTE_DEFAULT_CONFIG_PARITY 0
# endif

// <o> NRFX_UARTE_DEFAULT_CONFIG_BAUDRATE  - Default Baudrate
 
// <323584=> 1200 baud 
// <643072=> 2400 baud 
// <1290240=> 4800 baud 
// <2576384=> 9600 baud 
// <3862528=> 14400 baud 
// <5152768=> 19200 baud 
// <7716864=> 28800 baud 
// <8388608=> 31250 baud 
// <10289152=> 38400 baud 
// <15007744=> 56000 baud 
// <15400960=> 57600 baud 
// <20615168=> 76800 baud 
// <30801920=> 115200 baud 
// <61865984=> 230400 baud 
// <67108864=> 250000 baud 
// <121634816=> 460800 baud 
// <251658240=> 921600 baud 
// <268435456=> 1000000 baud 

# ifndef NRFX_UARTE_DEFAULT_CONFIG_BAUDRATE
# define NRFX_UARTE_DEFAULT_CONFIG_BAUDRATE 30801920
# endif

// <o> NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority
 
// <0=> 0 (highest) 
// <1=> 1 
// <2=> 2 
// <3=> 3 
// <4=> 4 
// <5=> 5 
// <6=> 6 
// <7=> 7 

# ifndef NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY
# define NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY 6
# endif

// <e> NRFX_UARTE_CONFIG_LOG_ENABLED - Enables logging in the module.
//==========================================================
# ifndef NRFX_UARTE_CONFIG_LOG_ENABLED
# define NRFX_UARTE_CONFIG_LOG_ENABLED 0
# endif
// <o> NRFX_UARTE_CONFIG_LOG_LEVEL  - Default Severity level
 
// <0=> Off 
// <1=> Error 
// <2=> Warning 
// <3=> Info 
// <4=> Debug 

# ifndef NRFX_UARTE_CONFIG_LOG_LEVEL
# define NRFX_UARTE_CONFIG_LOG_LEVEL 3
# endif

// <o> NRFX_UARTE_CONFIG_INFO_COLOR  - ANSI escape code prefix.
 
// <0=> Default 
// <1=> Black 
// <2=> Red 
// <3=> Green 
// <4=> Yellow 
// <5=> Blue 
// <6=> Magenta 
// <7=> Cyan 
// <8=> White 

# ifndef NRFX_UARTE_CONFIG_INFO_COLOR
# define NRFX_UARTE_CONFIG_INFO_COLOR 0
# endif

// <o> NRFX_UARTE_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.
 
// <0=> Default 
// <1=> Black 
// <2=> Red 
// <3=> Green 
// <4=> Yellow 
// <5=> Blue 
// <6=> Magenta 
// <7=> Cyan 
// <8=> White 

# ifndef NRFX_UARTE_CONFIG_DEBUG_COLOR
# define NRFX_UARTE_CONFIG_DEBUG_COLOR 0
# endif

// </e>


// </e>

// <e> UART_ENABLED - nrf_drv_uart - UART/UARTE peripheral driver - legacy layer
//==========================================================
# ifndef UART_ENABLED
# define UART_ENABLED 1
# endif
// <o> UART_DEFAULT_CONFIG_HWFC  - Hardware Flow Control
 
// <0=> Disabled 
// <1=> Enabled 

# ifndef UART_DEFAULT_CONFIG_HWFC
# define UART_DEFAULT_CONFIG_HWFC 0
# endif

// <o> UART_DEFAULT_CONFIG_PARITY  - Parity
 
// <0=> Excluded 
// <14=> Included 

# ifndef UART_DEFAULT_CONFIG_PARITY
# define UART_DEFAULT_CONFIG_PARITY 0
# endif

// <o> UART_DEFAULT_CONFIG_BAUDRATE  - Default Baudrate
 
// <323584=> 1200 baud 
// <643072=> 2400 baud 
// <1290240=> 4800 baud 
// <2576384=> 9600 baud 
// <3862528=> 14400 baud 
// <5152768=> 19200 baud 
// <7716864=> 28800 baud 
// <10289152=> 38400 baud 
// <15400960=> 57600 baud 
// <20615168=> 76800 baud 
// <30801920=> 115200 baud 
// <61865984=> 230400 baud 
// <67108864=> 250000 baud 
// <121634816=> 460800 baud 
// <251658240=> 921600 baud 
// <268435456=> 1000000 baud 

# ifndef UART_DEFAULT_CONFIG_BAUDRATE
# define UART_DEFAULT_CONFIG_BAUDRATE 30801920
# endif

// <o> UART_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority
 

// <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
// <0=> 0 (highest) 
// <1=> 1 
// <2=> 2 
// <3=> 3 
// <4=> 4 
// <5=> 5 
// <6=> 6 
// <7=> 7 

# ifndef UART_DEFAULT_CONFIG_IRQ_PRIORITY
# define UART_DEFAULT_CONFIG_IRQ_PRIORITY 6
# endif

// <q> UART_EASY_DMA_SUPPORT  - Driver supporting EasyDMA
 

# ifndef UART_EASY_DMA_SUPPORT
# define UART_EASY_DMA_SUPPORT 1
# endif

// <q> UART_LEGACY_SUPPORT  - Driver supporting Legacy mode
 

# ifndef UART_LEGACY_SUPPORT
# define UART_LEGACY_SUPPORT 1
# endif

// <e> UART0_ENABLED - Enable UART0 instance
//==========================================================
# ifndef UART0_ENABLED
# define UART0_ENABLED 1
# endif
// <q> UART0_CONFIG_USE_EASY_DMA  - Default setting for using EasyDMA
 

# ifndef UART0_CONFIG_USE_EASY_DMA
# define UART0_CONFIG_USE_EASY_DMA 1
# endif

// </e>

// <e> UART1_ENABLED - Enable UART1 instance
//==========================================================
# ifndef UART1_ENABLED
# define UART1_ENABLED 0
# endif
// </e>

// </e>
// </h> 

// <h> nRF_Libraries 

nrfx_prs.c

これなんだろう、と思いましたがこれがないとビルド時に以下のように出ます。


Checking project status
Project out of date
Building 'blinky_pca10056_mbr' from solution 'blinky_pca10056_mbr' in configuration 'Release'
1> Linking blinky_pca10056_mbr.elf
1> Output/blinky_pca10056_mbr Release/Obj/nrfx_uarte.o: In function `UARTE0_UART0_IRQHandler':
1> /home/nanbuwks/Downloads/Nordic/SDK/modules/nrfx/drivers/src/nrfx_uarte.c:571: multiple definition of `UARTE0_UART0_IRQHandler'
1> Output/blinky_pca10056_mbr Release/Obj/nrfx_uart.o:/home/nanbuwks/Downloads/Nordic/SDK/modules/nrfx/drivers/src/nrfx_uart.c:644: first defined here
Build failed

実行

これで実行すると、UARTから以下のように出力されます。


<info> app: 0
<info> app: 1
<info> app: 2
<info> app: 3
<info> app: 4
<info> app: 5
<info> app: 6

define NRF_LOG_BACKEND_UART_TX_PIN 4

と設定しているので、上記はP0.04から出力されます。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?