环境搭建

在进行对协议栈烧写时error - cannot create command input file '..\..\..\..\..\..\components\softdevice\s140\hex\main.__i'出现这个问题,当我把这个文件的权限改写以后"..\..\..\..\..\..\components\softdevice\s140\hex\s140_nrf52_7.2.0_softdevice.hex" - 1 Error(s), 0 Warning(s).这个文件又不行了,导致无法进行下一步,nrf52833_xxaa在进行录的时候一直提醒没有j-link驱动,请问这个调试器是必备硬件之一吗,我是一个刚接触蓝牙版块的小白,请各位大佬赐教,如果有大佬用vs code做这个板子开发的话也可以指教一下我,谢谢你们,跪求大佬指导

Parents
  • Hi

    For your project to be able to discover the header file in a said nRF5 SDK project, you need to add the folder where this header file is located to the project's user include directories. Please refer to the SEGGER blog post available here

    Best regards,

    Simon

  • hello,Could you please help me figure out how to fix this issue? Here is my code and a screenshot of the error.

    #include <stdbool.h>
    #include <stdint.h>
    #include <string.h>

    #include "nrf.h"
    #include "nrf_gpio.h"
    #include "nrf_delay.h"

    #include "ble.h"
    #include "ble_gap.h"
    #include "ble_gatts.h"

    #include "nrf_sdh.h"
    #include "nrf_sdh_ble.h"
    #include "app_error.h"

    /*================= 硬件与参数 =================*/
    #define LED_PIN 13 // DK LED1 = P0.13

    #define APP_BLE_CONN_CFG_TAG 1
    #define APP_BLE_OBSERVER_PRIO 3

    // 简单示例:用标准 16-bit UUID(只是占位,手机可见)
    #define LED_SERVICE_UUID 0x180F // 电池服务 UUID(占位)
    #define LED_CHAR_UUID 0x2A00 // 设备名 UUID(占位,但可用作自定义特征)

    /*================= 句柄与全局 =================*/
    static uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID;
    static uint16_t m_service_handle;
    static ble_gatts_char_handles_t m_led_char_handles;
    static uint8_t m_led_state = 0;

    static uint8_t m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;
    static uint8_t m_enc_advdata[31];
    static uint8_t m_enc_scanrsp[31];

    /*================= GPIO =================*/
    static void gpio_init(void)
    {
    nrf_gpio_cfg_output(LED_PIN);
    nrf_gpio_pin_clear(LED_PIN);
    }

    /*================= GAP 参数 =================*/
    static void gap_params_init(void)
    {
    ret_code_t err;
    static const char device_name[] = "nRF52833-LED";

    ble_gap_conn_sec_mode_t sec_mode;
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);

    err = sd_ble_gap_device_name_set(&sec_mode,
    (const uint8_t *)device_name,
    (uint16_t)strlen(device_name));
    APP_ERROR_CHECK(err);

    // 也可以根据需要设置外观、连接参数等,这里保持默认即可
    }

    /*================= 服务/特征 =================*/
    static void services_init(void)
    {
    ret_code_t err;

    // 1) 添加 Primary Service
    ble_uuid_t svc_uuid;
    svc_uuid.type = BLE_UUID_TYPE_BLE; // 使用 16-bit BLE UUID
    svc_uuid.uuid = LED_SERVICE_UUID;

    err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
    &svc_uuid,
    &m_service_handle);
    APP_ERROR_CHECK(err);

    // 2) 特征元数据
    ble_gatts_char_md_t char_md;
    memset(&char_md, 0, sizeof(char_md));
    char_md.char_props.read = 1;
    char_md.char_props.write = 1;

    // 3) 属性权限/位置
    ble_gatts_attr_md_t attr_md;
    memset(&attr_md, 0, sizeof(attr_md));
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
    attr_md.vloc = BLE_GATTS_VLOC_STACK;
    attr_md.rd_auth = 0;
    attr_md.wr_auth = 0;
    attr_md.vlen = 0;

    // 4) 特征 UUID
    ble_uuid_t char_uuid;
    char_uuid.type = BLE_UUID_TYPE_BLE;
    char_uuid.uuid = LED_CHAR_UUID;

    // 5) 属性值描述
    ble_gatts_attr_t attr_char_value;
    memset(&attr_char_value, 0, sizeof(attr_char_value));
    attr_char_value.p_uuid = &char_uuid;
    attr_char_value.p_attr_md = &attr_md;
    attr_char_value.init_len = sizeof(m_led_state);
    attr_char_value.init_offs = 0;
    attr_char_value.max_len = sizeof(m_led_state);
    attr_char_value.p_value = &m_led_state;

    // 6) 添加特征
    err = sd_ble_gatts_characteristic_add(m_service_handle,
    &char_md,
    &attr_char_value,
    &m_led_char_handles);
    APP_ERROR_CHECK(err);
    }

    /*================= 广播组包 + 启动 =================*/
    static void advertising_init_and_start(void)
    {
    ret_code_t err;

    // 广播数据:Flags + 完整 16-bit 服务列表(0x180F)
    // AD结构: [Len=2, Type=0x01, Flags=0x06], [Len=3, Type=0x03, UUID=0x180F (LE小端)]
    const uint8_t adv_raw[] = {
    2, 0x01, 0x06,
    3, 0x03, 0x0F, 0x18
    };
    memcpy(m_enc_advdata, adv_raw, sizeof(adv_raw));
    uint16_t adv_len = sizeof(adv_raw);

    // 扫描响应:完整本地名
    static const char device_name[] = "nRF52833-LED";
    const uint8_t name_len = (uint8_t)strlen(device_name);
    // [Len=1+N, Type=0x09, Name...]
    m_enc_scanrsp[0] = (uint8_t)(1 + name_len);
    m_enc_scanrsp[1] = 0x09;
    memcpy(&m_enc_scanrsp[2], device_name, name_len);
    uint16_t sr_len = 2 + name_len;

    ble_gap_adv_data_t adv_data = {
    .adv_data =
    {
    .p_data = m_enc_advdata,
    .len = adv_len
    },
    .scan_rsp_data =
    {
    .p_data = m_enc_scanrsp,
    .len = sr_len
    }
    };

    ble_gap_adv_params_t adv_params;
    memset(&adv_params, 0, sizeof(adv_params));
    adv_params.primary_phy = BLE_GAP_PHY_1MBPS;
    adv_params.duration = 0; // 永不超时
    adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
    adv_params.interval = MSEC_TO_UNITS(100, UNIT_0_625_MS); // 100ms

    err = sd_ble_gap_adv_set_configure(&m_adv_handle, &adv_data, &adv_params);
    APP_ERROR_CHECK(err);

    err = sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG);
    APP_ERROR_CHECK(err);
    }

    /*================= BLE 事件处理 =================*/
    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
    (void)p_context;

    switch (p_ble_evt->header.evt_id)
    {
    case BLE_GAP_EVT_CONNECTED:
    m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
    break;

    case BLE_GAP_EVT_DISCONNECTED:
    m_conn_handle = BLE_CONN_HANDLE_INVALID;
    // 断开后继续广播
    advertising_init_and_start();
    break;

    case BLE_GATTS_EVT_WRITE:
    {
    const ble_gatts_evt_write_t * p_wr =
    &p_ble_evt->evt.gatts_evt.params.write;

    if (p_wr->handle == m_led_char_handles.value_handle && p_wr->len >= 1)
    {
    m_led_state = p_wr->data[0];
    if (m_led_state)
    nrf_gpio_pin_set(LED_PIN);
    else
    nrf_gpio_pin_clear(LED_PIN);
    }
    } break;

    default:
    break;
    }
    }

    NRF_SDH_BLE_OBSERVER(m_ble_observer,
    APP_BLE_OBSERVER_PRIO,
    ble_evt_handler,
    NULL);

    /*================= SoftDevice/栈 初始化 =================*/
    static void ble_stack_init(void)
    {
    ret_code_t err;
    err = nrf_sdh_enable_request();
    APP_ERROR_CHECK(err);

    uint32_t ram_start = 0;
    err = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
    APP_ERROR_CHECK(err);

    err = nrf_sdh_ble_enable(&ram_start);
    APP_ERROR_CHECK(err);
    }

    /*================= 主函数 =================*/
    int main(void)
    {
    gpio_init();
    ble_stack_init();
    gap_params_init();
    services_init();
    advertising_init_and_start();

    while (true)
    {
    __WFE(); // 省电等待事件(事件到来由中断派发处理)
    __SEV(); // 清除可能的事件
    __WFE();
    }
    }

    /*================= 必要的错误/断言回调 =================*/
    void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name)
    {
    (void)error_code; (void)line_num; (void)p_file_name;
    __disable_irq();
    while (1) { __WFE(); }
    }

    // SoftDevice 断言回调(nrf_sdh.c 需要)
    void assert_nrf_callback(uint16_t line_num, const uint8_t * p_file_name)
    {
    app_error_handler(0xDEADBEEF, line_num, p_file_name);
    }

Reply
  • hello,Could you please help me figure out how to fix this issue? Here is my code and a screenshot of the error.

    #include <stdbool.h>
    #include <stdint.h>
    #include <string.h>

    #include "nrf.h"
    #include "nrf_gpio.h"
    #include "nrf_delay.h"

    #include "ble.h"
    #include "ble_gap.h"
    #include "ble_gatts.h"

    #include "nrf_sdh.h"
    #include "nrf_sdh_ble.h"
    #include "app_error.h"

    /*================= 硬件与参数 =================*/
    #define LED_PIN 13 // DK LED1 = P0.13

    #define APP_BLE_CONN_CFG_TAG 1
    #define APP_BLE_OBSERVER_PRIO 3

    // 简单示例:用标准 16-bit UUID(只是占位,手机可见)
    #define LED_SERVICE_UUID 0x180F // 电池服务 UUID(占位)
    #define LED_CHAR_UUID 0x2A00 // 设备名 UUID(占位,但可用作自定义特征)

    /*================= 句柄与全局 =================*/
    static uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID;
    static uint16_t m_service_handle;
    static ble_gatts_char_handles_t m_led_char_handles;
    static uint8_t m_led_state = 0;

    static uint8_t m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;
    static uint8_t m_enc_advdata[31];
    static uint8_t m_enc_scanrsp[31];

    /*================= GPIO =================*/
    static void gpio_init(void)
    {
    nrf_gpio_cfg_output(LED_PIN);
    nrf_gpio_pin_clear(LED_PIN);
    }

    /*================= GAP 参数 =================*/
    static void gap_params_init(void)
    {
    ret_code_t err;
    static const char device_name[] = "nRF52833-LED";

    ble_gap_conn_sec_mode_t sec_mode;
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);

    err = sd_ble_gap_device_name_set(&sec_mode,
    (const uint8_t *)device_name,
    (uint16_t)strlen(device_name));
    APP_ERROR_CHECK(err);

    // 也可以根据需要设置外观、连接参数等,这里保持默认即可
    }

    /*================= 服务/特征 =================*/
    static void services_init(void)
    {
    ret_code_t err;

    // 1) 添加 Primary Service
    ble_uuid_t svc_uuid;
    svc_uuid.type = BLE_UUID_TYPE_BLE; // 使用 16-bit BLE UUID
    svc_uuid.uuid = LED_SERVICE_UUID;

    err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
    &svc_uuid,
    &m_service_handle);
    APP_ERROR_CHECK(err);

    // 2) 特征元数据
    ble_gatts_char_md_t char_md;
    memset(&char_md, 0, sizeof(char_md));
    char_md.char_props.read = 1;
    char_md.char_props.write = 1;

    // 3) 属性权限/位置
    ble_gatts_attr_md_t attr_md;
    memset(&attr_md, 0, sizeof(attr_md));
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
    attr_md.vloc = BLE_GATTS_VLOC_STACK;
    attr_md.rd_auth = 0;
    attr_md.wr_auth = 0;
    attr_md.vlen = 0;

    // 4) 特征 UUID
    ble_uuid_t char_uuid;
    char_uuid.type = BLE_UUID_TYPE_BLE;
    char_uuid.uuid = LED_CHAR_UUID;

    // 5) 属性值描述
    ble_gatts_attr_t attr_char_value;
    memset(&attr_char_value, 0, sizeof(attr_char_value));
    attr_char_value.p_uuid = &char_uuid;
    attr_char_value.p_attr_md = &attr_md;
    attr_char_value.init_len = sizeof(m_led_state);
    attr_char_value.init_offs = 0;
    attr_char_value.max_len = sizeof(m_led_state);
    attr_char_value.p_value = &m_led_state;

    // 6) 添加特征
    err = sd_ble_gatts_characteristic_add(m_service_handle,
    &char_md,
    &attr_char_value,
    &m_led_char_handles);
    APP_ERROR_CHECK(err);
    }

    /*================= 广播组包 + 启动 =================*/
    static void advertising_init_and_start(void)
    {
    ret_code_t err;

    // 广播数据:Flags + 完整 16-bit 服务列表(0x180F)
    // AD结构: [Len=2, Type=0x01, Flags=0x06], [Len=3, Type=0x03, UUID=0x180F (LE小端)]
    const uint8_t adv_raw[] = {
    2, 0x01, 0x06,
    3, 0x03, 0x0F, 0x18
    };
    memcpy(m_enc_advdata, adv_raw, sizeof(adv_raw));
    uint16_t adv_len = sizeof(adv_raw);

    // 扫描响应:完整本地名
    static const char device_name[] = "nRF52833-LED";
    const uint8_t name_len = (uint8_t)strlen(device_name);
    // [Len=1+N, Type=0x09, Name...]
    m_enc_scanrsp[0] = (uint8_t)(1 + name_len);
    m_enc_scanrsp[1] = 0x09;
    memcpy(&m_enc_scanrsp[2], device_name, name_len);
    uint16_t sr_len = 2 + name_len;

    ble_gap_adv_data_t adv_data = {
    .adv_data =
    {
    .p_data = m_enc_advdata,
    .len = adv_len
    },
    .scan_rsp_data =
    {
    .p_data = m_enc_scanrsp,
    .len = sr_len
    }
    };

    ble_gap_adv_params_t adv_params;
    memset(&adv_params, 0, sizeof(adv_params));
    adv_params.primary_phy = BLE_GAP_PHY_1MBPS;
    adv_params.duration = 0; // 永不超时
    adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
    adv_params.interval = MSEC_TO_UNITS(100, UNIT_0_625_MS); // 100ms

    err = sd_ble_gap_adv_set_configure(&m_adv_handle, &adv_data, &adv_params);
    APP_ERROR_CHECK(err);

    err = sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG);
    APP_ERROR_CHECK(err);
    }

    /*================= BLE 事件处理 =================*/
    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
    (void)p_context;

    switch (p_ble_evt->header.evt_id)
    {
    case BLE_GAP_EVT_CONNECTED:
    m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
    break;

    case BLE_GAP_EVT_DISCONNECTED:
    m_conn_handle = BLE_CONN_HANDLE_INVALID;
    // 断开后继续广播
    advertising_init_and_start();
    break;

    case BLE_GATTS_EVT_WRITE:
    {
    const ble_gatts_evt_write_t * p_wr =
    &p_ble_evt->evt.gatts_evt.params.write;

    if (p_wr->handle == m_led_char_handles.value_handle && p_wr->len >= 1)
    {
    m_led_state = p_wr->data[0];
    if (m_led_state)
    nrf_gpio_pin_set(LED_PIN);
    else
    nrf_gpio_pin_clear(LED_PIN);
    }
    } break;

    default:
    break;
    }
    }

    NRF_SDH_BLE_OBSERVER(m_ble_observer,
    APP_BLE_OBSERVER_PRIO,
    ble_evt_handler,
    NULL);

    /*================= SoftDevice/栈 初始化 =================*/
    static void ble_stack_init(void)
    {
    ret_code_t err;
    err = nrf_sdh_enable_request();
    APP_ERROR_CHECK(err);

    uint32_t ram_start = 0;
    err = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
    APP_ERROR_CHECK(err);

    err = nrf_sdh_ble_enable(&ram_start);
    APP_ERROR_CHECK(err);
    }

    /*================= 主函数 =================*/
    int main(void)
    {
    gpio_init();
    ble_stack_init();
    gap_params_init();
    services_init();
    advertising_init_and_start();

    while (true)
    {
    __WFE(); // 省电等待事件(事件到来由中断派发处理)
    __SEV(); // 清除可能的事件
    __WFE();
    }
    }

    /*================= 必要的错误/断言回调 =================*/
    void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name)
    {
    (void)error_code; (void)line_num; (void)p_file_name;
    __disable_irq();
    while (1) { __WFE(); }
    }

    // SoftDevice 断言回调(nrf_sdh.c 需要)
    void assert_nrf_callback(uint16_t line_num, const uint8_t * p_file_name)
    {
    app_error_handler(0xDEADBEEF, line_num, p_file_name);
    }

Children
No Data
Related