Ⅰ, Overview
The previous article was about the configuration of St-chip-related configuration and OS cropping-related configurations, followed by an article on porting of Ucos, which is mainly for uc/os-ii ports below Os_cpu_a.asm, OS_CPU_C.C and Os_ Cpu.h file The underlying port code to tell.
Please download "Ucos2_stm32f1_3 simple task" as a reference project.
I will "ucos transplant detailed process" into a number of articles to tell, please pay attention to.
See below for details of this article (please click on "read the original text" To view the content link).
based on the principle of free sharing, easy to learn knowledge of mobile phones, regularly share technical knowledge on the platform. If you feel that the content you share is useful to you, and if you want to learn more about it, please use the search "embedddeveloper" or scan the QR code below and follow There will be more exciting content waiting for you.
Ⅱ, Download
The author will F0, F1, F3, F4 transplant to the latest UCOS2.92. Transplant good, independent 4 projects for everyone to download learning, research. Set up the task is the same, only for the chip, the ports directory under the relevant source code is different, the standard peripheral library also has differences. Each series for different types of chips just need to change the "model" on the line.
Software engineering that provides downloads is run on the board, ensuring that no problems are uploaded to the 360 cloud disk.
Ucos based on STM32F0 series instances:
https://yunpan.cn/cRCZrQ3dzeVQq access password e73f
Ucos based on STM32F1 series instances:
Https://yunpan.cn/cRCZxGFsqHa6Q access password 39ff
Ucos based on STM32F3 series instances:
Https://yunpan.cn/cRCZqPRCWs8UW access password b305
Ucos based on STM32F4 series instances:
Https://yunpan.cn/cRCZPqbFqXSPR access password f177
Ucos Source Code Engineering
Official website Download (need account):
Https://www.micrium.com/downloadcenter/download-results/?searchterm=hm-stmicroelectronics&supported=true
360 Cloud Disk Download (regular update to the latest):
Https://yunpan.cn/cRzcf8eSacEhE access password 1235
St Standard Peripherals Library
Official website Download (need account):
Http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/ stm32-embedded-software.html?querycriteria=productid=sc961
360 Cloud Disk Download (regular update to the latest):
https://yunpan.cn/cSaCpGejMSfr8 access password 60ae
Resources:
https://yunpan.cn/cRCdSt73GwT6j access password 499e
Ⅲ, Project Catalog Structure Description
The file structure and the project directory structure correspond to the relationship as shown.
First Class (Standard peripheral Library):
Startup code: Startup codes
Stm32f10x_stdperiph_driver: Standard Peripheral Library Driver
CMSIS: Standard interface
Class II (ΜC/OS-II real-time kernel):
Uc/os-ii Source: Kernel sources (processor independent)
UC/OS-II Ports:os Port underlying code (related to processor, build platform)
Category III (user application):
BSP: Application of the underlying code (initialization, driver, etc.)
App: App implementation code (configure OS, apps, etc.)
This paper mainly aims at the transplant description of UC/OS-II ports. We do not use Ucos's own debugging capabilities, and we no longer describe ( use ) os_dbg.c files.
Ⅳ, Configuring the Os_cpu_a.asm file
The Os_cpu_a.asm file is located under the engineering UC/OS-II ports structure and is mainly a part of the system's underlying assembly code.
This file mainly makes a declaration of external references (global variables, functions), and some system-related source code (compilation) has made a definition.
Below I will define a few source code to do a description, the porting process needs to be modified I will focus on it.
1. Global Declaration
The file at the beginning of the global variables and functions are declared once, but the use of the Assembly, such as the C language inside the extern.
The above section is the external (other source file) defined variables and functions, the following section is to declare the function defined in this file, I will describe the source code of this definition.
Change the Os_cpu_pendsvhandler to Pendsv_handler, in order to be compatible with the ST Standard Peripheral Library Boot code (STARTUP_STM32F10X_HD.S).
2.NVIC Configuration
This section defines the Nvic(interrupt control) register correlation, as defined by the macro definition in preprocessing, which defines the register address and state.
3. Code Generation Instructions
These instructions are mainly for a processing of assembly instructions.
4. State preservation and recovery
These two assembler functions are functions that the program runs in the critical section, saving and restoring data. The main function is to protect the data from being destroyed.
5. Run the highest priority task
This function is called when the task is switched, and it is not difficult to understand the task switch's original friend. UCOS is to perform tasks by priority, the higher the priority (the smaller the priority value), the easier it is to be executed. When the task being executed is suspended (or deleted), the system needs to switch to a task, and the rule of switching is to switch to the highest priority to execute.
6. Context Switches
The system switch task can be from two places, that is, from the task level and the interrupt level. Both functions have the same meaning, and when a task switch is required, one is executed according to the criteria.
7.pendsv_handler Interrupt
The Pendsv_handler interrupt function is defined here, mainly in the execution of this interrupt to the M3 kernel register to do some operations (save and modify).
Change the Os_cpu_pendsvhandler to Pendsv_handler, in order to be compatible with the ST Standard Peripheral Library Boot code (STARTUP_STM32F10X_HD.S).
8. Summary Os_cpu_a.asm
For Ucos porting, the Os_cpu_a.asm file is mostly about modifying the name of the Os_cpu_pendsvhandler, including the name at the time of the Declaration and the name when the source code is defined, and the other source code remains the same.
Ⅴ, Configuring the Os_cpu_c.c file
The os_cpu_c.c file is located under the engineering UC/OS-II ports structure and is mainly a part of the system's underlying C-language interface code.
The file has a number of hook functions, known as the hook function, mainly used for system initialization, task-related, such as: Osinithookbegin (), Osinithookend () when the system is initialized, Ostaskcreatehook when the task is created, etc. In fact, we transplant ourselves, there are many hook functions do not need to use, or do not have to implement the code inside the function body. Here I'll tell you a few important functions, some of which aren't important.
Below I will define a few source code to do a description, the porting process needs to be modified I will focus on it.
1. System Tick
These are all about the Systick system tick macro definition and function body, because we use the M3 standard (St Library has) Systick system tick function interface, we block out OS_CPU_C.C Systick related definitions.
2.OSInitHookBegin
This function is called by the beginning of the Osinit (), which is called by our main function to call Osinit ().
Attention:
#if os_cpu_hooks_en > 0u
That is, you need to configure os_cpu_hooks_en>0 in the Os_cfg.h file.
3.OSTaskStkInit Initializing the task stack
This function is important to call when creating a task. The main is to configure the chip core register and protect the data on the spot. This function differs greatly depending on the core of the chip.
Ⅶ, Configuring the Os_cpu.h file
The Os_cpu.h file is located under the engineering UC/OS-II ports structure, which is mainly related to some definitions (stacks, data types), declarations (functions), etc. of the underlying system.
The file below the source code is relatively simple, some do not use, that is, the porting process needs to be modified I will highlight.
1.OS Data types
This section is for system-defined data types, which are not modified here.
2. Critical area Management
We use the default critical section 3rd mode, which is primarily related to the Os_cpu_sr_save () function defined in the Os_cpu_a.asm file.
3. Function declaration
function declaration is relatively simple, here are a few functions we have in the Os_cpu_a.asm and os_cpu_c.c files are blocked, and here will also block them off.
Ⅷ, Description
Related articles can be viewed on my blog, I will also update regularly, new content is the first time to share.
When you master the porting of Ucos on one platform, other platforms are similar in principle, please do not limit a certain platform.
The above summary is for reference only, if has the wrong place, please understanding.
Ⅸ, finally
Attention, reply to "more content", will get more content (such as:UCOS instances, etc., constantly updated in ...) )。
If you like what I share, and you want to know more about it, please follow the public number at the beginning of the article, the new content continues to be updated, and more exciting content will appear later.
UCOS2_STM32F1 Transplant Detailed procedure (iii)