current position:Home>Application of RT thread - use RT thread on stm32l051 (v. conclusion of wireless temperature and humidity sensor)
Application of RT thread - use RT thread on stm32l051 (v. conclusion of wireless temperature and humidity sensor)
2022-04-29 09:54:09【Due to Jin Chen】
Application articles - stay STM32L051 Upper use RT-Thread Chapter five , It is also the end of this application .
Transplant the key driver , Timer use plus .
Catalog
Preface
The sensor acquisition is basically completed , Serial port communication is transplanted and modified , In fact, as a single product, the sensor has been working normally , But if we have special circumstances when using the product , For example, you need to send a specific wireless message , Or set different working modes , We can make certain configuration through key operation .
So this article will transplant a key driver , Able to support keys Short press , Long press for a fixed time , The program executed periodically at the same time is changed to use timer to control .
This article is about 《RT-Thread Application articles — stay STM32L051 Upper use RT-Thread》 Conclusion
️
A simple application : Wireless temperature and humidity sensor
️
A chip with a small memory :STM32L051C8T6
️
A small and beautiful Internet of things operating system :RT-Thread
stay STM32L051C8 Upper use RT-Thread Apply a series of blog posts to connect :
RT-Thread Application articles — stay STM32L051 Upper use RT-Thread ( One 、 Wireless temperature and humidity sensor And New projects )
RT-Thread Application articles — stay STM32L051 Upper use RT-Thread ( Two 、 Wireless temperature and humidity sensor And CubeMX To configure )
RT-Thread Application articles — stay STM32L051 Upper use RT-Thread ( 3、 ... and 、 Wireless temperature and humidity sensor And I2C Communications )
RT-Thread Application articles — stay STM32L051 Upper use RT-Thread ( Four 、 Wireless temperature and humidity sensor And A serial port communication )
One 、 Key operation
In the preliminary test framework , I used a simple key handling method , Here is also a test backup of the source code :
static void key_thread_entry(void *par){
while(1){
if(key1_read == 0){
rt_thread_mdelay(10); // To shake
if(key1_read == 0){
// Press the key ,do something
while(key1_read == 0){
rt_thread_mdelay(10);}
}
}
if(key2_read == 0){
rt_thread_mdelay(10); // To shake
if(key2_read == 0){
// Press the key ,do something
while(key2_read == 0){
rt_thread_mdelay(10);}
}
}
rt_thread_mdelay(1);
}
}
But in practice , If you want to achieve long press , Combine in such a way , Still need a suitable key driver .
1.1 Key driven migration
Key driven It's the one I've been using , I uploaded it before my blog ,.c.h The files are open source :
Several practical key drivers (STM32、51 All applicable )
The same as usual , Put the file under our own driver folder , Then right-click , Sync scons Configure to project :
Because the source code of this driver is given to , Transplantation and replacement are not troublesome , So take a simple look :
1.2 Key test
I also said in my blog about how to use the buttons , In this application, only 3 Middle button mode :
Let's look directly at the test results , The key is normal :
Key transplantation succeeded , Because all of our keystroke calls use the start thread that has been created , Therefore, compared with the previous additional memory occupation, there is no , There is only one global variable Timer21_count
, Here's the picture :
Details : unsigned int A few bytes may be different in different compilers or platforms , We just need a simple test :
Two 、 Timer operation
Although the key also uses a timer , But that timer is specially used for key driver , We also initialized a timing time at the beginning 1S Timer for , It was tested at first .
When using bare metal , It takes a certain period of time to carry out a certain work , We can only use timers , And used the operating system , The effect can also be achieved by directly using the delay function of the operating system in a separate thread .
In general applications , When the timing is not so strict , It can be used directly rt_thread_mdelay
, For example, the original cycle processing :
But more complex applications , All use rt_thread_mdelay
, It's inconvenient to manage more threads , If you use a timer with a semaphore ( In bare metal, it's a global variable ) That's a more standardized way .
2.1 Timer logic added
We need to create a counting global variable for the timer , Then, at a certain time, notify the thread that needs to execute the task , This informs us to create a new semaphore implementation ( Although notifications can also use global variables ), But now that it's used RT-Thread , Just put IPC The mechanism works , This ensures good habits and lays a good foundation for bigger applications in the future .
Our operation is shown in the figure below :
So our original cycle processing code is changed to the following :
2.2 Timer test
The test is nothing , The message received by serial communication is also normal , The keys and timers changed today are also normal .
Finally, all functions and results are normal :
3、 ... and 、 Always pay attention to accounting RAM size
Today's work is finished , This application is over , Finally, let's take a look at the occupation RAM Size :
Final procedure , When running, it needs to occupy RAM Size : 7456 byte , Our chips RAM:8192 byte .
The final size description
from the beginning , Because we use it on a chip with small memory RT-Thread , So every time the code is changed, the blogger will record the memory usage .
The final program we need to use is recorded above RAM The size is 7456 byte , In fact, there is still some optimization space for the memory occupation of this application , For example, the main thread 2K You can still reduce it a little , Keystroke threads don't actually need 512 Bytes and so on ...
But because this application is really simple , And the memory didn't overflow , Therefore, there is no bottleneck and no special effort to deal with the appropriate size of each thread .
In fact, in the blog , Bloggers often explain some details that affect memory , I hope all my friends who have read my blog will understand .
Conclusion
️ Bloggers hope that everyone can master the memory of their own programs .️
Master your own memory , First of all, we should understand how data is stored on the chip .
Using the operating system , Also understand the relationship between task stack and system stack . For each thread , You need to know which operations need to occupy memory .
For basic programming , You have to understand Different locations of modifier variables .
In fact, all these bloggers have explained in their blog posts , I believe that the little partners who pay attention to the blogger will gain something !
️
A simple application : Wireless temperature and humidity sensor
️
A chip with a small memory :STM32L051C8T6
️
A small and beautiful Internet of things operating system :RT-Thread
Okay , As of this article , We 《RT-Thread Application articles — stay STM32L051 Upper use RT-Thread》 Even if the series is over .
I hope you can give me more support , Your smile !
thank you !
copyright notice
author[Due to Jin Chen],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204290810437192.html
The sidebar is recommended
guess what you like
Ajax learning notes
Relearn react (1) - recognize the life cycle
Small problems encountered by react usereducer and Solutions
CSS realizes the square of adaptive screen width
Nginx + ModSecurity setup
Bootstrap web job
bootstrap
Swoft 2. X Foundation (HTTP, database, redis)
Docker actual combat case 2: nginx load balancing
Vue basic syntax
Random recommended
- Go basic syntax 3 (socket, httpserver)
- Nginx configures HTTPS and calls http
- Nginx parsing vulnerability
- How can the backend package Vue projects quickly
- Netty configures WSS protocol access through nginx (Practical)
- Total permutation problem_ Not containing the same element and containing the same element_ Leetcode46_ Leetcode47_ Backtracking solution + java code
- How to upload and download files using Axios in nodejs
- Vue excel file upload
- CondaHTTPError: HTTP 000 CONNECTION FAILED for url < https://conda.anaconda.org/fastai/noarch/repodat
- Multi function environmental monitoring pole scheme based on wireless gateway
- JPS in Hadoop, but http://hadoop01:50070/ How to solve the problem if there is no interface? 500ha70 cluster can't be accessed?
- Tool class for obtaining specific information in HTTP request
- UAV project tracking record 65 - wireless transceiver module circuit
- UAV project tracking record 76 - wireless transceiver module circuit
- Basic concept of angular velocity
- Front end login password encryption and decryption
- Vue parent-child component mutual transmission and intermodulation
- Vue nested loop array, select one of them and add the selected style
- The Vue seamless scroll list scrolls automatically
- Vue line graph moves dynamically to the right
- Install and configure nginx in Linux Environment
- Vue dynamically binds attributes and dynamically obtains attribute values
- Summary method of Vue value in key pair mapping
- Vue simply realizes the addition, deletion and modification of each tab page without route jump
- Vue time control common processing
- Vue validation array
- Simple and easy to let you know what AJAX is, even if you are a little white, a rookie can understand it!
- Receive the JSON string from the front end, and summarize the methods of parsing and value taking at the back end
- Solution: httpmessagenotreadableexception: JSON parse error: invalid UTF-8
- Vuetify: install vuetify from scratch
- Install CSS from tailwind
- Ubuntu 16 wireless network card model query and driver installation, Lenovo g400 bcm43142 network card WiFi
- Some color knowledge to understand at the front end
- Functional programming of front-end development
- A front-end interview question -- implementing an encapsulated Ajax device (promise version)
- Dynamic components of angular
- Front end written test pit -- JS implicit conversion
- Shallow understanding of HTTP
- React style modification background invalid
- Finding the k-th small element of ordered matrix (dichotomy idea)