記錄個IAR程序下載后硬件復位不運行,必須斷電復位才運行的問題
【問題測試】
有個F407的跑馬燈的例子,是MDK和IAR兩個版本,MDK版本的例子下載并復位后可以正常看到LED閃爍,而IAR的例子下進去后,不會閃爍。
使用TOOL的上位機內核寄存器監測工具測試發現,硬件復位后竟然還在調試狀態,邪門了



必須斷電復位,斷電復位后正常了:

或者LUA命令控制退出調試狀態

【問題解決】
起初以為是啟動代碼里面封裝的函數__iar_program_start造成,將其注釋掉,直接跳轉到mian也不行

最后測試發現是半主模式配置問題,之前測試的8.50版本是半主模式配置 + fputc重新寫,實際測試不會再執行半主操作了

進入IAR9,X后,這種配置不行了,必執行半主操作,導致運行起來了,還處于調試模式狀態。使用9.X要關閉半主,并且重新定向串口

/******************* * * Copyright 1998-2017 IAR Systems AB. * * This is a template implementation of the "__write" function used by * the standard library. Replace it with a system-specific * implementation. * * The "__write" function should output "size" number of bytes from * "buffer" in some application-specific way. It should return the * number of characters written, or _LLIO_ERROR on failure. * * If "buffer" is zero then __write should perform flushing of * internal buffers, if any. In this case "handle" can be -1 to * indicate that all handles should be flushed. * * The template implementation below assumes that the application * provides the function "MyLowLevelPutchar". It should return the * character written, or -1 on failure. * ********************/ #include <LowLevelIOInterface.h> #pragma module_name = "?__write" int MyLowLevelPutchar(int x) { comSendChar(COM1, x); return x; } /* * If the __write implementation uses internal buffering, uncomment * the following line to ensure that we are called with "buffer" as 0 * (i.e. flush) when the application terminates. */ size_t __write(int handle, const unsigned char * buffer, size_t size) { /* Remove the #if #endif pair to enable the implementation */ #if 1 size_t nChars = 0; if (buffer == 0) { /* * This means that we should flush internal buffers. Since we * don't we just return. (Remember, "handle" == -1 means that all * handles should be flushed.) */ return 0; } /* This template only writes to "standard out" and "standard err", * for all other file handles it returns failure. */ if (handle != _LLIO_STDOUT && handle != _LLIO_STDERR) { return _LLIO_ERROR; } for (/* Empty */; size != 0; --size) { if (MyLowLevelPutchar(*buffer++) < 0) { return _LLIO_ERROR; } ++nChars; } return nChars; #else /* Always return error code when implementation is disabled. */ return _LLIO_ERROR; #endif }
微信公眾號:armfly_com
安富萊論壇:www.armbbs.cn
安富萊淘寶:https://armfly.taobao.com

浙公網安備 33010602011771號