我有這樣的竟然是在微芯片的代碼中的錯誤問題:
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