Skip to content

mengrez/RT-Thread_HelloWorld

Repository files navigation

Helloworld RT-Thread OS 5 and a CH32 board

This is a simple helloworld program with leds, using RT-Thread OS 5 and a CH32V208WBU6 board

There are two ways of running the project: 1) From scratch 2) download it and upload the code to the board.

Note A: The present tutorial is based on a Windows OS.

1. From scratch

If you want to know how the project were constructed, follow the following steps Otherwise, you should skip this section and go directly to point 2.

Firstly, you must install the following tools:

VSCode: Visual Studio Code - Code Editing. Redefined

GitHub desktop: GitHub Desktop | Simple collaboration from your desktop (If you are good at Git please ignore this tool, and go straight to git commands)

1.1. Github repository

Once you install the tools, you need to download RT-Thread OS 5 from Github repository: RT-Thread/rt-thread: RT-Thread is an open source IoT real-time operating system (RTOS). (github.com)

Note B: RT-Thread OS is an open source RTOS for IoT application primary. For further details, you can check the following link: RT-Thread | An Open Source Embedded Real-time Operating System

1.1.1 How to download it

  1. Open Github desktop program on your PC and the Github repo link.
  2. In the Github repo, look for the following section

  1. Click Code button and select the "local tab"

  1. Click "copy clipboard" button to copy the URL that appears or click on "Open with Github Desktop" and authorize your browser invoke Github desktop.

Note C: I don't recommend to simply download the repo in a zip file. This is because, I encountered to many errors while unpacking the files from Zip.

  1. If you have the URL, open Github Desktop and click on File-> "Clone repository"

  1. Click on "URL tab" and paste the URL and select where repo will be downloaded.

  1. Finally, click on clone and let app download the repo.

1.2. Environment and compiling tools

Due to this project uses other tools different from RT-Thread Studio IDE. You need tools to compile the code using the proper env vars and spaces.

  1. Download SDK for CH32 RISCV cores: https://github.com/NanjingQinheng/sdk-toolchain-RISC-V-GCC-WCH/archive/refs/tags/V1.0.0.zip, Extract the zip file.
  2. Download Env tools from: Releases · RT-Thread/env-windows (github.com) For windows, download env-windows-1.4.0.7z
  3. Extract env-windows-1.4.0.7z where you would like. Review that the path does not contain non-ascii or space characters.
  4. Look into the path and open env.exe, if a font error appears, ignore it or change the font.

  1. Once it opens, click on "menu button" -> Settings"

  1. Select Integration in the side menu and click on "Register". After this, click on "Save Settings"

  1. Close env.exe window.

1.3 The creation of project

  1. Open the folder where you downloaded RT-Thread OS repo, and look into the following path: ...\bsp\wch\risc-v\ch32v208w-r0. Once you arrive there, click on your right mouse button and select "ComEmu here"

Note D: BSPrefers toa package that contains all the necessary files to run RT-Thread OS on a specific board.

  1. Once a console is opened, type the following command: scons --dist --target=vsc --project-path="path/your project name " --project-name="your project name".
  2. Go to project path, and open a ComEmu there. After that, click on vscode workspace.

  1. On VSCode, go to applications and open main.c. Once it opens, substitute the code with following:

  1. Save changes

2. Upload code.

Note E: if you download the project, please follow the following instruction to upload the code to the board.

Once you have the environment and compiling tools (see 1.2), you can proceed to compile the project from "ComEmu console".

  1. Open the directory of the project.
  2. Open rtconfig.py and change the EXECT_PATH with r'X:\your sdk path\bin'. Save the changes and remember to use the format with double backslashes between folders

  1. Open ComEmu console, and type the following: scons --exec-path=X:\your sdk path\bin. Remember to write down double backslash between folders.

It will take a time to compile it, the first time. After this, every time you compile, it will take fewer. In the following image, you can observe that none errors occurred. At this point, in project directory, you have a "rtthread.bin" file that will be used by you to upload the code to the board.

  1. Download ans install the WCH ISP studio tool: WCHISPTool_Setup.exe - NanjingQinhengMicroelectronics

  1. Once installed, open it. Connect the board, using a USB Serial TTL converter (FT232RL Board). This is because, the CH32V208 board does not include in-board programmer/debugger. Another option is to acquire a WCH-Link WCH-Link/Debugger . In this case, this utilizes CH32V208 capability to upload code using a ISP tool via serial port.

The FTDI board utilizes the following driver: FTDI-DriverWindows. To install it, you could follow the following tutorial: Installation Guide

Note E: Although the board includes two built-in Leds, they are not connected to any pin of the board. Therefore, you have to wire them to the correct pin, according to code.

  1. Open WCHISP Studio and select RISC-V MCU.

  1. Select the correct chip.

  1. Set Dnld port as Serial Port and check that DI_baud is at 115200.

  1. This step only occurs once Hold "Download" board button while connecting FTDI to USB port. Then press "search" button and click on "deprotect" at the end of the screen.

Once it finishes the console reports:

  1. Disconnect the device from USB.

  2. Every time you want to program the devices you have to do this Hold "Download" board button while connecting FTDI to USB port, then press "search" button. Change the size of the WCHISP screen to force download File to appear.

  1. Select "..." to search the bin file, you have created.

  2. Maximize the window's size to click on the "Download" and wait until the ISP ends

Once it finishes the console reports:

  1. Wire built-in leds to the correct pin, according to code and open your Serial Monitor of your preference.

About

A simple helloworld program with leds, using RT-Thread OS 5 and a CH32V208WBU6 board

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors