1

我正在为我的 STM32F3 Discovery 板开发 C++ 并使用 std::deque 作为队列。在尝试调试我的代码后(直接在带有 ST-link 的设备上或在模拟器中),代码最终在断点处停止,甚至在 main() 中输入我的代码之前。但是, SystemInit() 配置板就好了..

我已经将此行为追溯到使用 push_back() (和 push_front),因为从代码中将其注释掉可以解决问题。通过disassmebly发现,使用后,执行在断点指令BKPT处停止,恢复执行后不再继续执行。该指令是 _sysopen() 调用的一部分,调用路径为:

__main -> __scatterload -> __scatterload_null -> __rt_entry -> __rt_lib_init -> __rt_lib_init_atexit_1 -> _initio -> freopen -> _sysopen

让我感兴趣的是对 的调用_initio,如果不使用 push_back 则缺少该调用,因为没有__rt_lib_init_atexit_1. 引入 push_back 还使代码大小从 10 kB 变为 34 kB。

这可能是一些错误配置的结果,还是我应该尝试另一个 IDE?我没主意了。

4

2 回答 2

3

I had the same problem. I learnt it has something to do with so called 'semihosting' and that I should build with my project file 'retarget.c' that contains definitions of the functions like '_sys_xxxx()' that are target specific driver level functions (many versions of 'retarget.c' are part of the Keil-MDK and also ca be found on web). So I did but then linker thrown errors similar to this:

Error: L6200E: Symbol _sys_open multiply defined (by arm_xxx_lib.o and retarget.o)
Error: L6200E: Symbol _sys_close multiply defined (by arm_xxx_lib.o and retarget.o)
...

I solved this by editing original 'retarget.c' so that functions defined in it will override the ones in Keil-MDK libraries. The new 'retarged.c' is here:

#include <stdio.h>
#include <rt_misc.h>

#pragma import(__use_no_semihosting_swi)

#include <rt_sys.h>

extern void $Super$$_sys_open(void);

FILEHANDLE $Sub$$_sys_open(const char *name, int openmode)
{
 return 1; /* everything goes to the same output */
}

extern void $Super$$_sys_close(void);
int $Sub$$_sys_close(FILEHANDLE fh)
{
 return 0;
}

extern void $Super$$_sys_write(void);
int $Sub$$_sys_write(FILEHANDLE fh, const unsigned char *buf,
              unsigned len, int mode)
{
 //your_device_write(buf, len);
 return 0;
}

extern void $Super$$_sys_read(void);
int $Sub$$_sys_read(FILEHANDLE fh, unsigned char *buf,
             unsigned len, int mode)
{
 return -1; /* not supported */
}

extern void $Super$$_ttywrch(void);
void $Sub$$_ttywrch(int ch)
{
 char c = ch;
 //your_device_write(&c, 1);
}

extern void $Super$$_sys_istty(void);
int $Sub$$_sys_istty(FILEHANDLE fh)
{
 return 0; /* buffered output */
}

extern void $Super$$_sys_seek(void);
int $Sub$$_sys_seek(FILEHANDLE fh, long pos)
{
 return -1; /* not supported */
}

extern void $Super$$_sys_flen(void);
long $Sub$$_sys_flen(FILEHANDLE fh)
{
 return -1; /* not supported */
}

extern void $Super$$_sys_exit(void);
long $Sub$$_sys_exit(FILEHANDLE fh)
{
 return -1; /* not supported */
}

With this version of 'retarget.c' linker was satisfied and my program run w/o problem. Maybe this will help you as well.

于 2013-12-25T22:06:22.887 回答
0

scale_buffer.empty()尝试在调用.back()and之前检查 scale_buffer 是否包含任何元素.front()push_back()

于 2013-07-09T14:29:20.783 回答