RTTV4.04.使用stduio+cube配置。
配置TIM3正常使用,使用TIM1卡死在rt_thread_mdelay延时处。
rt_thread_mdelay延时的时钟使用SYS或者TIM6都卡在这。
怀疑是优先级的问题,更改TIM1定时器优先级最低也没有用。
board。h中定义
#define BSP_USING_TIM
#ifdef BSP_USING_TIM
#define BSP_USING_TIM1
#ifdef BSP_USING_TIM1
#ifndef TIM1_CONFIG
#define TIM1_CONFIG
{
.tim_handle.Instance = TIM1,
.tim_irqn = TIM1_UP_TIM10_IRQn,
.name = "timer1",
}
#endif /* TIM1_CONFIG /
#endif / TIM1_CONFIG /
#define BSP_USING_TIM3
#ifdef BSP_USING_TIM3
#ifndef TIM3_CONFIG
#define TIM3_CONFIG
{
.tim_handle.Instance = TIM3,
.tim_irqn = TIM3_IRQn,
.name = "timer3",
}
#endif / TIM3_CONFIG /
#endif / BSP_USING_TIM3 */
官方例程只改了设备名
/*
- Copyright (c) 2006-2021, RT-Thread Development Team
- SPDX-License-Identifier: Apache-2.0
- Change Logs:
- Date Author Notes
- 2021-12-21 Administrator the first version
/
/
- 程序清单:这是一个 hwtimer 设备使用例程
- 例程导出了 hwtimer_sample 命令到控制终端
- 命令调用格式:hwtimer_sample
- 程序功能:硬件定时器超时回调函数周期性的打印当前tick值,2次tick值之差换算为时间等同于定时时间值。
/
#include <rtthread.h>
#include <rtdevice.h>
#define HWTIMER_DEV_NAME "timer1" / 定时器名称 /
/ 定时器超时回调函数 */
static rt_err_t timeout_cb(rt_device_t dev, rt_size_t size)
{
rt_kprintf("this is hwtimer timeout callback fucntion!\n");
rt_kprintf("tick is :%d !\n", rt_tick_get());
return 0;
}
static int hwtimer_sample(int argc, char argv[])
{
rt_err_t ret = RT_EOK;
rt_hwtimerval_t timeout_s; / 定时器超时值 /
rt_device_t hw_dev = RT_NULL; / 定时器设备句柄 /
rt_hwtimer_mode_t mode; / 定时器模式 /
/ 查找定时器设备 /
hw_dev = rt_device_find(HWTIMER_DEV_NAME);
if (hw_dev == RT_NULL)
{
rt_kprintf("hwtimer sample run failed! can't find %s device!\n", HWTIMER_DEV_NAME);
return RT_ERROR;
}
/ 以读写方式打开设备 /
ret = rt_device_open(hw_dev, RT_DEVICE_OFLAG_RDWR);
if (ret != RT_EOK)
{
rt_kprintf("open %s device failed!\n", HWTIMER_DEV_NAME);
return ret;
}
/ 设置超时回调函数 /
rt_device_set_rx_indicate(hw_dev, timeout_cb);
/ 设置模式为周期性定时器 /
mode = HWTIMER_MODE_PERIOD;
ret = rt_device_control(hw_dev, HWTIMER_CTRL_MODE_SET, &mode);
if (ret != RT_EOK)
{
rt_kprintf("set mode failed! ret is :%d\n", ret);
return ret;
}
/ 设置定时器超时值为5s并启动定时器 /
timeout_s.sec = 5; / 秒 /
timeout_s.usec = 0; / 微秒 /
if (rt_device_write(hw_dev, 0, &timeout_s, sizeof(timeout_s)) != sizeof(timeout_s))
{
rt_kprintf("set timeout value failed\n");
return RT_ERROR;
}
/ 延时3500ms /
rt_thread_mdelay(3500);
/ 读取定时器当前值 /
rt_device_read(hw_dev, 0, &timeout_s, sizeof(timeout_s));
rt_kprintf("Read: Sec = %d, Usec = %d\n", timeout_s.sec, timeout_s.usec);
return ret;
}
/ 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(hwtimer_sample, hwtimer sample);
debug定位卡死在这里,搜了一下是硬件错误卡这里了。
/**
- [url=home.php?mod=space&uid=2666770]@Brief[/url] This is the code that gets called when the processor receives an
-
unexpected interrupt. This simply enters an infinite loop, preserving
-
the system state for examination by a debugger.
- [url=home.php?mod=space&uid=3142012]@param[/url] None
- @retval None
*/
.section .text.Default_Handler,"ax",%progbits
Default_Handler:
Infinite_Loop:
b Infinite_Loop
.size Default_Handler, .-Default_Handler
0
|
1个回答
|
|
|