본문 바로가기

공부/STM32F1

6.[stm32f103][hal] printf 사용하기

728x90
반응형

 

1. 소스

#include "main.h"
#include "stm32f1xx_hal.h"


UART_HandleTypeDef huart1;

void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);

 

int fputc(int ch, FILE *f)
{
    uint8_t temp[1]={ch};
    HAL_UART_Transmit(&huart1, temp, 1, 2);
  return(ch);
}

 

int main(void)
{

  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART1_UART_Init();
  
  HAL_StatusTypeDef R_stat;
  uint8_t UsartData[1];
  
  printf("Hello hny diy\r\n");
  
  while (1)
  {
      R_stat = HAL_UART_Receive(&huart1,UsartData,1,1000);
      if(R_stat == HAL_OK) HAL_UART_Transmit(&huart1,UsartData,1,1000);
  }


} 

 

728x90
반응형