Take a natural course in artificial intelligence, from theory to action, and then click here to enter the portal

At the end of the article there are experience and RTOS comparison, friends in a hurry can be directly dragged to the end of the article oh ~

1. Tencentos-tiny is open source

Tencentos-tiny, the operating system for Internet of Things, has been launched by Tencent.

TencentOS Tiny is a real-time operating system developed by Tencent for the Internet of Things, featuring low power consumption, low resource occupancy, modularity, security and reliability, which can effectively improve the development efficiency of Internet of Things terminal products. TencentOS Tiny provides a compact RTOS kernel that can be tailored and configured to be quickly ported to a variety of mainstream MCUS (such as the full STM32 family) and module chips. And, based on RTOS kernel provides a rich IoT components, internal integration mainstream Internet protocol stack (such as CoAP/MQTT/TLS/DTLS/LoRaWAN/NB – IoT, etc.), can help the Internet of things terminal equipment and business fast access tencent IoT cloud platform.

As a coder, what am I doing with all this balabala text??

Talk is cheap, Show me the code.

Put on Github, speak in code, and go!

2. File directory architecture overview

Tencentos-tiny’s entire file directory is shown, well, in a style I’m familiar with:

This file directory organization structure, mediocre, give a fair evaluation of it.

But there are a few notable features:

Board folder

This folder is a collection of development boards for Tencentos-Tiny adaptation, which is very good. Developers can submit PR and merge it after transplantation to avoid repeated transplantation work by subsequent developers. It can be used in hand, and the current situation is still considerable, as shown in the figure:

Device folder

In this folder, you can see that Tencentos-Tiny supports a wide range of communication modules, including common NB-iot modules, WIFI modules, 2G/4G modules and LORA modules:

Cloud components on TencentCloud_SDK

In the components/ Connectivity folder, you can see the cloud components on TencentCloud_SDK. There is no doubt that Tencent’s own OS is the best support for its own cloud platform:

3. Seeing is nothing, doing is nothing

The main control is STM32L431RCT6, just tencentos-tiny /board has been imported.

Enter the board/TencentOS_tiny_EVB_MX:

OS Configuration file

The configuration file tos_config.h for the Tencnetos-Tiny system is available upon entry. Again, the OS uses macro definition switches to configure required modules such as semaphores, event sets, queues, etc in the kernel:

Some important parameters in the system are also configured in the macro definition:

BSP board level support package

For hardware on the development board, tencentos-Tiny does not provide a device driver framework, so use the STM32CubeMX + HAL library directly to manipulate the hardware on the board:

Keil project — HelloWorld

I’m using Keil MDK 5.28 here, so going into the Keil folder, going to tencentos-Tiny provides many sample projects for this development board, which I didn’t expect, give it a like:

Tencentos-tiny (tencentos-tiny) tencentos-Tiny (Tencentos-Tiny) tencentos-Tiny (Tencentos-Tiny) tencentos-Tiny (Tencentos-Tiny) tencentos-Tiny (Tencentos-Tiny) tencentos-Tiny Enter the hello_world folder to open the project.

4. A preliminary TencentOS – tiny

After opening the project in the previous step, let’s explore this new system

Engineering structure

The overall engineering architecture is clear in MDK, as shown in figure:

Tencentos-tiny kernel startup process

To its credit, the kernel starts up very cleanly with a main function:

Board level initialization

Let’s start with the first step of the startup process: board-level initialization.

This function is in the McU_init. c file, because THE board I use is the Little Bear development board, there is no DHT11 and OLED, I just want to print HelloWorld through serial port, so I shield all the code needed:

Printf redirects to the serial port

In the main function, the OS starts with the following code:

printf("Welcome to TencentOS tiny\r\n");
Copy the code

So how does tencentos-tiny redirect printf?

The answer is again in McU_init.c:

If you want to know why you can redirect printf to a serial port by implementing these three functions, you can refer to my blog post: [STm32Cub-09] various ways to redirect printf to serial port output.

As can be seen from the code, the printf function is redirected to serial port 2. Since this is the support package of other development boards, the implementation code cannot be changed, so we can only find another USB to serial port, and connect the UART2 of Bear PI to the computer, as shown in the picture:

The HelloWorld example

After exploring how the OS is started, explore how the HelloWorld thread is created. Open the hello_world.c file and you can see that the code for creating the thread is very simple:

Let’s start by defining thread-specific macros:

Then there is the thread body function:

Finally, there is the function to create the thread:

So how does the function that creates the thread perform?

Don’t worry, the answer is in main.c:

So, when the function application_entry is defined in hello_world.c, the weakly defined function in main.c is invalidated and the system executes the user-defined function.

Compile the code

The code is then compiled with the following information:

Take a look in the map file:

Oh my god, this code is so simple!!

Download operation

Download the code to the development board, you can see the normal operation of the system in the serial assistant and print the result:

Tencentos-tiny is a new operating system, tencentos-tiny is a new operating system, tencentos-Tiny is a new operating system, tencentos-Tiny is a new operating system

5. Experience

Overall, TENcentos-Tiny gives me a good feeling:

  • Compared with the Internet of Things operating system of cloud manufacturers (such as Juchang LiteOS), TOS obviously has great advantages. It ADAPTS some mainstream development boards in board, which greatly facilitates developers. In addition, there is no big difference between the code style and bare computer development, and the amount of code is very small.
  • Compared to RT-Thread: This is not comparable to cars and trucks, not in the same class.

For those who have not studied RTOS in depth, WE suggest learning RT-Thread. The ecology is very perfect. If you have learned RTOS, tencentos-Tiny is worth a try. Later to develop micro channel small program is also very convenient, are their own things.

For more exciting articles and resources, please pay attention to my wechat official number: “McUlover666”.