当前位置:网站首页>On the problem that the while loop condition in keil does not hold but cannot jump out
On the problem that the while loop condition in keil does not hold but cannot jump out
2022-06-11 18:20:00 【Tristan Tsai】
As shown in the figure below while loop
Among variables As defined below
static uint8_t nb_uart_tx_done = 0;And assign a value to it in the interrupt 1, It is found that when the interrupt has been assigned , This while I can't jump out , The following are the variables observed by the simulation and while Do not jump out of the situation

Looking up the data, we found that this is the case :
When entering the cycle , It's actually going to be A Loaded from memory into registers to run , In the whole cycle ,A This variable is just reading the value in the register .
And when entering the interrupt , Interrupt will be loaded from memory A To register , After modification, it is stored in memory , Then exit the interrupt , Back in the loop . But it is used in the cycle at this time A No Reload from memory A This variable , So it's always in the loop .
resolvent :
nb_uart_tx_done Add... Before the definition of variables volatile, Understand self search in detail volatile Usage of .
static volatile uint8_t nb_uart_tx_done = 0; In this way, there will be no previous problem of loading into registers
As a general rule ,volatile Used in the following places :
1、 The variables modified in interrupt service program for other programs to detect need to add volatile;
2、 In a multitasking environment, the shared flag among tasks should be marked with volatile;
3、 Memory mapped hardware registers are usually added with volatile explain , Because every time you read and write it, it may have a different meaning ; in addition , In the above cases, data integrity is often considered at the same time ( Several interrelated symbols are interrupted and rewritten in the middle of reading ), stay 1 It can be realized by closing the middle of the line ,2 Task scheduling can be disabled in ,3 We can only rely on the good design of hardware .
边栏推荐
- Database lock and transaction isolation level
- [golang] leetcode - 292 Nim games (Mathematics)
- Experiment 3: design and verify all operations represented by linear table sequence on the computer
- [Golang]力扣Leetcode - 349. 两个数组的交集(哈希表)
- File class learning
- [practical Script] obtain the line number of a file, and then delete the file content.
- Some problems of DC-DC bootstrap capacitor
- SISO Decoder for Repetition(补充章节4)
- Nocturnal installs APK and BP agent
- 力扣34在排序数组中查找元素的第一个和最后一个位置
猜你喜欢

Système d'information sur les menaces à la sécurité des réseaux
![[c language] compress strings and add markup characters](/img/b7/f7918f3ee0c409faffc70addd5ee65.png)
[c language] compress strings and add markup characters

使用mysql判断日期是星期几
![[C语言]限制查找次数,输出次数内查找到的最大值](/img/e6/cbb8dd54b49ade453251a70c8455e8.png)
[C语言]限制查找次数,输出次数内查找到的最大值
![Spring 2021 daily question [week7 not finished]](/img/93/582608e18bf6d78c552fa9478cdd77.jpg)
Spring 2021 daily question [week7 not finished]

Several commands related to domain name

SISO Decoder for SPC (补充章节1)

ctf入门

How to learn and self-study
![[C语言]压缩字符串并添加标记字符](/img/b7/f7918f3ee0c409faffc70addd5ee65.png)
[C语言]压缩字符串并添加标记字符
随机推荐
Common operations of Visio
[untitled]
General terms in security field
力扣31 下一个排列
SISO Decoder for a General (n, N - 1) SPC Code (Supplementary section 3)
VIM common commands
Use egg Js+mongodb simple implementation of curdapi
SQL语句当查询条件为空时默认查询全部数据,不为空是则按照条件进行查询
Système d'information sur les menaces à la sécurité des réseaux
[c language] limit the number of searches and output the maximum value found in the number of internal searches
[c language] output the average score and the student data below or equal to the average score with the structure
Global and Chinese market of web content management software 2022-2028: Research Report on technology, participants, trends, market size and share
网络安全威胁情报体系
[MapReduce] a complete Mr program case teaches you how to package and run with idea
Spring 2021 daily question [end of week4]
Hwang
New work of "the father of LSTM": a new method towards self correcting neural network
高并发架构设计
Why OKR needs to be challenging
Network Security Threat Intelligence System