STM32F1+uCOSii migration

Keywords: Assembly Language

0.uCOSII introduction

0.0 uCOSii background

μ C/OS-II is a portable, curable, tailorable, preemptive multitask real-time kernel provided by Micrium company. It is suitable for a variety of microprocessors, microcontrollers and digital processing chips (which have been transplanted to more than 100 microprocessor applications). At the same time, the source code of the system is open, clean, consistent, detailed comments, suitable for system development.
μ C/OS-II has passed the certification of FAA commercial aircraft and conforms to the DO-178B standard of RTCA.

0.1 characteristics and composition

μ C/OS-II can provide the following services:
Semaphore
Mutex semaphore
Event identifier
Message Mailboxes
Message queue
task management
Fixed size memory block management
time management
In addition, on the μ C/OS-II kernel, there are the following independent modules for users to choose:
μ C/FS file system module
μ C/GUI graphic software module
μ C/TCP-IP protocol stack module
μ C/USB protocol stack module

μ C/OS-II can be roughly divided into five parts: core, task processing, time processing, task synchronization and communication, and CPU migration.

(1) core (OSCore.c)
It is the processing core of the operating system, including the initialization of the operating system, the operation of the operating system, the forerunner of interrupt in and out, clock beat, task scheduling, event processing and other parts. All the parts that can maintain the basic work of the system are here.
(2) task processing (OSTask.c)
The content of task processing is closely related to task operation. Including task creation, deletion, suspension, recovery, etc. Because μ C/OS-II is scheduled based on tasks, this part is also very important.
(3) clock part (OSTime.c)
The minimum clock unit in μ C/OS-II is timetick. Task delay and other operations are completed here.
(4) task synchronization and communication
It is the event processing part, including semaphore, mailbox, mailbox queue, event flag and other parts; it is mainly used for the interconnection between tasks and access to critical resources.
(5) interface with CPU
Refers to the porting part of μ C/OS-II for the CPU used. As μ C/OS-II is a universal operating system, the implementation of key issues needs to be transplanted according to the specific content and requirements of the specific CPU. This part is usually written in assembly language because it involves system pointers such as SP. It mainly includes the bottom implementation of interrupt level task switching, the bottom implementation of task level task switching, the generation and processing of clock beat, and the related processing of interrupt.

The above is some basic knowledge, not much to say, enter the main topic!

1.0 preparation for transplantation

Environment: KEIL-MDK v-5.25
Hardware: STM32F103VET6 core board
Template program: lighting program
Uocsii source code: http://micrium.com/downloadcenter/download-results/?searchterm=mp-uc-os-ii&supported=true You can download it.

The extracted file is as follows:

Doc - this folder contains some documents about uCOSII. You can see that all the migration files we need are in the source folder.

1.1 migration documents

Create a new UCOS empty folder under the project directory of our template program to place our migration files. At the same time, create three new folders under the UCOS path: 1.core, 2.config.
3. The config folder is as follows



Find the files we need under our Source, add them and copy them to our three folders as follows:

CORE:

CONFIG: only two files are required for this folder


includes.h: for some configuration files, I copied them.

/*
************************************************************************************************
Main include files

Files: INCLUDES.C ucos include files
 By Jean J. Labrosse
************************************************************************************************
*/

#ifndef __INCLUDES_H__
#define __INCLUDES_H__
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdarg.h>

#include "ucos_ii.h"
#include "os_cpu.h"
#include "os_cfg.h"

#include <stm32f10x.h>	    

#endif

Next is our last folder

PORT:


This file needs to be downloaded separately. I will pack the whole folder. https://pan.baidu.com/s/1-ZGLL-fc_cRwGfF87UaTsw
Now we have added all the files, but we just added them to the file path, not to the project. Next, we will add our files to the project;

2.0 engineering configuration

Add required documents to the project

Be careful:

1. Do not add UCOS II. C file to UCOS-CORE group, or there will be many errors.
2. Remember to add the header file path at the same time

After adding, we can try to compile the project. As a result, we will get many error reports, but there are many error reports that we can't find the header file app_cfg.h.

resolvent:

1. Open ucosii.h, and comment the declaration of app_cfg.h below, because we do not use this header file. Also declare our includes.h header file.
2. Open stm32f103x_it.c, and comment out the interrupt function void PendSV_Handler(void) and its contents:

3. Open the sys.h file, modify the definition here as follows, and it is 1. Because I use a punctual template, I must modify it here to support OS:
#Define system support OS 1 / / defines whether the system folder supports UCOS.
So far, the configuration of our UCOSii is basically completed, and no error is reported. Let's add our lighting program to the OS and run happily.

#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "includes.h"

//START task
//Set task priority
#define START_TASK_PRIO			10  ///Start task has the lowest priority
//Set task stack size
#define START_STK_SIZE			128
//Task task stack
OS_STK START_TASK_STK[START_STK_SIZE];
//Task function
void start_task(void *pdata);

//LED0 task
//Set task priority
#define LED0_TASK_PRIO			7
//Set task stack size
#define LED0_STK_SIZE			64
//task stack
OS_STK LED0_TASK_STK[LED0_STK_SIZE];
//Task function
void led0_task(void *pdata);

//LED1 task
//Set task priority
#define LED1_TASK_PRIO			6
//Set task stack size
#define LED1_STK_SIZE			64
//task stack
OS_STK LED1_TASK_STK[LED1_STK_SIZE];
//Task function
void led1_task(void *pdata);

//Floating point test task
#define FLOAT_TASK_PRIO			5
//Set task stack size
#define FLOAT_STK_SIZE			128
//task stack
//If printf is used in the task to print floating-point data, 8-byte alignment is required.
__align(8) OS_STK FLOAT_TASK_STK[FLOAT_STK_SIZE]; 
//Task function
void float_task(void *pdata);

int main(void)
{
	delay_init();       //Delay initialization
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //Interrupt grouping configuration
	uart_init(115200);    //Serial port baud rate setting
	LED_Init();  	//LED initialization
	
	OSInit();  		//UCOS initialization
	OSTaskCreate(start_task,(void*)0,(OS_STK*)&START_TASK_STK[START_STK_SIZE-1],START_TASK_PRIO); //Create start task
	OSStart(); 	//Start task
}

//Start task
void start_task(void *pdata)
{
	OS_CPU_SR cpu_sr=0;
	pdata=pdata;
	OSStatInit();  //Open statistics task
	
	OS_ENTER_CRITICAL();  //Enter critical area (close interrupt)
	OSTaskCreate(led0_task,(void*)0,(OS_STK*)&LED0_TASK_STK[LED0_STK_SIZE-1],LED0_TASK_PRIO);//Create LED0 task
	OSTaskCreate(led1_task,(void*)0,(OS_STK*)&LED1_TASK_STK[LED1_STK_SIZE-1],LED1_TASK_PRIO);//Create LED1 task
	OSTaskCreate(float_task,(void*)0,(OS_STK*)&FLOAT_TASK_STK[FLOAT_STK_SIZE-1],FLOAT_TASK_PRIO);//Create floating point test task
	OSTaskSuspend(START_TASK_PRIO);//Suspend start task
	OS_EXIT_CRITICAL();  //Exit critical area (open interrupt)
}
 

//LED0 task
void led0_task(void *pdata)
{
	while(1)
	{
		LED0=0; 
		delay_ms(80);
		LED0=1;
		delay_ms(100);
	}
}

//LED1 task
void led1_task(void *pdata)
{
	while(1)
	{
		LED1=0;
		delay_ms(300);
		LED1=1;
		delay_ms(300);
	}
}

//Floating point test task
void float_task(void *pdata)
{
	OS_CPU_SR cpu_sr=0;
	static float float_num=0.01;
	while(1)
	{
		float_num+=0.01f;
		OS_ENTER_CRITICAL();	//Enter critical area (close interrupt)
		printf("float_num The value is: %.4f\r\n",float_num); //Serial printing results
		OS_EXIT_CRITICAL();		//Exit critical area (open interrupt)
		delay_ms(500);
	}
}


The code has been pasted out. The data I transplanted to UCOSii is from brother atomy. After configuration, he will get an error message:
...\OBJ\LED.axf: Error: L6200E: Symbol SysTick_Handler multiply defined (by delay.o and stm32f10x_it.o).

At this time, you only need to shield the void SysTick_Handler(void) interrupt.

Statement: This article is only used to record the learning and deepen the impression. After all, there are too many kinds of articles. I also COPY them all the way.

Posted by please_explain on Sat, 26 Oct 2019 06:30:25 -0700