In the previous article: Full Analysis of FreeRTOS-2. Source code structure and transplantation, we have already explained the method of FreeRTOS transplantation, and gave an example of transplantation on ARM9. Let’s look at another example today: the chip of the board is STM32F407, the architecture It is ARM_CM4F, and the IDE is keil.
1. Just find a STM32F4 routine
Take the punctual atomic LCD experiment routine, first compile and download the program to see if it can run normally
very normal.
2. Put the FreeRTOS related code into the keil project directory
Copy the entire picture
Then delete it. Only the two folders, MemMang and RVDS, are kept in the portable folder, and all others are deleted.
Then delete the files in RVDS, because our chip is STM32F407, and the architecture is ARM_CM4F, so delete all others.
Find a FreeRTOSConfig.h similar to ours in the official demo, and copy it into the USER folder of our keil project
3. Add FreeRTOS code in keil
Add the necessary files into
Don't forget to set the header file path.
4. compile
Write two simple tasks, task 1: led cycle on and off, task 2: screen cycle black and white switching
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "lcd.h"
#include "FreeRTOS.h"
#include "task.h"
void vTask1( void *pvParameters )
{
for( ;; ) {
LED0=0;
delay_ms(5000);
LED0=1;
delay_ms(5000);
}
}
void vTask2( void *pvParameters )
{
for( ;; ) {
LCD_Clear(BLACK);
delay_ms(5000);
LCD_Clear(WHITE);
delay_ms(5000);
}
}
static void prvSetupHardware( void )
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
delay_init(168);
uart_init(115200);
LED_Init();
LCD_Init();
}
int main(void)
{
prvSetupHardware();
xTaskCreate(vTask1, "Task 1", 1000, NULL, 1, NULL);
xTaskCreate(vTask2, "Task 2", 1000, NULL, 1, NULL);
vTaskStartScheduler();
}
Then compile, there is an undefined error.
Compile the conditions in FreeRTOSConfig.h
#ifdef __ICCARM__
change into
#if defined(__ICCARM__)||defined(__CC_ARM)||defined(__GNU__)
recompile
It also prompts that port.o and stm32f4xx_it.o have duplicate definitions
Comment out SVC_Handler(), PendSV_Handler() SysTick_Handler() in stm32f4xx_it.c
Compile again, and it prompts that several functions are undefined. This is because related functions are configured in FreeRTOSConfig.h. We turn off the related configuration, that is, set it to 0.
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_MALLOC_FAILED_HOOK 0
The compilation is successful, the effect:
Both tasks are running, indicating that our migration has been successful.
Reference article: