Comprehensive experiment -- multitask embedded programming based on RTT Nano

chongqing jiaotong university

Final assignment

Course Name: Fundamentals of embedded system A
College: School of information science and Engineering
Class: Internet of things 1901
Name: Xu Jun
Student No.: 631907090127
Experiment type: comprehensive, design
Instructor: Lou Lu
Starting time: the first semester of 2021-2022 academic year

Introduction of domestic RT thread operating system

characteristic

1) Cross chip platform RT thread supports all mainstream microcontrollers to solve the problem of device fragmentation.
2) The real-time operating system kernel RT thread is completely self-developed, hard real-time, exquisite, efficient and highly customizable.
3) Cloud integrated device end and cloud integrated design, easy access to various mainstream IOT device cloud platforms.
4) Ultra low power design minimizes system power consumption, and adopts automatic power consumption control strategy for different application scenarios.
5) Fast start, power on is start, millisecond start-up time, really zero waiting for start-up.
6) Security design hierarchical system security architecture, providing various security mechanisms to ensure application and system security.
7) Intelligent AI engine integrates various algorithms and intelligent engines related to audio and image.
8) The open platform is an independent third-party open platform, supporting various third-party software packages and SDK s, and expanding system functions.

advantage

1) Rich components RT thread has rich native components, which can be customized for the system and easily expand the system functions. It includes a series of extension components such as device virtual file system, device manager framework, low-power management framework, protocol stack, graphics library, audio streaming media framework, firmware remote upgrade FOTA and other third-party components.

2) Easy to use developers say that RT thread is one of the most concise and elegant open source operating systems. RT thread has clear architecture, C language style kernel, object-oriented design and perfect modular design. It also has Unix code style, which makes the API concise and complete and the code comments clear. At the same time, debugging is convenient. Through the built-in Shell debugging tool, it is convenient to monitor the kernel information in real time.

3) It is highly scalable, easy to cut and expand. It is suitable for products of different grades, greatly increasing the reusability of software and improving the efficiency of development.

Functional framework

One of the main differences between RT thread and many other RTOS such as FreeRTOS and uC/OS is that it is not only a real-time kernel, but also has rich middle tier components, as shown in the figure below

Comparative analysis of bare metal and RTOS

In fact, these two have their own advantages and disadvantages. If you don't have many businesses and on-chip resources are limited, bare metal is bound to be better than RTOS. This is called killing chickens with a bull knife. But once there are many and complex tasks, the code is difficult to write and manage, and the dependencies between tasks are complex. At this time, when you write with bare metal, you will generally write a set of modular task and resource scheduling system yourself, which is actually equivalent to an os. Otherwise, it is very troublesome to use, and generally those who deal with so many complex tasks will not use a single chip microcomputer with few resources.

preparation

CubeMx installing Nano Pack

Download address

link

Installation steps

HELP-Manage embedded software packages)

From Url - new - fill in link - check,

Click OK and wait.

keil install RT thread

CubeMx create file

Select STM32F103c8T6 and add the Nano group component


RCC configuration

SYS configuration

USART1 configuration

PA3 and PA4 are set to OUT_PUT
Clock tree configuration

Project configuration

code

Add RT - Thread Nano to project

Code modification

Create a new file and add code

#include "rtthread.h"
#include "main.h"
#include "stdio.h"
 
struct rt_thread led1_thread;
rt_uint8_t rt_led1_thread_stack[128];
void led1_task_entry(void *parameter);
 
//Initialize thread function
void MX_RT_Thread_Init(void)
{
	//Initialize LED1 thread
	rt_thread_init(&led1_thread,"led1",led1_task_entry,RT_NULL,&rt_led1_thread_stack[0],sizeof(rt_led1_thread_stack),3,20);
	//Turn on thread scheduling
	rt_thread_startup(&led1_thread);
}
 
//Main task
void MX_RT_Thread_Process(void)
{
	printf("Hello RT_Thread!!!");
	rt_thread_delay(2000);
}
 
//LED1 task
void led1_task_entry(void *parameter)
{
	while(1)
	{
		HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3, GPIO_PIN_RESET);
		rt_thread_delay(500);
		HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3, GPIO_PIN_SET);
		rt_thread_delay(500);
	}
}


Modify serial port 2 to 1


Comment out

main. Add in C

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
extern void MX_RT_Thread_Init(void);
extern void MX_RT_Thread_Process(void);
 
/* USER CODE END PTD */

Add in the main function

MX_RT_Thread_Init();

Add light in while

HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_4);
		rt_thread_delay(1000);

Serial port output modification

summary

This experiment uses RTT nano to complete a lighting program and serial port output. His advantage is that it is convenient and compact, and has higher efficiency than bare metal in the face of a large number of multi tasks.

Keywords: Python

Added by Apenvolkje on Thu, 20 Jan 2022 05:55:03 +0200