Porting uCOS-III to STM32F10x

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.

Porting uCOS-III to STM32F10x

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:

  1. STM32F10x firmware library version 3.5.

  2. MDK4.23 compiler

  3. 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.

Porting uCOS-III to STM32F10x

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:

Porting uCOS-III to STM32F10x

2. Add project files:

Porting uCOS-III to STM32F10x

Porting uCOS-III to STM32F10x

Porting uCOS-III to STM32F10x

Porting uCOS-III to STM32F10x

Porting uCOS-III to STM32F10x

Main.c, Kernel.c, Kernel.h, Config.c, and Config.h code are provided below.

Porting uCOS-III to STM32F10xMain.c

Porting uCOS-III to STM32F10xKernel.c

Porting uCOS-III to STM32F10xKernel.h

Porting uCOS-III to STM32F10xConfig.c

Porting uCOS-III to STM32F10xConfig.h

app_cfg.h additional code is as follows:

Porting uCOS-III to STM32F10xapp_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:

Porting uCOS-III to STM32F10xcpu_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:

Porting uCOS-III to STM32F10x

    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;

Porting uCOS-III to STM32F10x

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

Porting uCOS-III to STM32F10x

Porting uCOS-III to STM32F10x

The programming result is too bloated:

Porting uCOS-III to STM32F10x

Enable level 3 optimization:

Porting uCOS-III to STM32F10x

Recompile to see the results:

Porting uCOS-III to STM32F10x

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.

Porting uCOS-III to STM32F10x

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.

Leave a Comment