阿里兄 发表于 2020-3-18 18:14:25

进入调试模式,发现代码停在 "BKPT 0xAB" 的解决办法

进入调试模式,发现代码停在 "BKPT 0xAB" 的解决办法


问题1(与编译软件无关):在程序中加入printf语句实现串口输出,但未写重定向函数fputc,出现编译无任何警号和错误直接下载无法运行,软件仿真可以运行至MAIN函数,硬件仿真在汇编窗口看到停留在“0x0800XXXX BEAB BKPT 0xAB //进入调试模式”处无法继续运行。


解决办法:编写fputc函数如下:
int fputc(int ch, FILE *f)
{
          USART_SendData(USART1, (uint8_t) ch);
      while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
      {}
      return ch;
}

问题2(与编译软件有关):重定向函数fputc编写无误,使用的是MDK4.22-3.40之间的编译环境,未使用微库,即MiclroLIB,因printf()之类的函数,使用了半主机模式。使用微库的话,不会使用半主机模式,所以就没有问题。
解决办法:在option for target->target 对话框中,选择Use MiclroLIB,重新编译程序即可。

问题3:重定向函数fputc编写无误,不用微库,即MiclroLIB,依然可以使用printf

解决办法:
在程序中加入如下语句:
#pragma import(__use_no_semihosting)
_sys_exit(int x)
{
x = x;
}
struct __FILE
{
int handle;
/* Whatever you require here. If the only file you are using is */
/* standard output using printf() for debugging, no file handling */
/* is required. */
};
/* FILE is typedef’ d in stdio.h. */
FILE __stdout;

页: [1]
查看完整版本: 进入调试模式,发现代码停在 "BKPT 0xAB" 的解决办法