TI-RTOS模块驱动示例-定时器模块

309 阅读3分钟

1 配置
APIs位置:
/docs/drivers/doxygen/html/_timer_8h.html#ti_drivers_Timer_Examples
/docs/drivers/doxygen/html/_g_p_i_o_8h.html#ti_drivers_GPIO_Examples
syscfg配置:
在这里插入图片描述

2 代码
在static void ProjectZero_init(void)中添加如下代码

//timer test

    //Timer_init();  //不用也可以
    Timer_Params_init(&params_rled);
    params_rled.periodUnits = Timer_PERIOD_HZ;
    params_rled.period = 4;
    params_rled.timerMode  = Timer_CONTINUOUS_CALLBACK;
    params_rled.timerCallback = TimerCallbackFunction_rled;
    handle_rled = Timer_open(CONFIG_TIMER_0, &params_rled);

    if (handle_rled == NULL) {
        // Timer_open() failed
        while (1);
    }
    int32_t status_rled = Timer_start(handle_rled);
    if (status_rled == Timer_STATUS_ERROR) {
        //Timer_start() failed
        while (1);
    }

    Timer_Params_init(&params_gled);
    params_gled.periodUnits = Timer_PERIOD_HZ;
    params_gled.period = 10;
    params_gled.timerMode  = Timer_CONTINUOUS_CALLBACK;
    params_gled.timerCallback = TimerCallbackFunction_gled;
    handle_gled = Timer_open(CONFIG_TIMER_1, &params_gled);

    if (handle_gled == NULL) {
        // Timer_open() failed
        while (1);
    }
    int32_t status_gled = Timer_start(handle_gled);
    if (status_gled == Timer_STATUS_ERROR) {
        //Timer_start() failed
        while (1);
    }

在其上添加回调函数

//test  timer callback
void TimerCallbackFunction_rled(Timer_Handle handle, int_fast16_t status)
{
    static uint8_t i = 0;

    i = ~i;

    PIN_setOutputValue(ledPinHandle, CONFIG_PIN_RLED, i);

}

void TimerCallbackFunction_gled(Timer_Handle handle, int_fast16_t status)
{
    static uint8_t i = 0;

    i = ~i;

    PIN_setOutputValue(ledPinHandle, CONFIG_PIN_GLED, i);

}

3 现象
红灯以4HZ频率闪烁,绿灯频率是10HZ,如果频率比较低,注意使用32位定时器

4 问题
重新上电后程序消失

5 问题排查

  • 使用另一个例程buttonled将void handleButtonCallback(Button_Handle handle, Button_EventMask events)函数中的两个led位置调换,下载程序后重新上电,程序没有消失

  • 重新导入项目工程仍存在上述问题

  • 更换同样开发板仍存在上述问题

  • 更换RSIP开发板不存在上述问题

  • 使用串口监听输出信息,正常启动时可以输出,重启后停止输出

  • 擦除后使用UNIFLASH_7.0.0工具直接下载.out文件或者.hex文件, 不重启也无法搜到ble,错误提示如下:
    Cortex_M4_0: Error: (Error -1170 @ 0x0) Unable to access the DAP. Reset the device, and retry the operation. If error persists, confirm configuration, power-cycle the board, and/or try more reliable JTAG settings (e.g. lower TCLK). (Emulation package 9.4.0.00129)

  • 询问FAE(案例号:CS0762436),确认不需要两个固件(FAE说错了,需要两个固件),提供了一个开箱视频和两个类似案例如下:

    • CC3235SF: Error connecting to the target: (Error -1170 @ 0x0)
    • Unable to access the DAP
  • 其中一个案例上面的image.syscfg > General Settings > Image Mode在CCS配置上面没有找到;另一个案例上说的先上电再插下载线也试了,和之前一样

  • 在网上看到一个类似的案例https://blog.csdn.net/wangwuzhuang/article/details/78491712,就此案例寻求FAE进一步支持

  • 在如下路径下,选择project_zero_unsecure_app.hex文件通过下载工具下载进去,报错问题解决,但是仍然不能使更改生效
    \ble5stack\hexfiles

1.6 问题分析

  • 可以正常工作的project_zero_unsecure_app.hex文件大小是405KB,不正常的project_zero_CC26X2R1_LAUNCHXL_tirtos_ticlang.hex文件大小是312KB,应该是例程生成的HEX没有配置BLE相关的程序,后续查看手册时注意相关内容
  • 通过UniFlash的Memory > Go CCFG可以看到烧录不正常的hex文件后,0x50003000后面没有数据,0x50003000对应的是 Customer Configuration section (由引导ROM和TI提供驱动程序来配置设备),CCFG相关内容查看路径即CCFG位置如下图:
    \startup_files\ccfg.c
    在这里插入图片描述

最终不能生效问题,具体解决方法:下载BIM hex文件(针对OAD升级),方法,使用smart RF Flash Programmer 2 or Uniflash,文件路径在examples → rtos → ---- LaunchPad → ble5stack → hexfiles → bim_onchip\ → Debug_unsecure,注意,如果下载的是保护文件,则用CCS下载并重启后,程序会消失,猜测是CCS下载的文件没有被带保护的BIM识别通过