Sharing is a virtue. If you enjoy content about “Embedded Hardware Development,” feel free to share it with your friends so more people can see it.
Recently, after reading the introduction of uCOS-III on Baidu, I found that many features have been significantly improved, and I feel it is necessary to upgrade the development environment. Baidu introduction: http://baike.baidu.com/view/8531313.htm
Environment:
-
STM32F10x firmware library version 3.5.
-
MDK4.23 compiler
-
uCOS-III v3.03
1. uCOS-III source file KRN-K3XX-000000.zip
Official website: http://micrium.com/page/downloads/source_code
My cloud disk: http://115.com/file/anr4r6a8#
2. uCOS-III official porting program
Micrium_uCOS-III-STM32F107-Eval-Atollic-TrueSTUDIO.zip
Official website: http://micrium.com/download/Micrium-Book-uCOS-III-STM32F107.exe
Cloud disk: http://115.com/file/dpuyusej#
1. The first step is to create a new project (detailed in the previous article).
2. Create a folder named uCOS_III. Under this folder, create four subfolders: uC-CPU, uC-LIB, uCOS-III.
1. Under uCOS-III, create three folders: Source, Ports, Cfg
Copy all files from KRN-K3XX-000000\Micrium\Software\uCOS-III\Source to Source;
Copy all files from KRN-K3XX-000000\Micrium\Software\uCOS-III\Cfg\Template to Cfg;
Copy all files from Micrium_uCOS-III-STM32F107-Eval-Atollic-TrueSTUDIO\Micrium\Software\uCOS-III\Ports\ARM-Cortex-M3\Generic\RealVie to Ports.
2. Under uC-LIB, create three folders: Source, Ports, Cfg
Copy text files from Micrium_uCOS-III-STM32F107-Eval-Atollic-TrueSTUDIO\Micrium\Software\uC-LIB to Source
Copy lib_cfg.h from Micrium_uCOS-III-STM32F107-Eval-Atollic-TrueSTUDIO\Micrium\Software\uC-LIB\Cfg\Template to Cfg
Copy lib_mem_a.asm from Micrium_uCOS-III-STM32F107-Eval-Atollic-TrueSTUDIO\Micrium\Software\uC-LIB\Ports\ARM-Cortex-M3\RealView to Ports
3. Under uC-CPU, create three folders: Source, Ports, Cfg
Copy three text files from Micrium_uCOS-III-STM32F107-Eval-Atollic-TrueSTUDIO\Micrium\Software\uC-CPU to Source
Copy three files from Micrium_uCOS-III-STM32F107-Eval-Atollic-TrueSTUDIO\Micrium\Software\uC-CPU\ARM-Cortex-M3\GNU to Ports
Copy cpu_cfg.h from Micrium_uCOS-III-STM32F107-Eval-Atollic-TrueSTUDIO\Micrium\Software\EvalBoards\Micrium\uC-Eval-STM32F107\Atollic\uCOS-III\APP to Cfg
4. Copy app_cfg.h from Micrium_uCOS-III-STM32F107-Eval-Atollic-TrueSTUDIO\Micrium\Software\EvalBoards\Micrium\uC-Eval-STM32F107\Atollic\uCOS-III\APP to Main.
Now, the project files have been copied.
1. Specify the project reference file path as shown in the figure:
2. Add project files:
Main.c, Kernel.c, Kernel.h, Config.c, and Config.h code are provided below.
Main.c
Kernel.c
Kernel.h
Config.c
Config.h
app_cfg.h additional code is as follows:
app_cfg.h
Next, modify cpu_a.s in Project\App\uCOS_III\uC-CPU\Ports, as this is GNU assembly code.
Replace as follows:
‘@’ with ‘;’
.global with EXPORT
The following code:
.text
.align 2
.thumb
.syntax unified
should be replaced with
PRESERVE8
AREA |.text|, CODE, READONLY
THUMB
Comment out the function name with ‘;’ before and after .thumb_func; and remove the ‘:’ immediately following the function name.
The modified code is as follows:
cpu_a.s
Modify os_cfg.h
Set OS_CFG_TS_EN macro definition to 0u
Set OS_CFG_SCHED_LOCK_TIME_MEAS_EN macro definition to 0u
Set OS_CFG_TASK_DEL_EN macro definition to 1u
Other definitions can be set to 1u or 0u based on your functional needs.
In Project\App\uCOS_III\uC-LIB\Source, the local variable in the Str_FmtNbr_Int32 function of lib_str.c is not initialized, which is not rigorous. Initialize it as follows:
CPU_CHAR *pstr_fmt = (CPU_CHAR *)0;
CPU_DATA i = 0u;
CPU_INT32U nbr_fmt = 0u;
CPU_INT32U nbr_log = 0u;
CPU_INT08U nbr_dig_max = 0u;
CPU_INT08U nbr_dig_min = 0u;
CPU_INT08U nbr_dig_fmtd = 0u;
CPU_INT08U nbr_neg_sign = 0u;
CPU_INT08U nbr_lead_char = 0u;
CPU_INT08U dig_val = 0u;
CPU_INT08U lead_char_delta_0 = 0u;
CPU_INT08U lead_char_delta_a = 0u;
CPU_BOOLEAN lead_char_dig = 0u;
CPU_BOOLEAN lead_char_0 = 0u;
CPU_BOOLEAN fmt_invalid = 0u;
CPU_BOOLEAN print_char = 0u;
CPU_BOOLEAN nbr_neg_fmtd = 0u;
Finally, modify the startup file startup_stm32f10x_hd.s. When loading different startup files, do not worry; the modifications are the same:
Replace OS_CPU_PendSVHandler with all PendSV_Handler
Replace OS_CPU_SysTickHandler with all SysTick_Handler
This allows the interrupt to execute the uCos interrupt functions.
Everything is now OK.
Simulate and observe port changes
The programming result is too bloated:
Enable level 3 optimization:
Recompile to see the results:
Scan the QR code to follow the WeChat public account “Embedded Hardware Development” and grow together with those who love hardware. Any good ideas or suggestions can be directly replied to in the public account.
Long press to automatically scan and follow
Sharing is a virtue. If you enjoy content about “Embedded Hardware Development,” feel free to share it with your friends so more people can see it.