Getting Started STM32 with RT-Thread RTOS – RT-Thread Tutorial Part 1

This article is a continuation of the  Series on RT-Thread STM32 Tutorials and carries the discussion on RT-Thread RTOS and implementation with STM32. The aim of this series is to provide easy and practical examples that anyone can understand. In this Getting Started STM32 with RT-Thread RTOS post, we will see how to install the IDE and create the first program.

You can find a video explanation of this tutorial here.

Getting Started STM32 with RT-Thread RTOS

In our last post, we have seen RT-Thread RTOS Introduction. In this post, we will start coding directly.

Tools and Components Required

  • STM32F411 Dev Board (You can use any STM32F4 controller)
  • RT-Thread Studio

RT-Thread Studio

We need to use the IDE to write code. RT-Thread supports many IDEs including IAR, Keil, etc. But they have launched its Innovative and Powerful Embedded Integrated Development Environment called RT-Thread Studio. RT-Thread Studio is built on Eclipse but has innovative interface interaction designs and it is deep customization of Eclipse, easy and simple to use, even new developers can easily get started.
RT-Thread Studio has the features of project creation and management, code editing, SDK management, RT-Thread configuration, build configuration, debugging configuration, program download, and debugging. Also, it combined the graphical configuration system with packages and component resources, reducing the duplication of work and improving development efficiency.

RT-Thread Studio Features

RT-Thread studio is a one-stop development tool, it has an easy-to-use graphical configuration system and a wealth of software packages and components resources, which makes IoT development simple and efficient.

  • The community version is free forever.
  •  Supports mainstream C/C++ language development.
  •  Powerful code editing and refactoring functionality.
  •  SDK Manager supports online downloads and updates the latest source package of RT-Thread.
  •  Easy-to-use project creation wizard can quickly validate prototypes.
  •  Brand new graphical configuration system, which supports both schema diagram and tree diagram configuration.
  •  The software package market offers a variety of package resources.
  •  Rich debugging facilities to quickly view and track code issues.

Okay, Let’s stop the theory here. We will start creating the project.

RT-Thread Studio Installation

Please download the RT-Thread Studio from their official website.

  • Install the RT-Thread Studio. Click Next.
RT-Thread Studio 1
  • Accept the Agreement and click Next.
RT-Thread Studio 2
  • Install the RT-Thread Studio in the proper location.
RT-Thread Studio 3
  • Click Next and Install.
  • Wait until it installs the RT-Thread Studio. Then launch RT-Thread Studio.
RT-Thread Studio 6

That’s it. It will open the RT-Thread Studio.

Project Creation

Follow the below video to create a project.

Build Error

If you use the latest RT-Thread Studio version 4.0.3 and the latest CSL (Chip Support Library) version 0.2.3, then you will get the below build error.

../drivers/drv_usart.c:338:16: error: ‘struct serial_configure’ has no member named ‘flowcontrol’
../drivers/drv_usart.c:340:10: error: ‘RT_SERIAL_FLOWCONTROL_NONE’ undeclared
../drivers/drv_usart.c:343:10: error: ‘RT_SERIAL_FLOWCONTROL_CTSRTS’ undeclared

We can solve this error by three methods.

  1. Downgrade the RT-Thread OS version to 4.0.2, and use the latest CSL (0.2.3)
  2. Downgrade the CSL version to 0.0.2, and use the latest RT-Thread OS version (4.0.3)
  3. Use the RT-Thread OS version over 4.1.0, then you won’t see the error.

We have explained the second method in the video. Please check that, if you don’t know how to do that. But we suggest you to use the third method. You can install that through the SDK manager.

You can also change the Chip Support Library by below easy method.

  1. Right-click the Project name in the Project Explorer
  2. Click Modify Project
  3. Click Chip support package version
  4. Then select your desired CSL version.

By this method, you can change the OS version also.

Source Code

We are not going to modify the source code. We will just use the default program now. The application main.c will be present under the HelloWorld/applications/main.c directory. You can also get the complete source code from GitHub.

/*
 * Copyright (c) 2006-2023, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2023-02-10     RT-Thread    first version
 */

#include <rtthread.h>

#define DBG_TAG "main"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>

int main(void)
{
    int count = 1;

    while (count++)
    {
        LOG_D("Hello RT-Thread!");
        rt_thread_mdelay(1000);
    }

    return RT_EOK;
}

Build the source code. It should build without any errors.

Connections

In this project, we are using the STM32F411 and its UART1 (PA9 and PA10) for Debug prints.

Connection diagram

Flashing and Demo

Flash the Code using RT-Thread Studio. Please refer to the below image.

RT-Thread Studio Flash
Flashing

Once you flash the code, then open any serial terminal application. Here, I am going to use the RT-Thread Studio’s inbuilt terminal. Set the baud rate (115200). You should see the print “Hello RT-Thread!“. Refer to the below images.

Video Explanation

What’s Next

In our next post, we will discuss about the RT-Thread RTOS thread management and STM32 GPIOs.

You can also read the below tutorials.

Linux Device Driver TutorialsC Programming Tutorials
FreeRTOS TutorialsNuttX RTOS Tutorials
RTX RTOS TutorialsInterrupts Basics
I2C Protocol – Part 1 (Basics)I2C Protocol – Part 2 (Advanced Topics)
STM32 TutorialsLPC2148 (ARM7) Tutorials
PIC16F877A Tutorials8051 Tutorials
Unit Testing in C TutorialsESP32-IDF Tutorials
Raspberry Pi TutorialsEmbedded Interview Topics
Reset Sequence in ARM Cortex-M4BLE Basics
VIC and NVIC in ARMSPI – Serial Peripheral Interface Protocol
STM32F7 Bootloader TutorialsRaspberry PI Pico Tutorials
STM32F103 Bootloader TutorialsRT-Thread RTOS Tutorials
Zephyr RTOS Tutorials – STM32Zephyr RTOS Tutorials – ESP32
AUTOSAR TutorialsUDS Protocol Tutorials
Product ReviewsSTM32 MikroC Bootloader Tutorial
VHDL Tutorials
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Table of Contents