参考链接(https://www.cnblogs.com/hjj801006/p/12690197.html)
今天在移植定时器驱动文件nrfx_timer.c,编译过程中报出了两个错误,在此记录一下。
1、在nRF_Dreivers中添加nrfx_timer.c文件时出现的问题
选中“nRF_Dreivers ” -> 右键选择“Add Existing Files to Group…” -> 选择nrfx_timer.c文件
注:添加完成nrfx_timer.c后,发现文件图标上面没有和其他文件图标上面的雪花形状的标记,原因是:
该文件没有被单独设置过option。
方法是:右击该文件打开它的option,修改属性然后点确定,它就会被标上雪花。
如果出现“browser information of one or more files is not available doing a project rebuild would fix this”的报错。
本人通过查询验证后的解决方法:
将“nrfx_timer.c”中的内容 “全选剪切→编译→粘贴回来→再编译”完美解决
2、编译报错
#include “nrf_drv_timer.h”
const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(0); —编译报错
int main()
{
uint32_t time_ms = 500;
uint32_t time_ticks;
uint32_t err_code = NRF_SUCCESS;
nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
err_code = nrf_drv_timer_init(&TIMER_LED, &timer_cfg, timer_led_event_handler);
APP_ERROR_CHECK(err_code);
time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_LED, time_ms);
nrf_drv_timer_extended_compare(
&TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
nrf_drv_timer_enable(&TIMER_LED);
}
nrfx_timer.c中:
#if !(NRFX_CHECK(NRFX_TIMER0_ENABLED) || NRFX_CHECK(NRFX_TIMER1_ENABLED) ||
NRFX_CHECK(NRFX_TIMER2_ENABLED) || NRFX_CHECK(NRFX_TIMER3_ENABLED) ||
NRFX_CHECK(NRFX_TIMER4_ENABLED))
#error “No enabled TIMER instances. Check <nrfx_config.h>.” ----------编译报错
#endif
编译程序,发现两处地方报错,最后发现问题原因:
sdk_config.h中,需要将
#ifndef TIMER0_ENABLED
#define TIMER0_ENABLED 1
#endif
#ifndef TIMER_ENABLED
#define TIMER_ENABLED 1
#endif
或者