收藏官网首页
查看: 10804|回复: 0

【一起来玩RTOS系列】之RT-Thread 邮箱用于线程间通信

321

主题

1054

帖子

4502

积分

论坛元老

Rank: 8Rank: 8

积分
4502
QQ
跳转到指定楼层
楼主
发表于 2017-12-9 22:26:24 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
汉枫LPB120模块
本帖最后由 bigfanofloT 于 2017-12-9 22:29 编辑

邮箱

邮箱服务是实时操作系统中一种典型的任务间通信方法,特点是开销比较低,效率较高。邮箱中的每一封邮件只能容纳固定的4字节内容(针对32位处理系统,指针的大小即为4个字节,所以一封邮件恰好能够容纳一个指针)。典型的邮箱也称作交换消息,如图所示,线程或中断服务例程把一封4字节长度的邮件发送到邮箱中。而一个或多个线程可以从邮箱中接收这些邮件进行处理。



RT-Thread操作系统采用的邮箱通信机制有点类似于传统意义上的管道,用于线程间通讯。非阻塞方式的邮件发送过程能够安全的应用于中断服务中,是线程,中断服务,定时器向线程发送消息的有效手段。通常来说,邮件收取过程可能是阻塞的,这取决于邮箱中是否有邮件,以及收取邮件时设置的超时时间。当邮箱中不存在邮件且超时时间不为0时,邮件收取过程将变成阻塞方式。所以在这类情况下,只能由线程进行邮件的收取。

RT-Thread操作系统的邮箱中可存放固定条数的邮件,邮箱容量在创建/初始化邮箱时设定,每个邮件大小为4字节。当需要在线程间传递比较大的消息时,可以把指向一个缓冲区的指针作为邮件发送到邮箱中。

在一个线程向邮箱发送邮件时,如果邮箱没满,将把邮件复制到邮箱中。如果邮箱已经满了,发送线程可以设置超时时间,选择是否等待挂起或直接返回-RT_EFULL。如果发送线程选择挂起等待,那么当邮箱中的邮件被收取而空出空间来时,等待挂起的发送线程将被唤醒继续发送的过程。

在一个线程从邮箱中接收邮件时,如果邮箱是空的,接收线程可以选择是否等待挂起直到收到新的邮件而唤醒,或设置超时时间。当达到设置的超时时间,邮箱依然未收到邮件时,这个选择超时等待的线程将被唤醒并返回-RT_ETIMEOUT。如果邮箱中存在邮件,那么接收线程将复制邮箱中的4个字节邮件到接收线程中。

邮箱控制块


  1. struct rt_mailbox
  2. {
  3.     struct rt_ipc_object parent;

  4.     rt_uint32_t* msg_pool;              /* 邮箱缓冲区的开始地址 */
  5.     rt_uint16_t size;                   /* 邮箱缓冲区的大小     */

  6.     rt_uint16_t entry;                  /* 邮箱中邮件的数目     */
  7.     rt_uint16_t in_offset, out_offset;  /* 邮箱缓冲的进出指针   */
  8.     rt_list_t suspend_sender_thread;    /* 发送线程的挂起等待队列 */
  9. };
  10. typedef struct rt_mailbox* rt_mailbox_t;
复制代码

rt_mailbox对象从rt_ipc_object中派生,由IPC容器管理。

邮箱相关接口

创建邮箱

创建邮箱对象可以调用如下的函数接口:

  1. rt_mailbox_t rt_mb_create (const char* name, rt_size_t size, rt_uint8_t flag);
复制代码

创建邮箱对象时会先创建一个邮箱对象控制块,然后给邮箱分配一块内存空间用来存放邮件,这块内存的大小等于邮件大小(4字节)与邮箱容量的乘积,接着初始化接收邮件和发送邮件在邮箱中的偏移量。

函数参数


      参数  描述

      name  邮箱名称;

      size  邮箱容量;

      flag  邮箱标志,它可以取如下数值:

  1. #define RT_IPC_FLAG_FIFO 0x00 /* IPC参数采用FIFO方式*/
  2. #define RT_IPC_FLAG_PRIO 0x01 /* IPC参数采用优先级方式*/
复制代码

函数返回

创建成功返回邮箱对象的句柄;否则返回-RT_NULL。

删除邮箱

当邮箱不再被使用时,应该删除它来释放相应的系统资源,一旦操作完成,邮箱将被永久性的删除。删除邮箱的函数接口如下:

  1. rt_err_t rt_mb_delete (rt_mailbox_t mb);
复制代码

删除邮箱时,如果有线程被挂起在该邮箱对象上,内核先唤醒挂起在该邮箱上的所有线程(线程获得返回值是-RT_ERROR),然后再释放邮箱使用的内存,最后删除邮箱对象。

函数参数


      参数  描述

        mb  邮箱对象的句柄。

函数返回

RT_EOK

初始化邮箱

初始化邮箱跟创建邮箱类似,只是初始化邮箱用于静态邮箱对象的初始化。其他与创建邮箱不同的是,此处静态邮箱对象所使用的内存空间是由用户线程指定的一个缓冲区空间,用户把缓冲区的指针传递给邮箱对象控制块,其余的初始化工作与创建邮箱时相同。函数接口如下:

  1. rt_err_t rt_mb_init(rt_mailbox_t mb, const char* name, void* msgpool,
  2.     rt_size_t size, rt_uint8_t flag)
复制代码

初始化邮箱时,该函数接口需要获得用户已经申请获得的邮箱对象控制块,缓冲区的指针,以及邮箱名称和邮箱容量。

函数参数


      参数  描述

        mb  邮箱对象的句柄;

      name  邮箱名称;

   msgpool  缓冲区指针;

      size  邮箱容量;

      flag  邮箱标志,它可以取如下数值:

  1. #define RT_IPC_FLAG_FIFO 0x00 /* IPC参数采用FIFO方式*/
  2. #define RT_IPC_FLAG_PRIO 0x01 /* IPC参数采用优先级方式*/
复制代码

函数返回

RT_EOK

注: 这里的size参数指定的是邮箱的容量,即如果msgpool的字节数是N,那么邮箱容量应该是N/4。
脱离邮箱

脱离邮箱将把邮箱对象从内核对象管理器中删除。脱离邮箱使用下面的接口:

  1. rt_err_t rt_mb_detach(rt_mailbox_t mb);
复制代码

使用该函数接口后,内核先唤醒所有挂在该邮箱上的线程(线程获得返回值是- RT_ERROR ),然后将该邮箱对象从内核对象管理器中删除。

函数参数


      参数  描述

        mb  邮箱对象的句柄。

函数返回

RT_EOK

发送邮件

线程或者中断服务程序可以通过邮箱给其他线程发送邮件,发送邮件函数接口如下:

  1. rt_err_t rt_mb_send (rt_mailbox_t mb, rt_uint32_t value);
复制代码

发送的邮件可以是32位任意格式的数据,一个整型值或者一个指向缓冲区的指针。当邮箱中的邮件已经满时,发送邮件的线程或者中断程序会收到-RT_EFULL 的返回值。

函数参数


      参数  描述

        mb  邮箱对象的句柄;

     value  邮件内容。

函数返回

发送成功返回RT_EOK;如果邮箱已经满了,返回-RT_EFULL。

等待方式发送邮件

用户也可以通过如下的函数接口向指定邮箱发送邮件:

  1. rt_err_t rt_mb_send_wait (rt_mailbox_t mb, rt_uint32_t value, rt_int32_t timeout);
复制代码

rt_mb_send_wait与rt_mb_send的区别在于,如果邮箱已经满了,那么发送线程将根据设定的timeout参数等待邮箱中因为收取邮件而空出空间。如果设置的超时时间到达依然没有空出空间,这时发送线程将被唤醒返回错误码。

函数参数


      参数  描述

        mb  邮箱对象的句柄;

     value  邮件内容;

   timeout  超时时间。

函数返回

发送成功返回RT_EOK;如果设置的时间超时依然未发送成功,返回-RT_ETIMEOUT,其他情况返回-RT_ERROR。

接收邮件

只有当接收者接收的邮箱中有邮件时,接收者才能立即取到邮件并返回RT_EOK的返回值,否则接收线程会根据超时时间设置,或挂起在邮箱的等待线程队列上,或直接返回。接收邮件函数接口如下:

  1. rt_err_t rt_mb_recv (rt_mailbox_t mb, rt_uint32_t* value, rt_int32_t timeout);
复制代码

接收邮件时,接收者需指定接收邮件的邮箱句柄,并指定接收到的邮件存放位置以及最多能够等待的超时时间。如果接收时设定了超时,当指定的时间内依然未收到邮件时,将返回-RT_ETIMEOUT。

函数参数


      参数  描述

        mb  邮箱对象的句柄;

     value  邮件内容;

   timeout  超时时间。

函数返回

成功收到返回RT_EOK,超时返回-RT_ETIMEOUT,其他返回-RT_ERROR。
使用场合

邮箱是一种简单的线程间消息传递方式,在RT-Thread操作系统的实现中能够一次传递4字节邮件,并且邮箱具备一定的存储功能,能够缓存一定数量的邮件数(邮件数由创建、初始化邮箱时指定的容量决定)。邮箱中一封邮件的最大长度是4字节,所以邮箱能够用于不超过4字节的消息传递,当传送的消息长度大于这个数目时就不能再采用邮箱的方式。 最重要的是,在32位系统上4字节的内容恰好适合放置一个指针,所以邮箱也适合那种仅传递指针的情况,例如:

  1. struct msg
  2. {
  3.     rt_uint8_t *data_ptr;
  4.     rt_uint32_t data_size;
  5. };
复制代码


对于这样一个消息结构体,其中包含了指向数据的指针data_ptr和数据块长度的变量data_size。当一个线程需要把这个消息发送给另外一个线程时,可以采用如下的操作:

  1. struct msg* msg_ptr;

  2. msg_ptr = (struct msg*)rt_malloc(sizeof(struct msg));
  3. msg_ptr->data_ptr = ...; /* 指向相应的数据块地址*/
  4. msg_ptr->data_size = len; /* 数据块的长度*/
  5. /* 发送这个消息指针给mb邮箱*/
  6. rt_mb_send(mb, (rt_uint32_t)msg_ptr);
复制代码


而在接收线程中,因为收取过来的是指针,而msg_ptr是一个新分配出来的内存块,所以在接收线程处理完毕后,需要释放相应的内存块:

  1. struct msg* msg_ptr;
  2. if (rt_mb_recv(mb, (rt_uint32_t*)&msg_ptr) == RT_EOK)
  3. {
  4.     /* 在接收线程处理完毕后,需要释放相应的内存块*/
  5.     rt_free(msg_ptr);
  6. }
复制代码


接下来在机智云gokit智能硬件开发板上演示如何创建并使用邮箱进行线程间的通信。

注意:使用邮箱时要打开宏


  1. /**
  2.   ***********************************
  3.   * File Name          : main.c
  4.   * Description        : Main program body
  5.   ***********************************
  6.   ** This notice applies to any and all portions of this file
  7.   * that are not between comment pairs USER CODE BEGIN and
  8.   * USER CODE END. Other portions of this file, whether
  9.   * inserted by the user or by software development tools
  10.   * are owned by their respective copyright owners.
  11.   *
  12.   * COPYRIGHT(c) 2017 STMicroelectronics
  13.   *
  14.   * Redistribution and use in source and binary forms, with or without modification,
  15.   * are permitted provided that the following conditions are met:
  16.   *   1. Redistributions of source code must retain the above copyright notice,
  17.   *      this list of conditions and the following disclaimer.
  18.   *   2. Redistributions in binary form must reproduce the above copyright notice,
  19.   *      this list of conditions and the following disclaimer in the documentation
  20.   *      and/or other materials provided with the distribution.
  21.   *   3. Neither the name of STMicroelectronics nor the names of its contributors
  22.   *      may be used to endorse or promote products derived from this software
  23.   *      without specific prior written permission.
  24.   *
  25.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26.   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27.   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28.   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  29.   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30.   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  31.   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32.   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  33.   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34.   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35.   *
  36.   ***********************************
  37.   */
  38. /* Includes ------------------------------------------------------------------*/
  39. #include "main.h"
  40. #include "STM32f1xx_hal.h"
  41. #include "usart.h"
  42. #include "gpio.h"

  43. /* USER CODE BEGIN Includes */
  44. #include "rtthread.h"
  45. #include "string.h"
  46. /* USER CODE END Includes */

  47. /* Private variables ---------------------------------------------------------*/

  48. /* USER CODE BEGIN PV */
  49. /* Private variables ---------------------------------------------------------*/

  50. /* USER CODE END PV */

  51. /* Private function prototypes -----------------------------------------------*/
  52. void SystemClock_Config(void);

  53. /* USER CODE BEGIN PFP */
  54. /* Private function prototypes -----------------------------------------------*/

  55. /* USER CODE END PFP */

  56. /* USER CODE BEGIN 0 */
  57. //重映射串口1到rt_kprintf
  58. void rt_hw_console_output(const char *str)
  59. {
  60.     /* empty console output */
  61.         char aa='\r';
  62.           rt_enter_critical();

  63.                 while(*str!='\0')
  64.                 {
  65.                         if(*str=='\n')
  66.                         {
  67.                                 HAL_UART_Transmit(&huart1, (uint8_t *)&aa, 1, 10);
  68.                         }
  69.                                 HAL_UART_Transmit(&huart1, (uint8_t *)(str++), 1, 10);
  70.                 }
  71.                
  72.                 rt_exit_critical();
  73. }

  74. void rt_hw_us_delay(int us)
  75. {
  76.     rt_uint32_t delta;

  77.     /* 获得延时经过的tick数 */
  78.     us = us * (SysTick->LOAD/(1000000/RT_TICK_PER_SECOND));

  79.     /* 获得当前时间 */
  80.     delta = SysTick->VAL;

  81.     /* 循环获得当前时间,直到达到指定的时间后退出循环 */
  82.     while (delta - SysTick->VAL< us);
  83. }

  84. void rt_hw_ms_delay(int ms)
  85. {
  86.         int i=0,j=0;
  87.         for(j=0;j<ms;j++)
  88.         {
  89.                 for (i=0;i<2;i++)
  90.                 rt_hw_us_delay(500);
  91.         }
  92. }
  93. uint32_t rt_hw_delay_Init(void)
  94. {
  95. #if !defined(STM32F0xx)
  96.         uint32_t c;
  97.         
  98.     /* Enable TRC */
  99.     CoreDebug->DEMCR &= ~0x01000000;
  100.     CoreDebug->DEMCR |=  0x01000000;
  101.         
  102.     /* Enable counter */
  103.     DWT->CTRL &= ~0x00000001;
  104.     DWT->CTRL |=  0x00000001;
  105.         
  106.     /* Reset counter */
  107.     DWT->CYCCNT = 0;
  108.         
  109.         /* Check if DWT has started */
  110.         c = DWT->CYCCNT;
  111.         
  112.         /* 2 dummys */
  113.         __ASM volatile ("NOP");
  114.         __ASM volatile ("NOP");
  115.         
  116.         /* Return difference, if result is zero, DWT has not started */
  117.         return (DWT->CYCCNT - c);
  118. #else
  119.         /* Return OK */
  120.         return 1;
  121. #endif
  122. }
  123. void rt_hw_delay_us(__IO uint32_t micros)
  124. {
  125. #if !defined(STM32F0xx)
  126.         uint32_t start = DWT->CYCCNT;
  127.         
  128.         /* Go to number of cycles for system */
  129.         micros *= (HAL_RCC_GetHCLKFreq() / 1000000);
  130.         
  131.         /* Delay till end */
  132.         while ((DWT->CYCCNT - start) < micros);
  133. #else
  134.         /* Go to clock cycles */
  135.         micros *= (SystemCoreClock / 1000000) / 5;
  136.         
  137.         /* Wait till done */
  138.         while (micros--);
  139. #endif
  140. }
  141. void rt_hw_delay_ms(__IO uint32_t mills)
  142. {
  143.         rt_hw_delay_us(1000*mills);
  144. }

  145. /*
  146. * 程序清单:邮箱例程
  147. *
  148. * 这个程序会创建2个动态线程,一个静态的邮箱对象,其中一个线程往邮箱中发送邮件,
  149. * 一个线程从邮箱中收取邮件。
  150. */

  151. /* 指向线程控制块的指针 */
  152. static rt_thread_t tid1 = RT_NULL;
  153. static rt_thread_t tid2 = RT_NULL;

  154. /* 邮箱控制块 */
  155. static struct rt_mailbox mb;
  156. /* 用于放邮件的内存池 */
  157. static char mb_pool[128];

  158. static char mb_str1[] = "I'm a mail!";
  159. static char mb_str2[] = "this is another mail!";

  160. /* 线程1入口 */
  161. static void thread1_entry(void* parameter)
  162. {
  163.     unsigned char* str;

  164.     while (1)
  165.     {
  166.         rt_kprintf("thread1: try to recv a mail\n");

  167.         /* 从邮箱中收取邮件 */
  168.         if (rt_mb_recv(&mb, (rt_uint32_t*)&str, RT_WAITING_FOREVER)
  169.                 == RT_EOK)
  170.         {
  171.             /* 显示邮箱内容 */
  172.             rt_kprintf("thread1: get a mail, the content:%s\n", str);

  173.             /* 延时10个OS Tick */
  174.             rt_thread_delay(10);
  175.         }
  176.     }
  177. }

  178. /* 线程2入口 */
  179. static void thread2_entry(void* parameter)
  180. {
  181.     rt_uint8_t count;

  182.     count = 0;
  183.     while (1)
  184.     {
  185.         count ++;
  186.         if (count & 0x1)
  187.         {
  188.             /* 发送mb_str1地址到邮箱中 */
  189.             rt_mb_send(&mb, (rt_uint32_t)&mb_str1[0]);
  190.         }
  191.         else
  192.         {
  193.             /* 发送mb_str2地址到邮箱中 */
  194.             rt_mb_send(&mb, (rt_uint32_t)&mb_str2[0]);
  195.         }

  196.         /* 延时20个OS Tick */
  197.         rt_thread_delay(20);
  198.     }
  199. }


  200. /* USER CODE END 0 */

  201. int main(void)
  202. {

  203.   /* USER CODE BEGIN 1 */

  204.   /* USER CODE END 1 */

  205.   /* MCU Configuration----------------------------------------------------------*/

  206. //  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  207. //  HAL_Init();

  208. //  /* USER CODE BEGIN Init */

  209. //  /* USER CODE END Init */

  210. //  /* Configure the system clock */
  211. //  SystemClock_Config();

  212. //  /* USER CODE BEGIN SysInit */

  213. //  /* USER CODE END SysInit */

  214. //  /* Initialize all configured peripherals */
  215. //  MX_GPIO_Init();
  216. //  MX_USART1_UART_Init();

  217.   /* USER CODE BEGIN 2 */
  218.         
  219.     /* 初始化一个mailbox */
  220.     rt_mb_init(&mb,
  221.         "mbt",             /* 名称是mbt */
  222.         &mb_pool[0],       /* 邮箱用到的内存池是mb_pool */
  223.         sizeof(mb_pool)/4, /* 大小是mb_pool/4,因为每封邮件的大小是4字节 */
  224.         RT_IPC_FLAG_FIFO); /* 采用FIFO方式进行线程等待 */

  225.     /* 创建线程1 */
  226.     tid1 = rt_thread_create("t1",
  227.         thread1_entry,    /* 线程入口是thread1_entry */
  228.         RT_NULL,         /* 入口参数是RT_NULL */
  229.         512,
  230.                                 2,
  231.                                 20);
  232.     if (tid1 != RT_NULL)
  233.         rt_thread_startup(tid1);


  234.     /* 创建线程2 */
  235.     tid2 = rt_thread_create("t2",
  236.         thread2_entry,     /* 线程入口是thread2_entry */
  237.         RT_NULL,         /* 入口参数是RT_NULL */
  238.         512,
  239.                                 2,
  240.                           20);
  241.     if (tid2 != RT_NULL)
  242.         rt_thread_startup(tid2);
  243.         
  244.                 rt_hw_delay_Init();
  245.                         
  246.                 printf("\r\n机智云  只为智能硬件而生\r\n");
  247.                 printf("Gizwits Smart Cloud for Smart Products\r\n");
  248.                 printf("链接|增值|开放|中立|安全|自有|自由|生态\r\n");
  249.                 printf("www.gizwits.com\r\n");
  250.                 printf("\r\nGokit RT-Thread Demo\r\n\r\n");
  251.                
  252.                 return 0;
  253.         
  254.   /* USER CODE END 2 */

  255.   /* Infinite loop */
  256.   /* USER CODE BEGIN WHILE */
  257. //  while (1)
  258. //  {
  259.   /* USER CODE END WHILE */

  260.   /* USER CODE BEGIN 3 */
  261. //               
  262. //  }
  263.   /* USER CODE END 3 */

  264. }

  265. /** System Clock Configuration
  266. */
  267. void SystemClock_Config(void)
  268. {

  269.   RCC_OscInitTypeDef RCC_OscInitStruct;
  270.   RCC_ClkInitTypeDef RCC_ClkInitStruct;

  271.     /**Initializes the CPU, AHB and APB busses clocks
  272.     */
  273.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  274.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  275.   RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  276.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  277.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  278.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  279.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  280.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  281.   {
  282.     _Error_Handler(__FILE__, __LINE__);
  283.   }

  284.     /**Initializes the CPU, AHB and APB busses clocks
  285.     */
  286.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  287.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  288.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  289.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  290.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  291.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  292.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  293.   {
  294.     _Error_Handler(__FILE__, __LINE__);
  295.   }

  296.     /**Configure the Systick interrupt time
  297.     */
  298.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  299.     /**Configure the Systick
  300.     */
  301.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  302.   /* SysTick_IRQn interrupt configuration */
  303.   HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  304. }

  305. /* USER CODE BEGIN 4 */

  306. /* USER CODE END 4 */

  307. /**
  308.   * @brief  This function is executed in case of error occurrence.
  309.   * @param  None
  310.   * @retval None
  311.   */
  312. void _Error_Handler(char * file, int line)
  313. {
  314.   /* USER CODE BEGIN Error_Handler_Debug */
  315.   /* User can add his own implementation to report the HAL error return state */
  316.   while(1)
  317.   {
  318.   }
  319.   /* USER CODE END Error_Handler_Debug */
  320. }

  321. #ifdef USE_FULL_ASSERT

  322. /**
  323.    * @brief Reports the name of the source file and the source line number
  324.    * where the assert_param error has occurred.
  325.    * @param file: pointer to the source file name
  326.    * @param line: assert_param error line source number
  327.    * @retval None
  328.    */
  329. void assert_failed(uint8_t* file, uint32_t line)
  330. {
  331.   /* USER CODE BEGIN 6 */
  332.   /* User can add his own implementation to report the file name and line number,
  333.     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  334.   /* USER CODE END 6 */

  335. }

  336. #endif

  337. /**
  338.   * @}
  339.   */

  340. /**
  341.   * @}
  342. */

  343. /*********** (C) COPYRIGHT STMicroelectronics ***END OF FILE**/
复制代码

串口信息:



源码下载:
Gokit_RT-Thread.zip (8.66 MB, 下载次数: 2, 售价: 1 金钱)



1、机智云QQ群:G1群:104975951 G2群:491509598 G3群:287087942
机智云爱好者-APP开发群: 599735135
QQ群目前非常活跃,欢迎大家参与进来,交流,讨论,答疑,解惑~~
2、机智云微信公众号: 机智云 gizwits、 机智云智能宠物屋go-iot
关注机智云Gizwits官方公众号随时掌握最新资讯和活动信息
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

加入Q群 返回顶部

版权与免责声明 © 2006-2024 Gizwits IoT Technology Co., Ltd. ( 粤ICP备11090211号 )

快速回复 返回顶部 返回列表