官方SDK参考路径如下:

最好是先找一个空白工程不要直接使用官方例程便于后续移植开发,移植如下:
1、新建freertos组对文件进行管理

添加的文件路径如下:
这些文件路径为:

路径为:

路径为:

路径为:

还需要添加官方对freertos二次封装的api文件:
路径为:

然后添加头路径索引,这里需要根据自己的路径,我这个仅作参考:

2、进行编译
编译之后可能会报一个定时器的错误,直接去FREERTOS_CONFIG.h文件中把定时器宏开启即可

清除这个报错之后还会有另个报错,报错是定时器中断重复定义,
- port_cmsis_systick.o(FreeRTOS CMSIS 移植层自带 RTC1 中断服务函数)
- drv_rtc.o(nrf_drv_rtc 驱动自带 RTC1_IRQHandler)
直接不使用 nrf_drv_rtc,工程移除 drv_rtc.c,全程只用 FreeRTOS 系统定时器即可,路径一般在

这个组下有个drv_rtc.c直接移除就行
三、解决main报错
头文件包含如下
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "nordic_common.h"
#include "nrf.h"
#include "app_error.h"
#include "app_timer.h"
#include "app_uart.h"
#include "app_scheduler.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "nrf_pwr_mgmt.h"
#include "nrf_drv_clock.h"
#include "nrf_drv_saadc.h"
#if defined (UART_PRESENT)
#include "nrf_uart.h"
#endif
#if defined (UARTE_PRESENT)
#include "nrf_uarte.h"
#endif
#include "bsp.h"
#include "bsp_btn_ble.h"
#include "ble.h"
#include "ble_hci.h"
#include "ble_srv_common.h"
#include "ble_advdata.h"
#include "ble_advertising.h"
#include "ble_conn_params.h"
#include "ble_conn_state.h"
#include "nrf_ble_gatt.h"
#include "nrf_ble_qwr.h"
#include "nrf_ble_lesc.h"
#include "ble_bas.h"
#include "ble_lbs.h"
#include "ble_hrs.h"
#include "ble_dis.h"
#include "ble_hts.h"
#include "my_ble_uarts.h"
#include "sensorsim.h"
#include "fds.h"
#include "device_name_op.h"
#include "nrf_sdh_soc.h"
#include "nrf_sdh_ble.h"
#include "nrf_sdh_freertos.h"
#include "peer_manager.h"
#include "peer_manager_handler.h"
#include"nrf_sdh.h"
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "semphr.h"
开始解决报错
首先sdk_config.h里搜索NRF_SDH_DISPATCH_MODEL,把这个宏定义为2即可
然后是定时器函数,我们需要把

组中的定时器app_timer2.c函数移除,然后添加app_timer_freertos.c函数,路径为:

现在只剩最后一个报错

这个是空闲钩子函数,打开freertos_config.h确保参数置1,

然后在main中进行实现
//log
#if NRF_LOG_ENABLED
static TaskHandle_t m_logger_thread; /**< Definition of Logger thread. */
#endif
void vApplicationIdleHook( void )
{
#if NRF_LOG_ENABLED
vTaskResume(m_logger_thread);
#endif
}

至此结束,关于函数的使用以及初始化部分在下一篇,有问题评论区见


