수정 파일..
stm32l4xx_hal_conf.h => 해당 기능 주석 해제.
#define HAL_UART_MODULE_ENABLED
HAL_USART_MODULE_ENABLED 로 되는거 주의!!
main.h => GPIO 추가.
#define USART1_TX_Pin GPIO_PIN_6
#define USART1_TX_GPIO_Port GPIOB
/* USER CODE BEGIN Private defines */
#define _DEBUG_MSG // 디버깅 메세지 삭제하려면 주석처리. 20210303 kts
#ifdef _DEBUG_MSG
#include <stdio.h>
#define MSG_LV 0
#if MSG_LV == 0
#define d_msgl(...) do{printf("#[%s %d] ",__FUNCTION__, __LINE__ ), printf(__VA_ARGS__);} while(0)
#define d_msg(...) printf(__VA_ARGS__)
#elif MSG_LV == 1
#define d_msgl(...)
#define d_msg(...) printf(__VA_ARGS__)
#endif
#else
#define d_msgl(...)
#define d_msg(...)
#endif
stm32l4xx_hal_msp.c => MSP Initialization 추가.
/**
* @brief UART MSP Initialization
* This function configures the hardware resources used in this example
* @param huart: UART handle pointer
* @retval None
*/
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(huart->Instance==USART1)
{
/* USER CODE BEGIN USART1_MspInit 0 */
/* USER CODE END USART1_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_USART1_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**USART1 GPIO Configuration
PB6 ------> USART1_TX
PB7 ------> USART1_RX
*/
GPIO_InitStruct.Pin = USART1_TX_Pin|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* USER CODE BEGIN USART1_MspInit 1 */
/* USER CODE END USART1_MspInit 1 */
}
}
/**
* @brief UART MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param huart: UART handle pointer
* @retval None
*/
void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
{
if(huart->Instance==USART1)
{
/* USER CODE BEGIN USART1_MspDeInit 0 */
/* USER CODE END USART1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_USART1_CLK_DISABLE();
/**USART1 GPIO Configuration
PB6 ------> USART1_TX
PB7 ------> USART1_RX
*/
HAL_GPIO_DeInit(GPIOB, USART1_TX_Pin|GPIO_PIN_7);
/* USER CODE BEGIN USART1_MspDeInit 1 */
/* USER CODE END USART1_MspDeInit 1 */
}
}
main.c
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) //for printf
UART_HandleTypeDef huart1;
#ifdef _DEBUG_MSG
PUTCHAR_PROTOTYPE
{
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 1);
return ch;
}
#endif
static void MX_USART1_UART_Init(void);
MX_USART1_UART_Init();
void SystemClock_Config(void) 에 추가.
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_ADC;
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_PLLSAI1;
PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_HSE;
=> 이거 설정 없어진것도 같고..
/**
* @brief USART1 Initialization Function
* @param None
* @retval None
*/
static void MX_USART1_UART_Init(void)
{
/* USER CODE BEGIN USART1_Init 0 */
/* USER CODE END USART1_Init 0 */
/* USER CODE BEGIN USART1_Init 1 */
/* USER CODE END USART1_Init 1 */
huart1.Instance = USART1;
huart1.Init.BaudRate = 921600;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART1_Init 2 */
/* USER CODE END USART1_Init 2 */
}
Hal 드라이버에 uart, dma .c 추가.
'Firmware > STM32' 카테고리의 다른 글
stm32f103 Virtual COM port (USB CDC) / CAN bus (0) | 2023.03.12 |
---|---|
stm32 SDIO SD 카드 테스트 / FR_NOT_READY (0) | 2023.01.15 |
큐브 모니터 사용법 STM32CubeMonitor (0) | 2022.06.16 |
cubemx CAN 속도 설정 (0) | 2021.03.09 |
stm32 아두이노 블루필 (0) | 2020.12.02 |