RTOs Real-time operating system UCOS-III to stm32f103 porting process (2)

Source: Internet
Author: User
Tags cpu usage

OK, cold winter, let's go on to the festivalUCOS-III TransplantTail.
Last session porting final compile we have fixed all the errors, but this does not mean that it is done, we also have to choose the Board to debug the code so that UCOS-III can smoothly in our board to run, here I choose isAtom Brother's Stm32f103rct6 V3.3 version of mini Development BoardTo do the transplant experiment.

So when the board is ready, let's start!
First, we open the project.app.cFile look inside theMain function, I found the main function inside.switch interrupts, initialize the system, create a start taskAndBoot the kernelFour things.

Then look at the starting task it just created, and see what it has done.
You can see that this is first initialized.BSP, CPU, and memory management, and then by settingos_cfg_stat_task_en macro equals 1 greater than 0, enabling the CPU usage function to be computed, setapp_cfg_serial_en macro equals def_enabled, initialize the serial port of the STM32, and set the serial port baud rate to 115200, but point intobsp_ser_init (115200)Will find it only initialized.Serial 2, and we want to use a serial port to transmit data (of course you can also use the serial port to transfer), the final processingWhile (1)The task inside.

The reason is to choose the serial function of the project template to do UCOS-III transplant, is to facilitate the direct use of the serial port for the program debugging. So what we're going to do now is to initialize the serial port in the main () function and the Apptaskstart () function using the serial port function of the template project itself. Inapp.c Add a line # include "Usart.h"Header file, and then inadd Uart_init (115200) to the Bsp_init () function under the Bsp.c fileis to initialize the serial port 1 in the Bsp_init function and turn backapp.c the main () function, add bsp_init () directly to the front。 In front of each function in the main function, add the phrase "printf ("Ucos-iii_test x\r\n");"(X is a digital ... Add 1 for each addition), and compile directly after it is finished.

After compiling the end found incredibly 0 Errors. is not too pleasantly surprised. Then with a doubt and a little excitement will be programmed into the program, open the Serial debugging assistant, click the Reset button, the heart of the small deer jumping looking forward to the appearance of printing information. However, a second passed, two seconds passed ... You will find nothing (at this point you should be suspicious of the compilation of the missing step, and then check that the addition has been added, and then compile and then download, found that there is no phenomenon). So what's wrong with that?
Let's take a look.Systick_handlerAndPendsv_handlerTwo functions,Systick_handleris the tick timer interrupt, this interrupt is equivalent to the heart of the operating system, in its interrupt service function,provides process/task context switching and task scheduling workPendsv_handlerfunction is when the operating system (OS) detects that an IRQ is active and isSysTickPreemption, it will trigger aPENDSV ExceptionFor a suspended execution of the context switch.
Open it"Startup_stm32f10x_hd.s" Startup fileSeeException Vector TableThese two functions are defined inside.

But we are"Stm32f10x_it.c"The file sees these two functions as empty. Both of these functions are commented out

So what we're going to do now is find the two functions defined in the UCOS-III source, openOS_CPU_C.Cfile, see the source CustomSystick_handlerThe function is namedOs_cpu_systickhandler, change its name toSystick_handler。 As shown in the following illustration:

Open it"Os_cpu_a.s"file, see the source CustomPendsv_handler functionis namedOs_cpu_pendsvhandler, change its name toPendsv_handler, and then change the declaration above, as shown in the following illustration:


And then compile it all over again, "0 Errors", burn the program to see if there is expected print information to appear

See the printing information has all appeared, indicatingMain functionRun without a problem, and thenprintfThe print function is deployed toApptaskstart Start Task, the context switch, task scheduling, and so on are normal. As shown in the following illustration:

Compile, burn.

found that the serial printing 10 information has been printed out, the program does not have any problems. Transplant UCOS-III is done.
The next study will be able to start their ownApptaskstartThe start task in the while (1) function in the debug LED flashing program, and then try to create several tasks themselves, to achieve the task between them to schedule each other. To play the same time, then to analyze the source of UCOS-III, it will be easier to accept some ~
I wish you "Rtos-ucos" Happy Journey ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.