首页 > 其他 > 详细

CUBEMX生成RT_Thread工程后报错修改

时间:2021-05-07 00:13:32      阅读:49      评论:0      收藏:0      [点我收藏+]

一、生成工程后修改

1.在stm32f4xx_it.c文件里面删除如下程序

/**
  * @brief This function handles Hard fault interrupt.
  */
void HardFault_Handler(void)
{
  /* USER CODE BEGIN HardFault_IRQn 0 */

  /* USER CODE END HardFault_IRQn 0 */
  while (1)
  {
    /* USER CODE BEGIN W1_HardFault_IRQn 0 */
    /* USER CODE END W1_HardFault_IRQn 0 */
  }
}

 2.加入下面两句

/* USER CODE BEGIN PTD */
extern void rt_exit_critical(void);
extern void rt_enter_critical(void);
/* USER CODE END PTD */

 3.加入串口打印函数

/* USER CODE BEGIN 4 */
//重映射串口1到rt_kprintf
void rt_hw_console_output(const char *str)
{
    /* empty console output */
	
	rt_enter_critical();

	while(*str!=‘\0‘)
	{
		if(*str==‘\n‘)
		{
			USART1->DR = (uint8_t)  ‘\r‘; 
			while((USART1->SR&0X40)==0);
		}
		USART1->DR =*str++;
		while((USART1->SR&0X40)==0);	
	}

	rt_exit_critical();
}

/* USER CODE END 4 */

 4.编译后还有一个错误在shell文件里面

linking...
RT_thread\RT_thread.axf: Error: L6218E: Undefined symbol rt_hw_console_getchar (referred from shell.o).
Not enough information to list image symbols.
Not enough information to list load addresses in the image map.
Finished: 2 information, 0 warning and 1 error messages.
"RT_thread\RT_thread.axf" - 1 Error(s), 0 Warning(s).
Target not created.
Build Time Elapsed:  00:00:25

 技术分享图片

 

 在main.c中加入如下函数

char rt_hw_console_getchar(void)
{
    int ch = -1;
 
    if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_RXNE) != RESET)
    {
        ch = huart1.Instance->DR & 0xff;
    }
    else
    {
        if(__HAL_UART_GET_FLAG(&huart1, UART_FLAG_ORE) != RESET)
        {
            __HAL_UART_CLEAR_OREFLAG(&huart1);
        }
        rt_thread_mdelay(50);
    }
    return ch;
}

 此时编译就没有报错了

Build started: Project: RT_thread
*** Using Compiler ‘V5.06 update 6 (build 750)‘, folder: ‘C:\User Software\keil5\ARM\ARMCC\Bin‘
Build target ‘RT_thread‘
"RT_thread\RT_thread.axf" - 0 Error(s), 0 Warning(s).
Build Time Elapsed:  00:00:01

CUBEMX生成RT_Thread工程后报错修改

原文:https://www.cnblogs.com/hyaiwx/p/14736994.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!