xinggaoyong
xinggaoyong
这家伙很懒,什么也没写!

注册于 2年前

回答
6
文章
0
关注者
1

发布于2年前

改成中断接收测试一下,暂时关闭DMA这一部分。此外,读数据线程代码部分做如下修改

  1. size_demo = rt_device_read(dev_uart,-1,ch,100);
  2. rt_kprintf("size_demo = %d\n");
  3. rt_kprintf("%s\n",ch);

发布于2年前

对lwgps2rtt.c文件做了如下修改,大家可以对照,可以正确的解析GPS数据了。

  1. //*****************************************************************************
  2. // file : lwgps2rtt.c
  3. // porting lwgps to rt-thread
  4. //
  5. // Change Logs:
  6. // Date Author Note
  7. // 2020/09/05 Cheney First draft version
  8. // 2020/09/13 Cheney 1. Update the comments.
  9. // 2. Support gps info query interface.
  10. // 2020/10/10 Cheney Support macros LWGPS_CFG_STATUS
  11. // 2020/12/15 Cheney Configure the uart before using it.
  12. //
  13. //*****************************************************************************
  14. //*****************************************************************************
  15. //
  16. //! \addtogroup lwgps
  17. //! @{
  18. //
  19. //*****************************************************************************
  20. #include <rtthread.h>
  21. #include <rtdevice.h>
  22. #include <board.h>
  23. #include "lwgps.h"
  24. #ifndef GPS_MODULE_BAUD_RATE
  25. #define GPS_MODULE_BAUD_RATE BAUD_RATE_9600
  26. #endif
  27. static lwgps_t h_lwgps;
  28. struct rt_ringbuffer rb ;
  29. static rt_uint8_t gpspool[200];
  30. static rt_device_t serial = RT_NULL;
  31. static struct rt_semaphore rx_sem;
  32. static rt_thread_t lwgps_tid = RT_NULL;
  33. static rt_mutex_t lwgps_mutex = RT_NULL;
  34. static rt_mutex_t uart_mutex = RT_NULL;
  35. /**
  36. * \brief gps uart date received callback
  37. *
  38. * \param dev: uart device
  39. * \param size: data size
  40. * \return rt_err_t: operation result.
  41. */
  42. static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
  43. {
  44. rt_sem_release(&rx_sem);
  45. return RT_EOK;
  46. }
  47. #if LWGPS_CFG_STATUS == 1
  48. void lwgps_process_cbk(lwgps_statement_t res)
  49. {
  50. // TODO: give the interface to user.
  51. }
  52. #endif
  53. /**
  54. * \brief lwgps process thread
  55. *
  56. * \param parameter: input parameters.
  57. */
  58. static void lwgps_thread_entry(void *parameter)
  59. {
  60. rt_uint8_t ch[100];
  61. rt_uint8_t arr[150];
  62. rt_uint8_t count = 0,result;
  63. while (RT_TRUE)
  64. {
  65. rt_sem_take(&rx_sem, RT_WAITING_FOREVER);
  66. /*add by xinggaoyong */
  67. result = rt_device_read(serial, -1, ch, 100);
  68. rt_ringbuffer_put(&rb, ch, result);
  69. count = count + result;
  70. if (count >= 100)
  71. {
  72. rt_mutex_take(lwgps_mutex, RT_WAITING_FOREVER);
  73. rt_ringbuffer_get(&rb, arr, count);
  74. #if LWGPS_CFG_STATUS == 1
  75. lwgps_process(&h_lwgps, arr, count, lwgps_process_cbk);
  76. #else
  77. lwgps_process(&h_lwgps, arr, count);
  78. /*处理结束后,清零count*/
  79. count = 0;
  80. #endif
  81. rt_mutex_release(lwgps_mutex);
  82. }
  83. }
  84. }
  85. /**
  86. * \brief get gps information
  87. *
  88. * \param gps_info: gps information.
  89. */
  90. void lwgps2rtt_get_gps_info(lwgps_t *gps_info)
  91. {
  92. rt_mutex_take(lwgps_mutex, RT_WAITING_FOREVER);
  93. rt_memcpy(gps_info, &h_lwgps, (sizeof(h_lwgps) - sizeof(h_lwgps.p)));
  94. //rt_kprintf("latitude is %f\n",gps_info)
  95. rt_mutex_release(lwgps_mutex);
  96. }
  97. /**
  98. * \brief module init
  99. *
  100. * \param uart_dev_name: uart device name
  101. */
  102. void lwgps2rtt_init(void)
  103. {
  104. rt_ringbuffer_init(&rb,gpspool,150);
  105. serial = rt_device_find("uart3");
  106. if (!serial)
  107. {
  108. rt_kprintf("uart find %s failed!\n", "uart3");
  109. return;
  110. }
  111. struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
  112. config.baud_rate = GPS_MODULE_BAUD_RATE;
  113. config.data_bits = DATA_BITS_8;
  114. config.stop_bits = STOP_BITS_1;
  115. config.parity = PARITY_NONE;
  116. rt_device_control(serial, RT_DEVICE_CTRL_CONFIG, &config);
  117. lwgps_mutex = rt_mutex_create("lwgps_mutex", RT_IPC_FLAG_FIFO);
  118. uart_mutex = rt_mutex_create("uart_mutex", RT_IPC_FLAG_FIFO);
  119. rt_sem_init(&rx_sem, "rx_sem", 0, RT_IPC_FLAG_FIFO);
  120. rt_device_open(serial, RT_DEVICE_FLAG_INT_RX);
  121. //rt_device_open(serial, RT_DEVICE_FLAG_RX_NON_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING);
  122. rt_device_set_rx_indicate(serial, uart_input);
  123. lwgps_init(&h_lwgps);
  124. lwgps_tid = rt_thread_create("lwgps", lwgps_thread_entry, RT_NULL, 2048, 20, 4);
  125. if (lwgps_tid != RT_NULL)
  126. rt_thread_startup(lwgps_tid);
  127. }
  128. /**
  129. * \brief module deinit
  130. *
  131. */
  132. void lwgps2rtt_deinit(void)
  133. {
  134. if (serial != RT_NULL)
  135. {
  136. rt_device_close(serial);
  137. rt_device_set_rx_indicate(serial, RT_NULL);
  138. }
  139. if (lwgps_tid != RT_NULL)
  140. {
  141. rt_thread_delete(lwgps_tid);
  142. }
  143. if (lwgps_mutex != RT_NULL)
  144. {
  145. rt_mutex_delete(lwgps_mutex);
  146. }
  147. serial = RT_NULL;
  148. lwgps_tid = RT_NULL;
  149. lwgps_mutex = RT_NULL;
  150. }
  151. /*add by xinggaoyong*/
  152. INIT_APP_EXPORT(lwgps2rtt_init);
  153. //*****************************************************************************
  154. //
  155. // Close the Doxygen group.
  156. //! @}
  157. //
  158. //*****************************************************************************

发布于2年前

发布于2年前

问题终于解决了。感谢@chenyaxing ,给了我启发,删除DEBUG目录以后,编译仍然报错,但是发现了问题,就是我在目录下创建了Source Insight工程,而且在编辑之后,产生了备份C文件,RT STUDIO里面加入了这个备份的C文件造成了编译错误。
链接:https://pan.baidu.com/s/1LAtHu130cS0wBPV0ShM94Q
提取码:1234
调试资料在这里,有需要的自取。
2022-06-15_210151.png

发布于2年前

是PA4,如果是这个问题的话,那刚下载第一次那个为啥可以探测到?另外这个时钟我在其他地方已经初始化了。我在具体看看这块,谢谢。

发布于2年前

这个问题怎么解决啊?我也是卡住了

回到
顶部

发布
问题

投诉
建议