久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

標(biāo)題: STM32 CubeIDE 使用RT-Thread Nano [打印本頁(yè)]

作者: qingyemurong    時(shí)間: 2020-9-24 21:44
標(biāo)題: STM32 CubeIDE 使用RT-Thread Nano
本帖最后由 qingyemurong 于 2020-9-24 22:13 編輯

STM32 CubeIDE 使用RT-Thread Nano

使用的 STM32 CubeIDE 版本 1.4
  在STM32 CubeIDE中已經(jīng)集成了RT-Thread Nano,可以直接在 IDE 中進(jìn)行下載添加。工程文件附件自己下載。

打開 STM32 CubeIDE   --------->**Software Packs**     ------------>**Manager Software Packs**界面(

  獲取 RT-Thread Nano 軟件包,需要在 STM32CubeIDE 中添加 [https://www.rt-thread.org/download/cube/RealThread.RT-Thread.pdsc](https://www.rt-thread.org/download/cube/RealThread.RT-Thread.pdsc)


回到 Manage software packages 界面,就會(huì)發(fā)現(xiàn) RT-Thread Nano 3.1.3 軟件包,選擇該軟件包,點(diǎn)擊 Install Now,如下圖所示(顏色填充表示已安裝)(


(
## 2.1 、創(chuàng)建一個(gè)基本工程
創(chuàng)建一個(gè)基本的工程文件,包含2個(gè)LED燈和USART1。





(

#


勾選 RT-Thread
(?x-oss
中斷與異常處理
RT-Thread 操作系統(tǒng)重定義 **HardFault_Handler**、**PendSV_Handler**、**SysTick_Handler** 中斷函數(shù),為了避免重復(fù)定義的問(wèn)題,在生成工程之前,需要在中斷配置中,代碼生成的選項(xiàng)中,取消選擇三個(gè)中斷函數(shù)(對(duì)應(yīng)注釋選項(xiàng)是 Hard fault interrupt, Pendable request, Time base :System tick timer),最后點(diǎn)擊生成代碼,具體操作如下圖中

(

# 3、工程代碼修改
1 、修改啟動(dòng)文件  startup_stm32f103rctx.s
**bl main**  修改為  **bl  entry**     
(

端口映射,函數(shù)可以放在main.c文件里面。
(


(

  1. /* USER CODE BEGIN 4 */
  2. char rt_hw_console_getchar(void)
  3. {
  4.         int ch = -1;
  5.         if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_RXNE) != RESET)
  6.         {
  7.                 ch = huart1.Instance->DR & 0xff;
  8.         }
  9.         else
  10.         {
  11.                 if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_ORE) != RESET)
  12.                 {
  13.                         __HAL_UART_CLEAR_OREFLAG(&huart1);
  14.                 }
  15.                 rt_thread_mdelay(10);
  16.         }
  17.         return ch;
  18. }
  19. void rt_hw_console_output(const char *str)
  20. {
  21.         rt_size_t i = 0, size = 0;
  22.         char a = '\r';
  23.         __HAL_UNLOCK(&huart1);
  24.         size = rt_strlen(str);
  25.         for (i = 0; i < size; i++)
  26.         {
  27.                 if (*(str + i) == '\n')
  28.                 {
  29.                         ITM_SendChar(a);
  30.                         HAL_UART_Transmit(&huart1, (uint8_t*) &a, 1, 1);
  31.                 }
  32.                 HAL_UART_Transmit(&huart1, (uint8_t*) (str + i), 1, 1);
  33.         }
  34. }

  35. /* USER CODE END 4 */
復(fù)制代碼


## 3.3 、編寫線程文件
創(chuàng)建一個(gè)**app_rt_thread.c**文件用于保存線程代碼
(


app_rt_thread.c文件內(nèi)容:

  1. #include "rtthread.h"
  2. #include "main.h"
  3. #include "stdio.h"
  4. #include <finsh.h>        


  5. /* 定義線程控制塊 */
  6. //添加LED閃爍線程
  7. static struct rt_thread led_thread;
  8. static char led_thread_stack[256];
  9. static void led_thread_entry(void *parameter);
  10. int MX_RT_Thread_Init(void);

  11. int MX_RT_Thread_Init(void)
  12. {
  13.         //初始化線程
  14.         rt_err_t rst;
  15.         rst = rt_thread_init(&led_thread,
  16.                                                 (const char *)"ledshine",  /* 線程名字 */
  17.                                                 led_thread_entry,  /* 線程入口函數(shù) */
  18.                                                 RT_NULL,           /* 線程入口函數(shù)參數(shù) */
  19.                                                 &led_thread_stack[0],
  20.                                                 sizeof(led_thread_stack),   /* 線程棧大小 */
  21.                                                 RT_THREAD_PRIORITY_MAX-2,  /* 線程的優(yōu)先級(jí) */
  22.                                                 20); /* 線程時(shí)間片 */
  23.         if(rst == RT_EOK)
  24.         {///* 啟動(dòng)線程,開啟調(diào)度 */
  25.                 rt_thread_startup(&led_thread);
  26.         }

  27. }


  28. /*
  29. *************************************************************************
  30. * 線程定義
  31. *************************************************************************
  32. */
  33. static void led_thread_entry(void *parameter)
  34. {
  35.         while(1)
  36.         {
  37.                 rt_kprintf("led1_thread running,LED1_ON\r\n");
  38.                 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
  39.                 rt_thread_mdelay(500);
  40.                 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
  41.                 rt_thread_mdelay(500);
  42.         }
  43. }

  44. MSH_CMD_EXPORT(led_thread_entry,thread running);
復(fù)制代碼



  1. /* USER CODE BEGIN Includes */
  2. #include "rtthread.h"

  3. extern int MX_RT_Thread_Init(void);
復(fù)制代碼





(

  1. int main(void)
  2. {
  3.   /* USER CODE BEGIN 1 */

  4.   /* USER CODE END 1 */

  5.   /* MCU Configuration--------------------------------------------------------*/

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

  8.   /* USER CODE BEGIN Init */

  9.   /* USER CODE END Init */

  10.   /* Configure the system clock */
  11.   SystemClock_Config();

  12.   /* USER CODE BEGIN SysInit */

  13.   /* USER CODE END SysInit */

  14.   /* Initialize all configured peripherals */
  15.   MX_GPIO_Init();
  16.   MX_USART1_UART_Init();
  17.   /* USER CODE BEGIN 2 */
  18.   MX_RT_Thread_Init();
  19.   /* USER CODE END 2 */

  20.   /* Infinite loop */
  21.   /* USER CODE BEGIN WHILE */
  22.   while (1)
  23.   {
  24.           HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_2);
  25.           rt_kprintf("led1_thread TEST\r\n");
  26.           rt_thread_mdelay(100);
  27.     /* USER CODE END WHILE */

  28.     /* USER CODE BEGIN 3 */
  29.   }
  30.   /* USER CODE END 3 */
  31. }
復(fù)制代碼


串口輸出:
(






RT_Thread.7z

1.61 MB, 下載次數(shù): 15, 下載積分: 黑幣 -5

工程文件


作者: 1255364767    時(shí)間: 2021-6-21 16:56
好用嗎?有沒有bug啊
作者: nuomistudio    時(shí)間: 2021-8-2 08:29
學(xué)習(xí)一下,后續(xù)開始搞rt




歡迎光臨 (http://www.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 天天天天操 | 欧美福利久久 | 日韩成人在线免费视频 | 国产在线成人 | 国产精品久久久久久久久久久久 | 欧美精品在线一区 | 亚洲精品久久久久久久久久久 | 久久免费大片 | 国产高清视频在线观看 | 亚洲精品日韩一区二区电影 | 三级视频网站 | 五月天婷婷丁香 | 中文字幕精品视频在线观看 | 日韩欧美中文字幕在线视频 | 三级免费 | 亚洲一区二区三区在线免费观看 | 欧美成人视屏 | 欧美色综合一区二区三区 | 精品国产91乱码一区二区三区 | 性做久久久久久免费观看欧美 | 久久国产麻豆 | av片在线播放 | 中文字幕高清免费日韩视频在线 | 国产精品1区2区3区 中文字幕一区二区三区四区 | 成人h片在线观看 | 国产日韩欧美电影 | 日韩在线中文字幕 | 91亚洲精品在线观看 | 欧美成人精品激情在线观看 | 蜜桃视频在线观看www社区 | 久久久精品亚洲 | 亚洲综合激情 | 日韩在线一区二区三区 | 91精品国产美女在线观看 | 国产ts人妖另类 | 国产精品精品视频一区二区三区 | 在线观看免费国产 | 国产成人精品久久二区二区91 | 一区二区三区高清不卡 | 中文字幕一区二区三区不卡 | 成人精品国产一区二区4080 |