You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
On some STM32 boards, changing the Serial Rx or Tx pin stalls the board after ~10s. Recovery requires a HW-reset. The failure depends on which HardwareSerial or pin is used. Specifically
setup: Nucleo-STM32L432KC and "-DENABLE_HWSERIAL1"
for Serial2 setTx(PA_2) or setRx(PA3) stall the board after ~10 seconds
skipping SERIAL_TEST.write() in example prevents the stall
HardwareSerial | setTx() | setRx() | both | none | remarks
------------------------------------------------------------------------------------
Serial1 | ok | ok | ok | ok | all Rx/Tx pin combinations
Serial / Serial2 | PA2 stall | PA15 ok / PA3 stall | stall | ok |
Hi @gicking
Could you provide the Arduino sketch as we do not support PIO here due to several misaligment. Without example code this issue will be closed.
Thanks for the sketch.
First by default Serial instance is mapped on USART2 using same pin than your SERIAL_TX as by default PA2 and PA15 are connected to STLink UART to provide VCP.
Now it stall because the void SystemClock_Config(void) does not change the LPUART source clock then 19200 is not reachable and due to constaint on LPUART IP. If you still want use LPUART then you have to change the clock source.
Note that it is not a bug as if user wants higher baudrate with LPUART1 the default clock config is correct. Anyway, as low baudrate is often used by Arduino sketches (9600), I made a PR to allow it by default.
It is up to end user to properly configure the clock depending on their needs.
You can test by adding this on your sketch:
extern"C"voidSystemClock_Config(void)
{
RCC_ClkInitTypeDefRCC_ClkInitStruct= {};
RCC_OscInitTypeDefRCC_OscInitStruct= {};
RCC_PeriphCLKInitTypeDefPeriphClkInit= {};
/** Configure the main internal regulator output voltage */if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) !=HAL_OK) {
Error_Handler();
}
/* Configure LSE Drive Capability */HAL_PWR_EnableBkUpAccess();
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
/** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */RCC_OscInitStruct.OscillatorType=RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSE
| RCC_OSCILLATORTYPE_MSI;
RCC_OscInitStruct.LSEState=RCC_LSE_ON;
RCC_OscInitStruct.HSIState=RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue=RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.MSIState=RCC_MSI_ON;
RCC_OscInitStruct.MSICalibrationValue=0;
RCC_OscInitStruct.MSIClockRange=RCC_MSIRANGE_6;
RCC_OscInitStruct.PLL.PLLState=RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource=RCC_PLLSOURCE_MSI;
RCC_OscInitStruct.PLL.PLLM=1;
RCC_OscInitStruct.PLL.PLLN=40;
RCC_OscInitStruct.PLL.PLLP=RCC_PLLP_DIV7;
RCC_OscInitStruct.PLL.PLLQ=RCC_PLLQ_DIV2;
RCC_OscInitStruct.PLL.PLLR=RCC_PLLR_DIV2;
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_ClkInitStruct.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider=RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider=RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider=RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) !=HAL_OK) {
Error_Handler();
}
/* Initializes the peripherals clock */PeriphClkInit.PeriphClockSelection=RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_USB;
PeriphClkInit.Lpuart1ClockSelection=RCC_LPUART1CLKSOURCE_HSI;
PeriphClkInit.UsbClockSelection=RCC_USBCLKSOURCE_PLLSAI1;
PeriphClkInit.PLLSAI1.PLLSAI1Source=RCC_PLLSOURCE_MSI;
PeriphClkInit.PLLSAI1.PLLSAI1M=1;
PeriphClkInit.PLLSAI1.PLLSAI1N=24;
PeriphClkInit.PLLSAI1.PLLSAI1P=RCC_PLLP_DIV7;
PeriphClkInit.PLLSAI1.PLLSAI1Q=RCC_PLLQ_DIV2;
PeriphClkInit.PLLSAI1.PLLSAI1R=RCC_PLLR_DIV2;
PeriphClkInit.PLLSAI1.PLLSAI1ClockOut=RCC_PLLSAI1_48M2CLK;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) !=HAL_OK) {
Error_Handler();
}
/* Enable MSI Auto calibration */HAL_RCCEx_EnableMSIPLLMode();
}
Activity
fpistm commentedon Jan 22, 2026
Hi @gicking
Could you provide the Arduino sketch as we do not support PIO here due to several misaligment. Without example code this issue will be closed.
gicking commentedon Jan 22, 2026
here you go. Behavior is the same: after ~12s the LED stops blinking and sending via Tx stops
Bug_Serial.zip
chore: enhance Nucleo L432KC system clock config
fpistm commentedon Jan 23, 2026
Hi @gicking
Thanks for the sketch.
First by default Serial instance is mapped on USART2 using same pin than your
SERIAL_TXas by default PA2 and PA15 are connected to STLink UART to provide VCP.Arduino_Core_STM32/variants/STM32L4xx/L432K(B-C)U_L442KCU/variant_NUCLEO_L432KC.h
Lines 89 to 96 in d8062ae
But it should not be an issue as you do not init Serial.Your issue is that you think you used USART2 with your
SERIAL_TESTbut you used LPUART1.Arduino_Core_STM32/variants/STM32L4xx/L432K(B-C)U_L442KCU/PeripheralPins.c
Lines 122 to 124 in d8062ae
Arduino_Core_STM32/variants/STM32L4xx/L432K(B-C)U_L442KCU/PeripheralPins.c
Lines 112 to 114 in d8062ae
I you really want use USART2 then your code should be:
Now it stall because the
void SystemClock_Config(void)does not change the LPUART source clock then 19200 is not reachable and due to constaint on LPUART IP. If you still want use LPUART then you have to change the clock source.Note that it is not a bug as if user wants higher baudrate with LPUART1 the default clock config is correct. Anyway, as low baudrate is often used by Arduino sketches (9600), I made a PR to allow it by default.
It is up to end user to properly configure the clock depending on their needs.
You can test by adding this on your sketch:
[-]Serial.setTx() / Serial.setRx() stall board[/-][+]Nucleo L432KC: LPUART low baudrate issue[/+]gicking commentedon Jan 26, 2026
Hi Frederic,
you are correct, with
PA_2_ALT1andPA_3_ALT1it now works flawlessly :-) Thanks!Have a great day, Georg
chore: enhance Nucleo L432KC system clock config
chore: enhance Nucleo L432KC system clock config