程序代码
//重定向printf()到串口发送和接收,方便应用int fputc(int ch, FILE *f){ uint8_t temp[1] = {ch}; HAL_UART_Transmit(&huart1, temp, 1, 0xffff);return ch;}//重定向scanf()函数和getchar()函数,方便应用int fgetc(FILE * f){ uint8_t ch = 0; HAL_UART_Receive(&huart1,&ch, 1, 0xffff); return ch;}/** * [url=home.php?mod=space&uid=247401]@brief[/url] The application entry point. * @retval int */int main(void){ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash inteRFace and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ printf("Hello World\n"); while(1) { /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */}
|