尝试返回指针数组会导致处理器硬故障

问题描述 投票:0回答:1

我有一些继承的代码正在移植到新设备(Cortex M0+ 内核英飞凌部分)。该代码在引导加载程序和应用程序之间具有共享 API。我正在尝试调试由此产生的硬故障。

在这个简化的代码片段中,调用了一个函数,该函数应该返回(我相信)包含多个指针的数组的地址。

//main.c

int main(void)
{
    bootloaderAPI_APIReallocateI2CBuffers(g_i2C_Buffer, g_i2c_BufferLength);
}

/***************************************************/

//i2c.c

/// Defines the type of the bootloader API function pointer.
typedef int (* BootloaderAPICall)(uint32_t*);    

/// The pointer to the bootloader API.
static BootloaderAPICall bootloaderAPI = NULL;

int bootloaderAPI_APIReallocateI2CBuffers(uint8_t* pBuf, uint32_t BufSize)
{
    uint32_t data[3];
    data[0] = BootloaderAPI_ReallocateI2CBuffers;
    data[1] = (uint32_t) pBuf;
    data[2] = BufSize;
    return bootloaderAPI(data);
}

当我点击 return 语句时,会生成硬故障。有一个硬故障处理程序用于记录硬故障的类型。在这种情况下,错误返回为“进入 ARM 模式”,但我承认我不知道这是什么意思。

有人知道为什么会产生这个错误吗?

c embedded cortex-m
1个回答
0
投票

“调用一个应该返回(我相信)数组地址的函数......”

我没有看到任何返回地址的函数。

“为什么会产生这个故障?”

我确实看到

return bootloaderAPI(data);
,就像
return (NULL)(data);
。 具有
NULL
值的函数指针在调用时会遇到问题,这是有道理的。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.