UART_HandleTypeDef huart3; /* USER CODE END PFP */ #ifdef __GNUC__ /* With GCC, 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__ */ /* USER CODE BEGIN 0 */ PUTCHAR_PROTOTYPE { /* Place your implementation of fputc here */ /* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */ HAL_UART_Transmit(&huart3, (uint8_t *)&ch, 1, 0xFFFF); return ch; } /* Single byte to store input */ uint8_t byte; void SystemClock_Config(void); /* UART3 Interrupt Service Routine */ void USART3_IRQHandler(void) { HAL_UART_IRQHandler(&huart3); } /* This callback is called by the HAL_UART_IRQHandler when the given number of bytes are received */ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { if (huart->Instance == USART3) { /* Transmit one byte with 100 ms timeout */ //HAL_UART_Transmit(&huart3, &byte, 1, 100); /* Receive one byte in interrupt mode */ HAL_UART_Receive_IT(&huart3, &byte, 1); } } void uart_gpio_init() { GPIO_InitTypeDef GPIO_InitStruct; __GPIOD_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_LOW; GPIO_InitStruct.Alternate = GPIO_AF7_USART3; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); } void uart_init() { __USART3_CLK_ENABLE(); huart3.Instance = USART3; huart3.Init.BaudRate = 115200; huart3.Init.WordLength = UART_WORDLENGTH_8B; huart3.Init.StopBits = UART_STOPBITS_1; huart3.Init.Parity = UART_PARITY_NONE; huart3.Init.Mode = UART_MODE_TX_RX; huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart3.Init.OverSampling = UART_OVERSAMPLING_16; HAL_UART_Init(&huart3); /* Peripheral interrupt init*/ HAL_NVIC_SetPriority(USART3_IRQn, 0, 0); HAL_NVIC_EnableIRQ(USART3_IRQn); } int main(void) { /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); uart_gpio_init(); uart_init(); HAL_UART_Receive_IT(&huart3, &byte, 1); while(1) {      printf("hello world \n");      HAL_Delay(1000); } }


stm32


큐브머시기코드 제네레이터 없어서 HAL로 직접함

uart 안되서 힘들었고 printf 안되어서 힘들었음



오늘 목표치는 달성해서 뿌듯하다..