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.
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
- Popular Resources
- Popular amplifiers
- The STM32 MCU drives the BMP280 absolute pressure sensor program and has been debugged
- DigiKey \"Smart Manufacturing, Non-stop Happiness\" Creative Competition - Small Weather Station - STM32F103 Sensor Driver Code
- LwIP application development practical guide: based on STM32
- FreeRTOS kernel implementation and application development practical guide: based on STM32
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- Do you know the future star material in the RF field?
- There is no virtual serial port when the STM32F0discovery development board is plugged into the computer?
- [National Technology N32WB452 Review] +Bootloader-IAP Upgrade
- CC1310 on-chip firmware upgrade project compilation
- AD2018 schematic wiring color change
- A review of technical articles in 2018
- Design of NB Iot small weather station based on GD32E231 and NB IOT communication module
- Enthusiasts seek guidance from people who are destined to help them get started with microcontrollers
- [Sipeed LicheeRV 86 Panel Review] 4-Transplanting lvgl-Adding touch control
- Application of Zigbee in .Net Micro Framework System