【发布时间】:2013-06-17 20:19:12
【问题描述】:
我正在进行的项目必须在程序运行之前测试 dsPIC30F 芯片的数据存储器。由于行业要求,我们不能使用 C 必须提供的任何预定义库。话虽如此,这是我测试 RAM 的方法:
Step 1 - Write the word 0xAAAA to a specific location in memory (defined by a LoopIndex added to the START_OF_RAM address)
Step 2 - increment LoopIndex
Step 3 - Repeat Steps 1-2 until LoopIndex + START_OF_RAM >= END_OF_RAM
Step 4 - Reset LoopIndex = 0
Step 5 - Read memory at LoopIndex+START_OF_RAM
Step 6 - If memory = 0xAAAA, continue, else throw RAM_FAULT_HANDLER
Step 7 - increment LoopIndex
Step 8 - Repeat Step 5 - 7 until LoopIndex + START_OF_RAM >= END_OF_RAM
现在,奇怪的是我可以单步执行代码,没问题。只要我的小指可以按 F8,它就会慢慢地循环遍历每个内存地址,但是当我尝试在第 4 步设置断点时,它会无缘无故地抛出一个随机的通用中断处理程序。我认为可能是因为我使用的for()可能超过了END_OF_RAM,但是我改变了条件的界限,它仍然不喜欢运行。
任何见解都会有所帮助。
void PerformRAMTest()
{
// Locals
uint32_t LoopIndex = 0;
uint16_t *AddressUnderTest;
uint32_t RAMvar = 0;
uint16_t i = 0;
// Loop through RAM and write the first pattern (0xAA) - from the beginning to the first RESERVED block
for(LoopIndex = 0x0000; LoopIndex < C_RAM_END_ADDRESS; LoopIndex+= 2)
{
AddressUnderTest = (uint32_t*)(C_RAM_START_ADDRESS + LoopIndex);
*AddressUnderTest = 0xAAAA;
}// end for
for(LoopIndex = 0x0000; LoopIndex < C_RAM_END_ADDRESS; LoopIndex += 2)
{
AddressUnderTest = (uint32_t*)(C_RAM_START_ADDRESS + LoopIndex);
if(*AddressUnderTest != 0xAAAA)
{
// If what was read does not equal what was written, log the
// RAM fault in NVM and call the RAMFaultHandler()
RAMFaultHandler();
}// end if
}
// Loop through RAM and write then verify the second pattern (0x55)
// - from the beginning to the first RESERVED block
// for(LoopIndex = C_RAM_START_ADDRESS; LoopIndex < C_RAM_END_ADDRESS; LoopIndex++)
// {
// AddressUnderTest = (uint32_t*)(C_RAM_START_ADDRESS + LoopIndex);
// *AddressUnderTest = 0x5555;
// if(*AddressUnderTest != 0x5555)
// {
// // If what was read does not equal what was written, log the
// // RAM fault in NVM and call the RAMFaultHandler()
// RAMFaultHandler();
// }
// }
}// end PerformRAMTest
可以看到第二遍测试写0x55。这是给我的原始实现,但它从来没有工作过(至少就调试/运行而言;用这种写入方法遇到相同的随机中断,然后在继续之前立即读取相同的地址)
更新:在几次 Clean&Builds 之后,代码现在将运行,直到它碰到堆栈指针 (WREG15),跳过,然后出错。以下是相关代码的新示例:
if(AddressUnderTest >= &SPLIMIT && AddressUnderTest <= SPLIMIT)
{
// if true, set the Loop Index to point to the end of the stack
LoopIndex = (uint16_t)SPLIMIT;
}
else if(AddressUnderTest == &SPLIMIT) // checkint to see if AddressUnderTest points directly to the stack [This works while the previous >= &SPLIMIT does not. It will increment into the stack, update, THEN say "oops, I just hit the stack" and error out.]
{
LoopIndex = &SPLIMIT;
}
else
{
*AddressUnderTest = 0xAAAA;
}
【问题讨论】:
-
您的程序和堆栈在内存中的哪个位置?
-
您不应该将
(C_RAM_START_ADDRESS + LoopIndex)转换为(uint16_t*)吗? -
@LeeDanielCrocker - 数据内存理论上应该从 0x0800 开始,程序内存开始,好吧,我们不知道。我们知道 W15 寄存器是堆栈指针,并且我们有一个变量 SPLIMIT,我尝试验证并启用 LoopIndex 跳过,但是,这也不起作用。
-
@Magtheridon96 - 从理论上讲,是的,但是,总 RAM 达到 0x17FFE,而且,这也是基于给我的代码。
-
那么,您可能在程序运行时覆盖了程序指令/数据/堆栈?这不能很好地结束。
标签: c testing embedded ram pic