tag 标签: stack

相关博文
  • 热度 21
    2013-3-10 12:08
    1790 次阅读|
    0 个评论
    Many people may have encountered problems like this: Even though there isn't a while/for loop in the program written, the MCU would run in a dead loop (not responding until reset) eventually... If we use debug mode to run the program for STM32, we would see the MCU would finally go into the infinite loop in HardFault_Handler() ISR. Why is this event happening? The problem may occur when there is large array of variables declared like buffer in functions . A program is more likely to get this problem when the large variable is in a recursive function. To solve this problem, we have to know what caused the error. When non-static variables are declared in functions and there is an interrupt/function call they would be stored in the stack area. When the function call/ISR finishes, the variables would be loaded again from the stack area. If the variable is of large size, the stack may be full and cannot store the variables, causing the MCU to fail to execute anymore. There are several ways to solve the problem. The easiest way is to increase the default stack size : This method is not only working with STM32, but also other MCUs like LPC213x/ADuC702x (ARM7). Make sure that the startup file (e.g. startup_stm32f1xx_xx.s) is not shared with other projects to prevent affecting other projects. To do this, save the startup file as another file and replace the current startup file by the newly saved one. Fig. 1 The standard startup file of STM32 Medium Density Device Open the startup file and save it to the project folder. Then remove the original startup file and add the one just saved in the project folder. Fig.2 Removing the original startup file After adding the file, the icon will not have a 'key' on it indicating the file is NOT read-only. Fig.3 The startup file added, icon without a key Everything is ready, then open the startup file by double-clicking on the item. Then you may see the trick on the stack size: Fig.4 The stack size configuration in the startup file   Increasing the stack size like modifying it to 0x00000800 or 0x00000F00 may help to solve the problem. The MCU would divide more RAM space for the stack. The same technique also applies to other MCUs, with modifying the corresponding startup file. Fig.5 Stack size config section of startup file of NXP's LPC2000 series MCU (ARM7) However, there is a drawback - the area in the RAM for storing variables would be decreased - less variables could be declared (we would see the error during compilation)... But if the MCU has loads of RAM space, this method should be the best to the problem. Another method is to use global variables for storing large variables . This would not only help to reduce the stack loading, but also reduce the CPU's time to store the variables into the stack when interrupt/function call takes place. One solution is to use static variables , so the variables would not be stored to the stack. However, this method very probably CANNOT be applied to variables declared in recursive functions since each call to this function would modify the one and only one variable and may cause unexpected error (logic error occurred then ).
相关资源
  • 所需E币: 0
    时间: 2020-8-8 18:24
    大小: 178.04KB
    上传者: kaidi2003
    ONSemiSoftwareStackReadinessOfLC823450.PDF
  • 所需E币: 5
    时间: 2019-12-26 10:33
    大小: 47.68KB
    上传者: 16245458_qq.com
    vxWorksNetworkStack介绍……
  • 所需E币: 5
    时间: 2019-12-25 15:17
    大小: 719.19KB
    上传者: 微风DS
    YISAI嵌入式操作系统资料……
  • 所需E币: 3
    时间: 2019-12-24 23:14
    大小: 365.07KB
    上传者: wsu_w_hotmail.com
    本应用笔记介绍移植UIP(轻量级的TCP/IP协议栈)到LPC1700系列的步骤和细节。有一个简单的Web服务器演示。AN10845PortinguIP1.0toLPC1700Rev.01―30June2009ApplicationnoteDocumentinformationInfoContentKeywordsuIP,TCP/IPStack,LPC1700AbstractThisapplicationnotedescribesthestepsanddetailsofportinguIP(alight-weightTCP/IPStack)toLPC1700.Asimplewebserverisimplementedasademo.NXPSemiconductorsAN10845PortinguIP1.0toLPC1700RevisionhistoryRevDateDescription0120090630Initialversion.ContactinformationFo……
  • 所需E币: 4
    时间: 2019-12-24 23:13
    大小: 466.22KB
    上传者: 978461154_qq
    本应用笔记介绍UIP(轻量级的TCP/IP协议栈)移植到LPC23xx/24xx的步骤和细节。有一个简单的Web服务器演示。AN10799PortinguIP1.0toLPC23xx/24xxRev.02―15June2009ApplicationnoteDocumentinformationInfoContentKeywordsuIP,TCP/IPStack,LPC23xx,LPC24xxAbstractThisapplicationnotedescribesthestepsanddetailsofportinguIP(alight-weightTCP/IPStack)toLPC23xx/24xx.Asimplewebserverisimplementedasademo.NXPSemiconductorsAN10799PortinguIP1.0toLPC23xx/24xxRevisionhistoryRevDateDescription0220090615Secondversion,minor……
  • 所需E币: 3
    时间: 2019-12-24 23:11
    大小: 299.77KB
    上传者: 微风DS
    将LPC2000设备作为应用目标提供初始化步骤,降低功耗的提示以及代码示例AN10404Initializationcode/hintsfortheLPC2000familyRev.01―1November2005ApplicationnoteDocumentinformationInfoContentKeywordsARMassemblycode,Initialization,Clock,Stack,powerconsumptionAbstractProvidesinitializationsteps,hintsforreducingpowerconsumptionandcodeexamplesthatwouldgettheLPC2000devicereadyforthetargetapplicationPhilipsSemiconductorsAN10404Initializationcode/hintsfortheLPC2000familyRevisionhistoryRevDateDescription……
  • 所需E币: 4
    时间: 2019-12-24 23:07
    大小: 190.23KB
    上传者: quw431979_163.com
    本应用笔记讨论了当在一个项目中使用LPC的TCP/IP协议栈NicheLite应用细节。也讨论了包括内存管理,栈操作和定制方面内容。AN10775NicheLiteforLPCimplementationnotesRev.02―13July2009ApplicationnoteDocumentinformationInfoContentKeywordsNetwork,Ethernet,TCP/IPStack,LPC2400,LPC3250AbstractThisapplicationnotediscussesimplementationdetailswhenusingtheNicheLiteforLPCTCP/IPstackinaproject.Aspectsdiscussedincludememorymanagement,stackoperationandcustomization.NXPSemiconductorsAN10775NicheLiteforLPCimplementationnotesRevisionhistoryRevDate……
  • 所需E币: 3
    时间: 2019-12-24 23:07
    大小: 469.33KB
    上传者: givh79_163.com
    LPC3250入门NicheLite指导。AN10846GettingstartedwithNicheLiteforLPC3250Rev.01―1July2009ApplicationnoteDocumentinformationInfoContentKeywordsLPC3250,NicheLite,Ethernet,TCP/IPStack,WebServer,TFTPAbstractAguidetogettingstartedwithNicheLiteforLPC3250.NXPSemiconductorsAN10846GettingstartedwithNicheLiteforLPC3250RevisionhistoryRevDateDescription0120090701Initialversion.ContactinformationForadditionalinformatio……
  • 所需E币: 4
    时间: 2020-1-13 09:55
    大小: 59KB
    上传者: rdg1993
    ControllingRadiatedEMIThroughPCBStackControllingRadiatedEMIThroughPCBStack-up(09/08/00,12:33p.m.ET)ByRickHartley,L-3Communications,AvionicSystemsThere'smorethanonewaytoskinacatandevenmorewaystobattleEMI,beginningatoneofthemostbasiclevelsofPCBdesign.ClearlythereareanumberofcircuitandPCBdesigntechniquesthatdesignersandengineersneedtomasterinordertocontrolhigh-frequency,radiatedEMI.It'sfairlywellunderstoodthatcircuitboardstack-upcanplayamajorroleintheefforttocontrolEMI.Agoodstack-uphelpstocontainelectricandmagneticfieldsandisaverystrongaidintheefforttobypass/decouplethepowerbus.Thisarticlewillexaminetheseissuesanddetailseveralboardstack-upsdesignedtoaccomplishthesegoals.ThepowerbusWhenanIC……