用STM32Cube 生成項目
1.? 新建Project ,芯片類型STM32F103C8
2.? 選中FREERTOS??

3. 選擇系統(tǒng)Timebase?

4.? 選擇串口1

5. 生產(chǎn)項目源代碼

6. 用Keil打開Project

7. 在main.c? 中添加代碼
找到這里
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
#ifdef __GNUC__
? /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
? ? set to 'Yes') calls __io_putchar() */
? #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
? #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/**
? * @brief? Retargets the C library printf function to the USART.
? * @param? None
? * @retval None
? */
PUTCHAR_PROTOTYPE
{
? ? HAL_UART_Transmit(&huart1,(uint8_t *)&ch,1,0xFFFF);
? ? return ch;
}
8. 在StartDefaultTask函數(shù)中 添加? printf?
void StartDefaultTask(void const * argument)
{
? /* USER CODE BEGIN 5 */
? /* Infinite loop */
? for(;;)
? {
? ? osDelay(100);
printf("Hello\n");
? }
? /* USER CODE END 5 */
}
7.? ?設(shè)置調(diào)試
? 1) 選擇Simulator?

? ?2)? DialogDLL 修改庫文件? 為? DRAMSTM.DLL? ?
? ? ? ?Parameter;? ? ?-pSTM32F103C8? ??
8.? ?Build F7?

9. Debug? 調(diào)試

10? 打開串口1的監(jiān)視窗口

11.? ?運行

12.? 查看輸出結(jié)果
