|
楼主 |
发表于 2013-3-6 16:46:51
|
显示全部楼层
本帖最后由 landings 于 2013-3-6 16:48 编辑
aozima 发表于 2013-3-6 15:08
"使用STM32 103不同容量的单片机的时候",需要修改board.h 中的 STM32_SRAM_SIZE 值
还有些问题请教,我现在程序成功启动了,但是出现
rtc is not configured
please configure with set_date and set_time
我暂时并不需要用到RTC,怎么关掉它呢?
二是,请问rt_mq_t是否需要初始化?我在控制台看到了(mq != RT_NULL) assert failed at rt_mq_recv:2085
原因是,我是照抄的RT Thread 1.0 PDF说明中,第十章的串口设备操作例程,它里面的rx_mq在声明以后,未见有初始化,导致在rt_mq_recv()中出错。是否是这个原因?不过,串口调试器还是可以看到接收到的字符被重新发送回了。
如果要避免这个错误提示,该怎么做?- /*
- * 程序清单:串口设备操作例程
- *
- * 在这个例程中,将启动一个devt线程,然后打开串口1和2
- * 当串口1和2有输入时,将读取其中的输入数据然后写入到
- * 串口1设备中。
- *
- */
- #include <rtthread.h>
-
- /* UART接收消息结构*/
- struct rx_msg
- {
- rt_device_t dev;
- rt_size_t size;
- };
- /* 用于接收消息的消息队列*/
- static rt_mq_t rx_mq;
- /* 接收线程的接收缓冲区*/
- static char uart_rx_buffer[64];
-
- /* 数据到达回调函数*/
- rt_err_t uart_input(rt_device_t dev, rt_size_t size)
- {
- struct rx_msg msg;
- msg.dev = dev;
- msg.size = size;
-
- /* 发送消息到消息队列中*/
- rt_mq_send(rx_mq, &msg, sizeof(struct rx_msg));
-
- return RT_EOK;
- }
-
- void device_thread_entry(void* parameter)
- {
- struct rx_msg msg;
- int count = 0;
- rt_device_t device, write_device;
- rt_err_t result = RT_EOK;
-
- /* 查找系统中的串口1设备 */
- device = rt_device_find("uart1");
- if (device!= RT_NULL)
- {
- /* 设置回调函数及打开设备*/
- rt_device_set_rx_indicate(device, uart_input);
- rt_device_open(device, RT_DEVICE_OFLAG_RDWR);
- }
- /* 设置写设备为uart1设备 */
- write_device = device;
-
- /* 查找系统中的串口2设备 */
- device= rt_device_find("uart2");
- if (device_!= RT_NULL)
- {
- /* 设置回调函数及打开设备*/
- rt_device_set_rx_indicate(device, uart_input);
- rt_device_open(device, RT_DEVICE_OFLAG_RDWR);
- }
-
- while (1)
- {
- /* 从消息队列中读取消息*/
- result = rt_mq_recv(rx_mq, &msg,
- sizeof(struct rx_msg), 50);
- if (result == -RT_ETIMEOUT)
- {
- /* 接收超时*/
- rt_kprintf("timeout count:%d\n", ++count);
- }
-
- /* 成功收到消息*/
- if (result == RT_EOK)
- {
- rt_uint32_t rx_length;
- rx_length = (sizeof(uart_rx_buffer) - 1) >
- msg.size ? msg.size : sizeof(uart_rx_buffer) - 1;
-
- /* 读取消息*/
- rx_length = rt_device_read(msg.dev, 0,
- &uart_rx_buffer[0], rx_length);
- uart_rx_buffer[rx_length] = '\0';
-
- /* 写到写设备中*/
- if (write_device != RT_NULL)
- rt_device_write(write_device, 0,
- &uart_rx_buffer[0], rx_length);
- }
- }
- }
-
- int rt_application_init()
- {
- /* 创建devt线程*/
- rt_thread_t thread = rt_thread_create("devt",
- device_thread_entry, RT_NULL,
- 1024, 25, 7);
- /* 创建成功则启动线程*/
- if (thread_!= RT_NULL)
- rt_thread_startup(&thread);
- }
复制代码 |
|