我有这样的竟然是在微芯片的代码中的错误问题:
sprintf(foo_str, "%f", NAN)
会(并将)抛出一个总线错误异常......(错误在他们的“_fconvert”函数中)调试/识别我修改了我的异常处理程序来打印出来(产品已经有一个ASCII UART连接到它的主机)什么是例外,违规地址是什么,然后它会自行重置。复位部分很难找到,它位于PIC32MX的许多Microchip文档之一中。这取代了和谐(1.10)生成的“_general_exception_handler()”,不知道这是否与和谐2.x的兼容
void _general_exception_handler (void)
{
char fail_str[96];
/* Mask off Mask of the ExcCode Field from the Cause Register
Refer to the MIPs Software User's manual */
_excep_code = (_CP0_GET_CAUSE() & 0x0000007C) >> 2;
_excep_addr = _CP0_GET_EPC();
_cause_str = cause[_excep_code];
sprintf(fail_str, "ERROR,%s,cause=%d,addr=%x,",
_cause_str, _excep_code, _excep_addr);
//"send_my_string" copies the string to the ring buffer
send_my_string(fail_str);
//"tx_chars_from_ring_buffer" returns # of chars left in the ring buffer
while(tx_chars_from_ring_buffer());
//queue up another set of chars equal to the length of the UART FIFO
sprintf(fail_str, "\r\r\r\r\r\r\r\r\r\r");
send_my_string(fail_str);
while(tx_chars_from_ring_buffer());
#if (__DEBUG)
while (1)
{
SYS_DEBUG_BreakPoint();
}
#endif
/* The following code illustrates a software Reset */
// assume interrupts are disabled
// assume the DMA controller is suspended
// assume the device is locked
/* perform a system unlock sequence */
// starting critical sequence
SYSKEY = 0x00000000; //write invalid key to force lock
SYSKEY = 0xAA996655; //write key1 to SYSKEY
SYSKEY = 0x556699AA; //write key2 to SYSKEY
// OSCCON is now unlocked
/* set SWRST bit to arm reset */
RSWRSTSET = 1;
/* read RSWRST register to trigger reset */
_excep_code = RSWRST;
/* prevent any unwanted code execution until reset occurs*/
while(1);
}
我没有与它玩了一下,以确保该消息得到了直通输出FIFO在复位被调用之前...
软件不知道。硬件知道。 –
可以将初始化为NULL的指针'static Log_t * pLog = NULL;'引起异常错误,因为它的地址为NULL。例如,如果正在使用'pLog'来从之前读取数据,那么它将被分配一个VALID ADDRESS。由于NULL意味着内存的开始,如果你试图访问禁止部分,它会抛出异常错误? – newb7777
是的。基本上它是硬件本身检测无效条件,比如访问保留的内存位置。您可以查看MCU的存储器映射图,以了解这些保留段的位置。处理器知道调用该异常处理程序,因为当硬件检测到异常时,异常会“向量化”到特定地址。实际上,它意味着如果出现异常,请在此指定地址执行代码,编译器/链接器负责其余部分。更多信息:http://microchipdeveloper.com/faq:82 – mindcruzer