visit
Preparation
MDK development environment: MDK-ARM 5.24 (official or evaluation version, version 5.14 and above) needs to be installed. This version is also a relatively new version, which can provide relatively complete debugging functions. How to install can be referred to the .First acquaintance with RT-Thread
As an operating system, what is the code size of RT-Thread? Before we can figure this out, the first thing we need to do is to get an example of RT-Thread that corresponds to this manual. This example can be obtained from the following link:This example is a zip file, unzip it. Here, we decompressed it to D:/. The directory structure after decompression is as shown below:We can output all the commands supported by the current system by inputting the Tab key or help + enter, as shown in the following figure.
User Entry Code
The above startup code is basically related to the RT-Thread system, so how do users add initialization code for their own applications? RT-Thread uses main function as the user code entry, all you need to do is just add your own code to the main function.int main(void)
{
/* user app entry */
return 0;
}
Note: In order to complete the initialization for the system functions before entering the main program, you can use the $sub$$ and $super$$ function identifiers to call another sample before entering the main program, this was, users can ignore the initialization operations before the main() function. See for details.
Example of a Marquee
For technical engineers working on electronics, marquee is probably the simplest example, it is like the first program Hello World in every programming language that programmers learned. So we will start with a marquee in the following example, to make it periodically update (turn on or off) the LED.Under UART#1, input msh command: led and then click Enter to run it, as shown:/*
* Manifest of programs: Marquee sample
*
* marquee is probably the simplest example, it is like the first program
* Hello World in every programming language that programmers learned. So we will start with a marquee in the following example, start a thread to make it periodically
* update (turn on or off) the LED.
*/
int led(void)
{
rt_uint8_t count;
rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT);
for(count = 0 ; count < 10 ;count++)
{
rt_pin_write(LED_PIN, PIN_HIGH);
rt_kprintf("led on, count : %d\r\n", count);
rt_thread_mdelay(500);
rt_pin_write(LED_PIN, PIN_LOW);
rt_kprintf("led off\r\n");
rt_thread_mdelay(500);
}
return 0;
}
MSH_CMD_EXPORT(led, RT-Thread first led sample);
Other Examples
Additional kernel examples can be found in the kernel-sample-0.1.0 directory.Frequently Asked Question
Compilation error occurred as follows:rt-thread\src\kservice.c(823): error: #929: incorrect use of vaarg fieldwidth = aarg(args, int);
rt-thread\src\kservice.c(842): error: #929: incorrect use of vaarg precision = aarg(args, int);
………
Solution:
RT-Thread Contact Info
Previously published at