请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:RM48L952 工具与软件:
/** @file sys_main.c
* @brief Application main file
* @date 11-Dec-2018
* @version 04.07.01
*
* This file contains an empty main function,
* which can be used for the application.
*/
/*
* Copyright (C) 2009-2018 Texas Instruments Incorporated - www.ti.com
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* USER CODE BEGIN (0) */
//#include <stdio.h>
/* USER CODE END */
/* Include Files */
#include "sys_common.h"
/* USER CODE BEGIN (1) */
/* USER CODE END */
/** @fn void main(void)
* @brief Application main function
* @note This function is empty by default.
*
* This function is called after startup.
* The user can use this function to implement the application.
*/
/* USER CODE BEGIN (2) */
#define STACK_GUARD_VALUE 0xBEEFBEEF
#define STACK_GUARD_ADDRESS 0x08000000
#define USER_STACK_BASE_ADDRESS 0x08000000
#define NUMBER_OF_VARIABLES 500
void test01(void);
void test02(void);
void test03(void);
void test04(void);
void test05(void);
void test06(void);
void test07(void);
void InitStackGuard(void);
void CheckStackGuard(void);
void CheckStackPointer(void);
unsigned int get_sp(void);
uint8_t gucUserStackOverflowFlag = 0U;
uint32_t gucSP;
/* USER CODE END */
int main(void)
{
/* USER CODE BEGIN (3) */
InitStackGuard();
while(1U)
{
test01();
}
/* USER CODE END */
}
/* USER CODE BEGIN (4) */
void test01(void)
{
int32_t i;
uint32_t uiTest01[NUMBER_OF_VARIABLES];
//CheckStackGuard();
CheckStackPointer();
for (i = 0; i < NUMBER_OF_VARIABLES; i++)
{
uiTest01[i] = i;
}
test02();
}
void test02(void)
{
//CheckStackGuard();
CheckStackPointer();
uint32_t uiTest02[4] = {0,};
}
// Stack Guard
void InitStackGuard(void)
{
*(volatile uint32_t *)STACK_GUARD_ADDRESS = STACK_GUARD_VALUE;
}
void CheckStackGuard(void)
{
if (*(volatile uint32_t *)STACK_GUARD_ADDRESS != STACK_GUARD_VALUE)
{
gucUserStackOverflowFlag = 1U;
//printf("Stack overflow detected! Guard value corrupted.\n");
while (1U)
{
;// 무한 루프 (오류 처리)
}
}
}
//CheckStackPointer
void CheckStackPointer(void)
{
if (gucSP < USER_STACK_BASE_ADDRESS)
{
gucUserStackOverflowFlag = 1U;
while (1U)
{
;// 무한 루프 (오류 처리)
}
}
}
unsigned int get_sp(void)
{
unsigned int sp;
__asm("MOV %0, SP" : "=r"(sp)); // SP 값을 sp 변수에 저장
return sp;
}
/* USER CODE END */


您好!
我在尝试读取代码中的堆栈指针时遇到了使用括号错误的问题。
是否有人能够解释为什么会发生此错误?
如果有任何帮助解决此问题的见解或建议、我将不胜感激。
感谢您投入宝贵的时间给予大力帮助!
此致、