天天看點

rt_thread nano中rt_kprintf()實作

在序列槽中直接添加這段rt_hw_console_output()控制台輸出指令,然後編譯并不會報錯,但是并不會在序列槽中輸出rt_thread的版本資訊

rt_thread nano中rt_kprintf()實作
void rt_hw_console_output(const char *str)
{
	rt_enter_critical();
    rt_size_t i = 0, size = 0;
    char a = '\r';
 
    size = rt_strlen(str);
    for (i = 0; i < size; i++)
    {
        if (*(str + i) == '\n')
        {
	        HAL_UART_Transmit(&huart1 , (uint8_t *)&a, 1 , 1);
 
        }
        HAL_UART_Transmit(&huart1, (uint8_t *)(str + i), 1, 1);
    }
		rt_exit_critical();
}
           

需要在components.c檔案中的rt_hw_board_init();函數中新增硬體的初始化SysInit()

void rt_hw_board_init()
{

    /* System Clock Update */
    SystemCoreClockUpdate();
    
    /* System Tick Configuration */
    _SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
		
	SysInit();//硬體初始化
    /* Call components board initial (use INIT_BOARD_EXPORT()) */
#ifdef RT_USING_COMPONENTS_INIT
    rt_components_board_init();
#endif

#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
    rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get());
#endif
}
           

硬體初始化

void SysInit(void)
{
	
		HAL_Init();
		SystemClock_Config();
	  	MX_GPIO_Init();
		MX_USART1_UART_Init();

		
}

           

繼續閱讀