cancel
Showing results for 
Search instead for 
Did you mean: 

UART COM issue with f030r8

user-stm
Associate II

Hello,

I am trying to use UART HAL with the stm32-f030r8 connected to the PC through a USB-TTL module.

The configuration is given below :

wire.PNG

- The F030R8 has JP1 OFF, JP6 ON, JP5 on E5V.

- The USB-TTL is :

usb-ttl.jpg

- The code is :

/* Includes ------------------------------------------------------------------*/
#include "main.h"

uint8_t test[] = "hello";
UART_HandleTypeDef huart2;

int main(void)
{

HAL_Init();

SystemClock_Config();

__USART2_CLK_ENABLE();
__GPIOA_CLK_ENABLE();

GPIO_InitTypeDef GPIO_InitStructure;

GPIO_InitStructure.Pin = GPIO_PIN_2;
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.Alternate = GPIO_AF1_USART2;
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
GPIO_InitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_InitStructure.Pin = GPIO_PIN_3;
GPIO_InitStructure.Mode = GPIO_MODE_AF_OD;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);

huart2.Instance = USART2;
huart2.Init.BaudRate = 9600;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.Parity = UART_PARITY_NONE ;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.StopBits = UART_STOPBITS_1;

while (1){
HAL_UART_Transmit(&huart2,test,sizeof(test),HAL_MAX_DELAY);
HAL_Delay(1000);
}

}

 

Then, the putty configuration is 9600 baud, 8 data bits, 1 stop bits, no parity; no flow control.

But I can't see anything in the terminal...

Would you please have suggestions ?

 

Thanks for your help ! 🙂

12 REPLIES 12
Pavel A.
Evangelist III

Disconnect the 5v wire (RED)  from the TTL module.

user-stm
Associate II

My last question refers to the configuration without TTL module. I put it below again :

 

As it is mentioned that "By default, the USART2 communication between the target STM32 and ST-LINK MCU is enabled", if we forget the USB-TTL module ie we have a unique wire (USB Type-A to Mini-B cable) between the PC and the stm32, do you know why is still have anything on putty ?

Configuration with JP1 OFF, JP6 ON and JP5 on U5V and the following code :

 

 
 
/* Includes ------------------------------------------------------------------*/
#include "main.h"
 
 
 
 
UART_HandleTypeDef huart2;
uint8_t test[] = "hello";
 
 
 
 
void SystemClock_Config2(void);
static void MX_GPIO_Init(void);
static void MX_USART2_UART_Init(void);
 
 
int main(void)
{
 
  HAL_Init();
 
  SystemClock_Config();
 
  MX_GPIO_Init();
  MX_USART2_UART_Init();
 
  while (1)
  {
 
HAL_UART_Transmit(&huart2,test,sizeof(test),HAL_MAX_DELAY);
HAL_Delay(2000);
 
  }
}
 
 
 
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
 
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
 
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
 
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  {
    Error_Handler();
  }
}
 
 
 
static void MX_USART2_UART_Init(void)
{
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 9600;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  if (HAL_UART_Init(&huart2) != HAL_OK)
  {
    Error_Handler();
  }
}
 
 
static void MX_GPIO_Init(void)
{
  __HAL_RCC_GPIOA_CLK_ENABLE();
}
 
void Error_Handler(void)
{
  __disable_irq();
  while (1)
  {
  }
}

 

On Nucleo (and Disco/EVAL), always start with reading the manual and looking at schematics for jumpers/solder bridges (SBxx) settings.

waclawekjan_0-1692874644017.png

But maybe instead of changing the SB settings, you might want to leave them for the PA2/PA3 being used through the on-board STLink's VCP; and if you want for some reason to use the additional external USB-UART connection, use different pins/UART.

Also, as others said, you have to cross-connect the cable, Rx to Tx and vice versa (unless the USB-UART converter's author mislabelled the wires).

JW