硬汉嵌入式论坛

 找回密码
 立即注册
查看: 237|回复: 2
收起左侧

[IAR] 记录个IAR程序下载后硬件复位不运行,必须断电复位才运行的问题

[复制链接]

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
117512
QQ
发表于 2025-7-26 14:37:05 | 显示全部楼层 |阅读模式
【问题测试】

有个F407的跑马灯的例子,是MDK和IAR两个版本,MDK版本的例子下载并复位后可以正常看到LED闪烁,而IAR的例子下进去后,不会闪烁。

使用TOOL的上位机内核寄存器监测工具测试发现,硬件复位后竟然还在调试状态,邪门了

下载 (2).png

下载 (3).png

下载 (4).png

必须断电复位,断电复位后正常了:

下载 (5).png

或者LUA命令控制退出调试状态

下载 (6).png

【问题解决】

起初以为是启动代码里面封装的函数__iar_program_start造成,将其注释掉,直接跳转到mian也不行

下载 (7).png

最后测试发现是半主模式配置问题,之前测试的8.50版本是半主模式配置 + fputc重新写,实际测试不会再执行半主操作了

下载 (8).png

进入IAR9,X后,这种配置不行了,必执行半主操作,导致运行起来了,还处于调试模式状态。使用9.X要关闭半主,并且重新定向串口



[C] 纯文本查看 复制代码
/*******************
 *
 * 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

}









回复

使用道具 举报

6

主题

37

回帖

55

积分

初级会员

积分
55
发表于 2025-7-26 16:56:35 | 显示全部楼层
学习了    硬汉点个大大的赞
回复

使用道具 举报

6

主题

33

回帖

51

积分

初级会员

积分
51
发表于 2025-7-26 19:50:16 | 显示全部楼层
这个太高端了,我几乎看不懂   我是搞应用开发的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-8-12 02:45 , Processed in 0.044249 second(s), 27 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表