STM32 learning record 13 ucosII transplantation

Publisher:幸福之舞Latest update time:2016-08-28 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
There are already many documents explaining how to migrate and set up projects. Here we will only explain the files that need to be modified and the reasons for the modifications.
1: os_cpu.h 
We need to modify this file: 
1) void OS_CPU_PendSVHandler(void) needs to be replaced with void PendSV_Handler(void) Generally, when we develop software based on stm32 chips, we will use the startup files provided in the standard peripheral library CMSIS, such as startup_stm32f10x_hd.s. However, Micrium does not use ST's standard startup files, but writes them separately into two .s files, namely init.s and vectors.s
(Micrium\Software\EvalBoards\ST\STM3210B-EVAL\RVMDK) init.s is responsible for entering main(), and vectors.s sets the interrupt vector. Since the interrupt vector OS_CPU_PendSVHandler is set in vectors.s, and we use startup_stm32f10x_hd.s as the startup file, and in the startup_stm32f10x_hd.s file, the interrupt vector of PendSV is named PendSV_Handler, so just replace the OS_CPU_PendSVHandler of the corresponding file with PendSV_Handler, where the function declaration is in OS_CPU_C.h and the specific interrupt service function prototype is in OS_CPU_A.ASM, which will be modified later. In this way, the replaced PendSV_Handler function is declared in OS_CPU_C.h, and there is a specific interrupt service function code in OS_CPU_A.ASM, which corresponds to the vector address in startup_stm32f10x_hd.s. 
2) Comment out the last three SysTick service functions 
void OS_CPU_SysTickHandler(void);   
void OS_CPU_SysTickInit(void);    
INT32U OS_CPU_SysTickClkFreq(void); 
Among them, the OS_CPU_SysTickHandler function has been defined in the ST standard library stm32f10x_it.c and is not needed here;
Among them, OS_CPU_SysTickInit is defined in os_cpu_c.c, depends on OS_CPU_SysTickClkFreq, is used to initialize the SysTick timer, and needs to be commented out; Among them, OS_CPU_SysTickClkFreq is defined in the BSP.c of the official EvalBoards, and the dependency needs to be removed. If necessary, we can implement it in bsp.c.
2: stm32f10x_it.c
Due to 1.2, it needs to be modified
SysTick is the "heartbeat" of the OS, which can be called a tick clock. It is essentially a timer, just like the PendSV interrupt. In startup_stm32f10x_hd.s, the interrupt vector of SysTick is named SysTick_Handler. Since the ST standard library already has related library functions, we only need to make the following changes: 
  Open the os_cpu_c.c file and find the content code of void OS_CPU_SysTickHandler(void) 
  OS_CPU_SR cpu_sr; 
  OS_ENTER_CRITICAL();                          
  OSIntNesting++; 
  OS_EXIT_CRITICAL(); 
  OSTimeTick();                                 
    OSIntExit();     
Copy it to the SysTick_Handler (void) function in the stm32f10x_it.c file;  
  void SysTick_Handler(void) 
  { 
    OS_CPU_SR cpu_sr; 
    OS_ENTER_CRITICAL();                          
    OSIntNesting++; 
    OS_EXIT_CRITICAL(); 
    OSTimeTick();                                                
    OSIntExit();                                  
    } 
And add in the file header: #include   
3: os_cup_a.asm
Due to 1.1, the prototype of the OS_CPU_PendSVHandler interrupt service function is in this file. We need to replace it with PendSV_Handler to match the interrupt vector in startup_stm32f10x_hd.s. 
1) Comment out EXPORT OS_CPU_PendSVHandler and change it to EXPORT PendSV_Handler, 
2) Find the OS_CPU_PendSVHandler program prototype and rename it to PendSV_Handler  
In this way, the PendSV_Handler interrupt service function is successfully established. At the same time, we need to comment out the relevant PendSV_Handler declarations and definitions in stm32f10x_it.h and stm32f10x_it.c to prevent conflicts.
4: os_cpu_c.c 
Since 1.2, make the following changes:
1) Comment out the contents of the last two functions OS_CPU_SysTickHandler() and OS_CPU_SysTickInit(); 
2) Disable the following macro definitions because they involve the Systick service function commented in the previous step 
#define OS_CPU_CM3_NVIC_ST_CTRL (*((volatile INT32U *)0xE000E010)) 
#define OS_CPU_CM3_NVIC_ST_RELOAD (*((volatile INT32U *)0xE000E014))   
#define OS_CPU_CM3_NVIC_ST_CURRENT (*((volatile INT32U *)0xE000E018)) 
#define OS_CPU_CM3_NVIC_ST_CAL (*((volatile INT32U *)0xE000E01C)) 
 
#define OS_CPU_CM3_NVIC_ST_CTRL_COUNT 0x00010000      
#define OS_CPU_CM3_NVIC_ST_CTRL_CLK_SRC 0x00000004      
#define OS_CPU_CM3_NVIC_ST_CTRL_INTEN 0x00000002      
#define OS_CPU_CM3_NVIC_ST_CTRL_ENABLE 0x00000001    
5: os_cfg.h 
This file is the header file for configuring the kernel. In this file, we can disable semaphores, mutexes, mailboxes, queues, semaphore sets, timers, memory management, and debug mode:  
#define OS_FLAG_EN 0 //Disable semaphore set     
#define OS_MBOX_EN 0 //Disable mailbox     
#define OS_MEM_EN 0 //Disable memory management     
#define OS_MUTEX_EN 0 //Disable mutex semaphore     
#define OS_Q_EN 0 //Disable queue     
#define OS_SEM_EN 0 //Disable semaphore     
#define OS_TMR_EN 0 //Disable timer     
#define OS_DEBUG_EN 0 //Disable debugging   
You can also disable the application's hook functions and multiple event controls
#define OS_APP_HOOKS_EN 0  
#define OS_EVENT_MULTI_EN 0  
The modifications are mainly to remove some functions, reduce the kernel size, and facilitate compilation and debugging. When needed, the corresponding functions will be enabled.

Keywords:STM32 Reference address:STM32 learning record 13 ucosII transplantation

Previous article:STM32 learning record 14 serial port interrupt in ucosii
Next article:STM32 learning record 12 interrupt vector table

Latest Microcontroller Articles
Change More Related Popular Components

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号