Transplantation of ucosII to STM32F103ZE (Part 2)

Publisher:TranquilDreamsLatest update time:2015-10-23 Source: eefocusKeywords:ucosII  STM32F103ZE Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
3.        System uC/OSII Introduction and Library File Introduction:
1.      Introduction to uC/OSII:
The uC/OS kernel can be basically divided into three parts: task scheduling, task synchronization and memory management:
Task scheduling
uC/OSII assigns a different priority to each task to ensure real-time performance. When a task switch occurs, it always switches to the highest priority task that is ready. There are two situations in which task switching occurs.
1. The task waits for resources to be ready or self-delays;
2. Exit interrupts;
Situation 1 can be understood as the task actively giving up the right to use the CPU. Situation 2 can be understood as after the interrupt, some resources may be ready and task switching is required.
It should be noted that the SysTick interrupt is the "heartbeat" of the OS and must be present. This allows the CPU to periodically switch tasks. Since uC/OSII does not support time slice round-robin scheduling, the only work that must be done in this interrupt is OS time management. That is, calling OSTimeTick()
Task synchronization
Task synchronization is similar to the practices of most operating systems. If you have studied operating systems or have multi-threaded programming experience, it should be easy to understand. It is nothing more than that task A gives up the right to use the CPU because a certain resource is not ready, and waits for task B or interrupt to make the resource ready. When the task is switched again, if task A has the highest priority, task A continues to execute. For specific implementation, please refer to the book recommended above.
Memory management
ucosii's memory management should have been mentioned before.
Ucosii code composition
os_core.c is the core of ucosii, which includes kernel initialization, task switching, event block management, etc., among which the event block is the basis of each synchronization quantity (here I call mutex, semaphore, mailbox, queue as synchronization quantity, which is not very scientific, but for convenience. The event flag group is not based on the event block, but the principle is similar).
os_task.c      task management code
os_flag.c       event flag management code
os_mbox.c     message mailbox management code
os_mutex.c    mutex semaphore management code
os_q.c        message queue management code
os_sem.c      synchronization quantity management code.
os_mem.c     memory management code.
os_time.c      time management code, mainly for various delays.
os_tmr.c       timer management code
Timer management code, this part of the code is only available from version V2.81. Mr. Shao's book talks about the code of version V2.55, which does not have this part. If you understand the previous code, this part of the code is not difficult to understand. A timer is generally composed of 3 parts: timing time, callback function and attributes. When the timing time is reached, the callback function is processed once. The timer attribute indicates whether the timer is periodic timing or only one-time timing. If the user enables OS_TMR_EN, ucosii will create a timer task internally to handle each timer. This task should generally be activated by calling OSTmrSignal() in the interrupt function of the hardware timer. So in essence, the timer in os_tmr.c is differentiated from a hardware timer.
By default, the timer task is activated by OSTimeTickHook() in the SysTick interrupt.
Transplantation related files
os_cpu.h:       data type definition, processor related code and several function prototypes.
os_cpu_c.c:      define some user hook functions.
os_cpu_a.asm:  transplantation of functions that need to be completed with assembly code, mainly task switching functions.
os_dbg.c:       kernel debugging related data and functions, can be left unchanged. The
introduction of ucosii kernel ends here.
2.      Introduction to STM32F10x library files:
after decompressing the stm32f10x_stdperiph_lib.zip library file downloaded from the ST official website, there are six files, as shown below: Libraries contains the source code of the library, Project contains examples of using various stm32 peripherals and a project template, Utilitiess is an example of using the st company evaluation board, _htmresc are two icons stm32f10x_stdperiph_lib_um.chm teaches us how to use the standard peripheral library. We are mainly concerned about the Libraries and Project folders, from which we will copy the required information later. 1)  Establish the project folder structure: It should be a large project to use a 32-bit microcontroller, so the project directory should also be planned. Here is a recommended directory structure. Ø  Suppose a folder named stm32-ucosII-demo is created, and there are 6 folders App, Bsp, Libraries, OS-uCOSII, Project, and Readme under this directory. App is used to store application files, Bsp is used to store version-level driver files, Libraries is used to store STM32 standard peripheral library files, OS-uCOSII is used to store uCOS files, Project is used to store project files, and Readme is used to store the self-description or description files of this project in TXT format. Ø  Create two subfolders Output and List under Project. Ø  Create two subfolders core and port under OS-uCOSII. 2)  Organize the library code: Since many codes in the CMSIS folder under Libraries are related to the compiler and chip, there are many folders and the depth is large, which is not conducive to project maintenance. In fact, a project often uses a fixed compiler and chip, so it is necessary to organize the library. a)  Copy the STM32F10x_StdPeriph_Lib_V3.5.0Libraries folder under the newly unzipped STM32F10x_StdPeriph_Driver to the new folder Stm32-ucosII-demoLibraries. b) 
Transplantation of ucosII to STM32F103ZE (Part 2)


 

    





    

    
    Create a CM3 folder in the new folder Stm32-ucosII-demo Libraries directory, copy
core_cm3.c, core_cm3.h under STM32F10x_StdPeriph_Lib_V3.5.0LibrariesCMSISCM3CoreSupport and
stm3210x.h, system_stm32f10x.c, system_stm32f100x.h under STM32F10x_StdPeriph_Lib_V3.5.0LibrariesCMSISCM3DeviceSupportSTSTM32F10x to the new LibrariesCM3 folder, and remove the read-only attribute of these three files.
c)      Create a startup folder in the new folder LibrariesCM3 directory, and copy the corresponding startup files under LibrariesCMSISCM3DeviceSupportSTSTM32F10xstartuparm to the startup folder according to the chip type you selected. Here is the startup_stm32f10x_hd.s.
d)      Copy stm32f10x_it.c, stm32f10x_it.h, stm32f10x_conf.h under STM32F10x_StdPeriph_Lib_V3.5.0ProjectSTM32F10x_StdPeriph_Template to the new Stm32-ucosII--demoApp.
e)      The tree directory diagram of all files is as follows: f)  Here is a brief introduction to the library file . The content under LibrariesSTM32F10x_StdPeriph_Driver is easy to understand, which is the driver code of each peripheral module of stm32. misc.h and misc.c are the driver codes of NVIC and SysTick related to the CM3 core. What is under LibrariesCMSIS? [page] CMSIS English full name: Cortex Microcontroller Software Interface Standard, is the Cortex series processor hardware abstraction layer, can be understood as the software interface of the cortex core. core_cm3.c, core_cm3.h Their directory name is CoreSupport, indicating that these two files are CCM3 core support files, and other chips using the CM3 core can also be used, not necessarily stm32. These two files are used to obtain the settings of the CM3 core and configure some core registers. stm32f10x.h, system_stm32f10x.c, system_stm32f10x.h and startup_stm32f10x_hd.s are in the DeviceSupport directory, indicating that these files are related to specific chips, that is, support files for stm32 chips. Among them, stm32f10x.h is the entry of the standard peripheral library, and the code using the standard peripheral library must include this header file. system__stm32f10x.c, system__stm32f10x.h are chip-level initialization library function files. They provide library functions to initialize the stm32 chip, configure PLL, system clock and built-in flash interface. startup_stm32f10x_hd.s is the startup file of the stm32 chip. hd indicates that it is a high-density chip. OK, the ST official library folder STM32F10x_StdPeriph_Lib_V3.5.0 is no longer used and can be closed. 3)  Create a keiil development project Use keil MDK to create a new project named stm32-ucosii-demo and save it to the stm32-ucosII-demoProject folder. During this process, you will be asked to select a stm32 series chip (I chose STM32F103ZE because my board uses this chip). Next, please note that when the pop-up pops up whether to copy the startup code to the project folder, you should select No, because the startup code is already in the standard peripheral library. Rename the top-level directory Target 1 in the project window of UV4 to STM32-uCOSII-DEMO (right-click Target 1, call up the Manage Components menu in the properties to set it), and delete the first Source Group 1. Next, create the following subdirectories in the project: STM32-uCOSII-DEMO, STM32F10x_StdPeriph_Driver, STM32F10x_CM3, APP, BSP, uCosII_core, uCosII_port. Load all (or some necessary) .c files in the LibrariesSTM32F10x_StdPeriph_Driversrc directory into the STM32F10x_StdPeriph_Driver in the project. Load all .c and .h files in the LibrariesCM3 directory and the corresponding .s files in the LibrariesCMSISstartup directory into the STM32F10x_CM3 in the project. Recommended keil tree project directory diagram:
Transplantation of ucosII to STM32F103ZE (Part 2)

 
     






                           
                  
    



  Transplantation of ucosII to STM32F103ZE (Part 2)

 


Transplantation of ucosII to STM32F103ZE (Part 2)
 

Keywords:ucosII  STM32F103ZE Reference address:Transplantation of ucosII to STM32F103ZE (Part 2)

Previous article:Transplantation of ucosII to STM32F103ZE (Part 3)
Next article:Porting ucosII to STM32F103ZE (Part 1)

Recommended ReadingLatest update time:2024-11-16 15:37

UCOSii (II) - Task readiness and scheduling
1. Task readiness and scheduling 1.1 Task Status From the task status switching diagram in the ucosii user manual (which can be downloaded from the address mentioned in the previous article): If you have studied courses like "Operating Systems", you will find this picture easy to understand. DORMANT Here I finally
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components
Guess you like
    502 Bad Gateway

    502 Bad Gateway


    openresty

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号