cancel
Showing results for 
Search instead for 
Did you mean: 

Why SMT32L031x UART pins do not work?

LSant.7
Associate II

Hello, I have a custom board with a SMT32L031F6P6 on it: PA2 and PA3 USART2 channel seems not to work even if they are correctly set in the .ioc file.

I have tried the same code on the NUCLEO-L031K6 board using VCP-TX and VCP-RX (PA2 e PA15) default pins and it works correctly, but if I move the UART pins to the Arduino-compatible ones, PA9 and PA10, it dosen't work anymore.

What am I doing wrong? The UM1956 says that "Only one USART is available and it is shared between Arduino Nano and VCP. The selection is done by remapping (no hardware configuration to change)." but I think something is missing.

This is the working code, in CubeIDE v.11.0:

...
#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__ */
...
int main(void)
{
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_USART2_UART_Init();
 
  while (1)
  {  
          printf("hello\r\n");
	  HAL_Delay(500);
  }
}
 
...
 
static void MX_USART2_UART_Init(void)
{
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 115200;
  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();
  }
}
 
...
 
PUTCHAR_PROTOTYPE
{
  /* Place your implementation of fputc here */
  /* e.g. write a character to the USART2 and Loop until the end of transmission */
  HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 0xFFFF);
 
  return ch;
}

1 ACCEPTED SOLUTION

Accepted Solutions
LSant.7
Associate II

sorry, this question was useless, I fix the problem just resoldering the mcu. Is it possible to delete it?

View solution in original post

3 REPLIES 3

> PA2 and PA3 (Arduino Nano-compatible pins) USART2 channel seems not to work

> [...]

> if I move the UART pins to the Arduino-compatible ones, PA9 and PA10, it dosen't work anymore.

So, which pair is it: PA2/PA3, or PA9/PA10?

Read out content of UART and relevant GPIO, and check/post/compare to working case.

JW

Karl Yamashita
Lead II

Upload the ioc file so we can see how you configured it

I Can't Believe It's Not Butter. If you find my answers useful, click the accept button so that way others can see the solution.
LSant.7
Associate II

sorry, this question was useless, I fix the problem just resoldering the mcu. Is it possible to delete it?