STM32F103 FreeRtos migration notes

Publisher:Heavenly999Latest update time:2017-02-20 Source: eefocusKeywords:STM32F103 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

RTOS version: FreeRTOS_V8.2.2

1. Download the FreeRTOS source file.
       You can download it from Baidu, or download it from the official website http://www.freertos.org/a00104.html.
       You can download it from the following location

       The latest version is 8.2.2
. Download the source code, unzip it, and add the source code to the project.
      2.1 Create a new transplant project (you can also copy Atom's), and create a folder FreeRTOS in the project to store the source code.
      2.2 Open the unzipped source code "..\FreeRTOSv8.2.2", which contains several folders and files.

The red circle in the picture above is the source code. Copy the entire folder to the "FreeRTOS" folder of the new project.
2.4 In the source code folder "..\FreeRTOSv8.2.2\FreeRTOS\Demo\CORTEX_STM32F103_Keil", find the file "FreeRTOSConfig.h" and copy it to the project folder "FreeRTOS"

3. Open the MDK software, create a new project, and add files

Add files as shown above. The red box is the FreeRTOS file added;
"port.c" file path..\FreeRTOS\Source\portable\RVDS\ARM_CM3
"heap_2.c" file path..\FreeRTOS\Source\portable\MemMang
"list.c", "queue.c", "tasks.c" file path..\FreeRTOS\Source

5. After completing the above work, write the main function

#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "misc.h"
#include "led.h"

void LED0_Task(void *pvParameters);
void LED1_Task(void *pvParameters);


int main()
{     
   LED_Init(); //Initialize the hardware interface connected to the LED
   xTaskCreate(LED0_Task,(const char *)"LED0",configMINIMAL_STACK_SIZE,NULL,tskIDLE_PRIORITY+3,NULL);
   xTaskCreate(LED1_Task,(const char *)"LED1",configMINIMAL_STACK_SIZE,NULL,tskIDLE_PRIORITY+4,NULL);
   vTaskStartScheduler();
}

void LED0_Task(void *pvParameters)
{
   while(1)
   {
       LED0=!LED0;
       vTaskDelay(1000/portTICK_RATE_MS);
   }
}

void LED1_Task(void *pvParameters)
{
   while(1)
   {
       LED1=!LED1;
       vTaskDelay(300/portTICK_RATE_MS);
   }
}

Only two LEDs are set up, flashing at different frequencies

6. To modify the startup file, first remove the read-only attribute of the startup file, otherwise it cannot be modified (the ones that have been removed are skipped)

I don't understand why this was changed. IMPORT and EXPORT are used to call internal reference files and external reference files respectively, which is similar to the meaning of extern in C language. Modify these places to make the function name the same as that in the port.c file, so that the freertos function can be called.

7. After finishing, I started compiling and correcting the errors. After completion, I downloaded it and saw that the two lights were flashing at different frequencies.

8. The above is almost complete. In addition, what should we do when an interrupt occurs? A protection mechanism is needed.

//External interrupt 2 service routine
void EXTI2_IRQHandler(void)
{
   taskENTER_CRITICAL();

   delay_us(1000);
   if(KEY2==0) //Key KEY2
   {
       BEEP=!BEEP;
   }    
   
   EXTI_ClearITPendingBit(EXTI_Line2); //Clear the interrupt flag on LINE2  
   taskEXIT_CRITICAL();
}

After testing, I found that based on the two lights, I wrote a KEY (using interrupt mode) to trigger the buzzer, which is also feasible.

I have understood the above, which is basically an introduction. Now I will mainly study UCOS-III. Although freertos is completely free and UCOS needs to be charged, most domestic companies still use UCOS as long as they do not export. It is better to follow the crowd to make a living. The way of thinking is similar.

I have summarized three stages of MCU time utilization for engineers.

In the first stage, as long as there is a delay, use the delay method and wait until you get hurt.

The second stage is to use the flag bit. I have always done this before. If I want to detect something in 10ms, I will set a main timer and constantly check whether it has been detected. If it has been detected, I will execute it. If it has not been detected, I will execute other things.

In the third stage, the operating system is used to save the time for the above queries. When a task is completed, it will automatically enter the next high-priority place. Although there is an idle mode, the efficiency is still very high when tasks are concentrated.


Keywords:STM32F103 Reference address:STM32F103 FreeRtos migration notes

Previous article:The influence of signal source characteristics on conversion results in STM32 ADC applications
Next article:STM32 Serial Port IAP Experiment Notes

Recommended ReadingLatest update time:2024-11-17 03:32

STM32 Getting Started - Marquee (Based on STM32F103ZET6)
I recently started learning stm32, and I really felt the difference between stm32 and 51, but there is also a connection. I always feel that the biggest difference between 32 and 51 is that before using a peripheral, you need to enable the clock of the peripheral (to reduce power consumption) and related configuration
[Microcontroller]
STM32 Getting Started - Marquee (Based on STM32F103ZET6)
STM32F103RBT6 Timer2 source code
Use of STM32F103RBT6 timer Timer2. Copy code Here is the timer timing: (1) The STM32 clock is: 72MHz, then each oscillation time is: T=1/f=1/72MHz, and 72M oscillation cycles are: 1S (2) Frequency division number: 72M/20000-1 Because starting from 0, it is actually: 72M/20000=3600, and the frequency division is how m
[Microcontroller]
STM32F103VCT6+W5500 UDP communication is successful
STM32F103VCT6+W5500 UDP communication is successful, and the dual-machine UDP communication between the computer and the W5500 module is realized. It should be noted here that after the UDP sets the target port, it must be connected with this set target port. Otherwise, the communication will not be possible. If UDP
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号