Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix: an interrupt may return to the end of function "rt_hw_context_switch_to" #5274

Closed
wants to merge 2 commits into from

Conversation

hwang1024
Copy link

[
Description:
In cortex-M uC, there is a tail-chain mechanism to fasen interrupt/exception response,
from simulation tool: KEIL V4, it shows that a mismatch of stack restore occours if: an interrupt/exception happens at the moment that returning from previous interrupt, and MSP will be restored instead of task's PSP, and it'll cause a return to the end of function: rt_hw_context_switch_to, causes a hard fault in the end.

Purpose:
To solve the issue in case an interrupt service is tail-chained by another interrupt, and return back to function rt_hw_context_switch_to

Tested Enviroment:
KEIL V4.03 with similator / STM32F103RC, with project "rt-thread-v4.0.2\rt-thread\bsp\stm32\stm32f103-yf-ufun\project.uvproj"
1> debug(simulator) => run => set breakpoint at end of function "void SysTick_Handler(void)"
2> peripherals => core peripherals => NVIC (nested vectored...) =>index 53 USART1 (Set pending bit manually)
3> run & check...
]

以下的内容不应该在提交PR时的message修改,修改下述message,PR会被直接关闭。请在提交PR后,浏览器查看PR并对以下检查项逐项check,没问题后逐条在页面上打钩。
The following content must not be changed in the submitted PR message. Otherwise, the PR will be closed immediately. After submitted PR, please use a web browser to visit PR, and check items one by one, and ticked them if no problem.

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 本拉取/合并请求代码是高质量的 Code in this PR is of high quality
  • 本拉取/合并使用formatting等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification

@CLAassistant
Copy link

CLAassistant commented Nov 13, 2021

CLA assistant check
All committers have signed the CLA.

@BernardXiong BernardXiong added the Status: waiting for test Waiting test for this PR. label Nov 15, 2021
@BernardXiong BernardXiong self-assigned this Nov 15, 2021
@mysterywolf
Copy link
Member

related:
其他的Cortex M4 M7 M0是否也存在同样的问题?
GCC IAR下是否存在同样的问题?
#4728 此pr也提到了一些context_switch_to函数的问题。

@cndabai
Copy link
Contributor

cndabai commented Nov 17, 2021

楼主指的是在返回task时,还是在使用MSP吗?可以详细讲一下复现流程嘛,这边按照上面步骤一直没有复现

@hwang1024
Copy link
Author

可能和KEIL 版本有关系, 用uV4.03版本模拟仿真每次都能复现,不用RTOS只使用MSP就没问题,会让开发者觉得系统不稳定

@hwang1024
Copy link
Author

step1
step2
step3
step4
uVversion

@mysterywolf
Copy link
Member

mysterywolf commented Nov 17, 2021

@cndabai 用Keil5重复上述同样操作,不用keil4,测试例程可以选择stm32-blue-pill,这个bsp已经设置好仿真参数了,开箱就能仿真。

@cndabai
Copy link
Contributor

cndabai commented Nov 18, 2021

keil5并没有复现,这边LR是0xFFFFFFFD,正常,返回后是PSP
一会下个keil4再试一下
楼主了解这个BUG产生的原因吗?有没有在其他环境下试一下,是模拟器问题吗
image

@mysterywolf
Copy link
Member

如果Keil5没有 但是Keil4出现,高度怀疑是keil自己的原因。

@mysterywolf
Copy link
Member

@hwang1024 建议升级到keil5再尝试复现一下,如果是keil本身的bug,我们是没有办法替他的bug来修改程序的

@cndabai
Copy link
Contributor

cndabai commented Nov 18, 2021

keil4.10也没遇到。不知道是不是姿势不对
image
image
image

@mysterywolf mysterywolf added the discussion This PR/issue needs to be discussed later label Nov 18, 2021
@mysterywolf mysterywolf removed the request for review from Guozhanxin November 19, 2021 16:37
@Guozhanxin
Copy link
Member

If it can't be reproduced, then temporarily close the current pr?

@Guozhanxin Guozhanxin added -1 No vote and removed Status: waiting for test Waiting test for this PR. labels Nov 29, 2021
@mysterywolf
Copy link
Member

mysterywolf commented Nov 29, 2021

如果keil5复现不出来这个问题的话,那么八成这个问题是由于keil4自己的问题导致的,我们的代码不会对keil4自己的问题负责。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-1 No vote discussion This PR/issue needs to be discussed later
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants