其他分享
首页 > 其他分享> > RT-thread Nano移植

RT-thread Nano移植

作者:互联网

目录

一.获取 RT-Thread NANO软件包

二、打开STM32CubeMx1.添加NANO软件包2.安装3.创建工程

三.keil代码实现1.在Application/User文件夹,新建app_rt_thread.c文件,并添加如下代码2.在usart.c文件添加如下代码:3,在main.c文件添加如下代码:

四.结果五.参考


一.获取 RT-Thread NANO软件包

csdn - 安全中心

二、打开STM32CubeMx

1.添加NANO软件包

å¨è¿éæå¥å¾çæè¿°

 å¨è¿éæå¥å¾çæè¿°

 

å¨è¿éæå¥å¾çæè¿°

 

2.安装

å¨è¿éæå¥å¾çæè¿°

3.创建工程

å¨è¿éæå¥å¾çæè¿°

 

å¨è¿éæå¥å¾çæè¿°

 å¨è¿éæå¥å¾çæè¿°

 

å¨è¿éæå¥å¾çæè¿°

 

å¨è¿éæå¥å¾çæè¿°

 å¨è¿éæå¥å¾çæè¿°

å¨è¿éæå¥å¾çæè¿° 

å¨è¿éæå¥å¾çæè¿° 

 

三.keil代码实现

1.在Application/User文件夹,新建app_rt_thread.c文件,并添加如下代码

#include "rtthread.h"
#include "main.h"
#include "stdio.h"
 
struct rt_thread led_thread;
rt_uint8_t rt_led_thread_stack[128];
void led_task_entry(void *parameter);
 
//初始化线程函数
void MX_RT_Thread_Init(void)
{
	//初始化LED线程
	rt_thread_init(&led_thread,"led",led_task_entry,RT_NULL,&rt_led_thread_stack[0],sizeof(rt_led_thread_stack),3,20);
	//开启线程调度
	rt_thread_startup(&led_thread);
}
 
//主任务
void MX_RT_Thread_Process(void)
{
	printf("Hello RT_Thread!!!");
	rt_thread_delay(2000);
}
 
//LED任务
void led_task_entry(void *parameter)
{
	while(1)
	{
		HAL_GPIO_WritePin(LED_GPIO_Port,LED_Pin, GPIO_PIN_RESET);
		rt_thread_delay(500);
		HAL_GPIO_WritePin(LED_GPIO_Port,LED_Pin, GPIO_PIN_SET);
		rt_thread_delay(500);
	}
}

2.在usart.c文件添加如下代码:

/* USER CODE BEGIN 0 */
#include "stdio.h"
 
/* USER CODE END 0 */
.
.
.
/* USER CODE BEGIN 1 */
#ifdef __GNUC__
  /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
     set to 'Yes') calls __io_putchar() */
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/**
  * @brief  Retargets the C library printf function to the USART.
  * @param  None
  * @retval None
  */
PUTCHAR_PROTOTYPE
{
  /* Place your implementation of fputc here */
  /* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */
  HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
 
  return ch;
}
 
/* USER CODE END 1 */

 3,在main.c文件添加如下代码:

/* USER CODE END Header */
 
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "usart.h"
#include "gpio.h"
 
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
 
/* USER CODE END Includes */
 
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
extern void MX_RT_Thread_Init(void);
extern void MX_RT_Thread_Process(void);
 
/* USER CODE END PTD */
.
.
.
 
 
int main(void)
{
  /* USER CODE BEGIN 1 */
 
  /* USER CODE END 1 */
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART1_UART_Init();
  /* USER CODE BEGIN 2 */
  MX_RT_Thread_Init();
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
	MX_RT_Thread_Process();
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

四.结果

å¨è¿éæå¥å¾çæè¿°

 å¨è¿éæå¥å¾çæè¿°

 

标签:RT,rt,CODE,Nano,thread,void,USER
来源: https://blog.csdn.net/IT23131/article/details/122297355