cancel
Showing results for 
Search instead for 
Did you mean: 

UART does not work with STM32U575

BLS_Karo
Associate II

Hi ST community,

I create a simple application using USART1 baudrate 9600 TX pin - PB6 & Rx pin - PB7. I send uart frame each 1 second. J22 connects to CP210x. I see that the RX led of CP210x toggle each 1 second but when I open terminal screen on the laptop with same baudrate, nothing is shown. HAL_transmit return HAL_OK. Tx pin and Rx GPIO pin is configured as default, no pull up and pull down. What is problem here?

 
 
void SystemClock_Config(void)

{

RCC_OscInitTypeDef RCC_OscInitStruct = {0};

RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};



/** Configure the main internal regulator output voltage

*/

if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE3) != HAL_OK)

{

Error_Handler();

}



/** Configure LSE Drive Capability

*/

HAL_PWR_EnableBkUpAccess();

__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_MEDIUMHIGH);



/** Initializes the CPU, AHB and APB buses clocks

*/

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSI

|RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_LSE

|RCC_OSCILLATORTYPE_MSI;

RCC_OscInitStruct.LSEState = RCC_LSE_ON;

RCC_OscInitStruct.HSIState = RCC_HSI_ON;

RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;

RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;

RCC_OscInitStruct.LSIState = RCC_LSI_ON;

RCC_OscInitStruct.MSIState = RCC_MSI_ON;

RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;

RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_0;

RCC_OscInitStruct.LSIDiv = RCC_LSI_DIV1;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;

RCC_OscInitStruct.PLL.PLLMBOOST = RCC_PLLMBOOST_DIV4;

RCC_OscInitStruct.PLL.PLLM = 4;

RCC_OscInitStruct.PLL.PLLN = 14;

RCC_OscInitStruct.PLL.PLLP = 2;

RCC_OscInitStruct.PLL.PLLQ = 4;

RCC_OscInitStruct.PLL.PLLR = 4;

RCC_OscInitStruct.PLL.PLLRGE = RCC_PLLVCIRANGE_1;

RCC_OscInitStruct.PLL.PLLFRACN = 0;

if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

{

Error_Handler();

}



/** Initializes the CPU, AHB and APB buses clocks

*/

RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2

|RCC_CLOCKTYPE_PCLK3;

RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1;



if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)

{

Error_Handler();

}

}

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 = 9600;

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.Init.ClockPrescaler = UART_PRESCALER_DIV1;

huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

if (HAL_UART_Init(&huart1) != HAL_OK)

{

Error_Handler();

}

if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)

{

Error_Handler();

}

if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)

{

Error_Handler();

}

if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK)

{

Error_Handler();

}

/* USER CODE BEGIN USART1_Init 2 */



/* USER CODE END USART1_Init 2 */



}
in main.c
uint8_t buffer[] = {"Hello World!\n"};

/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

if (HAL_UART_Transmit(&huart1, buffer, 13, 1000) != HAL_OK)

{

Error_Handler();

}

HAL_Delay(1000);

/* USER CODE END WHILE */



/* USER CODE BEGIN 3 */

}

/* USER CODE END 3 */

BLS_Karo_0-1777869807138.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
BLS_Karo
Associate II

Hi all, I have resolved the problem, 1k impedance resister is too large. It cause unexpected noise on Uart bus. I removed it and it worked, so I will close this thread.

View solution in original post

5 REPLIES 5
mbarg.1
Lead

If you do not include more details, there are tons of errors that could be in your code.

Attach whole project and we can try to help you.

Error in clocks, setup of otput mux are most common errors that block USARTs; oscilloscope is required to assert that usart is not sending anything ...

Hi @mbarg.1 I attach my project below, please help me check it, I also check logic analyzer but the data on bus is weird

FBL
ST Employee

Hello @BLS_Karo 

Do you reproduce on a reference board? like U575 eval or nucleo? Check mapping in USART1 MSP init.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.




Best regards,
FBL

@FBL No. I implement on my custom board, the purpose is talking to BLE module. I also check msp init, the gpio mapping is correct

 

 

BLS_Karo
Associate II

Hi all, I have resolved the problem, 1k impedance resister is too large. It cause unexpected noise on Uart bus. I removed it and it worked, so I will close this thread.