This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] RM48L952:我想读取堆栈指针、但是 i'm 收到错误信息。

Guru**** 2513185 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1451299/rm48l952-i-want-to-read-the-stack-pointer-but-i-m-getting-an-error

器件型号: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 */

您好!

我在尝试读取代码中的堆栈指针时遇到了使用括号错误的问题。

是否有人能够解释为什么会发生此错误?

如果有任何帮助解决此问题的见解或建议、我将不胜感激。

感谢您投入宝贵的时间给予大力帮助!

此致、

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Kim、

    对延迟响应深表歉意。

    我已经在与我们的编译器团队讨论此问题、并将尽快尝试提供更新。

    ——
    谢谢、此致、
    Jagadish。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    假设您使用的是 TI Arm 编译器(简称为 armcl )、而不是 TI Arm Clang 编译器(简称为 tiarmclang )。  函数 get_sp 在第一个帖子中有一个 _asm 使用所谓的 GCC 语法的语句。  遗憾的是、TI Arm 编译器不支持此语法。   

    作为一种变通办法、请考虑...

    #include <stdint.h>
    
    uintptr_t get_sp()
    {
        int64_t local_variable;
    
        return (uintptr_t)&local_variable + sizeof(local_variable);
    }

    这是一个丑陋的黑客。  生成的代码会更大且更慢一些。  但计算结果相同。

    谢谢。此致、

    -George.