FreeRTOS porting-based on STM32F407

First create a new or find a Keil-based STM32 basic project. Here I have created a STM32F407VET6 project template. The project structure is shown in the rectangular box in step 1 of the following figure.

Now we need to transplant FreeRTOS, copy the source code files of FreeRTOS to the project folder, some unused files can be deleted (which files need to be used can refer to the source code structure analysis part of the previous article), and then create them in Keil A FreeRTOS directory, add the c file to the project. Note that port.c comes from the ARM_CM4F of RDVS, which corresponds to the SMT32F407 hardware ported to.

FreeRTOS porting-based on STM32F407

After adding the c file, add the search path of the corresponding h file, as follows:

FreeRTOS porting-based on STM32F407

Then you can compile, first compile the first time:


......(省略显示若干行)
FreeRTOS\portable\RVDS\ARM_CM4F\port.c: 0 warnings, 1 error
compiling heap_4.c...
.\FreeRTOS\include\FreeRTOS.h(98): error:  #5: cannot open source input file "FreeRTOSConfig.h": No such file or directory
  #include "FreeRTOSConfig.h"
FreeRTOS\portable\MemMang\heap_4.c: 0 warnings, 1 error
".\Objects\Template_FreeRTOS.axf" - 8 Error(s), 0 Warning(s).
Target not created.
Build Time Elapsed:  00:00:23

There is an error, "FreeRTOSConfig.h" cannot be found, this file is in the Demo file of the FreeRTOS source code

Put the "FreeRTOSConfig.h" file in the Demo into the include folder under the FreeRTOS folder, and
perform the second compilation:


......(省略显示若干行)
compiling tasks.c...
compiling timers.c...
compiling port.c...
FreeRTOS\portable\RVDS\ARM_CM4F\port.c(713): error:  #20: identifier "SystemCoreClock" is undefined

ortNVIC_SYSTICK_LOAD_REG = ( 
onfigSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL;
FreeRTOS\portable\RVDS\ARM_CM4F\port.c: 0 warnings, 1 error

It also prompts that "SystemCoreClock" is not defined, because SysyemCoreClock is used in "FreeRTOSConfig.h": to mark the frequency of the MCU,

In "FreeRTOSConfig.h": Line 87~95:


#ifdef __ICCARM__
    #include <stdint.h>
    extern uint32_t SystemCoreClock;
#endif

#define configUSE_PREEMPTION            1
#define configUSE_IDLE_HOOK             1
#define configUSE_TICK_HOOK             1
#define configCPU_CLOCK_HZ              ( SystemCoreClock )

Conditional compilation


#ifdef __ICCARM__

change into

#if defined(__ICCARM__)||defined(__CC_ARM)||defined(__GNU__)

Perform the third compilation again:


......(省略显示若干行)
compiling port.c...
compiling heap_4.c...
linking...
.\Objects\Template_FreeRTOS.axf: Error: L6200E: Symbol SVC_Handler multiply defined (by port.o and stm32f4xx_it.o).
.\Objects\Template_FreeRTOS.axf: Error: L6200E: Symbol PendSV_Handler multiply defined (by port.o and stm32f4xx_it.o).
.\Objects\Template_FreeRTOS.axf: Error: L6200E: Symbol SysTick_Handler multiply defined (by port.o and stm32f4xx_it.o).
Not enough information to list image symbols.
Not enough information to list the image map.
Finished: 2 information, 0 warning and 3 error messages.
".\Objects\Template_FreeRTOS.axf" - 3 Error(s), 0 Warning(s).
Target not created.
Build Time Elapsed:  00:00:02

It also prompts that port.o and stm32f4xx_it.o have duplicate definitions (.o is the compiled object file, in fact, there is a problem with the corresponding .c file)

Comment out SVC_Handler() PendSV_Handler() SysTick_Handler() in stm32f4xx_it.c

Line 110~145 of the modified stm32f4xx_it.c:


/**
 \* @brief This function handles SVCall exception.
 \* @param None
 \* @retval None
 */
//void SVC_Handler(void)
//{
//}

/**
 \* @brief This function handles Debug Monitor exception.
 \* @param None
 \* @retval None
 */
void DebugMon_Handler(void)
{
}

/**
 \* @brief This function handles PendSVC exception.
 \* @param None
 \* @retval None
 */
//void PendSV_Handler(void)
//{
//}

/**
 \* @brief This function handles SysTick Handler.
 \* @param None
 \* @retval None
 */
//void SysTick_Handler(void)
//{
// 
//}

Perform the fourth compilation again:

......(省略显示若干行)
linking...
.\Objects\Template_FreeRTOS.axf: Error: L6218E: Undefined symbol vApplicationIdleHook (referred from tasks.o).
.\Objects\Template_FreeRTOS.axf: Error: L6218E: Undefined symbol vApplicationStackOverflowHook (referred from tasks.o).
.\Objects\Template_FreeRTOS.axf: Error: L6218E: Undefined symbol vApplicationTickHook (referred from tasks.o).
.\Objects\Template_FreeRTOS.axf: Error: L6218E: Undefined symbol vApplicationMallocFailedHook (referred from heap_4.o).
Not enough information to list image symbols.
Finished: 1 information, 0 warning and 4 error messages.
".\Objects\Template_FreeRTOS.axf" - 4 Error(s), 0 Warning(s).

It also prompts that 4 hook functions are undefined,

This is because these hook functions are defined in "FreeRTOSConfig.h", but the function definitions are not found. Let’s comment out these definitions first.

Just define macro definitions such as configUSE_IDLE_HOOK as 0,


查看"FreeRTOSConfig.h"的93~108行:

#define configUSE_IDLE_HOOK             1
#define configUSE_TICK_HOOK             1
#define configCPU_CLOCK_HZ              ( SystemCoreClock )
#define configTICK_RATE_HZ              ( ( TickType_t ) 1000 )
#define configMAX_PRIORITIES            ( 5 )
#define configMINIMAL_STACK_SIZE        ( ( unsigned short ) 130 )
#define configTOTAL_HEAP_SIZE           ( ( size_t ) ( 75 * 1024 ) )
#define configMAX_TASK_NAME_LEN         ( 10 )
#define configUSE_TRACE_FACILITY        1
#define configUSE_16_BIT_TICKS          0
#define configIDLE_SHOULD_YIELD         1
#define configUSE_MUTEXES               1
#define configQUEUE_REGISTRY_SIZE       8
#define configCHECK_FOR_STACK_OVERFLOW  2
#define configUSE_RECURSIVE_MUTEXES     1
#define configUSE_MALLOC_FAILED_HOOK    1

Modify the value of line 93 94 106 108 to 0, that is:


#define configUSE_IDLE_HOOK             0
#define configUSE_TICK_HOOK             0
......(省略显示11行)
#define configCHECK_FOR_STACK_OVERFLOW  0
......(省略显示1行)
#define configUSE_MALLOC_FAILED_HOOK    0

Perform the fifth compilation again:

......(省略显示若干行)
compiling port.c...
compiling heap_4.c...
linking...
Program Size: Code=1880 RO-data=424 RW-data=68 ZI-data=2036  
".\Objects\Template_FreeRTOS.axf" - 0 Error(s), 0 Warning(s).
Build Time Elapsed:  00:00:01

Finally, the compilation is ok, so the transplantation is basically successful. In the next article, I will write a basic routine of FreeRTOS to test whether it can be used normally.
Get the project code used in this article:
WeChat public account reply "freertos project template"
compressed package contains 3 folders:

  1. Template_lib: library files needed to build the project, including STM32 library files (v1.4.0) and FreeRTOS library files (v9.0.0)
  2. Template_noOS: STM32F407 project template based on Keil5.15 (FreeRTOS is not used)
  3. Template_FreeRTOS: STM32F407 + FreeRTOS project template based on Keil5.15

Guess you like

Origin blog.51cto.com/15060517/2641091